@SafeVarargs private static Component checkComponent(final Transformation transformation, final String uuid, final String name, final String description, final List<String> functionParameters, final Tuple<String, String>... parameterMappings) { // TODO: changed Configuration.class to Component.class (y Configuration.class here - these are components!) final List<Component> configurations = Lambda.filter(Lambda.having(Lambda.on(Component.class).getUuid(), Matchers.equalTo(uuid)), transformation.getComponents()); MatcherAssert.assertThat(configurations, Matchers.hasSize(1)); final Component component = configurations.get(0); MatcherAssert.assertThat(component.getUuid(), Matchers.equalTo(uuid)); MatcherAssert.assertThat(component.getName(), Matchers.equalTo(name)); MatcherAssert.assertThat(component.getDescription(), Matchers.equalTo(description)); final Map<String, String> componentParameterMappings = component.getParameterMappings(); for (final Tuple<String, String> parameterMapping : parameterMappings) { final String key = parameterMapping.v1(); final String value = parameterMapping.v2(); MatcherAssert.assertThat(componentParameterMappings, Matchers.hasKey(key)); MatcherAssert.assertThat(componentParameterMappings, Matchers.hasValue(value)); } CustomTransformationDeserializerTest.checkFunction(component, uuid, name, description, functionParameters.toArray(new String[functionParameters.size()])); return component; }
@Test public void deserializeNestedTransformationTest() throws IOException { final CharSource source = Resources.asCharSource(Resources.getResource("deser-nested-transformation.json"), Charset.forName("UTF-8")); final Mapping mapping = objectMapper.readValue(source.openStream(), Mapping.class); final Component transformationComponent = mapping.getTransformation(); MatcherAssert.assertThat(transformationComponent.getName(), Matchers.equalTo("transformation")); MatcherAssert.assertThat(transformationComponent.getDescription(), Matchers.equalTo("transformation")); MatcherAssert.assertThat(transformationComponent.getParameterMappings(), Matchers.allOf(Matchers.hasKey("dataset"), Matchers.hasKey("variable_name"), Matchers.hasKey("transformationOutputVariable"))); MatcherAssert.assertThat( transformationComponent.getParameterMappings(), Matchers.allOf(Matchers.hasValue("http://data.slub-dresden.de/resources/1/schema#dataset"), Matchers.hasValue("http://data.slub-dresden.de/resources/1/schema#variable_name"), Matchers.hasValue("http://purl.org/dc/elements/1.1/title"))); CustomTransformationDeserializerTest.testTransformation((Transformation) transformationComponent.getFunction()); }
/** * Create a new {@code Component} as a copy from a existing component with a specific id. <br> * <b>Use with care!</b> * <p> * This factory is to be used by {@link org.dswarm.persistence.model.job.utils.TransformationDeserializer} to avoid reflection * based access to a private/protected field, since the Json deserializer needs a way to set the id that was provided by the * JSON. * </p> * <p> * The id is otherwise assigned by the database/Hibernate layer. You should never need this outside of * {@code TransformationDeserializer}. * </p> * * @param component the base component that will be copied * @param uuid the target component's id value * @return a new component with the given id and all other attributes copied from the provided component. */ public static Component withId(final Component component, final String uuid) { final Component newComponent = new Component(uuid); newComponent.setFunction(component.getFunction()); newComponent.setInputComponents(component.getInputComponents()); newComponent.setOutputComponents(component.getOutputComponents()); newComponent.setParameterMappings(component.getParameterMappings()); newComponent.setDescription(component.getDescription()); newComponent.setName(component.getName()); return newComponent; } }