use of org.kie.workbench.common.dmn.api.definition.model.Import in project kie-wb-common by kiegroup.
the class HrefBuilderTest method testGetHrefForImportedDRGElementWhenImportHasAnOddName.
@Test
public void testGetHrefForImportedDRGElementWhenImportHasAnOddName() {
final DRGElement drgElement = mock(DRGElement.class);
final Name drgElementName = mock(Name.class);
final Name importName = mock(Name.class);
final Id id = mock(Id.class);
final Definitions definitions = mock(Definitions.class);
final Import anImport = mock(Import.class);
final List<Import> imports = singletonList(anImport);
final String includedModelName = "d.i.v.i.";
when(importName.getValue()).thenReturn(includedModelName);
when(anImport.getName()).thenReturn(importName);
when(anImport.getNamespace()).thenReturn("https://github.com/kiegroup/dmn/something");
when(id.getValue()).thenReturn("0000-1111-2222");
when(drgElementName.getValue()).thenReturn(includedModelName + ".Decision");
when(drgElement.getId()).thenReturn(id);
when(drgElement.getName()).thenReturn(drgElementName);
when(drgElement.getParent()).thenReturn(definitions);
when(definitions.getImport()).thenReturn(imports);
final String actual = HrefBuilder.getHref(drgElement);
final String expected = "https://github.com/kiegroup/dmn/something#0000-1111-2222";
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.definition.model.Import in project kie-wb-common by kiegroup.
the class DMNDomainValidatorImplTest method testImportedModelValidation.
@Test
@SuppressWarnings("unchecked")
public void testImportedModelValidation() throws IOException {
final StringReader stringReader1 = mock(StringReader.class);
final StringReader stringReader2 = mock(StringReader.class);
doReturn(resolver).when(domainValidator).getValidatorImportReaderResolver(metadata);
doReturn(stringReader1, stringReader2).when(domainValidator).getStringReader(Mockito.any());
definitions.getImport().add(new Import());
when(importsHelper.getImportXML(eq(metadata), Mockito.<List>any())).thenAnswer(i -> {
final Map<org.kie.dmn.model.api.Import, String> importedModels = new HashMap<>();
final List<org.kie.dmn.model.api.Import> imports = (List) i.getArguments()[1];
importedModels.put(imports.get(0), IMPORTED_DMN_XML);
return importedModels;
});
domainValidator.validate(diagram, resultConsumer);
verify(dmnMarshaller).marshall(diagram);
verify(dmnDiagramUtils).getDefinitions(diagram);
verify(dmnValidator).validateUsing(DMNValidator.Validation.VALIDATE_MODEL, DMNValidator.Validation.VALIDATE_COMPILATION, DMNValidator.Validation.ANALYZE_DECISION_TABLE);
verify(domainValidator).getStringReader(DMN_XML);
verify(domainValidator).getStringReader(IMPORTED_DMN_XML);
verify(dmnValidatorBuilder).usingImports(resolver);
verify(dmnValidatorBuilder).theseModels(readerArgumentCaptor.capture());
assertThat(readerArgumentCaptor.getAllValues()).containsExactly(stringReader1, stringReader2);
verify(resultConsumer).accept(Collections.emptyList());
}
use of org.kie.workbench.common.dmn.api.definition.model.Import in project kie-wb-common by kiegroup.
the class ImportRecordEngineTest method testCreate.
@Test
public void testCreate() {
final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
final Import import1 = mock(Import.class);
final Import import2 = mock(Import.class);
final Import import3 = mock(Import.class);
final List<Import> expectedImports = asList(import1, import2, import3);
final List<Import> actualImports = new ArrayList<>(asList(import1, import2));
when(importFactory.makeImport(record)).thenReturn(import3);
when(stateProvider.getImports()).thenReturn(actualImports);
final List<BaseIncludedModelActiveRecord> actualResult = recordEngine.create(record);
final List<BaseIncludedModelActiveRecord> expectedResult = singletonList(record);
verify(definitionsHandler).create(record);
assertEquals(expectedImports, actualImports);
assertEquals(expectedResult, actualResult);
}
use of org.kie.workbench.common.dmn.api.definition.model.Import in project kie-wb-common by kiegroup.
the class ImportRecordEngineTest method testUpdateWhenIncludedModelIsValid.
@Test
public void testUpdateWhenIncludedModelIsValid() {
final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
final ArgumentCaptor<Name> nameCaptor = ArgumentCaptor.forClass(Name.class);
final Import anImport = mock(Import.class);
final String name = "name";
final String oldName = "oldName";
when(record.getName()).thenReturn(name);
when(record.isValid()).thenReturn(true);
when(includedModelsIndex.getImport(record)).thenReturn(anImport);
when(anImport.getName()).thenReturn(new Name(oldName));
final List<BaseIncludedModelActiveRecord> actualResult = recordEngine.update(record);
final List<BaseIncludedModelActiveRecord> expectedResult = singletonList(record);
verify(anImport).setName(nameCaptor.capture());
verify(itemDefinitionHandler).update(oldName, name);
verify(dmnIncludedModelHandler).update(oldName, name);
verify(pmmlIncludedModelHandler).update(oldName, name);
final Name actualName = nameCaptor.getValue();
final Name expectedName = new Name(name);
assertEquals(expectedName, actualName);
assertEquals(expectedResult, actualResult);
}
use of org.kie.workbench.common.dmn.api.definition.model.Import 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);
}
Aggregations