@Test public void testLoadsTransformerFromYaml() throws Exception { String contents = "- renameType:\n"+ " old_val: myoldname\n"+ " new_val: mynewname\n"+ "- renameClassTag:\n"+ " old_val: myoldname\n"+ " new_val: mynewname\n"+ "- renameField:\n"+ " class_name: myclassname\n"+ " old_val: myoldname\n"+ " new_val: mynewname\n"+ "- catalogItemId:\n"+ " old_symbolic_name: myclassname\n"+ " new_symbolic_name: myclassname\n"+ " new_version: '2.0'\n"+ "- xslt:\n"+ " url: classpath: " substitutions:\n"+ " old_val: myoldname\n"+ " new_val: mynewname\n"+ "- rawDataTransformer:\n"+ " type: "+MyRawDataTransformer.class.getName()+"\n"; CompoundTransformer transformer = CompoundTransformerLoader.load(contents); Collection<RawDataTransformer> rawDataTransformers = transformer.getRawDataTransformers().get(BrooklynObjectType.ENTITY); assertTrue(Iterables.get(rawDataTransformers, 0) instanceof XsltTransformer); assertTrue(Iterables.get(rawDataTransformers, 1) instanceof XsltTransformer); assertTrue(Iterables.get(rawDataTransformers, 2) instanceof XsltTransformer); assertTrue(Iterables.get(rawDataTransformers, 3) instanceof XsltTransformer); assertTrue(Iterables.get(rawDataTransformers, 4) instanceof XsltTransformer); assertTrue(Iterables.get(rawDataTransformers, 5) instanceof MyRawDataTransformer); }
public static CompoundTransformer load(String contents) { CompoundTransformer.Builder builder = CompoundTransformer.builder(); Iterable<Object> toplevel = Yamls.parseAll(contents); Collection<?> rules = (Collection<?>)Iterables.getOnlyElement(toplevel); for (Object obj : rules) { Map<?, ?> map = (Map<?, ?>)obj; Entry<?, ?> entry = Iterables.getOnlyElement(map.entrySet()); addRule(builder, (String)entry.getKey(), (Map<?, ?>)entry.getValue()); } LOG.info("Loaded " + rules.size() + " transforms"); return builder.build(); }
CompoundTransformerLoader { public static CompoundTransformer load(String contents) { CompoundTransformer.Builder builder = CompoundTransformer.builder(); Iterable<Object> toplevel = Yamls.parseAll(contents); Collection<?> rules = (Collection<?>)Iterables.getOnlyElement(toplevel); for (Object obj : rules) { Map<?, ?> map = (Map<?, ?>)obj; Entry<?, ?> entry = Iterables.getOnlyElement(map.entrySet()); addRule(builder, (String)entry.getKey(), (Map<?, ?>)entry.getValue()); } LOG.info("Loaded " + rules.size() + " transforms"); return builder.build(); } }
CompoundTransformerLoader { public static CompoundTransformer load(String contents) { CompoundTransformer.Builder builder = CompoundTransformer.builder(); Iterable<Object> toplevel = Yamls.parseAll(contents); Collection<?> rules = (Collection<?>)Iterables.getOnlyElement(toplevel); for (Object obj : rules) { Map<?, ?> map = (Map<?, ?>)obj; Entry<?, ?> entry = Iterables.getOnlyElement(map.entrySet()); addRule(builder, (String)entry.getKey(), (Map<?, ?>)entry.getValue()); } LOG.info("Loaded " + rules.size() + " transforms"); return builder.build(); }  }
CompoundTransformerLoader { public static CompoundTransformer load(String contents) { CompoundTransformer.Builder builder = CompoundTransformer.builder(); Iterable<Object> toplevel = Yamls.parseAll(contents); Collection<?> rules = (Collection<?>)Iterables.getOnlyElement(toplevel); for (Object obj : rules) { Map<?, ?> map = (Map<?, ?>)obj; Entry<?, ?> entry = Iterables.getOnlyElement(map.entrySet()); addRule(builder, (String)entry.getKey(), (Map<?, ?>)entry.getValue()); } LOG.info("Loaded " + rules.size() + " transforms"); return builder.build(); }  static CompoundTransformer load(String contents); }
CompoundTransformerLoader { public static CompoundTransformer load(String contents) { CompoundTransformer.Builder builder = CompoundTransformer.builder(); Iterable<Object> toplevel = Yamls.parseAll(contents); Collection<?> rules = (Collection<?>)Iterables.getOnlyElement(toplevel); for (Object obj : rules) { Map<?, ?> map = (Map<?, ?>)obj; Entry<?, ?> entry = Iterables.getOnlyElement(map.entrySet()); addRule(builder, (String)entry.getKey(), (Map<?, ?>)entry.getValue()); } LOG.info("Loaded " + rules.size() + " transforms"); return builder.build(); }  static CompoundTransformer load(String contents);  }