Search in sources :

Example 51 with Element

use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.

the class BPMNDiagramMarshallerTest method testUnmarshallProcessProperties.

@Test
@SuppressWarnings("unchecked")
public void testUnmarshallProcessProperties() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_PROCESSPROPERTIES);
    assertDiagram(diagram, 4);
    assertEquals("BPSimple", diagram.getMetadata().getTitle());
    DiagramSet diagramProperties = null;
    Iterator<Element> it = nodesIterator(diagram);
    while (it.hasNext()) {
        Element element = it.next();
        if (element.getContent() instanceof View) {
            Object oDefinition = ((View) element.getContent()).getDefinition();
            if (oDefinition instanceof BPMNDiagram) {
                BPMNDiagramImpl bpmnDiagram = (BPMNDiagramImpl) oDefinition;
                diagramProperties = bpmnDiagram.getDiagramSet();
                break;
            }
        }
    }
    assertEquals("BPSimple", diagramProperties.getName().getValue());
    assertEquals("This is a\n" + "simple\n" + "process", diagramProperties.getDocumentation().getValue());
    assertEquals("JDLProj.BPSimple", diagramProperties.getId().getValue());
    assertEquals("org.jbpm", diagramProperties.getPackageProperty().getValue());
    assertEquals(Boolean.valueOf(true), diagramProperties.getExecutable().getValue());
    assertEquals(Boolean.valueOf(true), diagramProperties.getAdHoc().getValue());
    assertEquals("This is the\n" + "Process\n" + "Instance\n" + "Description", diagramProperties.getProcessInstanceDescription().getValue());
}
Also used : BPMNDiagram(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DiagramSet(org.kie.workbench.common.stunner.bpmn.definition.property.diagram.DiagramSet) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FlowElement(org.eclipse.bpmn2.FlowElement) RootElement(org.eclipse.bpmn2.RootElement) Element(org.kie.workbench.common.stunner.core.graph.Element) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 52 with Element

use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.

the class BPMNDiagramMarshallerTest method testUnmarshallScriptTask.

@Test
public void testUnmarshallScriptTask() throws Exception {
    Diagram<Graph, Metadata> diagram = unmarshall(BPMN_SCRIPTTASK);
    ScriptTask javascriptScriptTask = null;
    ScriptTask javaScriptTask = null;
    Iterator<Element> it = nodesIterator(diagram);
    while (it.hasNext()) {
        Element element = it.next();
        if (element.getContent() instanceof View) {
            Object oDefinition = ((View) element.getContent()).getDefinition();
            if (oDefinition instanceof ScriptTask) {
                ScriptTask task = (ScriptTask) oDefinition;
                if ("Javascript Script Task".equals(task.getGeneral().getName().getValue())) {
                    javascriptScriptTask = task;
                } else if ("Java Script Task".equals(task.getGeneral().getName().getValue())) {
                    javaScriptTask = task;
                }
            }
        }
    }
    assertNotNull(javascriptScriptTask);
    assertNotNull(javascriptScriptTask.getExecutionSet());
    assertNotNull(javascriptScriptTask.getExecutionSet().getScript());
    assertEquals(javascriptScriptTask.getTaskType().getValue(), TaskTypes.SCRIPT);
    assertEquals("Javascript Script Task", javascriptScriptTask.getGeneral().getName().getValue());
    assertEquals("var str = FirstName + LastName;", javascriptScriptTask.getExecutionSet().getScript().getValue().getScript());
    assertEquals("javascript", javascriptScriptTask.getExecutionSet().getScript().getValue().getLanguage());
    assertEquals("true", javascriptScriptTask.getExecutionSet().getIsAsync().getValue().toString());
    assertEquals("true", javascriptScriptTask.getExecutionSet().getIsAsync().getValue().toString());
    assertNotNull(javaScriptTask);
    assertNotNull(javaScriptTask.getExecutionSet());
    assertNotNull(javaScriptTask.getExecutionSet().getScript());
    assertEquals(javaScriptTask.getTaskType().getValue(), TaskTypes.SCRIPT);
    assertEquals("Java Script Task", javaScriptTask.getGeneral().getName().getValue());
    assertEquals("if (name.toString().equals(\"Jay\")) {\n" + "\n" + "      System.out.println(\"Hello\\n\" + name.toString() + \"\\n\");\n" + "\n" + "} else {\n" + "\n" + "\n" + "  System.out.println(\"Hi\\n\" + name.toString() + \"\\n\");\n" + "\n" + "\n" + "}\n", javaScriptTask.getExecutionSet().getScript().getValue().getScript());
    assertEquals("java", javaScriptTask.getExecutionSet().getScript().getValue().getLanguage());
    assertEquals("true", javaScriptTask.getExecutionSet().getIsAsync().getValue().toString());
    assertEquals("true", javaScriptTask.getExecutionSet().getIsAsync().getValue().toString());
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) ScriptTask(org.kie.workbench.common.stunner.bpmn.definition.ScriptTask) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FlowElement(org.eclipse.bpmn2.FlowElement) RootElement(org.eclipse.bpmn2.RootElement) Element(org.kie.workbench.common.stunner.core.graph.Element) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 53 with Element

use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.

the class ClientFactoryServicesTest method testNewElementRemote.

@Test
@SuppressWarnings("unchecked")
public void testNewElementRemote() {
    String id = "id1";
    String defSetId = "defSet1";
    ServiceCallback<Element> callback = mock(ServiceCallback.class);
    Element def = mock(Element.class);
    when(clientFactoryManager.newElement(eq(id), eq(defSetId))).thenReturn(null);
    when(factoryService.newElement(eq(id), eq(defSetId))).thenReturn(def);
    tested.newElement(id, defSetId, callback);
    verify(callback, times(1)).onSuccess(eq(def));
    verify(clientFactoryManager, times(1)).newElement(eq(id), eq(defSetId));
    verify(clientFactoryManager, times(0)).newElement(anyString(), any(Class.class));
    verify(factoryService, times(1)).newElement(eq(id), eq(defSetId));
    verify(factoryService, times(0)).newElement(anyString(), any(Class.class));
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 54 with Element

use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.

the class ClientFactoryServicesTest method testNewElementByTpeRemote.

@Test
@SuppressWarnings("unchecked")
public void testNewElementByTpeRemote() {
    String id = "id1";
    ServiceCallback<Element> callback = mock(ServiceCallback.class);
    Element def = mock(Element.class);
    when(clientFactoryManager.newElement(eq(id), eq(MyType.class))).thenReturn(null);
    when(factoryService.newElement(eq(id), eq(MyType.class))).thenReturn(def);
    tested.newElement(id, MyType.class, callback);
    verify(callback, times(1)).onSuccess(eq(def));
    verify(clientFactoryManager, times(0)).newElement(anyString(), anyString());
    verify(clientFactoryManager, times(1)).newElement(anyString(), eq(MyType.class));
    verify(factoryService, times(0)).newElement(anyString(), anyString());
    verify(factoryService, times(1)).newElement(anyString(), any(Class.class));
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 55 with Element

use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.

the class ClientFactoryServicesTest method testNewElementByTpeLocal.

@Test
@SuppressWarnings("unchecked")
public void testNewElementByTpeLocal() {
    String id = "id1";
    ServiceCallback<Element> callback = mock(ServiceCallback.class);
    Element def = mock(Element.class);
    when(clientFactoryManager.newElement(eq(id), eq(MyType.class))).thenReturn(def);
    tested.newElement(id, MyType.class, callback);
    verify(callback, times(1)).onSuccess(eq(def));
    verify(clientFactoryManager, times(0)).newElement(anyString(), anyString());
    verify(clientFactoryManager, times(1)).newElement(anyString(), eq(MyType.class));
    verify(factoryService, times(0)).newElement(anyString(), anyString());
    verify(factoryService, times(0)).newElement(anyString(), any(Class.class));
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Element (org.kie.workbench.common.stunner.core.graph.Element)85 Test (org.junit.Test)55 View (org.kie.workbench.common.stunner.core.graph.content.view.View)34 Graph (org.kie.workbench.common.stunner.core.graph.Graph)27 FlowElement (org.eclipse.bpmn2.FlowElement)24 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)24 RootElement (org.eclipse.bpmn2.RootElement)24 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)24 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Node (org.kie.workbench.common.stunner.core.graph.Node)11 Map (java.util.Map)7 Optional (java.util.Optional)6 Before (org.junit.Before)6 Collection (java.util.Collection)5 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)5 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)5 Matchers.anyString (org.mockito.Matchers.anyString)5 Logger (java.util.logging.Logger)4 BPMNDiagram (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram)4