/** * Update the cache by making sure, that every component as a valid id set. The reason behind this is, that {@code Component}s * are compared only by their ID, if they are compared in a shallow manner (e.g. when used in a {@code Set}). * * @param components a map of (id -> {@code Component}) */ private static void assignComponentIds(final Map<String, Component> components) { for (final String componentId : components.keySet()) { final Component component = components.get(componentId); if (component.getUuid() == null) { final Component newComponent = Component.withId(component, componentId); components.put(componentId, newComponent); } } }
if (component.getUuid() == null) { component = Component.withId(component, id); components.put(id, component);
private Element convertIfElseFunction(final Component multipleInputComponent, final String collectionNameAttribute, final Element collection) throws DMPConverterException { final Map<String, String> parameters = multipleInputComponent.getParameterMappings(); if (parameters == null) { throw new DMPConverterException("cannot convert if/else component; there are not parameter mappings"); } if (!parameters.containsKey(IF_VARIABLE_IDENTIFIER)) { throw new DMPConverterException("cannot convert if/else component; cannot find parameter mapping for if-branch in parameter mappings"); } final String ifBranchComponentVariableName = parameters.get(IF_VARIABLE_IDENTIFIER); if (!parameters.containsKey(ELSE_VARIABLE_IDENTIFIER)) { throw new DMPConverterException("cannot convert if/else component; cannot find parameter mapping for else-branch in parameter mappings"); } final String elseBranchComponentVariableName = parameters.get(ELSE_VARIABLE_IDENTIFIER); final String ifElseComponentID = multipleInputComponent.getUuid(); final String ifElseComponentName = IF_ELSE_COMPONENT_NAME_PREFIX + ifElseComponentID; collection.setAttribute(METAMORPH_DATA_TARGET, MF_VARIABLE_PREFIX + collectionNameAttribute); createDataElement(collection, ifBranchComponentVariableName, ifElseComponentName + IF_BRANCH_POSTFIX, Optional.empty()); createDataElement(collection, elseBranchComponentVariableName, ifElseComponentName + ELSE_BRANCH_POSTFIX, Optional.empty()); return collection; }
/** * sort components re. their natural order (begin from the end, i.e., component without output components) * * @param components original components set * @return */ private static javaslang.collection.List<Component> sortComponents(final Set<Component> components) { final Optional<Component> optionalLastComponent = components.stream() .filter(component -> { final Set<Component> outputComponents = component.getOutputComponents(); return outputComponents == null || outputComponents.isEmpty(); }) .findFirst(); if (!optionalLastComponent.isPresent()) { return javaslang.collection.List.ofAll(components); } final Component lastComponent = optionalLastComponent.get(); final javaslang.collection.List<Component> lastComponentList = javaslang.collection.List.of(lastComponent); final javaslang.collection.Map<String, Component> componentMap = javaslang.collection.HashSet.ofAll(components) .toMap(component -> Tuple.of(component.getUuid(), component)); final javaslang.collection.List<Component> emptyComponentList = javaslang.collection.List.empty(); return addComponents(lastComponentList, componentMap, emptyComponentList); }
.map(inputComponent -> newComponentMap.get(inputComponent.getUuid())) .filter(optionInputComponent -> !optionInputComponent.isEmpty()) .map(Option::get)
public void checkDeletedComponent(final Component component) { final Component deletedComponent = jpaService.getObject(component.getUuid()); Assert.assertNull("component should be null", deletedComponent); }
/** * @param actualComponentId * @param expectedComponents * @param actualComponents * @param type * @see {@link BasicJPAServiceTestUtils#compareObjects(Set, Map)} */ private void prepareAndCompareComponents(final String actualComponentId, final Set<Component> expectedComponents, final Set<Component> actualComponents, final String type) throws JsonProcessingException, JSONException { Assert.assertNotNull(type + " components of actual component '" + actualComponentId + "' shouldn't be null", actualComponents); Assert.assertFalse(type + " components of actual component '" + actualComponentId + "' shouldn't be empty", actualComponents.isEmpty()); final Map<String, Component> actualComponentsMap = Maps.newHashMap(); for (final Component actualComponent : actualComponents) { actualComponentsMap.put(actualComponent.getUuid(), actualComponent); } compareObjects(expectedComponents, actualComponentsMap); }
/** * note: result will be cache (temporarily - for re-utilisation in a test) * * @return * @throws Exception */ public Component getFullNameComponent() throws Exception { final String component4Name = "full name"; if (!cache.containsKey(component4Name)) { final Component transformationComponent = getFirstNameTransformationComponentDefaultCompleteComponent(); final Component transformationComponent2 = getFamilyNameTransformationComponentDefaultCompleteComponent(); final Function function4 = functionServiceTestUtils.getSimpleConcatFunction(); final Map<String, String> parameterMapping4 = Maps.newLinkedHashMap(); final String functionParameterName5 = "firstString"; final String componentVariableName5 = transformationComponent.getUuid() + ".outputVariable"; final String functionParameterName6 = "secondString"; final String componentVariableName6 = transformationComponent2.getUuid() + ".outputVariable"; parameterMapping4.put(functionParameterName5, componentVariableName5); parameterMapping4.put(functionParameterName6, componentVariableName6); final Set<Component> component4InputComponents = Sets.newLinkedHashSet(); component4InputComponents.add(transformationComponent); component4InputComponents.add(transformationComponent2); final Component component4 = createComponent(component4Name, parameterMapping4, function4, component4InputComponents, null); cache.put(component4Name, component4); } return cache.get(component4Name); }
@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; }
/** * {@inheritDoc} <br /> * Assert both transformations have either no components or their components are equal, see * {@link org.dswarm.persistence.service.test.utils.BasicJPAServiceTestUtils#compareObjects(Set, Map)} for details. */ @Override public void compareObjects(final Transformation expectedTransformation, final Transformation actualTransformation) throws JsonProcessingException, JSONException { super.compareObjects(expectedTransformation, actualTransformation); if (expectedTransformation.getComponents() == null || expectedTransformation.getComponents().isEmpty()) { final boolean actualTransformationHasNoComponents = (actualTransformation.getComponents() == null || actualTransformation.getComponents() .isEmpty()); Assert.assertTrue("the actual transformation should not have any components", actualTransformationHasNoComponents); } else { // (!null && !empty) final Set<Component> actualComponents = actualTransformation.getComponents(); Assert.assertNotNull("components of actual transformation '" + actualTransformation.getUuid() + "' shouldn't be null", actualComponents); Assert.assertFalse("components of actual transformation '" + actualTransformation.getUuid() + "' shouldn't be empty", actualComponents.isEmpty()); final Map<String, Component> actualComponentsMap = Maps.newHashMap(); for (final Component actualComponent : actualComponents) { actualComponentsMap.put(actualComponent.getUuid(), actualComponent); } componentServiceTestUtils.compareObjects(expectedTransformation.getComponents(), actualComponentsMap); } }
if (expectedComponent != null && expectedComponent.getUuid() != null) { if (checkedExpectedComponents.contains(expectedComponent.getUuid())) { checkedExpectedComponents.add(expectedComponent.getUuid()); if (actualComponent != null && actualComponent.getUuid() != null) { if (checkedActualComponents.contains(actualComponent.getUuid())) { checkedActualComponents.add(actualComponent.getUuid()); Assert.assertNull("the function of actual component '" + actualComponent.getUuid() + "' should be null", actualComponent.getFunction()); Assert.assertNotNull("the function of actual component '" + actualComponent.getUuid() + "' shouldn't be null", actualComponent.getFunction()); prepareAndCompareComponents(actualComponent.getUuid(), expectedComponent.getInputComponents(), actualComponent.getInputComponents(), "input"); prepareAndCompareComponents(actualComponent.getUuid(), expectedComponent.getOutputComponents(), actualComponent.getOutputComponents(), "output"); Assert.assertNotNull("parameter mappings of actual component '" + actualComponent.getUuid() + "' shouldn't be null", actualParameterMappings); Assert.assertFalse("parameter mappings of actual component '" + actualComponent.getUuid() + "' shouldn't be empty", actualParameterMappings.isEmpty()); Assert.assertEquals("different number of parameter mappings", expectedComponent.getParameterMappings().size(), actualComponent
Assert.assertNotNull("the component input components set shouldn't be null", component.getInputComponents()); Assert.assertEquals("the component input components set are not equal", 1, component.getInputComponents().size()); Assert.assertTrue("the component input components set doesn't contain component '" + component1.getUuid() + "'", component.getInputComponents() .contains(component1)); Assert.assertEquals("the component input component '" + component1.getUuid() + "' are not equal", component1, component.getInputComponents() .iterator().next()); Assert.assertNotNull("the component output components set shouldn't be null", component.getOutputComponents()); Assert.assertEquals("the component output components set are not equal", 1, component.getOutputComponents().size()); Assert.assertTrue("the component output components set doesn't contain component '" + component2.getUuid() + "'", component .getOutputComponents().contains(component2)); Assert.assertEquals("the component output component '" + component2.getUuid() + "' are not equal", component2, component.getOutputComponents() .iterator().next());
Assert.assertNotNull("the component input components set shouldn't be null", mainComponent.getInputComponents()); Assert.assertEquals("the component input components set are not equal", 1, mainComponent.getInputComponents().size()); Assert.assertTrue("the component input components set doesn't contain component '" + component1.getUuid() + "'", mainComponent .getInputComponents().contains(component1)); Assert.assertEquals("the component input component '" + component1.getUuid() + "' are not equal", component1, mainComponent .getInputComponents().iterator().next()); Assert.assertNotNull("the component output components set shouldn't be null", mainComponent.getOutputComponents()); Assert.assertEquals("the component output components set are not equal", 1, mainComponent.getOutputComponents().size()); Assert.assertTrue("the component output components set doesn't contain component '" + component2.getUuid() + "'", mainComponent .getOutputComponents().contains(component2)); Assert.assertEquals("the component output component '" + component2.getUuid() + "' are not equal", component2, mainComponent .getOutputComponents().iterator().next());
public Component createComponent(final String name, final Map<String, String> parameterMappings, final Function function, final Set<Component> inputComponents, final Set<Component> outputComponents) throws Exception { // component needs to be a persistent object from the beginning final Component component = createObject().getObject(); component.setName(name); component.setFunction(function); component.setParameterMappings(parameterMappings); if (inputComponents != null) { component.setInputComponents(inputComponents); } if (outputComponents != null) { component.setOutputComponents(outputComponents); } // update method needs to be utilised here, because component was already created final Component updatedComponent = updateAndCompareObject(component, component); Assert.assertNotNull("the updated component shouldn't be null", updatedComponent); Assert.assertNotNull("the component name shouldn't be null", updatedComponent.getUuid()); return updatedComponent; }