private void testInverseTransform(String caseFile, String expectedFile) throws IOException { String expectedObject = loadString("parts/" + expectedFile + ".yaml"); Map<String, Object> actual = parser.inverseTransform(readJsonGson("parts/" + caseFile + ".json")); assertYamlEquivalent(expectedObject, YamlUtils.dump(actual)); } }
public static List<Map<String, Object>> readJsonArrayGson(String path) { return fromJson(TestUtils.createReader(path)); }
static InputStream getResourceAsStream(String resource) { final InputStream in = getContextClassLoader().getResourceAsStream(resource); return in == null ? TestUtils.class.getResourceAsStream(resource) : in; }
private void testInverseTransform(String caseFile, String expectedFile) throws IOException { String expectedObject = loadString("parts/env_vars/" + expectedFile + ".yaml"); Map<String, Object> actual = parser.inverseTransform(readJsonArrayGson("parts/env_vars/" + caseFile + ".json")); assertYamlEquivalent(expectedObject, YamlUtils.dump(actual)); } }
private void testTransform(String caseFile, String expectedFile) throws IOException { JsonArray expected = (JsonArray) readJsonObject("parts/env_vars/" + expectedFile + ".json"); JsonArray actual = parser.transform(readYamlObject("parts/env_vars/" + caseFile + ".yaml")); assertThat(actual, is(expected)); }
private void testInverseTransform(String caseFile, String expectedFile) throws IOException { Map<String, Object> actual = parser.inverseTransform(readJsonGson("parts/materials/" + caseFile + ".json")); JsonObject transform = parser.transform(actual); assertEquals((readJsonObject("parts/materials/" + expectedFile + ".json")), transform); } }
private void testInverseTransform(String caseFile, String expectedFile) throws IOException { Map<String, Object> inverse = paramterTransform.inverseTransform(readJsonArrayGson("parts/parameters/" + caseFile + ".json")); JsonArray actual = paramterTransform.transform(inverse); assertEquals((readJsonObject("parts/parameters/" + expectedFile + ".json")), actual); }
private static InputStreamReader createReader(String path) { final InputStream resourceAsStream = getResourceAsStream(path); return new InputStreamReader(resourceAsStream); }
@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 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))); }
public static JsonElement readJsonObject(String path) { JsonParser parser = new JsonParser(); return parser.parse(TestUtils.createReader(path)); }
private JsonConfigCollection readRootYaml(String caseFile) throws IOException { return rootTransform.transform(readYamlObject("parts/roots/" + caseFile + ".yaml"), "test code"); }
private void testTransform(String caseFile, String expectedFile) throws IOException { JsonArray expected = (JsonArray) readJsonObject("parts/parameters/" + expectedFile + ".json"); JsonArray actual = paramterTransform.transform(readYamlObject("parts/parameters/" + caseFile + ".yaml")); assertThat(actual, is(expected)); }
private void testInverseTransform(String caseFile, String expectedFile) throws IOException { Map<String, Object> inverse = parser.inverseTransform(readJsonGson("parts/stages/" + caseFile + ".json")); JsonObject actual = parser.transform(inverse); assertEquals((readJsonObject("parts/stages/" + expectedFile + ".json")), actual); } }
public static String loadString(String path) throws IOException { final InputStream resourceAsStream = getResourceAsStream(path); return IOUtils.toString(resourceAsStream); }
@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))); }
public static Object readYamlObject(String path) throws IOException { YamlConfig config = new YamlConfig(); config.setAllowDuplicates(false); YamlReader reader = new YamlReader(TestUtils.createReader(path), config); return reader.read(); }
private void testTransform(String caseFile, String expectedFile) throws IOException { JsonObject expectedObject = (JsonObject) readJsonObject("parts/materials/" + expectedFile + ".json"); JsonObject jsonObject = parser.transform(readYamlObject("parts/materials/" + caseFile + ".yaml")); assertThat(jsonObject, is(new JsonObjectMatcher(expectedObject))); }
private void testInverseTransform(String caseFile, String expectedFile) throws IOException { Map<String, Object> inverse = parser.inverseTransform(readJsonGson("parts/jobs/" + caseFile + ".json")); assertYamlEquivalent(loadString("parts/jobs/" + expectedFile + ".yaml"), YamlUtils.dump(inverse)); } }
private void testInverseTransform(String caseFile, String expectedFile) throws IOException { Map<String, Object> inverse = parser.inverseTransform(readJsonGson("parts/tasks/" + caseFile + ".json")); JsonObject actual = parser.transform(inverse); assertEquals((readJsonObject("parts/tasks/" + expectedFile + ".json")), actual); } }