use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision in project kie-wb-common by kiegroup.
the class StunnerConverterTest method testDecision.
@Test
public void testDecision() {
final StylingSet decisionStylingSet = mock(StylingSet.class);
final Decision decision = spy(new Decision());
when(decision.getStylingSet()).thenReturn(decisionStylingSet);
final JSITDecision jsitDecision = mock(JSITDecision.class);
when(jsitDecision.getTYPE_NAME()).thenReturn(JSITDecision.TYPE);
final JSIStyle style = mock(JSIStyle.class);
final JSIDMNShape shape = mock(JSIDMNShape.class);
final JSIDMNStyle dmnStyleOfDrgShape = mock(JSIDMNStyle.class);
when(shape.getStyle()).thenReturn(style);
doReturn(style).when(converter).getUnwrappedJSIStyle(style);
doReturn(true).when(converter).isJSIDMNStyle(style);
doReturn(dmnStyleOfDrgShape).when(converter).getJSIDmnStyle(style);
final NodeEntry nodeEntry = mock(NodeEntry.class);
when(nodeEntry.getDmnElement()).thenReturn(jsitDecision);
when(nodeEntry.getId()).thenReturn("_id");
when(nodeEntry.getDmnShape()).thenReturn(shape);
final Element graphElement = mock(Element.class);
final Node graphNode = mock(Node.class);
final View content = mock(View.class);
when(factoryManager.newElement(anyString(), anyString())).thenReturn(graphElement);
when(graphElement.asNode()).thenReturn(graphNode);
when(graphNode.getContent()).thenReturn(content);
when(content.getDefinition()).thenReturn(decision);
final JSIColor randomColor = mock(JSIColor.class);
when(randomColor.getRed()).thenReturn(12);
when(randomColor.getGreen()).thenReturn(34);
when(randomColor.getBlue()).thenReturn(56);
when(dmnStyleOfDrgShape.getFontColor()).thenReturn(randomColor);
when(dmnStyleOfDrgShape.getStrokeColor()).thenReturn(randomColor);
when(dmnStyleOfDrgShape.getFillColor()).thenReturn(randomColor);
when(dmnStyleOfDrgShape.getFontSize()).thenReturn(11d);
converter.make(nodeEntry);
verify(decisionStylingSet).setFontSize(fontSizeArgumentCaptor.capture());
Assertions.assertThat(fontSizeArgumentCaptor.getValue().getValue()).isEqualTo(11d);
verify(decisionStylingSet).setBorderColour(borderColourArgumentCaptor.capture());
Assertions.assertThat(borderColourArgumentCaptor.getValue().getValue()).isEqualTo("#0c2238");
verify(decisionStylingSet).setBgColour(bgColourArgumentCaptor.capture());
Assertions.assertThat(bgColourArgumentCaptor.getValue().getValue()).isEqualTo("#0c2238");
verify(decisionStylingSet).setFontColour(fontColourArgumentCaptor.capture());
Assertions.assertThat(fontColourArgumentCaptor.getValue().getValue()).isEqualTo("#0c2238");
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method makeDecision.
private JSITDecision makeDecision(final String id) {
final JSITDecision decision = spy(new JSITDecision());
doReturn(id).when(decision).getId();
return decision;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision in project kie-wb-common by kiegroup.
the class DecisionConverter method nodeFromDMN.
@Override
public Node<View<Decision>, ?> nodeFromDMN(final NodeEntry nodeEntry) {
final JSITDecision dmn = Js.uncheckedCast(nodeEntry.getDmnElement());
@SuppressWarnings("unchecked") final Node<View<Decision>, ?> node = (Node<View<Decision>, ?>) factoryManager.newElement(nodeEntry.getId(), getDefinitionId(Decision.class)).asNode();
final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final Name name = new Name(dmn.getName());
final InformationItemPrimary informationItem = InformationItemPrimaryPropertyConverter.wbFromDMN(dmn.getVariable(), dmn);
Expression expression = null;
final JSITExpression jsiWrapped = dmn.getExpression();
if (Objects.nonNull(jsiWrapped)) {
final JSITExpression jsiExpression = Js.uncheckedCast(JsUtils.getUnwrappedElement(jsiWrapped));
expression = ExpressionPropertyConverter.wbFromDMN(jsiExpression, Js.uncheckedCast(dmn), nodeEntry.getComponentWidthsConsumer());
}
final Decision decision = new Decision(id, description, name, new Question(), new AllowedAnswers(), informationItem, expression, new StylingSet(), new GeneralRectangleDimensionsSet());
decision.setDiagramId(nodeEntry.getDiagramId());
decision.setQuestion(QuestionPropertyConverter.wbFromDMN(dmn.getQuestion()));
decision.setAllowedAnswers(AllowedAnswersPropertyConverter.wbFromDMN(dmn.getAllowedAnswers()));
node.getContent().setDefinition(decision);
if (Objects.nonNull(informationItem)) {
informationItem.setParent(decision);
}
if (Objects.nonNull(expression)) {
expression.setParent(decision);
}
DMNExternalLinksToExtensionElements.loadExternalLinksFromExtensionElements(dmn, decision);
return node;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method testMergeNodeRequirements.
@Test
public void testMergeNodeRequirements() {
final JSITDecision existingNode1 = makeDecision("id1");
final JSITBusinessKnowledgeModel existingNode2 = makeBusinessKnowledgeModel("id2");
final JSITKnowledgeSource existingNode3 = makeKnowledgeSource("id3");
final JSITDecision node1 = makeDecision("id1");
final JSITBusinessKnowledgeModel node2 = makeBusinessKnowledgeModel("id2");
final JSITKnowledgeSource node3 = makeKnowledgeSource("id3");
final JSITBusinessKnowledgeModel node4 = makeBusinessKnowledgeModel("id4");
final JSITKnowledgeSource node5 = makeKnowledgeSource("id5");
final DMNMarshaller dmnMarshaller = spy(new DMNMarshaller());
final JSITAuthorityRequirement node1AuthorityRequirement = mock(JSITAuthorityRequirement.class);
final JSITInformationRequirement node1InformationRequirement = mock(JSITInformationRequirement.class);
final JSITKnowledgeRequirement node1KnowledgeRequirement = mock(JSITKnowledgeRequirement.class);
final JSITAuthorityRequirement node2AuthorityRequirement = mock(JSITAuthorityRequirement.class);
final JSITKnowledgeRequirement node2KnowledgeRequirement = mock(JSITKnowledgeRequirement.class);
final JSITAuthorityRequirement node3AuthorityRequirement = mock(JSITAuthorityRequirement.class);
final List<JSITAuthorityRequirement> node1ExistingAuthorityRequirement = new ArrayList<>();
final List<JSITInformationRequirement> node1ExistingInformationRequirement = new ArrayList<>();
final List<JSITKnowledgeRequirement> node1ExistingKnowledgeRequirement = new ArrayList<>();
final List<JSITAuthorityRequirement> node2ExistingAuthorityRequirement = new ArrayList<>();
final List<JSITKnowledgeRequirement> node2ExistingKnowledgeRequirement = new ArrayList<>();
final List<JSITAuthorityRequirement> node3ExistingAuthorityRequirement = new ArrayList<>();
doReturn(node1).when(dmnMarshaller).getWrappedJSITDRGElement(eq(node1), any());
doReturn(node2).when(dmnMarshaller).getWrappedJSITDRGElement(eq(node2), any());
doReturn(node3).when(dmnMarshaller).getWrappedJSITDRGElement(eq(node3), any());
doReturn(node4).when(dmnMarshaller).getWrappedJSITDRGElement(eq(node4), any());
doReturn(node5).when(dmnMarshaller).getWrappedJSITDRGElement(eq(node5), any());
doReturn(true).when(dmnMarshaller).instanceOfDecision(eq(node1));
doReturn(true).when(dmnMarshaller).instanceOfBusinessKnowledgeModel(eq(node2));
doReturn(true).when(dmnMarshaller).instanceOfKnowledgeSource(eq(node3));
doReturn(true).when(dmnMarshaller).instanceOfBusinessKnowledgeModel(eq(node4));
doReturn(true).when(dmnMarshaller).instanceOfKnowledgeSource(eq(node5));
doReturn(node1ExistingAuthorityRequirement).when(existingNode1).getAuthorityRequirement();
doReturn(node1ExistingInformationRequirement).when(existingNode1).getInformationRequirement();
doReturn(node1ExistingKnowledgeRequirement).when(existingNode1).getKnowledgeRequirement();
doReturn(node2ExistingAuthorityRequirement).when(existingNode2).getAuthorityRequirement();
doReturn(node2ExistingKnowledgeRequirement).when(existingNode2).getKnowledgeRequirement();
doReturn(node3ExistingAuthorityRequirement).when(existingNode3).getAuthorityRequirement();
doReturn(new ArrayList<>(singletonList(node1AuthorityRequirement))).when(node1).getAuthorityRequirement();
doReturn(new ArrayList<>(singletonList(node1KnowledgeRequirement))).when(node1).getKnowledgeRequirement();
doReturn(new ArrayList<>(singletonList(node1InformationRequirement))).when(node1).getInformationRequirement();
doReturn(new ArrayList<>(singletonList(node2AuthorityRequirement))).when(node2).getAuthorityRequirement();
doReturn(new ArrayList<>(singletonList(node2KnowledgeRequirement))).when(node2).getKnowledgeRequirement();
doReturn(new ArrayList<>(singletonList(node3AuthorityRequirement))).when(node3).getAuthorityRequirement();
doAnswer((e) -> setList(node1ExistingAuthorityRequirement, e)).when(existingNode1).setAuthorityRequirement(any());
doAnswer((e) -> setList(node1ExistingInformationRequirement, e)).when(existingNode1).setInformationRequirement(any());
doAnswer((e) -> setList(node1ExistingKnowledgeRequirement, e)).when(existingNode1).setKnowledgeRequirement(any());
doAnswer((e) -> setList(node2ExistingAuthorityRequirement, e)).when(existingNode2).setAuthorityRequirement(any());
doAnswer((e) -> setList(node2ExistingKnowledgeRequirement, e)).when(existingNode2).setKnowledgeRequirement(any());
doAnswer((e) -> setList(node3ExistingAuthorityRequirement, e)).when(existingNode3).setAuthorityRequirement(any());
doAnswer((e) -> addAll(node1ExistingAuthorityRequirement, e)).when(existingNode1).addAllAuthorityRequirement(any());
doAnswer((e) -> addAll(node1ExistingInformationRequirement, e)).when(existingNode1).addAllInformationRequirement(any());
doAnswer((e) -> addAll(node1ExistingKnowledgeRequirement, e)).when(existingNode1).addAllKnowledgeRequirement(any());
doAnswer((e) -> addAll(node2ExistingAuthorityRequirement, e)).when(existingNode2).addAllAuthorityRequirement(any());
doAnswer((e) -> addAll(node2ExistingKnowledgeRequirement, e)).when(existingNode2).addAllKnowledgeRequirement(any());
doAnswer((e) -> addAll(node3ExistingAuthorityRequirement, e)).when(existingNode3).addAllAuthorityRequirement(any());
dmnMarshaller.mergeNodeRequirements(node1, existingNode1);
dmnMarshaller.mergeNodeRequirements(node2, existingNode2);
dmnMarshaller.mergeNodeRequirements(node3, existingNode3);
dmnMarshaller.mergeNodeRequirements(node4, existingNode2);
dmnMarshaller.mergeNodeRequirements(node5, existingNode3);
// Merge twice. But the values must be added once.
dmnMarshaller.mergeNodeRequirements(node1, existingNode1);
dmnMarshaller.mergeNodeRequirements(node2, existingNode2);
dmnMarshaller.mergeNodeRequirements(node3, existingNode3);
dmnMarshaller.mergeNodeRequirements(node4, existingNode2);
dmnMarshaller.mergeNodeRequirements(node5, existingNode3);
assertEquals(1, node1ExistingAuthorityRequirement.size());
assertEquals(1, node1ExistingInformationRequirement.size());
assertEquals(1, node1ExistingKnowledgeRequirement.size());
assertEquals(1, node2ExistingAuthorityRequirement.size());
assertEquals(1, node2ExistingKnowledgeRequirement.size());
assertEquals(1, node3ExistingAuthorityRequirement.size());
assertEquals(node1AuthorityRequirement, node1ExistingAuthorityRequirement.get(0));
assertEquals(node1InformationRequirement, node1ExistingInformationRequirement.get(0));
assertEquals(node1KnowledgeRequirement, node1ExistingKnowledgeRequirement.get(0));
assertEquals(node2AuthorityRequirement, node2ExistingAuthorityRequirement.get(0));
assertEquals(node2KnowledgeRequirement, node2ExistingKnowledgeRequirement.get(0));
assertEquals(node3AuthorityRequirement, node3ExistingAuthorityRequirement.get(0));
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method testGetExistingNode.
@Test
public void testGetExistingNode() {
final JSITDecision nodeDRGElement = makeDecision("id1");
final JSITDecision definitionsDRGElement1 = makeDecision("id1");
final JSITDecision definitionsDRGElement2 = makeDecision("id2");
final JSITDecision definitionsDRGElement3 = makeDecision("id3");
final DMNMarshaller dmnMarshaller = new DMNMarshaller();
final JSITDefinitions definitions = spy(new JSITDefinitions());
final List<JSITDRGElement> definitionsDRGElements = new ArrayList<>(asList(definitionsDRGElement1, definitionsDRGElement2, definitionsDRGElement3));
doReturn(definitionsDRGElements).when(definitions).getDrgElement();
final Optional<JSITDRGElement> existingNode = dmnMarshaller.getExistingNode(definitions, nodeDRGElement);
assertTrue(existingNode.isPresent());
assertEquals(definitionsDRGElement1, existingNode.get());
}
Aggregations