Search in sources :

Example 1 with FileSource

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

the class StubResponseRendererTest method init.

@BeforeEach
public void init() {
    fileSource = Mockito.mock(FileSource.class);
    globalSettingsHolder = new GlobalSettingsHolder();
    responseTransformers = new ArrayList<>();
    stubResponseRenderer = new StubResponseRenderer(fileSource, globalSettingsHolder, null, responseTransformers);
}
Also used : GlobalSettingsHolder(com.github.tomakehurst.wiremock.global.GlobalSettingsHolder) FileSource(com.github.tomakehurst.wiremock.common.FileSource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with FileSource

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

the class GetAllStubFilesTask method execute.

@Override
public ResponseDefinition execute(Admin admin, Request request, PathParams pathParams) {
    FileSource fileSource = admin.getOptions().filesRoot().child(FILES_ROOT);
    List<String> filePaths = new ArrayList<>();
    for (TextFile textFile : fileSource.listFilesRecursively()) {
        filePaths.add(textFile.getPath());
    }
    Collections.sort(filePaths);
    return ResponseDefinition.okForJson(filePaths);
}
Also used : FileSource(com.github.tomakehurst.wiremock.common.FileSource) ArrayList(java.util.ArrayList) TextFile(com.github.tomakehurst.wiremock.common.TextFile)

Example 3 with FileSource

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

the class DeleteStubFileTask method execute.

@Override
public ResponseDefinition execute(Admin admin, Request request, PathParams pathParams) {
    FileSource fileSource = admin.getOptions().filesRoot().child(FILES_ROOT);
    File filename = new File(fileSource.getPath(), pathParams.get("0"));
    boolean deleted = filename.delete();
    if (deleted) {
        return ResponseDefinition.ok();
    } else {
        return new ResponseDefinition(HTTP_INTERNAL_ERROR, "File not deleted");
    }
}
Also used : FileSource(com.github.tomakehurst.wiremock.common.FileSource) ResponseDefinition(com.github.tomakehurst.wiremock.http.ResponseDefinition) File(java.io.File)

Example 4 with FileSource

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

the class AdminApiTest method listStubFiles.

@Test
public void listStubFiles() throws Exception {
    FileSource fileSource = wireMockServer.getOptions().filesRoot().child(FILES_ROOT);
    fileSource.createIfNecessary();
    fileSource.writeTextFile("bar.txt", "contents");
    fileSource.writeTextFile("zoo.txt", "contents");
    WireMockResponse response = testClient.get("/__admin/files");
    assertEquals(200, response.statusCode());
    String pathSeparatorRegex = File.separator;
    if (File.separator.equals("\\")) {
        pathSeparatorRegex = "\\\\";
    }
    assertThat(new String(response.binaryContent()), matches("\\[ \".*" + pathSeparatorRegex + "bar.txt\", \".*zoo.*txt\" ]"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) FileSource(com.github.tomakehurst.wiremock.common.FileSource) Test(org.junit.jupiter.api.Test)

Example 5 with FileSource

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

the class AdminApiTest method deleteStubFile.

@Test
public void deleteStubFile() throws Exception {
    String fileName = "bar.txt";
    FileSource fileSource = wireMockServer.getOptions().filesRoot().child(FILES_ROOT);
    fileSource.createIfNecessary();
    fileSource.writeTextFile(fileName, "contents");
    int statusCode = testClient.delete("/__admin/files/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)

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