4949import org .springframework .web .server .session .DefaultWebSessionManager ;
5050import org .springframework .web .server .session .WebSessionManager ;
5151
52- import static org .junit .Assert .assertEquals ;
53- import static org .junit .Assert .assertNull ;
54- import static org .junit .Assert .assertSame ;
55- import static org .junit .Assert .assertTrue ;
56- import static org .junit .Assert .fail ;
57- import static org .springframework .web .reactive .HandlerMapping .PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE ;
52+ import static org .junit .Assert .*;
53+ import static org .springframework .web .reactive .HandlerMapping .*;
5854
5955/**
6056 * Unit tests for {@link ResourceWebHandler}.
57+ *
6158 * @author Rossen Stoyanchev
6259 */
6360public class ResourceWebHandlerTests {
@@ -75,7 +72,6 @@ public class ResourceWebHandlerTests {
7572
7673 @ Before
7774 public void setUp () throws Exception {
78-
7975 List <Resource > paths = new ArrayList <>(2 );
8076 paths .add (new ClassPathResource ("test/" , getClass ()));
8177 paths .add (new ClassPathResource ("testalternatepath/" , getClass ()));
@@ -90,6 +86,7 @@ public void setUp() throws Exception {
9086 this .exchange = new DefaultServerWebExchange (this .request , this .response , this .sessionManager );
9187 }
9288
89+
9390 @ Test
9491 public void getResource () throws Exception {
9592 this .exchange .getAttributes ().put (PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE , "foo.css" );
@@ -100,7 +97,7 @@ public void getResource() throws Exception {
10097 assertEquals (17 , headers .getContentLength ());
10198 assertEquals ("max-age=3600" , headers .getCacheControl ());
10299 assertTrue (headers .containsKey ("Last-Modified" ));
103- assertEquals (headers .getLastModified (), resourceLastModifiedDate ("test/foo.css" ));
100+ assertEquals (headers .getLastModified () / 1000 , resourceLastModifiedDate ("test/foo.css" ) / 1000 );
104101 assertEquals ("bytes" , headers .getFirst ("Accept-Ranges" ));
105102 assertEquals (1 , headers .get ("Accept-Ranges" ).size ());
106103 assertResponseBody ("h1 { color:red; }" );
@@ -118,7 +115,7 @@ public void getResourceHttpHeader() throws Exception {
118115 assertEquals (17 , headers .getContentLength ());
119116 assertEquals ("max-age=3600" , headers .getCacheControl ());
120117 assertTrue (headers .containsKey ("Last-Modified" ));
121- assertEquals (headers .getLastModified (), resourceLastModifiedDate ("test/foo.css" ));
118+ assertEquals (headers .getLastModified () / 1000 , resourceLastModifiedDate ("test/foo.css" ) / 1000 );
122119 assertEquals ("bytes" , headers .getFirst ("Accept-Ranges" ));
123120 assertEquals (1 , headers .get ("Accept-Ranges" ).size ());
124121 assertNull (this .response .getBody ());
@@ -142,7 +139,7 @@ public void getResourceNoCache() throws Exception {
142139
143140 assertEquals ("no-store" , this .response .getHeaders ().getCacheControl ());
144141 assertTrue (this .response .getHeaders ().containsKey ("Last-Modified" ));
145- assertEquals (this .response .getHeaders ().getLastModified (), resourceLastModifiedDate ("test/foo.css" ));
142+ assertEquals (this .response .getHeaders ().getLastModified () / 1000 , resourceLastModifiedDate ("test/foo.css" ) / 1000 );
146143 assertEquals ("bytes" , this .response .getHeaders ().getFirst ("Accept-Ranges" ));
147144 assertEquals (1 , this .response .getHeaders ().get ("Accept-Ranges" ).size ());
148145 }
@@ -172,7 +169,7 @@ public void getResourceWithHtmlMediaType() throws Exception {
172169 assertEquals (MediaType .TEXT_HTML , headers .getContentType ());
173170 assertEquals ("max-age=3600" , headers .getCacheControl ());
174171 assertTrue (headers .containsKey ("Last-Modified" ));
175- assertEquals (headers .getLastModified (), resourceLastModifiedDate ("test/foo.html" ));
172+ assertEquals (headers .getLastModified () / 1000 , resourceLastModifiedDate ("test/foo.html" ) / 1000 );
176173 assertEquals ("bytes" , headers .getFirst ("Accept-Ranges" ));
177174 assertEquals (1 , headers .get ("Accept-Ranges" ).size ());
178175 }
@@ -187,7 +184,7 @@ public void getResourceFromAlternatePath() throws Exception {
187184 assertEquals (17 , headers .getContentLength ());
188185 assertEquals ("max-age=3600" , headers .getCacheControl ());
189186 assertTrue (headers .containsKey ("Last-Modified" ));
190- assertEquals (headers .getLastModified (), resourceLastModifiedDate ("testalternatepath/baz.css" ));
187+ assertEquals (headers .getLastModified () / 1000 , resourceLastModifiedDate ("testalternatepath/baz.css" ) / 1000 );
191188 assertEquals ("bytes" , headers .getFirst ("Accept-Ranges" ));
192189 assertEquals (1 , headers .get ("Accept-Ranges" ).size ());
193190 assertResponseBody ("h1 { color:red; }" );
@@ -545,7 +542,6 @@ public void partialContentMultipleByteRanges() throws Exception {
545542
546543 TestSubscriber .subscribe (this .response .getBody ())
547544 .assertValuesWith (buf -> {
548-
549545 String content = DataBufferTestUtils .dumpString (buf , StandardCharsets .UTF_8 );
550546 String [] ranges = StringUtils .tokenizeToStringArray (content , "\r \n " , false , true );
551547
@@ -563,20 +559,19 @@ public void partialContentMultipleByteRanges() throws Exception {
563559 assertEquals ("Content-Type: text/plain" , ranges [9 ]);
564560 assertEquals ("Content-Range: bytes 8-9/10" , ranges [10 ]);
565561 assertEquals ("t." , ranges [11 ]);
566-
567562 });
568563 }
569564
570- @ Test // SPR-14005
565+ @ Test // SPR-14005
571566 public void doOverwriteExistingCacheControlHeaders () throws Exception {
572567 this .exchange .getAttributes ().put (PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE , "foo.css" );
573568 this .response .getHeaders ().setCacheControl (CacheControl .noStore ().getHeaderValue ());
574-
575569 this .handler .handle (this .exchange ).blockMillis (5000 );
576570
577571 assertEquals ("max-age=3600" , this .response .getHeaders ().getCacheControl ());
578572 }
579573
574+
580575 private long resourceLastModified (String resourceName ) throws IOException {
581576 return new ClassPathResource (resourceName , getClass ()).getFile ().lastModified ();
582577 }
0 commit comments