@Test public void shouldRespondSuccessToParseDirectoryRequestWhenSimpleCaseFile() throws UnhandledRequestTypeException, IOException { GoPluginApiResponse response = parseAndGetResponseForDir(setupCase("simple")); assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE)); 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))); }
@Test public void shouldRespondSuccessToParseDirectoryRequestWhenAliasesCaseFile() throws UnhandledRequestTypeException, IOException { GoPluginApiResponse response = parseAndGetResponseForDir(setupCase("aliases")); assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE)); JsonObject responseJsonObject = getJsonObjectFromResponse(response); assertNoError(responseJsonObject); JsonArray pipelines = responseJsonObject.get("pipelines").getAsJsonArray(); assertThat(pipelines.size(), is(1)); JsonObject expected = (JsonObject) readJsonObject("examples.out/aliases.gocd.json"); assertThat(responseJsonObject, is(new JsonObjectMatcher(expected))); }
@Test public void shouldRespondSuccessToParseDirectoryRequestWhenRichCaseFile() throws UnhandledRequestTypeException, IOException { GoPluginApiResponse response = parseAndGetResponseForDir(setupCase("rich")); assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE)); JsonObject responseJsonObject = getJsonObjectFromResponse(response); assertNoError(responseJsonObject); JsonArray pipelines = responseJsonObject.get("pipelines").getAsJsonArray(); assertThat(pipelines.size(), is(1)); JsonObject expected = (JsonObject) readJsonObject("examples.out/rich.gocd.json"); assertThat(responseJsonObject, is(new JsonObjectMatcher(expected))); }
@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))); }
@Test public void shouldRespondSuccessToParseDirectoryRequestWhenEmpty() throws UnhandledRequestTypeException { GoPluginApiResponse response = parseAndGetResponseForDir(tempDir.getRoot()); assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE)); JsonObject responseJsonObject = getJsonObjectFromResponse(response); assertNoError(responseJsonObject); }
@Test public void shouldParseDirectoryWithCustomPatternWhenInConfigurations() throws UnhandledRequestTypeException, IOException { File simpleCaseDir = setupCase("simple", "go.yml"); DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest("configrepo", "1.0", "parse-directory"); String requestBody = "{\n" + " \"directory\":\"" + simpleCaseDir + "\",\n" + " \"configurations\":[" + "{" + "\"key\" : \"file_pattern\"," + "\"value\" : \"simple.go.yml\" " + "}" + "]\n" + "}"; parseDirectoryRequest.setRequestBody(requestBody); GoPluginApiResponse response = plugin.handle(parseDirectoryRequest); assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE)); JsonObject responseJsonObject = getJsonObjectFromResponse(response); assertNoError(responseJsonObject); JsonArray pipelines = responseJsonObject.get("pipelines").getAsJsonArray(); assertThat(pipelines.size(), is(1)); }
@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 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)); }