Search in sources :

Example 31 with DecisionService

use of org.kie.workbench.common.dmn.api.definition.model.DecisionService in project kie-wb-common by kiegroup.

the class DecisionServiceParametersListWidgetTest method testGetNewItems.

@Test
public void testGetNewItems() {
    final DecisionServiceParametersList value = mock(DecisionServiceParametersList.class);
    final DecisionService decisionService = mock(DecisionService.class);
    final String id1 = "id1";
    final String id2 = "id2";
    final String id3 = "id3";
    final String newItem1 = "aaa";
    final String newItem2 = "bbb";
    final String newItem3 = "ccc";
    final String newItem4 = "ddd";
    final List<DMNElementReference> list = createListOfDMNElementReferenceWithIds(id1, id2, id3);
    final List<InputData> currentItems = Arrays.asList(createInputDataWithId(id2), createInputDataWithId(id3), createInputDataWithId(id1));
    final List<InputData> inputs = Arrays.asList(createInputDataWithId(newItem3), createInputDataWithId(newItem2), createInputDataWithId(newItem4), createInputDataWithId(newItem1));
    doReturn(value).when(widget).getValue();
    when(value.getDecisionService()).thenReturn(decisionService);
    when(decisionService.getInputData()).thenReturn(list);
    final List<InputData> result = widget.getNewItems(inputs, currentItems);
    assertThat(result).extracting(inputData -> inputData.getId().getValue()).containsExactly(newItem1, newItem2, newItem3, newItem4);
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) DecisionServiceParameters_Outputs(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants.DecisionServiceParameters_Outputs) HTMLElement(org.jboss.errai.common.client.dom.HTMLElement) ClientTranslationService(org.kie.workbench.common.stunner.core.client.i18n.ClientTranslationService) Mockito.doReturn(org.mockito.Mockito.doReturn) DecisionServiceParameters_EncapsulatedDecisions(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants.DecisionServiceParameters_EncapsulatedDecisions) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) Mockito.doNothing(org.mockito.Mockito.doNothing) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) List(java.util.List) Stream(java.util.stream.Stream) DMNDiagramsSession(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSession) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Node(org.kie.workbench.common.stunner.core.graph.Node) Mockito.mock(org.mockito.Mockito.mock) GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) DecisionServiceParameters_Inputs(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants.DecisionServiceParameters_Inputs) Mockito.spy(org.mockito.Mockito.spy) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ArrayList(java.util.ArrayList) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Elemental2DomUtil(org.jboss.errai.common.client.dom.elemental2.Elemental2DomUtil) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) DecisionServiceParametersList(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceParametersList) Before(org.junit.Before) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Mockito.verify(org.mockito.Mockito.verify) ParameterGroup(org.kie.workbench.common.dmn.client.widgets.decisionservice.parameters.parametergroup.ParameterGroup) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Mockito.never(org.mockito.Mockito.never) HTMLDivElement(elemental2.dom.HTMLDivElement) DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Assert.assertEquals(org.junit.Assert.assertEquals) DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) DecisionServiceParametersList(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceParametersList) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Test(org.junit.Test)

Example 32 with DecisionService

use of org.kie.workbench.common.dmn.api.definition.model.DecisionService in project kie-wb-common by kiegroup.

the class DecisionServiceParametersListWidgetTest method testGetSortedInputs.

