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);
}
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);
}
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");
}
}
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\" ]"));
}
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");
}
Aggregations