Search in sources :

Example 26 with ItemDefinition

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

the class ItemDefinitionPropertyConverterTest method testSetUnaryTestsWhenUnaryTestsIsNull.

@Test
public void testSetUnaryTestsWhenUnaryTestsIsNull() {
    final ItemDefinition wb = mock(ItemDefinition.class);
    final UnaryTests wbAllowedValues = mock(UnaryTests.class);
    final org.kie.dmn.model.api.ItemDefinition dmn = mock(org.kie.dmn.model.api.ItemDefinition.class);
    final org.kie.dmn.model.api.UnaryTests dmnAllowedValues = null;
    when(dmn.getAllowedValues()).thenReturn(dmnAllowedValues);
    setUnaryTests(wb, dmn);
    verify(wb, never()).setAllowedValues(wbAllowedValues);
    verify(wbAllowedValues, never()).setParent(wb);
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) ItemDefinitionPropertyConverter.setUnaryTests(org.kie.workbench.common.dmn.backend.definition.v1_1.ItemDefinitionPropertyConverter.setUnaryTests) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) Test(org.junit.Test)

Example 27 with ItemDefinition

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

the class ItemDefinitionPropertyConverterTest method testWbFromDMNWhenDMNIsNotNull.

@Test
public void testWbFromDMNWhenDMNIsNotNull() {
    final org.kie.dmn.model.api.ItemDefinition dmn = mock(org.kie.dmn.model.api.ItemDefinition.class);
    final String id = "id";
    final String name = "name";
    final Id expectedId = new Id(id);
    final Name expectedName = new Name(name);
    final String expectedTypeLanguage = "typeLanguage";
    final boolean expectedIsCollection = true;
    final String description = "description";
    final boolean expectedAllowOnlyVisualChange = false;
    final String qNameNamespaceURI = "qName namespaceURI";
    final String qNameLocalPart = "qName local part";
    final String qNamePrefix = "qName prefix";
    final Description expectedDescription = new Description(description);
    final javax.xml.namespace.QName expectedTypeRef = new javax.xml.namespace.QName(qNameNamespaceURI, qNameLocalPart, qNamePrefix);
    when(dmn.getId()).thenReturn(id);
    when(dmn.getName()).thenReturn(name);
    when(dmn.getTypeLanguage()).thenReturn(expectedTypeLanguage);
    when(dmn.isIsCollection()).thenReturn(expectedIsCollection);
    when(dmn.getDescription()).thenReturn(description);
    when(dmn.getTypeRef()).thenReturn(expectedTypeRef);
    final ItemDefinition actualItemDefinition = wbFromDMN(dmn);
    final Id actualId = actualItemDefinition.getId();
    final Name actualName = actualItemDefinition.getName();
    final String actualTypeLanguage = actualItemDefinition.getTypeLanguage();
    final boolean actualIsCollection = actualItemDefinition.isIsCollection();
    final Description actualDescription = actualItemDefinition.getDescription();
    final QName actualTypeRef = actualItemDefinition.getTypeRef();
    final boolean actualAllowOnlyVisualChange = actualItemDefinition.isAllowOnlyVisualChange();
    assertEquals(expectedId, actualId);
    assertEquals(expectedName, actualName);
    assertEquals(expectedTypeLanguage, actualTypeLanguage);
    assertEquals(expectedIsCollection, actualIsCollection);
    assertEquals(expectedDescription, actualDescription);
    assertEquals(expectedAllowOnlyVisualChange, actualAllowOnlyVisualChange);
    assertEquals(expectedTypeRef.getLocalPart(), actualTypeRef.getLocalPart());
    assertEquals(expectedTypeRef.getPrefix(), actualTypeRef.getPrefix());
    assertEquals(expectedTypeRef.getNamespaceURI(), actualTypeRef.getNamespaceURI());
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Test(org.junit.Test)

Example 28 with ItemDefinition

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

the class DMNDocumentationFactoryTest method testCreate.

@Test
public void testCreate() {
    final String diagramName = "Diagram name";
    final String diagramDescription = "Diagram description";
    final String image = "<image>";
    final String admin = "admin";
    final String currentDate = "2 January 1992";
    final String namespace = "://namespace";
    final String expectedDroolsLogo = "droolsLogo";
    final String expectedSupportedByRedHatLogo = "supportedByRedHatLogo";
    final List<DRGElement> drgElements = singletonList(mock(DRGElement.class));
    final ItemDefinition uuid = makeItemDefinition("tUUID", "String");
    final ItemDefinition id = makeItemDefinition("id", "tUUID");
    final ItemDefinition name = makeItemDefinition("name", "String");
    final ItemDefinition person = makeItemDefinition("tPerson", null, id, name);
    final List<ItemDefinition> itemDefinitions = asList(uuid, person);
    final UnaryTests unaryTests = new UnaryTests();
    unaryTests.setText(new Text("[1, 2, 3]"));
    id.setAllowedValues(unaryTests);
    id.setIsCollection(true);
    doReturn(image).when(documentationFactory).getDiagramImage();
    doReturn(i18n).when(documentationFactory).getDocumentationI18n();
    doReturn(moment).when(documentationFactory).moment();
    when(definitions.getNamespace()).thenReturn(new Text(namespace));
    when(graphUtils.getDefinitions(diagram)).thenReturn(definitions);
    when(definitions.getName()).thenReturn(new Name(diagramName));
    when(definitions.getDescription()).thenReturn(new Description(diagramDescription));
    when(graphUtils.getDRGElements(diagram)).thenReturn(drgElements);
    when(definitions.getItemDefinition()).thenReturn(itemDefinitions);
    when(sessionInfo.getIdentity()).thenReturn(user);
    when(user.getIdentifier()).thenReturn(admin);
    when(moment.format("D MMMM YYYY")).thenReturn(currentDate);
    final DMNDocumentation documentation = documentationFactory.create(diagram);
    assertEquals(namespace, documentation.getNamespace());
    assertEquals(diagramName, documentation.getDiagramName());
    assertEquals(diagramDescription, documentation.getDiagramDescription());
    assertEquals(image, documentation.getDiagramImage());
    assertEquals(admin, documentation.getCurrentUser());
    assertEquals(currentDate, documentation.getCurrentDate());
    assertEquals(expectedDroolsLogo, documentation.getDroolsLogoURI());
    assertEquals(expectedSupportedByRedHatLogo, documentation.getSupportedByRedHatLogoURI());
    assertEquals(i18n, documentation.getI18n());
    assertNotNull(documentation.getModuleName());
    assertNotNull(documentation.getDataTypes());
    assertTrue(documentation.hasGraphNodes());
    final List<DMNDocumentationDataType> dataTypes = documentation.getDataTypesList();
    assertEquals(4, dataTypes.size());
    assertEquals("", dataTypes.get(0).getConstraint());
    assertEquals("tUUID", dataTypes.get(0).getName());
    assertEquals("String", dataTypes.get(0).getType());
    assertEquals("", dataTypes.get(0).getListLabel());
    assertEquals(0, dataTypes.get(0).getLevel());
    assertTrue(dataTypes.get(0).isTopLevel());
    assertEquals("", dataTypes.get(1).getConstraint());
    assertEquals("tPerson", dataTypes.get(1).getName());
    assertEquals("Structure", dataTypes.get(1).getType());
    assertEquals("", dataTypes.get(1).getListLabel());
    assertEquals(0, dataTypes.get(1).getLevel());
    assertTrue(dataTypes.get(1).isTopLevel());
    assertEquals("Constraints: [1, 2, 3]", dataTypes.get(2).getConstraint());
    assertEquals("id", dataTypes.get(2).getName());
    assertEquals("tUUID", dataTypes.get(2).getType());
    assertEquals("List: Yes", dataTypes.get(2).getListLabel());
    assertEquals(1, dataTypes.get(2).getLevel());
    assertFalse(dataTypes.get(2).isTopLevel());
    assertEquals("", dataTypes.get(3).getConstraint());
    assertEquals("name", dataTypes.get(3).getName());
    assertEquals("String", dataTypes.get(3).getType());
    assertEquals("", dataTypes.get(3).getListLabel());
    assertEquals(1, dataTypes.get(3).getLevel());
    assertFalse(dataTypes.get(3).isTopLevel());
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Test(org.junit.Test)

Example 29 with ItemDefinition

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

the class DMNIncludedModelsServiceImplTest method testLoadItemDefinitionsByNamespace.

@Test
public void testLoadItemDefinitionsByNamespace() {
    final WorkspaceProject workspaceProject = mock(WorkspaceProject.class);
    final String modelName = "model1";
    final String namespace = "://namespace";
    final org.kie.dmn.model.api.ItemDefinition itemDefinition1 = mock(org.kie.dmn.model.api.ItemDefinition.class);
    final org.kie.dmn.model.api.ItemDefinition itemDefinition2 = mock(org.kie.dmn.model.api.ItemDefinition.class);
    final org.kie.dmn.model.api.ItemDefinition itemDefinition3 = mock(org.kie.dmn.model.api.ItemDefinition.class);
    final ItemDefinition wbItemDefinition1 = mock(ItemDefinition.class);
    final ItemDefinition wbItemDefinition2 = mock(ItemDefinition.class);
    final ItemDefinition wbItemDefinition3 = mock(ItemDefinition.class);
    final List<org.kie.dmn.model.api.ItemDefinition> itemDefinitions = asList(itemDefinition1, itemDefinition2, itemDefinition3);
    doReturn(wbItemDefinition1).when(service).wbFromDMN(itemDefinition1, modelName);
    doReturn(wbItemDefinition2).when(service).wbFromDMN(itemDefinition2, modelName);
    doReturn(wbItemDefinition3).when(service).wbFromDMN(itemDefinition3, modelName);
    when(importsHelper.getImportedItemDefinitionsByNamespace(workspaceProject, modelName, namespace)).thenReturn(itemDefinitions);
    final List<ItemDefinition> actualItemDefinitions = service.loadItemDefinitionsByNamespace(workspaceProject, modelName, namespace);
    final List<ItemDefinition> expectedItemDefinitions = asList(wbItemDefinition1, wbItemDefinition2, wbItemDefinition3);
    assertEquals(expectedItemDefinitions, actualItemDefinitions);
}
Also used : WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Test(org.junit.Test)

Example 30 with ItemDefinition

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

the class DMNMarshallerImportsClientHelper method getImportedItemDefinitionsByNamespaceAsync.

public void getImportedItemDefinitionsByNamespaceAsync(final String modelName, final String namespace, final ServiceCallback<List<ItemDefinition>> callback) {
    loadDMNDefinitions().then(definitions -> {
        final List<ItemDefinition> result = new ArrayList<>();
        for (final Map.Entry<String, JSITDefinitions> entry : definitions.entrySet()) {
            final JSITDefinitions definition = Js.uncheckedCast(entry.getValue());
            if (Objects.equals(definition.getNamespace(), namespace)) {
                final List<JSITItemDefinition> items = definition.getItemDefinition();
                for (int j = 0; j < items.size(); j++) {
                    final JSITItemDefinition jsitItemDefinition = Js.uncheckedCast(items.get(j));
                    final ItemDefinition converted = ImportedItemDefinitionPropertyConverter.wbFromDMN(jsitItemDefinition, modelName);
                    result.add(converted);
                }
            }
        }
        result.sort(Comparator.comparing(o -> o.getName().getValue()));
        callback.onSuccess(result);
        return promises.resolve(result);
    });
}
Also used : JSITInvocable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocable) Arrays(java.util.Arrays) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) JSITDMNElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElement) Promises(org.uberfire.client.promise.Promises) JSITInputData(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputData) BuiltInTypeUtils.isBuiltInType(org.kie.workbench.common.dmn.api.editors.types.BuiltInTypeUtils.isBuiltInType) HashMap(java.util.HashMap) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) Promise(elemental2.promise.Promise) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) Js(jsinterop.base.Js) Map(java.util.Map) JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) DMNMarshallerImportsHelper(org.kie.workbench.common.dmn.api.marshalling.DMNMarshallerImportsHelper) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) StringUtils.isEmpty(org.kie.workbench.common.stunner.core.util.StringUtils.isEmpty) DMNIncludedNode(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedNode) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JSITInformationItem(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) FileUtils(org.kie.workbench.common.stunner.core.util.FileUtils) List(java.util.List) ImportedItemDefinitionPropertyConverter(org.kie.workbench.common.dmn.client.marshaller.converters.ImportedItemDefinitionPropertyConverter) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) DMNImportTypes(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes) ImportedItemDefinitionPropertyConverter.withNamespace(org.kie.workbench.common.dmn.client.marshaller.converters.ImportedItemDefinitionPropertyConverter.withNamespace) Optional(java.util.Optional) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) QName(javax.xml.namespace.QName) Comparator(java.util.Comparator) Collections(java.util.Collections) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)

Aggregations

ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)119 Test (org.junit.Test)86 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)39 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)37 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)36 ArrayList (java.util.ArrayList)18 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)16 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)9 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)7 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)7 JSITItemDefinition (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)7 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)6 DataTypeManager (org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager)6 QName (javax.xml.namespace.QName)4 Import (org.kie.workbench.common.dmn.api.definition.model.Import)4 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)4 RefreshDataTypesListEvent (org.kie.workbench.common.dmn.client.editors.types.common.events.RefreshDataTypesListEvent)4 DMNGraphUtils (org.kie.workbench.common.dmn.client.graph.DMNGraphUtils)4 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)3