Search in sources :

Example 6 with FileSource

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

the class AdminApiTest method deleteStubFileInTree.

@Test
public void deleteStubFileInTree() throws Exception {
    String fileName = "foo/bar.txt";
    FileSource fileSource = wireMockServer.getOptions().filesRoot().child(FILES_ROOT);
    fileSource.createIfNecessary();
    fileSource.writeTextFile(fileName, "contents");
    int statusCode = testClient.delete("/__admin/files/foo/bar.txt").statusCode();
    assertEquals(200, statusCode);
    assertFalse(Paths.get(fileSource.getTextFileNamed(fileName).getPath()).toFile().exists(), "File should have been deleted");
}
Also used : FileSource(com.github.tomakehurst.wiremock.common.FileSource) Test(org.junit.jupiter.api.Test)

Example 7 with FileSource

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

the class AdminApiTest method createStubFileContentInTree.

@Test
public void createStubFileContentInTree() throws Exception {
    String fileName = "foo/bar.txt";
    FileSource fileSource = wireMockServer.getOptions().filesRoot().child(FILES_ROOT);
    fileSource.createIfNecessary();
    int statusCode = testClient.putWithBody("/__admin/files/foo/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 8 with FileSource

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

the class CommandLineOptionsTest method fileSourceDefaultsToSingleRootFileSource.

@Test
public void fileSourceDefaultsToSingleRootFileSource() {
    CommandLineOptions options = new CommandLineOptions();
    FileSource fileSource = options.filesRoot();
    assertThat(fileSource, instanceOf(SingleRootFileSource.class));
}
Also used : FileSource(com.github.tomakehurst.wiremock.common.FileSource) ClasspathFileSource(com.github.tomakehurst.wiremock.common.ClasspathFileSource) SingleRootFileSource(com.github.tomakehurst.wiremock.common.SingleRootFileSource) SingleRootFileSource(com.github.tomakehurst.wiremock.common.SingleRootFileSource) Test(org.junit.jupiter.api.Test)

Example 9 with FileSource

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

the class EditStubFileTask method execute.

@Override
public ResponseDefinition execute(Admin admin, Request request, PathParams pathParams) {
    byte[] fileContent = request.getBody();
    FileSource fileSource = admin.getOptions().filesRoot().child(FILES_ROOT);
    String filename = pathParams.get("0");
    fileSource.writeBinaryFile(filename, fileContent);
    return ResponseDefinition.okForJson(fileContent);
}
Also used : FileSource(com.github.tomakehurst.wiremock.common.FileSource)

Example 10 with FileSource

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

the class WireMockServerRunner method run.

public void run(String... args) {
    CommandLineOptions options = new CommandLineOptions(args);
    if (options.help()) {
        out.println(options.helpText());
        return;
    }
    FileSource fileSource = options.filesRoot();
    fileSource.createIfNecessary();
    FileSource filesFileSource = fileSource.child(FILES_ROOT);
    filesFileSource.createIfNecessary();
    FileSource mappingsFileSource = fileSource.child(MAPPINGS_ROOT);
    mappingsFileSource.createIfNecessary();
    wireMockServer = new WireMockServer(options);
    if (options.recordMappingsEnabled()) {
        wireMockServer.enableRecordMappings(mappingsFileSource, filesFileSource);
    }
    if (options.specifiesProxyUrl()) {
        addProxyMapping(options.proxyUrl());
    }
    try {
        wireMockServer.start();
        boolean https = options.httpsSettings().enabled();
        if (!options.getHttpDisabled()) {
            options.setActualHttpPort(wireMockServer.port());
        }
        if (https) {
            options.setActualHttpsPort(wireMockServer.httpsPort());
        }
        if (!options.bannerDisabled()) {
            out.println(BANNER);
            out.println();
        } else {
            out.println();
            out.println("The WireMock server is started .....");
        }
        out.println(options);
    } catch (FatalStartupException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : FileSource(com.github.tomakehurst.wiremock.common.FileSource) FatalStartupException(com.github.tomakehurst.wiremock.common.FatalStartupException) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer)

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