SpecificationTransformerTypeBased implements Transformer<T, S> { protected Mappings<Task, Resource> generateMappings(Mappings<Task, Resource> typeMappings, Architecture<Resource, Link> architecture) { Mappings<Task, Resource> mappings = new Mappings<Task, Resource>(); for (Mapping<Task, Resource> typeMapping : typeMappings) { Task source = typeMapping.getSource(); Resource target = typeMapping.getTarget(); Resource instance = architecture.getVertex("r" + CONNECTOR + target.getId()); Mapping<Task, Resource> mapping = new Mapping<Task, Resource>( "m" + source.getId() + CONNECTOR + instance.getId(), source, instance); Attributes attributes = typeMapping.getAttributes(); for (String key : attributes.keySet()) { mapping.setAttribute(key, attributes.getAttribute(key)); } mappings.add(mapping); } return mappings; }  @Override S transform(T typeBasedSpec);  }
@Test public void generateMappingsTest() { Resource r1 = new Resource("type1"); Resource r2 = new Resource("type2"); ResourceTypes<Resource> types = new ResourceTypes<Resource>(); types.put("r1", r1); types.put("r2", r2); Link l1 = new Link("linkType1"); LinkTypes<Link> linkTypes = new LinkTypes<Link>(); linkTypes.put("l1", l1); Task t1 = new Task("t1"); Task t2 = new Task("t2"); Mappings<Task, Resource> typeMappings = new Mappings<Task, Resource>(); Mapping<Task, Resource> m1 = new Mapping<Task, Resource>("m1", t1, r1); Mapping<Task, Resource> m2 = new Mapping<Task, Resource>("m2", t1, r2); Mapping<Task, Resource> m3 = new Mapping<Task, Resource>("m3", t2, r1); m3.setAttribute("M1", 0); typeMappings.add(m1); typeMappings.add(m2); typeMappings.add(m3); SpecificationTransformerTypeBased<SpecificationTypeBased, Specification> transformer = new SpecificationTransformerTypeBased<SpecificationTypeBased, Specification>(); Architecture<Resource, Link> arch = transformer.generateArchitecture(types, linkTypes); Mappings<Task, Resource> mappings = transformer.generateMappings(typeMappings, arch); Assert.assertNotNull(mappings); Assert.assertEquals(mappings.size(), 3); Assert.assertEquals(mappings.get(t1).size(), 2); Assert.assertEquals(mappings.get(t2).size(), 1); Assert.assertEquals(mappings.get(t2).iterator().next().getAttribute("M1"), 0); }