Search in sources :

Example 16 with FileSource

use of com.github.tomakehurst.wiremock.common.FileSource 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

FileSource (com.github.tomakehurst.wiremock.common.FileSource)16 Test (org.junit.jupiter.api.Test)8 SingleRootFileSource (com.github.tomakehurst.wiremock.common.SingleRootFileSource)4 ClasspathFileSource (com.github.tomakehurst.wiremock.common.ClasspathFileSource)3 ResponseDefinition (com.github.tomakehurst.wiremock.http.ResponseDefinition)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 FatalStartupException (com.github.tomakehurst.wiremock.common.FatalStartupException)1 TextFile (com.github.tomakehurst.wiremock.common.TextFile)1 Parameters (com.github.tomakehurst.wiremock.extension.Parameters)1 ResponseTemplateTransformer (com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer)1 GlobalSettingsHolder (com.github.tomakehurst.wiremock.global.GlobalSettingsHolder)1 Request (com.github.tomakehurst.wiremock.http.Request)1 MockRequest.mockRequest (com.github.tomakehurst.wiremock.matching.MockRequest.mockRequest)1 NoFileSource.noFileSource (com.github.tomakehurst.wiremock.testsupport.NoFileSource.noFileSource)1 WireMockResponse (com.github.tomakehurst.wiremock.testsupport.WireMockResponse)1 WireMockTestClient (com.github.tomakehurst.wiremock.testsupport.WireMockTestClient)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1