com.github.tomakehurst.wiremock.common.SingleRootFileSource Java Examples
The following examples show how to use
com.github.tomakehurst.wiremock.common.SingleRootFileSource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WireMockBaseTest.java From parsec-libraries with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupServer() throws IOException { String rootDirPath = "parsec_wiremock_test"; File root = Files.createTempDirectory(rootDirPath).toFile(); new File(root, WireMockApp.MAPPINGS_ROOT).mkdirs(); new File(root, WireMockApp.FILES_ROOT).mkdirs(); wireMockServer = new WireMockServer( WireMockConfiguration.options() .dynamicPort() .fileSource(new SingleRootFileSource(rootDirPath)) ); wireMockServer.start(); wireMockBaseUrl = "http://localhost:"+wireMockServer.port(); WireMock.configureFor(wireMockServer.port()); }
Example #2
Source File: BitbucketWireMockBase.java From blueocean-plugin with MIT License | 6 votes |
@Before public void setup() throws Exception { super.setup(); this.authenticatedUser = login(); WireMockRule bitbucketApi = getWireMockRule(); String files = wireMockFileSystemPath()+"__files"; String mappings = wireMockFileSystemPath()+"mappings"; String proxyUrl = wireMockProxyUrl(); new File(mappings).mkdirs(); new File(files).mkdirs(); bitbucketApi.enableRecordMappings(new SingleRootFileSource(mappings), new SingleRootFileSource(files)); if (useProxy) { bitbucketApi.stubFor( WireMock.get(urlMatching(".*")).atPriority(10).willReturn(aResponse() .proxiedFrom(proxyUrl))); } this.apiUrl = String.format("http://localhost:%s",bitbucketApi.port()); }
Example #3
Source File: HttpRequestTest.java From blueocean-plugin with MIT License | 6 votes |
private static WireMockRule createWireMockServerRule(String resourceFolder) { final WireMockRule rule = new WireMockRule( wireMockConfig() .dynamicPort() .usingFilesUnderClasspath(resourceFolder) ); String mappingsPath = String.format("src/test/resources/%s/mappings", resourceFolder); String filesPath = String.format("src/test/resources/%s/__files", resourceFolder); new File(mappingsPath).mkdirs(); new File(filesPath).mkdirs(); rule.enableRecordMappings( new SingleRootFileSource(mappingsPath), new SingleRootFileSource(filesPath) ); return rule; }
Example #4
Source File: GithubMockBase.java From blueocean-plugin with MIT License | 6 votes |
@Override public void setup() throws Exception { super.setup(); //setup github api mock with WireMock new File("src/test/resources/api/mappings").mkdirs(); new File("src/test/resources/api/__files").mkdirs(); githubApi.enableRecordMappings(new SingleRootFileSource("src/test/resources/api/mappings"), new SingleRootFileSource("src/test/resources/api/__files")); if (useProxy) { githubApi.stubFor( WireMock.get(urlMatching(".*")) .atPriority(10) .willReturn(aResponse().proxiedFrom("https://api.github.com/"))); } this.user = login("vivek", "Vivek Pandey", "[email protected]"); this.githubApiUrl = String.format("http://localhost:%s",githubApi.port()); this.crumb = getCrumb( j.jenkins ); }
Example #5
Source File: ResourcesFileSource.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
private static FileSource[] toSources(Resource[] resources) { FileSource[] sources = new FileSource[resources.length]; for (int i = 0; i < resources.length; i++) { Resource resource = resources[i]; if (resource instanceof ClassPathResource) { ClassPathResource classes = (ClassPathResource) resource; sources[i] = new ClasspathFileSource(classes.getPath()); } else if (resource instanceof FileSystemResource) { FileSystemResource files = (FileSystemResource) resource; sources[i] = new SingleRootFileSource(files.getFile()); } else if (resource instanceof UrlResource) { sources[i] = fileOrFallbackToClasspath(resource); } else { throw new IllegalArgumentException( "Unsupported resource type for file source: " + resource.getClass()); } } return sources; }
Example #6
Source File: WireMockBase.java From blueocean-plugin with MIT License | 5 votes |
protected static WireMockRule createWireMockServerRule(String resourceFolder, String baseUrl) { ReplaceUrlTransformer replaceUrlTransformer = new ReplaceUrlTransformer(); final WireMockRule rule = new WireMockRule( wireMockConfig() .dynamicPort() .dynamicHttpsPort() .usingFilesUnderClasspath(resourceFolder) .extensions( new GzipDecompressTransformer(), replaceUrlTransformer ) ); String mappingsPath = String.format("src/test/resources/%s/mappings", resourceFolder); String filesPath = String.format("src/test/resources/%s/__files", resourceFolder); new File(mappingsPath).mkdirs(); new File(filesPath).mkdirs(); rule.enableRecordMappings( new SingleRootFileSource(mappingsPath), new SingleRootFileSource(filesPath) ); if (useProxy) { rule.stubFor( WireMock.get(urlMatching(".*")) .atPriority(10) .willReturn(aResponse().proxiedFrom(baseUrl))); } replaceUrlTransformer.configure(baseUrl, rule); return rule; }
Example #7
Source File: ResourcesFileSource.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private static FileSource fileOrFallbackToClasspath(Resource resource) { UrlResource file = (UrlResource) resource; try { URI uri = file.getURI(); if (compressedResource(uri)) { return new ClasspathFileSource(pathFromCompressed(uri)); } return new SingleRootFileSource(getFile(file)); } catch (IOException e) { throw new IllegalStateException(e); } }
Example #8
Source File: AbstractGitHubWireMockTest.java From github-branch-source-plugin with MIT License | 5 votes |
void prepareMockGitHubFileMappings() { new File("src/test/resources/api/mappings").mkdirs(); new File("src/test/resources/api/__files").mkdirs(); new File("src/test/resources/raw/mappings").mkdirs(); new File("src/test/resources/raw/__files").mkdirs(); githubApi.enableRecordMappings(new SingleRootFileSource("src/test/resources/api/mappings"), new SingleRootFileSource("src/test/resources/api/__files")); githubRaw.enableRecordMappings(new SingleRootFileSource("src/test/resources/raw/mappings"), new SingleRootFileSource("src/test/resources/raw/__files")); }
Example #9
Source File: GitHubSCMSourceTest.java From github-branch-source-plugin with MIT License | 5 votes |
@Before public void prepareMockGitHubStubs() throws Exception { new File("src/test/resources/api/mappings").mkdirs(); new File("src/test/resources/api/__files").mkdirs(); githubApi.enableRecordMappings(new SingleRootFileSource("src/test/resources/api/mappings"), new SingleRootFileSource("src/test/resources/api/__files")); githubApi.stubFor( get(urlEqualTo("/repos/cloudbeers/yolo/pulls/2")) .inScenario("Pull Request Merge Hash") .whenScenarioStateIs(Scenario.STARTED) .willReturn( aResponse() .withHeader("Content-Type", "application/json; charset=utf-8") .withBodyFile("body-yolo-pulls-2-mergeable-null.json")) .willSetStateTo("Pull Request Merge Hash - retry 1")); githubApi.stubFor( get(urlEqualTo("/repos/cloudbeers/yolo/pulls/2")) .inScenario("Pull Request Merge Hash") .whenScenarioStateIs("Pull Request Merge Hash - retry 1") .willReturn( aResponse() .withHeader("Content-Type", "application/json; charset=utf-8") .withBodyFile("body-yolo-pulls-2-mergeable-null.json")) .willSetStateTo("Pull Request Merge Hash - retry 2")); githubApi.stubFor( get(urlEqualTo("/repos/cloudbeers/yolo/pulls/2")) .inScenario("Pull Request Merge Hash") .whenScenarioStateIs("Pull Request Merge Hash - retry 2") .willReturn( aResponse() .withHeader("Content-Type", "application/json; charset=utf-8") .withBodyFile("body-yolo-pulls-2-mergeable-true.json")) .willSetStateTo("Pull Request Merge Hash - retry 2")); }
Example #10
Source File: WireMockRuleFactory.java From github-branch-source-plugin with MIT License | 4 votes |
public WireMockRecorderRule(Options options, String url) { super(options); this.stubFor(get(urlMatching(".*")).atPriority(10).willReturn(aResponse().proxiedFrom(url))); this.enableRecordMappings(new SingleRootFileSource(mappingLocation + "/mappings"), new SingleRootFileSource(mappingLocation + "/__files")); }