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);
}
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());
}
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());
}
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);
}
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);
});
}
Aggregations