@Test
public void testGetSortedInputs() {
    final DecisionServiceParametersList value = mock(DecisionServiceParametersList.class);
    final DecisionService decisionService = mock(DecisionService.class);
    final String id1 = "id1";
    final String id2 = "id2";
    final String id3 = "id3";
    final String newId1 = "newId1";
    final String newId2 = "newId2";
    final List<DMNElementReference> list = createListOfDMNElementReferenceWithIds(id1, id2, id3);
    final List<InputData> unsortedInputs = Arrays.asList(createInputDataWithId(id2), createInputDataWithId(id3), createInputDataWithId(newId2), createInputDataWithId(id1), createInputDataWithId(newId1));
    doReturn(value).when(widget).getValue();
    when(value.getDecisionService()).thenReturn(decisionService);
    when(decisionService.getInputData()).thenReturn(list);
    final List<InputData> sorted = widget.getSortedInputs(unsortedInputs);
    assertThat(sorted).extracting(inputData -> inputData.getId().getValue()).containsExactly(id1, id2, id3, newId1, newId2);
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) DecisionServiceParameters_Outputs(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants.DecisionServiceParameters_Outputs) HTMLElement(org.jboss.errai.common.client.dom.HTMLElement) ClientTranslationService(org.kie.workbench.common.stunner.core.client.i18n.ClientTranslationService) Mockito.doReturn(org.mockito.Mockito.doReturn) DecisionServiceParameters_EncapsulatedDecisions(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants.DecisionServiceParameters_EncapsulatedDecisions) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) Mockito.doNothing(org.mockito.Mockito.doNothing) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) List(java.util.List) Stream(java.util.stream.Stream) DMNDiagramsSession(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSession) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Node(org.kie.workbench.common.stunner.core.graph.Node) Mockito.mock(org.mockito.Mockito.mock) GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) DecisionServiceParameters_Inputs(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants.DecisionServiceParameters_Inputs) Mockito.spy(org.mockito.Mockito.spy) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ArrayList(java.util.ArrayList) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Elemental2DomUtil(org.jboss.errai.common.client.dom.elemental2.Elemental2DomUtil) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) DecisionServiceParametersList(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceParametersList) Before(org.junit.Before) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Mockito.verify(org.mockito.Mockito.verify) ParameterGroup(org.kie.workbench.common.dmn.client.widgets.decisionservice.parameters.parametergroup.ParameterGroup) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Mockito.never(org.mockito.Mockito.never) HTMLDivElement(elemental2.dom.HTMLDivElement) DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Assert.assertEquals(org.junit.Assert.assertEquals) DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) DecisionServiceParametersList(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceParametersList) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Test(org.junit.Test)

Example 33 with DecisionService

use of org.kie.workbench.common.dmn.api.definition.model.DecisionService in project kie-wb-common by kiegroup.

the class DecisionServiceParametersListWidgetTest method testRefresh.

