use of org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord in project kie-wb-common by kiegroup.
the class ImportRecordEngineTest method testIsValidWhenNameIsUnique.
@Test
public void testIsValidWhenNameIsUnique() {
final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
final Import import1 = mock(Import.class);
final Import import2 = mock(Import.class);
final Name name1 = mock(Name.class);
final Name name2 = mock(Name.class);
final FlashMessage flashMessage = mock(FlashMessage.class);
final List<Import> imports = new ArrayList<>(asList(import1, import2));
when(name1.getValue()).thenReturn("file1");
when(name2.getValue()).thenReturn("file2");
when(record.getName()).thenReturn("file-new");
when(import1.getName()).thenReturn(name1);
when(import2.getName()).thenReturn(name2);
when(includedModelsIndex.getImport(record)).thenReturn(import2);
when(stateProvider.getImports()).thenReturn(imports);
when(messageFactory.getNameIsNotUniqueFlashMessage(record)).thenReturn(flashMessage);
final boolean valid = recordEngine.isValid(record);
assertTrue(valid);
verifyZeroInteractions(flashMessageEvent);
}
use of org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord in project kie-wb-common by kiegroup.
the class ImportRecordEngineTest method testIsValidWhenNameIsUnchanged.
@Test
public void testIsValidWhenNameIsUnchanged() {
final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
final Import import1 = mock(Import.class);
final Import import2 = mock(Import.class);
final Name name1 = mock(Name.class);
final Name name2 = mock(Name.class);
final FlashMessage flashMessage = mock(FlashMessage.class);
final List<Import> imports = new ArrayList<>(asList(import1, import2));
when(name1.getValue()).thenReturn("file1");
when(name2.getValue()).thenReturn("file2");
when(record.getName()).thenReturn("file2");
when(import1.getName()).thenReturn(name1);
when(import2.getName()).thenReturn(name2);
when(includedModelsIndex.getImport(record)).thenReturn(import2);
when(stateProvider.getImports()).thenReturn(imports);
when(messageFactory.getNameIsNotUniqueFlashMessage(record)).thenReturn(flashMessage);
final boolean valid = recordEngine.isValid(record);
assertTrue(valid);
verifyZeroInteractions(flashMessageEvent);
}
use of org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord in project kie-wb-common by kiegroup.
the class ImportRecordEngineTest method testIsValidWhenNameIsBlank.
@Test
public void testIsValidWhenNameIsBlank() {
final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
final Import anImport = mock(Import.class);
final Name name = mock(Name.class);
final FlashMessage flashMessage = mock(FlashMessage.class);
final List<Import> imports = new ArrayList<>(singletonList(anImport));
when(name.getValue()).thenReturn("file");
when(record.getName()).thenReturn("");
when(anImport.getName()).thenReturn(name);
when(includedModelsIndex.getImport(record)).thenReturn(anImport);
when(stateProvider.getImports()).thenReturn(imports);
when(messageFactory.getNameIsBlankFlashMessage(record)).thenReturn(flashMessage);
final boolean valid = recordEngine.isValid(record);
assertFalse(valid);
verify(flashMessageEvent).fire(flashMessage);
}
use of org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord in project kie-wb-common by kiegroup.
the class IncludedModelModalTest method testIncludePMML.
@Test
public void testIncludePMML() {
final String path = "path";
final String name = "name";
final String namespace = "namespace";
final int modelCount = 2;
final KieAssetsDropdownItem dropdownItem = mock(KieAssetsDropdownItem.class);
when(view.getModelNameInput()).thenReturn(name);
when(dropdown.getValue()).thenReturn(Optional.of(dropdownItem));
when(dropdownItem.getValue()).thenReturn(namespace);
when(dropdownItem.getMetaData()).thenReturn(new Maps.Builder<String, String>().put(PATH_METADATA, path).put(IMPORT_TYPE_METADATA, DMNImportTypes.PMML.getDefaultNamespace()).put(PMML_MODEL_COUNT_METADATA, Integer.toString(modelCount)).build());
doNothing().when(modal).hide();
modal.include();
verify(modal).createIncludedModel(dropdownItem);
verify(grid).refresh();
verify(modal).hide();
verify(refreshDecisionComponentsEvent).fire(any(RefreshDecisionComponents.class));
verify(modal).refreshDataTypesList(includedModelActiveRecordArgumentCaptor.capture());
final BaseIncludedModelActiveRecord baseActiveRecord = includedModelActiveRecordArgumentCaptor.getValue();
assertTrue(baseActiveRecord instanceof PMMLIncludedModelActiveRecord);
final PMMLIncludedModelActiveRecord pmmlActiveRecord = (PMMLIncludedModelActiveRecord) baseActiveRecord;
assertEquals(path, pmmlActiveRecord.getPath());
assertEquals(name, pmmlActiveRecord.getName());
assertEquals(namespace, pmmlActiveRecord.getNamespace());
assertEquals(modelCount, (int) pmmlActiveRecord.getModelCount());
}
use of org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord in project kie-wb-common by kiegroup.
the class IncludedModelModalTest method testRefreshDataTypesList.
@Test
public void testRefreshDataTypesList() {
final BaseIncludedModelActiveRecord includedModel = mock(BaseIncludedModelActiveRecord.class);
final Consumer<List<ItemDefinition>> listConsumer = list -> {
/* Nothing. */
};
final String modelName = "model1";
final String namespace = "://namespace1";
when(includedModel.getName()).thenReturn(modelName);
when(includedModel.getNamespace()).thenReturn(namespace);
doReturn(listConsumer).when(modal).getItemDefinitionConsumer();
modal.refreshDataTypesList(includedModel);
verify(client).loadItemDefinitionsByNamespace(modelName, namespace, listConsumer);
}
Aggregations