ImportTransformer { public static ImportTransformer getTransformer(String transformerSpec) throws AtlasBaseException { String[] params = StringUtils.split(transformerSpec, TRANSFORMER_PARAMETER_SEPARATOR); String key = (params == null || params.length < 1) ? transformerSpec : params[0]; final ImportTransformer ret; if (StringUtils.isEmpty(key)) { throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "Error creating ImportTransformer. Invalid transformer-specification: {}.", transformerSpec); } else if (key.equals("replace")) { String toFindStr = (params == null || params.length < 2) ? "" : params[1]; String replaceStr = (params == null || params.length < 3) ? "" : params[2]; ret = new Replace(toFindStr, replaceStr); } else if (key.equals("lowercase")) { ret = new Lowercase(); } else if (key.equals("uppercase")) { ret = new Uppercase(); } else { throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "Error creating ImportTransformer. Unknown transformer: {}.", transformerSpec); } return ret; } protected  ImportTransformer(String transformType); static ImportTransformer getTransformer(String transformerSpec); String getTransformType(); abstract Object apply(Object o);  }
@Test public void createWithCorrectParameters() throws AtlasBaseException, IllegalAccessException { String param1 = "@cl1"; String param2 = "@cl2"; ImportTransformer e = ImportTransformer.getTransformer(String.format("%s:%s:%s", "replace", param1, param2)); assertTrue(e instanceof ImportTransformer.Replace); assertEquals(((ImportTransformer.Replace)e).getToFindStr(), param1); assertEquals(((ImportTransformer.Replace)e).getReplaceStr(), param2); }
@Test public void createSeveralWithCorrectParameters() throws AtlasBaseException, IllegalAccessException { String param1 = "@cl1"; String param2 = "@cl2"; ImportTransformer e1 = ImportTransformer.getTransformer(String.format("%s:%s:%s", "replace", param1, param2)); ImportTransformer e2 = ImportTransformer.getTransformer(String.format("replace:tt1:tt2")); assertTrue(e1 instanceof ImportTransformer.Replace); assertEquals(((ImportTransformer.Replace)e1).getToFindStr(), param1); assertEquals(((ImportTransformer.Replace)e1).getReplaceStr(), param2); assertTrue(e2 instanceof ImportTransformer.Replace); assertEquals(((ImportTransformer.Replace)e2).getToFindStr(), "tt1"); assertEquals(((ImportTransformer.Replace)e2).getReplaceStr(), "tt2"); }
@Test public void createWithDefaultParameters() throws AtlasBaseException { ImportTransformer e1 = ImportTransformer.getTransformer("replace:@cl1"); ImportTransformer e2 = ImportTransformer.getTransformer("replace"); assertTrue(e1 instanceof ImportTransformer.Replace); assertEquals(((ImportTransformer.Replace)e1).getToFindStr(), "@cl1"); assertEquals(((ImportTransformer.Replace)e1).getReplaceStr(), ""); assertTrue(e2 instanceof ImportTransformer.Replace); assertEquals(((ImportTransformer.Replace)e2).getToFindStr(), ""); assertEquals(((ImportTransformer.Replace)e2).getReplaceStr(), ""); }