### Question:
DagRequest { public DagRequest resolveVariables() throws IOException, TemplateException { String rawReq = JsonUtil.toJson(this); Template t = new Template("DagRequest", new StringReader(rawReq), TEMPLATE_CFG); Map model = new HashMap(); for (String key : this.params.keySet()) { Variable v = this.params.get(key); switch (v.type) { case "number": model.put(key, v.convertToNumber()); break; case "date": model.put(key, v.convertToDate()); break; case "string": model.put(key, v.convertToString()); break; case "boolean": model.put(key, v.convertToBoolean()); break; default: model.put(key, v.value); } } Writer out = new StringWriter(); t.process(model, out); String transformedTemplate = out.toString(); return JsonUtil.fromJson(transformedTemplate, DagRequest.class); } DagRequest(); DagRequest resolveVariables(); static Configuration TEMPLATE_CFG; public Dag dag; public Set<String> goals; public Engine engine; public Map<String, Variable> params; public TriggerOptions trigger; }### Answer:
@Test public void resolveVariables() throws IOException, TemplateException { ClassLoader classLoader = getClass().getClassLoader(); URL resource = classLoader.getResource("dagrequests/example1.json"); String jsonRequest = new String(Files.readAllBytes(Paths.get(resource.getPath())), StandardCharsets.UTF_8); DagRequest req = JsonUtil.fromJson(jsonRequest, DagRequest.class); DagRequest newReq = req.resolveVariables(); assertEquals(6, newReq.dag.steps.size()); String dateStrValue = newReq.params.get("DATE_VAR").value; Date date = Date.from(Instant.ofEpochMilli(Long.parseLong(dateStrValue))); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm"); String dateString = sdf.format(date); Iterator<Step> it = newReq.dag.steps.iterator(); while (it.hasNext()) { Step step = it.next(); if (step.id.equals("5c969069d47a400e547d25d9")) { assertEquals("some string value", step.config.get("path")); } if (step.id.equals("5c9697213cc63f7d6665abb0")) { assertEquals("123", step.config.get("xlabel")); List<String> dimensions = (List<String>) step.config.get("dimension"); assertEquals(dateString, dimensions.get(0)); } } }