Search in sources :

Example 1 with ClasspathFileSource

use of com.github.tomakehurst.wiremock.common.ClasspathFileSource in project wiremock by wiremock.

the class JsonFileMappingsSourceTest method loadsMappingsViaClasspathFileSource.

@Test
public void loadsMappingsViaClasspathFileSource() {
    ClasspathFileSource fileSource = new ClasspathFileSource("jar-filesource");
    JsonFileMappingsSource source = new JsonFileMappingsSource(fileSource);
    InMemoryStubMappings stubMappings = new InMemoryStubMappings();
    source.loadMappingsInto(stubMappings);
    List<StubMapping> allMappings = stubMappings.getAll();
    assertThat(allMappings, hasSize(2));
    List<String> mappingRequestUrls = asList(allMappings.get(0).getRequest().getUrl(), allMappings.get(1).getRequest().getUrl());
    assertThat(mappingRequestUrls, is(asList("/second_test", "/test")));
}
Also used : ClasspathFileSource(com.github.tomakehurst.wiremock.common.ClasspathFileSource) InMemoryStubMappings(com.github.tomakehurst.wiremock.stubbing.InMemoryStubMappings) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) Test(org.junit.jupiter.api.Test)

Example 2 with ClasspathFileSource

use of com.github.tomakehurst.wiremock.common.ClasspathFileSource in project spring-cloud-contract by spring-cloud.

the class ResourcesFileSource method toSources.

private static FileSource[] toSources(Resource[] resources) {
    FileSource[] sources = new FileSource[resources.length];
    for (int i = 0; i < resources.length; i++) {
        Resource resource = resources[i];
        if (resource instanceof ClassPathResource) {
            ClassPathResource classes = (ClassPathResource) resource;
            sources[i] = new ClasspathFileSource(classes.getPath());
        } else if (resource instanceof FileSystemResource) {
            FileSystemResource files = (FileSystemResource) resource;
            sources[i] = new SingleRootFileSource(files.getFile());
        } else if (resource instanceof UrlResource) {
            sources[i] = fileOrFallbackToClasspath(resource);
        } else {
            throw new IllegalArgumentException("Unsupported resource type for file source: " + resource.getClass());
        }
    }
    return sources;
}
Also used : UrlResource(org.springframework.core.io.UrlResource) ClasspathFileSource(com.github.tomakehurst.wiremock.common.ClasspathFileSource) FileSource(com.github.tomakehurst.wiremock.common.FileSource) SingleRootFileSource(com.github.tomakehurst.wiremock.common.SingleRootFileSource) UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) ClasspathFileSource(com.github.tomakehurst.wiremock.common.ClasspathFileSource) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource) SingleRootFileSource(com.github.tomakehurst.wiremock.common.SingleRootFileSource)

Aggregations

ClasspathFileSource (com.github.tomakehurst.wiremock.common.ClasspathFileSource)2 FileSource (com.github.tomakehurst.wiremock.common.FileSource)1 SingleRootFileSource (com.github.tomakehurst.wiremock.common.SingleRootFileSource)1 InMemoryStubMappings (com.github.tomakehurst.wiremock.stubbing.InMemoryStubMappings)1 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)1 Test (org.junit.jupiter.api.Test)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1 Resource (org.springframework.core.io.Resource)1 UrlResource (org.springframework.core.io.UrlResource)1