Issue: SPR-12323
This commit is contained in:
Brian Clozel
2015-05-19 23:57:30 +02:00
parent c5d6cc4134
commit 57e0c789a8
2 changed files with 68 additions and 22 deletions

View File

@@ -26,11 +26,14 @@ import static org.mockito.Mockito.verify;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.mock.web.test.MockHttpServletRequest;
/**
* Unit tests for
@@ -46,6 +49,8 @@ public class WebJarsResourceResolverTests {
private ResourceResolverChain chain;
private HttpServletRequest request = new MockHttpServletRequest();
@Before
public void setup() {
// for this to work, an actual WebJar must be on the test classpath
@@ -104,4 +109,31 @@ public class WebJarsResourceResolverTests {
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
}
@Test
public void resolveResourceExisting() {
Resource expected = mock(Resource.class);
this.locations = Collections.singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
String file = "/foo/2.3/foo.txt";
given(this.chain.resolveResource(this.request, file, this.locations)).willReturn(expected);
Resource actual = this.resolver.resolveResource(this.request, file, this.locations, this.chain);
assertEquals(expected, actual);
verify(this.chain, times(1)).resolveResource(this.request, file, this.locations);
}
@Test
public void resolveResourceWebJar() {
Resource expected = mock(Resource.class);
String file = "/underscorejs/underscore.js";
String expectedPath = "/underscorejs/1.8.2/underscore.js";
this.locations = Collections.singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
given(this.chain.resolveResource(this.request, expectedPath, this.locations)).willReturn(expected);
Resource actual = this.resolver.resolveResource(this.request, file, this.locations, this.chain);
assertEquals(expected, actual);
verify(this.chain, times(1)).resolveResource(this.request, file, this.locations);
}
}