private static InputStreamReader createReader(String path) { final InputStream resourceAsStream = getResourceAsStream(path); return new InputStreamReader(resourceAsStream); }
public static String loadString(String path) throws IOException { final InputStream resourceAsStream = getResourceAsStream(path); return IOUtils.toString(resourceAsStream); }
private File setupCase(String caseName, String extension) throws IOException { File simpleFile = tempDir.newFile(caseName + "." + extension); FileUtils.copyInputStreamToFile(getResourceAsStream("examples/" + caseName + ".gocd.yaml"), simpleFile); return tempDir.getRoot(); }
@Test public void shouldUpdateTargetVersionWhenItIsTheDefaultOrMissingAcrossAllPipelinesAndEnvironments() throws Exception { FileUtils.copyInputStreamToFile(getResourceAsStream("/parts/roots/version_1.yaml"), tempDir.newFile("v1_1.gocd.yaml")); FileUtils.copyInputStreamToFile(getResourceAsStream("/parts/roots/version_not_present.yaml"), tempDir.newFile("v1_not_present.gocd.yaml")); FileUtils.copyInputStreamToFile(getResourceAsStream("/parts/roots/version_1.yaml"), tempDir.newFile("v1_2.gocd.yaml")); GoPluginApiResponse response = parseAndGetResponseForDir(tempDir.getRoot()); assertNoError(getJsonObjectFromResponse(response)); }
@Test public void shouldFailToUpdateTargetVersionWhenItIs_NOT_TheSameAcrossAllFiles() throws Exception { FileUtils.copyInputStreamToFile(getResourceAsStream("/parts/roots/version_1.yaml"), tempDir.newFile("v1_1.gocd.yaml")); FileUtils.copyInputStreamToFile(getResourceAsStream("/parts/roots/version_1.yaml"), tempDir.newFile("v1_2.gocd.yaml")); FileUtils.copyInputStreamToFile(getResourceAsStream("/parts/roots/version_2.yaml"), tempDir.newFile("v2_1.gocd.yaml")); GoPluginApiResponse response = parseAndGetResponseForDir(tempDir.getRoot()); String expectedFailureMessage = "java.lang.RuntimeException: Versions across files are not unique. Found" + " versions: [1, 2]. There can only be one version across the whole repository."; assertFirstError(getJsonObjectFromResponse(response), expectedFailureMessage, "YAML config plugin"); }
@Test public void shouldUpdateTargetVersionWhenItIsTheSameAcrossAllFiles() throws Exception { FileUtils.copyInputStreamToFile(getResourceAsStream("/parts/roots/version_2.yaml"), tempDir.newFile("v2_1.gocd.yaml")); FileUtils.copyInputStreamToFile(getResourceAsStream("/parts/roots/version_2.yaml"), tempDir.newFile("v2_2.gocd.yaml")); GoPluginApiResponse response = parseAndGetResponseForDir(tempDir.getRoot()); assertNoError(getJsonObjectFromResponse(response)); }
@Test public void respondsToParseContentRequest() throws Exception { final Gson gson = new Gson(); DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest("configrepo", "2.0", ConfigRepoMessages.REQ_PARSE_CONTENT); StringWriter w = new StringWriter(); IOUtils.copy(getResourceAsStream("examples/simple.gocd.yaml"), w); request.setRequestBody(gson.toJson( Collections.singletonMap("contents", Collections.singletonMap("simple.gocd.yaml", w.toString()) ) )); GoPluginApiResponse response = plugin.handle(request); assertEquals(SUCCESS_RESPONSE_CODE, response.responseCode()); JsonObject responseJsonObject = getJsonObjectFromResponse(response); assertNoError(responseJsonObject); JsonArray pipelines = responseJsonObject.get("pipelines").getAsJsonArray(); assertThat(pipelines.size(), is(1)); JsonObject expected = (JsonObject) readJsonObject("examples.out/simple.gocd.json"); assertThat(responseJsonObject, is(new JsonObjectMatcher(expected))); }