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