@Test public void shouldRespondSuccessToParseDirectoryRequestWhenPluginHasConfiguration() throws UnhandledRequestTypeException { GoApiResponse settingsResponse = DefaultGoApiResponse.success("{}"); when(goAccessor.submit(any(GoApiRequest.class))).thenReturn(settingsResponse); GoPluginApiResponse response = parseAndGetResponseForDir(tempDir.getRoot()); verify(goAccessor, times(1)).submit(any(GoApiRequest.class)); assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE)); }
@Test public void shouldRespondSuccessWithErrorMessagesToParseDirectoryRequestWhenParsingErrorCaseFile() throws UnhandledRequestTypeException, IOException { GoPluginApiResponse response = parseAndGetResponseForDir(setupCase("invalid-materials")); assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE)); JsonObject responseJsonObject = getJsonObjectFromResponse(response); JsonArray pipelines = responseJsonObject.get("pipelines").getAsJsonArray(); assertThat(pipelines.size(), is(0)); assertFirstError(responseJsonObject, "Error parsing YAML. : Line 21, column 0: Expected a 'block end' but found: scalar : ", "invalid-materials.gocd.yaml"); }
@Test public void shouldRespondSuccessWithErrorMessagesToParseDirectoryRequestWhenSimpleInvalidCaseFile() throws UnhandledRequestTypeException, IOException { GoPluginApiResponse response = parseAndGetResponseForDir(setupCase("simple-invalid")); assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE)); JsonObject responseJsonObject = getJsonObjectFromResponse(response); JsonArray pipelines = responseJsonObject.get("pipelines").getAsJsonArray(); assertThat(pipelines.size(), is(0)); assertFirstError(responseJsonObject, "Failed to parse pipeline pipe1; expected a hash of pipeline materials", "simple-invalid.gocd.yaml"); }
@Test public void shouldRespondSuccessWithErrorMessagesToParseDirectoryRequestWhenDuplicateKeysCaseFile() throws UnhandledRequestTypeException, IOException { GoPluginApiResponse response = parseAndGetResponseForDir(setupCase("duplicate-materials")); assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE)); JsonObject responseJsonObject = getJsonObjectFromResponse(response); JsonArray pipelines = responseJsonObject.get("pipelines").getAsJsonArray(); assertThat(pipelines.size(), is(0)); assertFirstError(responseJsonObject, "Line 9, column 20: Duplicate key found 'upstream'", "duplicate-materials.gocd.yaml"); }
@Test public void shouldContainValidFieldsInResponseMessage() throws UnhandledRequestTypeException { GoApiResponse settingsResponse = DefaultGoApiResponse.success("{}"); when(goAccessor.submit(any(GoApiRequest.class))).thenReturn(settingsResponse); GoPluginApiResponse response = parseAndGetResponseForDir(tempDir.getRoot()); assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE)); final JsonParser parser = new JsonParser(); JsonElement responseObj = parser.parse(response.responseBody()); assertTrue(responseObj.isJsonObject()); JsonObject obj = responseObj.getAsJsonObject(); assertTrue(obj.has("errors")); assertTrue(obj.has("pipelines")); assertTrue(obj.has("environments")); assertTrue(obj.has("target_version")); }
@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 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 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 shouldRespondSuccessToParseDirectoryRequestWhenEmpty() throws UnhandledRequestTypeException { GoPluginApiResponse response = parseAndGetResponseForDir(tempDir.getRoot()); assertThat(response.responseCode(), is(SUCCESS_RESPONSE_CODE)); JsonObject responseJsonObject = getJsonObjectFromResponse(response); assertNoError(responseJsonObject); }
@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 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)); }