Search in sources :

Example 11 with FileSource

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

the class Recorder method getStubMappingPostProcessor.

public SnapshotStubMappingPostProcessor getStubMappingPostProcessor(Options options, RecordSpec recordSpec) {
    FileSource filesRoot = options.filesRoot().child(FILES_ROOT);
    final SnapshotStubMappingTransformerRunner transformerRunner = new SnapshotStubMappingTransformerRunner(options.extensionsOfType(StubMappingTransformer.class).values(), recordSpec.getTransformers(), recordSpec.getTransformerParameters(), filesRoot);
    return new SnapshotStubMappingPostProcessor(recordSpec.shouldRecordRepeatsAsScenarios(), transformerRunner, recordSpec.getExtractBodyCriteria(), new SnapshotStubMappingBodyExtractor(filesRoot));
}
Also used : FileSource(com.github.tomakehurst.wiremock.common.FileSource)

Example 12 with FileSource

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

the class HandlebarsJsonPathHelperTest method extractsValueFromAMap.

@Test
public void extractsValueFromAMap() {
    ResponseTemplateTransformer transformer = new ResponseTemplateTransformer(true) {

        @Override
        protected Map<String, Object> addExtraModelElements(Request request, ResponseDefinition responseDefinition, FileSource files, Parameters parameters) {
            return ImmutableMap.<String, Object>of("mapData", ImmutableMap.of("things", "abc"));
        }
    };
    final ResponseDefinition responseDefinition = transformer.transform(mockRequest(), aResponse().withBody("{{jsonPath mapData '$.things'}}").build(), noFileSource(), Parameters.empty());
    assertThat(responseDefinition.getBody(), is("abc"));
}
Also used : Parameters(com.github.tomakehurst.wiremock.extension.Parameters) FileSource(com.github.tomakehurst.wiremock.common.FileSource) NoFileSource.noFileSource(com.github.tomakehurst.wiremock.testsupport.NoFileSource.noFileSource) MockRequest.mockRequest(com.github.tomakehurst.wiremock.matching.MockRequest.mockRequest) Request(com.github.tomakehurst.wiremock.http.Request) ResponseDefinition(com.github.tomakehurst.wiremock.http.ResponseDefinition) ResponseTemplateTransformer(com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer) Test(org.junit.jupiter.api.Test)

Example 13 with FileSource

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

the class CommandLineOptionsTest method loadResourcesFromClasspathSetsFileSourceToUseClasspath.

@Test
public void loadResourcesFromClasspathSetsFileSourceToUseClasspath() {
    CommandLineOptions options = new CommandLineOptions("--load-resources-from-classpath=classpath-filesource");
    FileSource fileSource = options.filesRoot();
    assertThat(fileSource, instanceOf(ClasspathFileSource.class));
    assertThat(fileSource.getTextFileNamed("__files/stuff.txt").readContentsAsString(), equalTo("THINGS!"));
}
Also used : FileSource(com.github.tomakehurst.wiremock.common.FileSource) ClasspathFileSource(com.github.tomakehurst.wiremock.common.ClasspathFileSource) SingleRootFileSource(com.github.tomakehurst.wiremock.common.SingleRootFileSource) ClasspathFileSource(com.github.tomakehurst.wiremock.common.ClasspathFileSource) Test(org.junit.jupiter.api.Test)

Example 14 with FileSource

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

the class AdminApiTest method editStubFileContent.

@Test
public void editStubFileContent() throws Exception {
    String fileName = "bar.txt";
    FileSource fileSource = wireMockServer.getOptions().filesRoot().child(FILES_ROOT);
    fileSource.createIfNecessary();
    fileSource.writeTextFile(fileName, "AAA");
    int statusCode = testClient.putWithBody("/__admin/files/bar.txt", "BBB", "text/plain").statusCode();
    assertEquals(200, statusCode);
    assertEquals("BBB", fileSource.getTextFileNamed(fileName).readContentsAsString(), "File should have been changed");
}
Also used : FileSource(com.github.tomakehurst.wiremock.common.FileSource) Test(org.junit.jupiter.api.Test)

Example 15 with FileSource

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

the class StubMappingPersistenceAcceptanceTest method init.

@BeforeEach
public void init() throws Exception {
    rootDir = Files.createTempDirectory("temp-filesource");
    mappingsDir = rootDir.resolve("mappings");
    FileSource fileSource = new SingleRootFileSource(rootDir.toAbsolutePath().toString());
    fileSource.createIfNecessary();
    FileSource filesFileSource = fileSource.child(FILES_ROOT);
    filesFileSource.createIfNecessary();
    FileSource mappingsFileSource = fileSource.child(MAPPINGS_ROOT);
    mappingsFileSource.createIfNecessary();
    wireMockServer = new WireMockServer(wireMockConfig().fileSource(fileSource).dynamicPort());
    wireMockServer.start();
    testClient = new WireMockTestClient(wireMockServer.port());
    WireMock.configureFor(wireMockServer.port());
    wm = wireMockServer;
}
Also used : WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient) FileSource(com.github.tomakehurst.wiremock.common.FileSource) SingleRootFileSource(com.github.tomakehurst.wiremock.common.SingleRootFileSource) SingleRootFileSource(com.github.tomakehurst.wiremock.common.SingleRootFileSource) BeforeEach(org.junit.jupiter.api.BeforeEach)

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