use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.
the class DMNIncludedModelsServiceImplTest method testLoadModelsWhenWorkspaceProjectIsNotNull.
@Test
public void testLoadModelsWhenWorkspaceProjectIsNotNull() throws Exception {
final WorkspaceProject workspaceProject = mock(WorkspaceProject.class);
final Path rootPath = mock(Path.class);
final String uri = "/src/path/file.dmn";
final Path path1 = mock(Path.class);
final Path path2 = mock(Path.class);
final Path path3 = mock(Path.class);
final IncludedModel includedModel1 = mock(IncludedModel.class);
final IncludedModel includedModel2 = mock(IncludedModel.class);
when(workspaceProject.getRootPath()).thenReturn(rootPath);
when(rootPath.toURI()).thenReturn(uri);
when(pathsHelper.getModelsPaths(workspaceProject)).thenReturn(asList(path1, path2, path3));
when(includedModelFactory.create(dmnModelPath, path1)).thenReturn(includedModel1);
when(includedModelFactory.create(dmnModelPath, path2)).thenReturn(includedModel2);
when(includedModelFactory.create(dmnModelPath, path3)).thenThrow(new DMNIncludeModelCouldNotBeCreatedException());
final List<IncludedModel> includedModels = service.loadModels(dmnModelPath, workspaceProject);
assertEquals(2, includedModels.size());
assertEquals(includedModel1, includedModels.get(0));
assertEquals(includedModel2, includedModels.get(1));
}
use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.
the class DMNIncludedModelsServiceImplTest method testLoadModelsWhenWorkspaceProjectIsNull.
@Test
public void testLoadModelsWhenWorkspaceProjectIsNull() throws Exception {
final WorkspaceProject workspaceProject = null;
final Path path1 = mock(Path.class);
final Path path2 = mock(Path.class);
final Path path3 = mock(Path.class);
final IncludedModel includedModel1 = mock(IncludedModel.class);
final IncludedModel includedModel2 = mock(IncludedModel.class);
when(pathsHelper.getModelsPaths(workspaceProject)).thenReturn(asList(path1, path2, path3));
when(includedModelFactory.create(dmnModelPath, path1)).thenReturn(includedModel1);
when(includedModelFactory.create(dmnModelPath, path2)).thenReturn(includedModel2);
when(includedModelFactory.create(dmnModelPath, path3)).thenThrow(new DMNIncludeModelCouldNotBeCreatedException());
final List<IncludedModel> includedModels = service.loadModels(dmnModelPath, workspaceProject);
assertEquals(2, includedModels.size());
assertEquals(includedModel1, includedModels.get(0));
assertEquals(includedModel2, includedModels.get(1));
}
use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.
the class DMNIncludedNodeFactoryTest method testMakeDMNIncludeModel.
@Test
public void testMakeDMNIncludeModel() {
final Path path = mock(Path.class);
final IncludedModel includedModel = mock(IncludedModel.class);
final String drgElementId = "0000-1111-3333-4444";
final String drgElementName = "Can Drive?";
final String expectedFileName = "file.dmn";
final String expectedModelName = "model";
final String expectedImportedElementId = "0000-1111-3333-4444";
final String expectedImportedElementName = "model.Can Drive?";
final String expectedImportedItemDefinitionName = "model.tCustomBoolean";
final DRGElement importedElementId = makeDecision(drgElementId, drgElementName, "tCustomBoolean");
when(path.getFileName()).thenReturn(expectedFileName);
when(includedModel.getModelName()).thenReturn(expectedModelName);
final DMNIncludedNode node = factory.makeDMNIncludeModel(path, includedModel, importedElementId);
final Decision drgElement = (Decision) node.getDrgElement();
assertEquals(expectedImportedElementId, drgElement.getId().getValue());
assertEquals(expectedImportedElementName, drgElement.getName().getValue());
assertEquals(expectedImportedItemDefinitionName, drgElement.getVariable().getTypeRef().getLocalPart());
assertEquals(expectedFileName, node.getFileName());
assertTrue(drgElement.isAllowOnlyVisualChange());
}
use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.
the class IncludedModelFactoryTest method testCreatePMML.
@Test
public void testCreatePMML() throws Exception {
final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
final Package aPackage = mock(Package.class);
final String packageName = "com.kie.pmml";
final String fileName = "file.pmml";
final String uri = "/src/main/java/com/kie/pmml/file.pmml";
final Integer expectedModelsCount = 2;
when(aPackage.getPackageName()).thenReturn(packageName);
when(includedModelPath.getFileName()).thenReturn(fileName);
when(moduleService.resolvePackage(includedModelPath)).thenReturn(aPackage);
when(importTypesHelper.isDMN(includedModelPath)).thenReturn(false);
when(importTypesHelper.isPMML(includedModelPath)).thenReturn(true);
when(pathsHelper.getRelativeURI(dmnModelPath, includedModelPath)).thenReturn(uri);
when(pmmlDocumentFactory.getDocumentByPath(includedModelPath)).thenReturn(pmmlDocument);
when(pmmlDocument.getModels()).thenReturn(asList(mock(PMMLModelMetadata.class), mock(PMMLModelMetadata.class)));
final IncludedModel includedModel = factory.create(dmnModelPath, includedModelPath);
assertTrue(includedModel instanceof PMMLIncludedModel);
final PMMLIncludedModel pmmlIncludedModel = (PMMLIncludedModel) includedModel;
assertEquals(packageName, includedModel.getModelPackage());
assertEquals(fileName, includedModel.getModelName());
assertEquals(uri, includedModel.getPath());
assertEquals(expectedModelsCount, pmmlIncludedModel.getModelCount());
}
use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method loadModels.
public void loadModels(final ServiceCallback<List<IncludedModel>> callback) {
final List<IncludedModel> models = new ArrayList<>();
dmnImportsContentService.getModelsURIs().then(items -> promises.all(Arrays.asList(items), file -> {
final String fileName = FileUtils.getFileName(file);
if (fileName.endsWith("." + DMNImportTypes.DMN.getFileExtension())) {
return dmnImportsContentService.loadFile(file).then(fileContent -> promises.create((success, failed) -> dmnImportsService.getWbDefinitions(fileContent, new ServiceCallback<Definitions>() {
@Override
public void onSuccess(final Definitions definitions) {
final String modelPackage = "";
final String namespace = definitions.getNamespace().getValue();
final String importType = DMNImportTypes.DMN.getDefaultNamespace();
final int drgElementCount = definitions.getDrgElement().size();
final int itemDefinitionCount = definitions.getItemDefinition().size();
models.add(new DMNIncludedModel(fileName, modelPackage, fileName, namespace, importType, drgElementCount, itemDefinitionCount));
success.onInvoke(promises.resolve());
}
@Override
public void onError(final ClientRuntimeError error) {
// Swallow. Since it must try to load other paths.
success.onInvoke(promises.resolve());
}
})));
}
if (fileName.endsWith("." + DMNImportTypes.PMML.getFileExtension())) {
return dmnImportsContentService.getPMMLDocumentMetadata(file).then(pmmlDocumentMetadata -> {
int modelCount = pmmlDocumentMetadata.getModels() != null ? pmmlDocumentMetadata.getModels().size() : 0;
models.add(new PMMLIncludedModel(fileName, "", fileName, DMNImportTypes.PMML.getDefaultNamespace(), modelCount));
return promises.resolve();
});
}
return promises.reject("Error: " + fileName + " is an invalid file. Only *.dmn and *.pmml are supported");
}).then(v -> {
callback.onSuccess(models);
return promises.resolve();
}));
}
Aggregations