@Test
public void testRefresh() {
    final DecisionServiceParametersList value = mock(DecisionServiceParametersList.class);
    final DecisionService decisionService = mock(DecisionService.class);
    final String contentDefinitionId = "contentId";
    final Node node = mock(Node.class);
    final Edge edge1 = mock(Edge.class);
    final Child child1 = mock(Child.class);
    final Node targetNode1 = mock(Node.class);
    final Edge edge2 = mock(Edge.class);
    final Child child2 = mock(Child.class);
    final Node targetNode2 = mock(Node.class);
    final Edge edge3 = mock(Edge.class);
    final Child child3 = mock(Child.class);
    final Node targetNode3 = mock(Node.class);
    final Edge edgeNotChild = mock(Edge.class);
    final Object notChild = mock(Object.class);
    final List<Edge> edges = Arrays.asList(edge1, edge2, edge3, edgeNotChild);
    final DRGElement drgElement1 = mock(DRGElement.class);
    final DRGElement drgElement2 = mock(DRGElement.class);
    final DRGElement drgElement3 = mock(DRGElement.class);
    final Optional<DRGElement> targetDrg1 = Optional.of(drgElement1);
    final Optional<DRGElement> targetDrg2 = Optional.of(drgElement2);
    final Optional<DRGElement> targetDrg3 = Optional.of(drgElement3);
    final List<InputData> sortedList = new ArrayList<>();
    when(decisionService.getContentDefinitionId()).thenReturn(contentDefinitionId);
    when(value.getDecisionService()).thenReturn(decisionService);
    when(edge1.getContent()).thenReturn(child1);
    when(edge1.getTargetNode()).thenReturn(targetNode1);
    when(edge2.getContent()).thenReturn(child2);
    when(edge2.getTargetNode()).thenReturn(targetNode2);
    when(edge3.getContent()).thenReturn(child3);
    when(edge3.getTargetNode()).thenReturn(targetNode3);
    when(edgeNotChild.getContent()).thenReturn(notChild);
    when(node.getOutEdges()).thenReturn(edges);
    doNothing().when(widget).clear();
    doNothing().when(widget).loadGroupsElements();
    doNothing().when(widget).loadInputsParameters(anyList());
    doNothing().when(widget).loadDecisionsFromNode(any(), any());
    doNothing().when(widget).loadInputsFromNode(any(), any());
    doNothing().when(widget).loadInputsFromOthersDiagrams(anyList(), any(Node.class));
    doReturn(value).when(widget).getValue();
    doReturn(node).when(widget).getNode(contentDefinitionId);
    doReturn(targetDrg1).when(widget).getTargetDRGElement(edge1);
    doReturn(targetDrg2).when(widget).getTargetDRGElement(edge2);
    doReturn(targetDrg3).when(widget).getTargetDRGElement(edge3);
    doReturn(Optional.empty()).when(widget).getTargetDRGElement(edgeNotChild);
    doReturn(sortedList).when(widget).getSortedInputs(anyList());
    widget.refresh();
    verify(widget).loadDecisionsFromNode(node, targetNode1);
    verify(widget).loadDecisionsFromNode(node, targetNode2);
    verify(widget).loadDecisionsFromNode(node, targetNode3);
    verify(widget).loadInputsFromNode(anyList(), eq(targetNode1));
    verify(widget).loadInputsFromNode(anyList(), eq(targetNode2));
    verify(widget).loadInputsFromNode(anyList(), eq(targetNode3));
    verify(widget).loadInputsFromOthersDiagrams(anyList(), eq(targetNode1));
    verify(widget).loadInputsFromOthersDiagrams(anyList(), eq(targetNode2));
    verify(widget).loadInputsFromOthersDiagrams(anyList(), eq(targetNode3));
    verify(widget).getSortedInputs(anyList());
    verify(widget).loadInputsParameters(sortedList);
    verify(widget).loadGroupsElements();
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) DecisionServiceParametersList(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceParametersList) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 34 with DecisionService

use of org.kie.workbench.common.dmn.api.definition.model.DecisionService in project kie-wb-common by kiegroup.

the class DMNElementsSynchronizerTest method testSynchronizeDecisionServiceNode.

@Test
public void testSynchronizeDecisionServiceNode() {
    final DecisionService from = mock(DecisionService.class);
    final DecisionService to = mock(DecisionService.class);
    final InformationItemPrimary variable = mock(InformationItemPrimary.class);
    when(from.getVariable()).thenReturn(variable);
    synchronizer.synchronizeDecisionServiceNode(from, to);
    verify(to).setVariable(variable);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Test(org.junit.Test)

Example 35 with DecisionService

use of org.kie.workbench.common.dmn.api.definition.model.DecisionService in project kie-wb-common by kiegroup.

the class DMNElementsSynchronizerTest method testSynchronizeSpecializedProperties_DecisionServiceNode.

@Test
public void testSynchronizeSpecializedProperties_DecisionServiceNode() {
    doNothing().when(synchronizer).synchronizeDecisionServiceNode(any(DecisionService.class), any(DecisionService.class));
    final DecisionService from = mock(DecisionService.class);
    final DecisionService to = mock(DecisionService.class);
    synchronizer.synchronizeSpecializedProperties(from, to);
    verify(synchronizer).synchronizeDecisionServiceNode(from, to);
}
Also used : DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Test(org.junit.Test)

Aggregations

DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)38 Test (org.junit.Test)19 View (org.kie.workbench.common.stunner.core.graph.content.view.View)19 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)13 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)13 Node (org.kie.workbench.common.stunner.core.graph.Node)13 ArrayList (java.util.ArrayList)12 List (java.util.List)12 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)12 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 DecisionServiceDividerLineY (org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY)11 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)9 InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)9 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)9 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)9 Optional (java.util.Optional)7 DMNElementReference (org.kie.workbench.common.dmn.api.definition.model.DMNElementReference)7 KnowledgeRequirement (org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement)7 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)6