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