Search in sources :

Example 36 with ItemDefinition

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

the class ItemDefinitionUtilsTest method testFindByName.

@Test
public void testFindByName() {
    final String name = "item1";
    final ItemDefinition item1 = makeItem("item1");
    final ItemDefinition item2 = makeItem("item2");
    final Definitions definitions = mock(Definitions.class);
    final List<ItemDefinition> itemDefinitions = asList(item1, item2);
    when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions);
    when(definitions.getItemDefinition()).thenReturn(itemDefinitions);
    final Optional<ItemDefinition> actual = utils.findByName(name);
    final Optional<ItemDefinition> expected = Optional.of(item1);
    assertEquals(expected, actual);
}
Also used : Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Test(org.junit.Test)

Example 37 with ItemDefinition

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

the class ItemDefinitionUtilsTest method testGetConstraintTextWhenItemDefinitionHasAllowedValues.

@Test
public void testGetConstraintTextWhenItemDefinitionHasAllowedValues() {
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final UnaryTests allowedValues = mock(UnaryTests.class);
    final String expectedText = "(1..10)";
    when(allowedValues.getText()).thenReturn(new Text(expectedText));
    when(itemDefinition.getAllowedValues()).thenReturn(allowedValues);
    final String actualText = utils.getConstraintText(itemDefinition);
    assertEquals(expectedText, actualText);
}
Also used : 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) Test(org.junit.Test)

Example 38 with ItemDefinition

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

the class ItemDefinitionStoreTest method testIndex.

@Test
public void testIndex() {
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final String uuid = "789";
    store.index(uuid, itemDefinition);
    assertEquals(itemDefinition, store.get(uuid));
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Test(org.junit.Test)

Example 39 with ItemDefinition

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

the class DataTypeUpdateHandlerTest method testRefreshSubDataType.

@Test
public void testRefreshSubDataType() {
    final DataType dataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final String newType = "newType";
    final String type = "type";
    final String uuid = "uuid";
    when(dataType.getType()).thenReturn(type);
    when(dataType.getUUID()).thenReturn(uuid);
    when(itemDefinitionStore.get(uuid)).thenReturn(itemDefinition);
    when(dataTypeManager.from(dataType)).thenReturn(dataTypeManager);
    when(dataTypeManager.withType(newType)).thenReturn(dataTypeManager);
    handler.refreshSubDataType(dataType, newType);
    final InOrder inOrder = Mockito.inOrder(dataTypeManager, dataTypeManager, recordEngine, handler);
    inOrder.verify(dataTypeManager).from(dataType);
    inOrder.verify(dataTypeManager).withType(newType);
    inOrder.verify(recordEngine).doUpdate(dataType, itemDefinition);
}
Also used : InOrder(org.mockito.InOrder) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 40 with ItemDefinition

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

the class ItemDefinitionDestroyHandlerTest method testDestroy.

@Test
public void testDestroy() {
    final String uuid = "uuid";
    final String oldItemDefinitionName = "oldItemDefinitionName";
    final DataType dataType = mock(DataType.class);
    final Name name = mock(Name.class);
    final ItemDefinition itemDefinition = makeItemDefinition();
    final ItemDefinition itemDefinitionParent = makeItemDefinition(itemDefinition);
    final List<ItemDefinition> itemDefinitions = new ArrayList<ItemDefinition>() {

        {
            add(itemDefinition);
        }
    };
    when(name.getValue()).thenReturn(oldItemDefinitionName);
    when(itemDefinitionStore.get(uuid)).thenReturn(itemDefinition);
    when(dataType.getUUID()).thenReturn(uuid);
    doReturn(Optional.of(itemDefinitionParent)).when(handler).findItemDefinitionParent(dataType);
    doReturn(name).when(itemDefinition).getName();
    doReturn(itemDefinitions).when(handler).itemDefinitions();
    doNothing().when(handler).notifyPropertiesPanel(Mockito.<String>any());
    handler.destroy(dataType, true);
    assertEquals(emptyList(), itemDefinitionParent.getItemComponent());
    assertEquals(emptyList(), itemDefinitions);
    verify(handler).notifyPropertiesPanel(oldItemDefinitionName);
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) ArrayList(java.util.ArrayList) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Test(org.junit.Test)

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