public ParameterTransformTest() { paramterTransform = new ParameterTransform(); }
public Map<String, Object> inverseTransform(List<Map<String, Object>> params) { if (params == null || params.isEmpty()) return null; Map<String, Object> result = new LinkedTreeMap<>(); Map<String, Object> inverseParams = new LinkedTreeMap<>(); for (Map<String, Object> param : params) { inverseParams.putAll(inverseTransformParam(param)); } result.put(YAML_PIPELINE_PARAMETERS_FIELD, inverseParams); return result; }
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); }
public JsonObject transform(Map.Entry<String, Object> entry) { String pipelineName = entry.getKey(); JsonObject pipeline = new JsonObject(); pipeline.addProperty(JSON_PIPELINE_NAME_FIELD, pipelineName); Map<String, Object> pipeMap = (Map<String, Object>) entry.getValue(); addOptionalString(pipeline, pipeMap, JSON_PIPELINE_GROUP_FIELD, YAML_PIPELINE_GROUP_FIELD); addOptionalString(pipeline, pipeMap, JSON_PIPELINE_TEMPLATE_FIELD, YAML_PIPELINE_TEMPLATE_FIELD); addOptionalString(pipeline, pipeMap, JSON_PIPELINE_LABEL_TEMPLATE_FIELD, YAML_PIPELINE_LABEL_TEMPLATE_FIELD); addOptionalBoolean(pipeline, pipeMap, JSON_PIPELINE_PIPE_LOCKING_FIELD, YAML_PIPELINE_PIPE_LOCKING_FIELD); addOptionalString(pipeline, pipeMap, JSON_PIPELINE_LOCK_BEHAVIOR_FIELD, YAML_PIPELINE_LOCK_BEHAVIOR_FIELD); addOptionalObject(pipeline, pipeMap, JSON_PIPELINE_TRACKING_TOOL_FIELD, YAML_PIPELINE_TRACKING_TOOL_FIELD); addOptionalObject(pipeline, pipeMap, JSON_PIPELINE_MINGLE_FIELD, YAML_PIPELINE_MINGLE_FIELD); addTimer(pipeline, pipeMap); JsonArray jsonEnvVariables = variablesTransform.transform(pipeMap); if (jsonEnvVariables != null && jsonEnvVariables.size() > 0) pipeline.add(JSON_ENV_VAR_FIELD, jsonEnvVariables); addMaterials(pipeline, pipeMap); if (!pipeline.has(JSON_PIPELINE_TEMPLATE_FIELD)) { addStages(pipeline, pipeMap); } JsonArray params = parameterTransform.transform(pipeMap); if (params != null && params.size() > 0) { pipeline.add(YAML_PIPELINE_PARAMETERS_FIELD, params); } return pipeline; }
public Map<String, Object> inverseTransform(Map<String, Object> pipeline) { Map<String, Object> result = new LinkedTreeMap<>(); Map<String, Object> pipelineMap = new LinkedTreeMap<>(); String name = (String) pipeline.get(JSON_PIPELINE_NAME_FIELD); pipelineMap.put(YAML_PIPELINE_GROUP_FIELD, pipeline.get(JSON_PIPELINE_GROUP_FIELD)); addOptionalValue(pipelineMap, pipeline, JSON_PIPELINE_TEMPLATE_FIELD, YAML_PIPELINE_TEMPLATE_FIELD); addOptionalValue(pipelineMap, pipeline, JSON_PIPELINE_LABEL_TEMPLATE_FIELD, YAML_PIPELINE_LABEL_TEMPLATE_FIELD); addOptionalValue(pipelineMap, pipeline, JSON_PIPELINE_PIPE_LOCKING_FIELD, YAML_PIPELINE_PIPE_LOCKING_FIELD); addOptionalValue(pipelineMap, pipeline, JSON_PIPELINE_LOCK_BEHAVIOR_FIELD, YAML_PIPELINE_LOCK_BEHAVIOR_FIELD); addOptionalValue(pipelineMap, pipeline, JSON_PIPELINE_TRACKING_TOOL_FIELD, YAML_PIPELINE_TRACKING_TOOL_FIELD); addInverseTimer(pipelineMap, pipeline); Map<String, Object> yamlEnvVariables = variablesTransform.inverseTransform((List<Map<String, Object>>) pipeline.get(JSON_ENV_VAR_FIELD)); if (yamlEnvVariables != null && yamlEnvVariables.size() > 0) pipelineMap.putAll(yamlEnvVariables); addInverseMaterials(pipelineMap, (List<Map<String, Object>>) pipeline.get(JSON_PIPELINE_MATERIALS_FIELD)); if (!pipelineMap.containsKey(YAML_PIPELINE_TEMPLATE_FIELD)) { addInverseStages(pipelineMap, (List<Map<String, Object>>) pipeline.get(JSON_PIPELINE_STAGES_FIELD)); } Map<String, Object> params = parameterTransform.inverseTransform((List<Map<String, Object>>) pipeline.get("parameters")); if (params != null && !params.isEmpty()) { pipelineMap.putAll(params); } result.put(name, pipelineMap); return result; }
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)); }
public RootTransform() { EnvironmentVariablesTransform environmentVarsTransform = new EnvironmentVariablesTransform(); MaterialTransform material = new MaterialTransform(); ParameterTransform parameterTransform = new ParameterTransform(); JobTransform job = new JobTransform(environmentVarsTransform, new TaskTransform()); StageTransform stage = new StageTransform(environmentVarsTransform, job); this.pipelineTransform = new PipelineTransform(material, stage, environmentVarsTransform, parameterTransform); this.environmentsTransform = new EnvironmentsTransform(environmentVarsTransform); }