33
33
public class LocalFileAcceptorTest extends TestCase {
34
34
35
35
private static final int TEST_FILE_SIZE = 1024 * 1024 ;
36
- @ ClassRule
37
- static WireMockRule wireMockRule = new WireMockRule (wireMockConfig ().dynamicPort ());
36
+ @ ClassRule static WireMockRule wireMockRule = new WireMockRule (wireMockConfig ().dynamicPort ());
38
37
39
38
@ BeforeClass
40
39
public static void beforeClass () {
@@ -45,16 +44,22 @@ public static void beforeClass() {
45
44
public void corruptedFileEmptyPreexistingSet () throws IOException , NoSuchAlgorithmException {
46
45
Pair <Path , String > tempFile = generateTempFile ();
47
46
Path destinationDir = Files .createTempDirectory ("dice-where" );
48
- IpInfoSiteSource ipInfoSiteSource = new IpInfoSiteSource (
49
- new URL ("http://localhost:" + wireMockRule .port () + "/data/file.mdb" ));
50
- wireMockRule .stubFor (WireMock .head (UrlPattern .ANY ).willReturn (
51
- aResponse ().withStatus (HttpStatus .SC_OK )
52
- .withHeader ("Etag" , "aaa" )
53
- .withHeader ("Content-Length" , Long .toString (TEST_FILE_SIZE ))
54
- .withHeader ("Last-Modified" , "Thu, 01 Dec 1994 16:00:00 GMT" )));
55
- wireMockRule .stubFor (WireMock .get (UrlPattern .ANY )
56
- .willReturn (aResponse ().withBody (
57
- IOUtils .toByteArray (new FileInputStream (tempFile .getLeft ().toFile ())))));
47
+ IpInfoSiteSource ipInfoSiteSource =
48
+ new IpInfoSiteSource (new URL ("http://localhost:" + wireMockRule .port () + "/data/file.mdb" ));
49
+ wireMockRule .stubFor (
50
+ WireMock .head (UrlPattern .ANY )
51
+ .willReturn (
52
+ aResponse ()
53
+ .withStatus (HttpStatus .SC_OK )
54
+ .withHeader ("Etag" , "aaa" )
55
+ .withHeader ("Content-Length" , Long .toString (TEST_FILE_SIZE ))
56
+ .withHeader ("Last-Modified" , "Thu, 01 Dec 1994 16:00:00 GMT" )));
57
+ wireMockRule .stubFor (
58
+ WireMock .get (UrlPattern .ANY )
59
+ .willReturn (
60
+ aResponse ()
61
+ .withBody (
62
+ IOUtils .toByteArray (new FileInputStream (tempFile .getLeft ().toFile ())))));
58
63
59
64
FileInfo fileInfo = ipInfoSiteSource .fileInfo ();
60
65
ipInfoSiteSource .produce (new LocalFileAcceptor (destinationDir .resolve ("file.mdb" )), false );
@@ -68,72 +73,100 @@ public void corruptedFilePreexistingSet() throws IOException, NoSuchAlgorithmExc
68
73
Pair <Path , String > existingFile = generateTempFile ();
69
74
Path destinationDir = Files .createTempDirectory ("dice-where" );
70
75
Files .copy (existingFile .getLeft (), destinationDir .resolve ("existingFile.mdb" ));
71
- IpInfoSiteSource ipInfoSiteSource = new IpInfoSiteSource (
72
- new URL ("http://localhost:" + wireMockRule .port () + "/data/file.mdb" ));
73
- wireMockRule .stubFor (WireMock .head (UrlPattern .ANY ).willReturn (
74
- aResponse ().withStatus (HttpStatus .SC_OK )
75
- .withHeader ("Etag" , "aaa" )
76
- .withHeader ("Content-Length" , Long .toString (TEST_FILE_SIZE ))
77
- .withHeader ("Last-Modified" , "Thu, 01 Dec 1994 16:00:00 GMT" )));
78
- wireMockRule .stubFor (WireMock .get (UrlPattern .ANY )
79
- .willReturn (aResponse ().withBody (
80
- IOUtils .toByteArray (new FileInputStream (tempFile .getLeft ().toFile ())))));
76
+ IpInfoSiteSource ipInfoSiteSource =
77
+ new IpInfoSiteSource (new URL ("http://localhost:" + wireMockRule .port () + "/data/file.mdb" ));
78
+ wireMockRule .stubFor (
79
+ WireMock .head (UrlPattern .ANY )
80
+ .willReturn (
81
+ aResponse ()
82
+ .withStatus (HttpStatus .SC_OK )
83
+ .withHeader ("Etag" , "aaa" )
84
+ .withHeader ("Content-Length" , Long .toString (TEST_FILE_SIZE ))
85
+ .withHeader ("Last-Modified" , "Thu, 01 Dec 1994 16:00:00 GMT" )));
86
+ wireMockRule .stubFor (
87
+ WireMock .get (UrlPattern .ANY )
88
+ .willReturn (
89
+ aResponse ()
90
+ .withBody (
91
+ IOUtils .toByteArray (new FileInputStream (tempFile .getLeft ().toFile ())))));
81
92
82
93
FileInfo fileInfo = ipInfoSiteSource .fileInfo ();
83
94
ipInfoSiteSource .produce (new LocalFileAcceptor (destinationDir .resolve ("file.mdb" )), false );
84
95
assertNotEquals (tempFile .getRight ().toLowerCase (), fileInfo .getMd5Checksum ().stringFormat ());
85
96
assertEquals (Files .list (destinationDir ).count (), 1 );
86
97
assertFalse (Files .exists (destinationDir .resolve ("file.mdb" )));
87
- assertTrue (Arrays .equals (Files .readAllBytes (existingFile .getLeft ()),
88
- Files .readAllBytes (Files .list (destinationDir ).findFirst ().get ())));
98
+ assertTrue (
99
+ Arrays .equals (
100
+ Files .readAllBytes (existingFile .getLeft ()),
101
+ Files .readAllBytes (Files .list (destinationDir ).findFirst ().get ())));
89
102
}
90
103
91
104
@ Test
92
105
public void goodFileEmptyPreexistingSet () throws IOException , NoSuchAlgorithmException {
93
106
Pair <Path , String > tempFile = generateTempFile ();
94
107
Path destinationDir = Files .createTempDirectory ("dice-where" );
95
- IpInfoSiteSource ipInfoSiteSource = new IpInfoSiteSource (
96
- new URL ("http://localhost:" + wireMockRule .port () + "/data/file.mdb" ));
97
- wireMockRule .stubFor (WireMock .head (UrlPattern .ANY ).willReturn (
98
- aResponse ().withStatus (HttpStatus .SC_OK )
99
- .withHeader ("Etag" , tempFile .getRight ())
100
- .withHeader ("Content-Length" , Long .toString (TEST_FILE_SIZE ))
101
- .withHeader ("Last-Modified" , "Thu, 01 Dec 1994 16:00:00 GMT" )));
102
- wireMockRule .stubFor (WireMock .get (UrlPattern .ANY )
103
- .willReturn (aResponse ().withBody (
104
- IOUtils .toByteArray (new FileInputStream (tempFile .getLeft ().toFile ())))));
108
+ IpInfoSiteSource ipInfoSiteSource =
109
+ new IpInfoSiteSource (new URL ("http://localhost:" + wireMockRule .port () + "/data/file.mdb" ));
110
+ wireMockRule .stubFor (
111
+ WireMock .head (UrlPattern .ANY )
112
+ .willReturn (
113
+ aResponse ()
114
+ .withStatus (HttpStatus .SC_OK )
115
+ .withHeader ("Etag" , tempFile .getRight ())
116
+ .withHeader ("Content-Length" , Long .toString (TEST_FILE_SIZE ))
117
+ .withHeader ("Last-Modified" , "Thu, 01 Dec 1994 16:00:00 GMT" )));
118
+ wireMockRule .stubFor (
119
+ WireMock .get (UrlPattern .ANY )
120
+ .willReturn (
121
+ aResponse ()
122
+ .withBody (
123
+ IOUtils .toByteArray (new FileInputStream (tempFile .getLeft ().toFile ())))));
105
124
106
125
FileInfo fileInfo = ipInfoSiteSource .fileInfo ();
107
126
ipInfoSiteSource .produce (new LocalFileAcceptor (destinationDir .resolve ("file.mdb" )), false );
108
127
assertEquals (tempFile .getRight ().toLowerCase (), fileInfo .getMd5Checksum ().stringFormat ());
109
128
assertEquals (1 , Files .list (destinationDir ).count ());
110
- assertTrue (Arrays .equals (Files .readAllBytes (tempFile .getLeft ()),
111
- Files .readAllBytes (destinationDir .resolve ("file.mdb" ))));
129
+ assertTrue (
130
+ Arrays .equals (
131
+ Files .readAllBytes (tempFile .getLeft ()),
132
+ Files .readAllBytes (destinationDir .resolve ("file.mdb" ))));
112
133
}
113
134
114
135
@ Test
115
136
public void goodFilePreexistingSet () throws IOException , NoSuchAlgorithmException {
116
137
Pair <Path , String > tempFile = generateTempFile ();
117
138
Pair <Path , String > existingFile = generateTempFile ();
139
+
118
140
Path destinationDir = Files .createTempDirectory ("dice-where" );
119
141
Files .copy (existingFile .getLeft (), destinationDir .resolve ("existingFile.mdb" ));
120
- IpInfoSiteSource ipInfoSiteSource = new IpInfoSiteSource (
121
- new URL ("http://localhost:" + wireMockRule .port () + "/data/file.mdb" ));
122
- wireMockRule .stubFor (WireMock .head (UrlPattern .ANY ).willReturn (
123
- aResponse ().withStatus (HttpStatus .SC_OK )
124
- .withHeader ("Etag" , tempFile .getRight ())
125
- .withHeader ("Content-Length" , Long .toString (TEST_FILE_SIZE ))
126
- .withHeader ("Last-Modified" , "Thu, 01 Dec 1994 16:00:00 GMT" )));
127
- wireMockRule .stubFor (WireMock .get (UrlPattern .ANY )
128
- .willReturn (aResponse ().withBody (
129
- IOUtils .toByteArray (new FileInputStream (tempFile .getLeft ().toFile ())))));
130
142
143
+ wireMockRule .stubFor (
144
+ WireMock .head (UrlPattern .ANY )
145
+ .willReturn (
146
+ aResponse ()
147
+ .withStatus (HttpStatus .SC_OK )
148
+ .withHeader ("Etag" , tempFile .getRight ())
149
+ .withHeader ("Content-Length" , Long .toString (TEST_FILE_SIZE ))
150
+ .withHeader ("Last-Modified" , "Thu, 01 Dec 1994 16:00:00 GMT" )));
151
+
152
+ wireMockRule .stubFor (
153
+ WireMock .get (UrlPattern .ANY )
154
+ .willReturn (
155
+ aResponse ()
156
+ .withBody (
157
+ IOUtils .toByteArray (new FileInputStream (tempFile .getLeft ().toFile ())))));
158
+
159
+ IpInfoSiteSource ipInfoSiteSource =
160
+ new IpInfoSiteSource (new URL ("http://localhost:" + wireMockRule .port () + "/data/file.mdb" ));
131
161
FileInfo fileInfo = ipInfoSiteSource .fileInfo ();
162
+
132
163
ipInfoSiteSource .produce (new LocalFileAcceptor (destinationDir .resolve ("file.mdb" )), false );
133
164
assertEquals (tempFile .getRight ().toLowerCase (), fileInfo .getMd5Checksum ().stringFormat ());
134
165
assertEquals (2 , Files .list (destinationDir ).count ());
135
- assertTrue (Arrays .equals (Files .readAllBytes (tempFile .getLeft ()),
136
- Files .readAllBytes (destinationDir .resolve ("file.mdb" ))));
166
+ assertTrue (
167
+ Arrays .equals (
168
+ Files .readAllBytes (tempFile .getLeft ()),
169
+ Files .readAllBytes (destinationDir .resolve ("file.mdb" ))));
137
170
}
138
171
139
172
private Pair <Path , String > generateTempFile () throws IOException , NoSuchAlgorithmException {
@@ -145,4 +178,4 @@ private Pair<Path, String> generateTempFile() throws IOException, NoSuchAlgorith
145
178
String hex = (new HexBinaryAdapter ()).marshal (md .digest (contents ));
146
179
return Pair .of (tempFile , hex );
147
180
}
148
- }
181
+ }
0 commit comments