public YamlConfigParser() { this(new RootTransform()); }
private GoPluginApiResponse handlePipelineExportRequest(GoPluginApiRequest request) { return handlingErrors(() -> { ParsedRequest parsed = ParsedRequest.parse(request); Map<String, Object> pipeline = parsed.getParam("pipeline"); String name = (String) pipeline.get("name"); Map<String, String> responseMap = Collections.singletonMap("pipeline", new RootTransform().inverseTransformPipeline(pipeline)); DefaultGoPluginApiResponse response = success(gson.toJson(responseMap)); response.addResponseHeader("Content-Type", "application/x-yaml; charset=utf-8"); response.addResponseHeader("X-Export-Filename", name + ".gocd.yaml"); return response; }); }
private JsonConfigCollection readRootYaml(String caseFile) throws IOException { return rootTransform.transform(readYamlObject("parts/roots/" + caseFile + ".yaml"), "test code"); }
public void parseStream(JsonConfigCollection result, InputStream input, String location) { try (InputStreamReader contentReader = new InputStreamReader(input)) { if (input.available() < 1) { result.addError("File is empty", location); return; } YamlConfig config = new YamlConfig(); config.setAllowDuplicates(false); YamlReader reader = new YamlReader(contentReader, config); Object rootObject = reader.read(); JsonConfigCollection filePart = rootTransform.transform(rootObject, location); result.append(filePart); } catch (YamlReader.YamlReaderException e) { result.addError(e.getMessage(), location); } catch (IOException e) { result.addError(e.getMessage() + " : " + e.getCause().getMessage() + " : ", location); } } }
@Before public void Setup() { pipelineTransform = mock(PipelineTransform.class); environmentsTransform = mock(EnvironmentsTransform.class); rootTransform = new RootTransform(pipelineTransform, environmentsTransform); }
@Test public void shouldPreserveOrderOfPipelines() throws IOException { MaterialTransform materialTransform = mock(MaterialTransform.class); StageTransform stageTransform = mock(StageTransform.class); EnvironmentVariablesTransform environmentTransform = mock(EnvironmentVariablesTransform.class); ParameterTransform parameterTransform = mock(ParameterTransform.class); pipelineTransform = new PipelineTransform(materialTransform, stageTransform, environmentTransform, parameterTransform); rootTransform = new RootTransform(pipelineTransform, environmentsTransform); JsonConfigCollection collection = readRootYaml("pipeline_order"); JsonArray pipelines = collection.getJsonObject().get("pipelines").getAsJsonArray(); assertThat(pipelines.get(0).getAsJsonObject().get("name").getAsString(), is("pipe1")); assertThat(pipelines.get(1).getAsJsonObject().get("name").getAsString(), is("pipe2")); assertThat(pipelines.get(2).getAsJsonObject().get("name").getAsString(), is("pipe3")); }