Skip to content

Commit

Permalink
KOGITO-1183: BPMN Editor - Imports not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
romartin committed Apr 8, 2020
1 parent 7c89375 commit 714b072
Show file tree
Hide file tree
Showing 37 changed files with 668 additions and 185 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,6 @@

package org.kie.workbench.common.stunner.bpmn.definition.property.diagram.imports;

import java.util.Objects;

import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;
import org.jboss.errai.databinding.client.api.Bindable;
Expand All @@ -26,8 +24,8 @@
@Bindable
public class DefaultImport {

protected static final String DELIMITER = "|";
protected static final String IDENTIFIER = "default";
public static final String DELIMITER = "|";
public static final String IDENTIFIER = "default";

private String className;

Expand Down Expand Up @@ -79,20 +77,6 @@ public void setClassName(final String className) {
this.className = className;
}

@Override
public boolean equals(Object o) {
if (o instanceof DefaultImport) {
DefaultImport other = (DefaultImport) o;
return Objects.equals(className, other.className);
}
return false;
}

@Override
public int hashCode() {
return Objects.hashCode(className);
}

@Override
public String toString() {
if (className == null || className.isEmpty()) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,12 +16,9 @@

package org.kie.workbench.common.stunner.bpmn.definition.property.diagram.imports;

import java.util.Objects;

import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;
import org.jboss.errai.databinding.client.api.Bindable;
import org.kie.workbench.common.stunner.core.util.HashUtil;

@Portable
@Bindable
Expand Down Expand Up @@ -96,22 +93,6 @@ public void setNamespace(final String namespace) {
this.namespace = namespace;
}

@Override
public boolean equals(Object o) {
if (o instanceof WSDLImport) {
WSDLImport other = (WSDLImport) o;
return Objects.equals(location, other.location) &&
Objects.equals(namespace, other.namespace);
}
return false;
}

@Override
public int hashCode() {
return HashUtil.combineHashCodes(Objects.hashCode(location),
Objects.hashCode(namespace));
}

@Override
public String toString() {
if (location == null || namespace == null ||
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.kie.workbench.common.stunner.bpmn.definition.property.diagram.imports.DefaultImport.DELIMITER;
import static org.kie.workbench.common.stunner.bpmn.definition.property.diagram.imports.DefaultImport.IDENTIFIER;
Expand All @@ -46,22 +47,22 @@ public void setClassName() {
public void testEquals() {
DefaultImport tested1 = new DefaultImport();
DefaultImport tested2 = new DefaultImport();
assertEquals(tested1, tested2);
assertNotEquals(tested1, tested2);

DefaultImport tested3 = new DefaultImport(CLASS_NAME);
DefaultImport tested4 = new DefaultImport(CLASS_NAME);
assertEquals(tested3, tested4);
assertNotEquals(tested3, tested4);
}

@Test
public void testHashCode() {
DefaultImport tested1 = new DefaultImport();
DefaultImport tested2 = new DefaultImport();
assertEquals(tested1.hashCode(), tested2.hashCode());
assertNotEquals(tested1.hashCode(), tested2.hashCode());

DefaultImport tested3 = new DefaultImport(CLASS_NAME);
DefaultImport tested4 = new DefaultImport(CLASS_NAME);
assertEquals(tested3.hashCode(), tested4.hashCode());
assertNotEquals(tested3.hashCode(), tested4.hashCode());
}

@Test
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.kie.workbench.common.stunner.bpmn.definition.property.diagram.imports.WSDLImport.DELIMITER;
import static org.kie.workbench.common.stunner.bpmn.definition.property.diagram.imports.WSDLImport.IDENTIFIER;
Expand Down Expand Up @@ -60,22 +61,22 @@ public void setNamespace() {
public void testEquals() {
WSDLImport tested1 = new WSDLImport();
WSDLImport tested2 = new WSDLImport();
assertEquals(tested1, tested2);
assertNotEquals(tested1, tested2);

WSDLImport tested3 = new WSDLImport(LOCATION, NAMESPACE);
WSDLImport tested4 = new WSDLImport(LOCATION, NAMESPACE);
assertEquals(tested3, tested4);
assertNotEquals(tested3, tested4);
}

@Test
public void testHashCode() {
WSDLImport tested1 = new WSDLImport();
WSDLImport tested2 = new WSDLImport();
assertEquals(tested1.hashCode(), tested2.hashCode());
assertNotEquals(tested1.hashCode(), tested2.hashCode());

WSDLImport tested3 = new WSDLImport(LOCATION, NAMESPACE);
WSDLImport tested4 = new WSDLImport(LOCATION, NAMESPACE);
assertEquals(tested3.hashCode(), tested4.hashCode());
assertNotEquals(tested3.hashCode(), tested4.hashCode());
}

@Test
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,17 +58,17 @@ public List<DefaultImport> getValue(BaseElement element) {
@Override
public void setValue(BaseElement element, List<DefaultImport> value) {
value.stream()
.map(this::extensionOf)
.map(DefaultImportsElement::extensionOf)
.forEach(getExtensionElements(element)::add);
}

protected FeatureMap.Entry extensionOf(DefaultImport defaultImport) {
public static FeatureMap.Entry extensionOf(DefaultImport defaultImport) {
return new EStructuralFeatureImpl.SimpleFeatureMapEntry(
(EStructuralFeature.Internal) DOCUMENT_ROOT__IMPORT,
importTypeDataOf(defaultImport));
}

protected ImportType importTypeDataOf(DefaultImport defaultImport) {
public static ImportType importTypeDataOf(DefaultImport defaultImport) {
ImportType importType = DroolsFactory.eINSTANCE.createImportType();
importType.setName(defaultImport.getClassName());
return importType;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,7 +44,7 @@ public final T getDefaultValue() {

public abstract void setValue(BaseElement element, T value);

protected FeatureMap getExtensionElements(BaseElement element) {
public static FeatureMap getExtensionElements(BaseElement element) {
if (element.getExtensionValues() == null || element.getExtensionValues().isEmpty()) {
ExtensionAttributeValue eav = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
element.getExtensionValues().add(eav);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,7 +54,11 @@ public void testSetValue() {
BaseElement baseElement = bpmn2.createProcess();
CustomElement.defaultImports.of(baseElement).set(defaultImports);

assertEquals(defaultImports, CustomElement.defaultImports.of(baseElement).get());
List<DefaultImport> result = CustomElement.defaultImports.of(baseElement).get();
assertEquals(3, result.size());
assertEquals(CLASS_NAME + 1, result.get(0).getClassName());
assertEquals(CLASS_NAME + 2, result.get(1).getClassName());
assertEquals(CLASS_NAME + 3, result.get(2).getClassName());
}

@Test
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2018 Red Hat, Inc. and/or its affiliates.
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -179,7 +179,11 @@ public void defaultImports() {

p.setDefaultImports(defaultImports);

assertEquals(defaultImports, CustomElement.defaultImports.of(p.getProcess()).get());
List<DefaultImport> result = CustomElement.defaultImports.of(p.getProcess()).get();
assertEquals(3, result.size());
assertEquals("className1", result.get(0).getClassName());
assertEquals("className2", result.get(1).getClassName());
assertEquals("className3", result.get(2).getClassName());
}

@Test
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates.
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,29 +17,37 @@
package org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.processes;

import java.util.Collections;
import java.util.List;

import org.eclipse.bpmn2.Definitions;
import org.eclipse.bpmn2.Process;
import org.eclipse.bpmn2.di.BPMNDiagram;
import org.junit.Before;
import org.junit.Test;
import org.kie.workbench.common.stunner.bpmn.backend.converters.TypedFactoryManager;
import org.kie.workbench.common.stunner.bpmn.backend.converters.customproperties.elements.DefaultImportsElement;
import org.kie.workbench.common.stunner.bpmn.backend.converters.customproperties.elements.ElementDefinition;
import org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.ConverterFactory;
import org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.DefinitionResolver;
import org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.DefinitionsPropertyReader;
import org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.ProcessPropertyReader;
import org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.PropertyReaderFactory;
import org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl;
import org.kie.workbench.common.stunner.bpmn.definition.property.diagram.DiagramSet;
import org.kie.workbench.common.stunner.bpmn.definition.property.diagram.imports.DefaultImport;
import org.kie.workbench.common.stunner.bpmn.definition.property.diagram.imports.Imports;
import org.kie.workbench.common.stunner.bpmn.definition.property.diagram.imports.ImportsValue;
import org.kie.workbench.common.stunner.bpmn.definition.property.variables.AdvancedData;
import org.kie.workbench.common.stunner.bpmn.definition.property.variables.ProcessData;
import org.kie.workbench.common.stunner.core.api.FactoryManager;
import org.kie.workbench.common.stunner.core.graph.Node;
import org.kie.workbench.common.stunner.core.graph.content.Bounds;
import org.kie.workbench.common.stunner.core.graph.content.view.View;
import org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl;
import org.kie.workbench.common.stunner.core.graph.impl.NodeImpl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2;
import static org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.di;
Expand All @@ -58,13 +66,15 @@ public class RootProcessConverterTest {
private RootProcessConverter tested;

@Before
@SuppressWarnings("all")
public void setUp() {
Definitions definitions = bpmn2.createDefinitions();
process = bpmn2.createProcess();
definitions.getRootElements().add(process);
BPMNDiagram bpmnDiagram = di.createBPMNDiagram();
bpmnDiagram.setPlane(di.createBPMNPlane());
definitions.getDiagrams().add(bpmnDiagram);
ElementDefinition.getExtensionElements(process).add(DefaultImportsElement.extensionOf(new DefaultImport(getClass().getName())));

definitionResolver = new DefinitionResolver(definitions, Collections.emptyList());

Expand All @@ -84,26 +94,34 @@ public void setUp() {
}

@Test
public void createNode() {
assertTrue(BPMNDiagramImpl.class.isInstance(tested.createNode("id").getContent().getDefinition()));
public void testCreateNode() {
assertTrue(tested.createNode("id").getContent().getDefinition() instanceof BPMNDiagramImpl);
}

@Test
public void createDiagramSet() {
assertTrue(DiagramSet.class.isInstance(tested.createDiagramSet(process,
new ProcessPropertyReader(process,
definitionResolver.getDiagram(),
definitionResolver.getShape(process.getId()),
definitionResolver.getResolutionFactor()),
new DefinitionsPropertyReader(definitionResolver.getDefinitions(),
definitionResolver.getDiagram(),
definitionResolver.getShape(process.getId()),
definitionResolver.getResolutionFactor()))));
public void testCreateProcessData() {
assertNotNull(tested.createProcessData("id"));
}

@Test
public void createProcessData() {
assertTrue(ProcessData.class.isInstance(tested.createProcessData("id")));
public void testCreateDiagramSet() {
DiagramSet diagramSet = createDiagramSet();
assertNotNull(diagramSet);
}

@Test
public void testImports() {
DiagramSet diagramSet = createDiagramSet();
Imports imports = diagramSet.getImports();
assertNotNull(imports);
ImportsValue importsValue = imports.getValue();
assertNotNull(importsValue);
List<DefaultImport> defaultImports = importsValue.getDefaultImports();
assertNotNull(defaultImports);
assertFalse(defaultImports.isEmpty());
DefaultImport defaultImport = defaultImports.get(0);
assertNotNull(defaultImport);
assertEquals(getClass().getName(), defaultImport.getClassName());
}

@Test
Expand All @@ -116,4 +134,16 @@ public void convertAdvancedData() {
tested.createAdvancedData("id", "testßval");
assertTrue(tested.convertProcess().isSuccess());
}

private DiagramSet createDiagramSet() {
return tested.createDiagramSet(process,
new ProcessPropertyReader(process,
definitionResolver.getDiagram(),
definitionResolver.getShape(process.getId()),
definitionResolver.getResolutionFactor()),
new DefinitionsPropertyReader(definitionResolver.getDefinitions(),
definitionResolver.getDiagram(),
definitionResolver.getShape(process.getId()),
definitionResolver.getResolutionFactor()));
}
}

0 comments on commit 714b072

Please sign in to comment.