@Test public void testCreateDMN() throws Exception { final Package aPackage = mock(Package.class); final String packageName = "com.kie.dmn"; final String fileName = "file.dmn"; final String uri = "/src/main/java/com/kie/dmn/file.dmn"; final Integer expectedDrgElementsCount = 2; final Integer expectedItemDefinitionsCount = 3; when(aPackage.getPackageName()).thenReturn(packageName); when(includedModelPath.getFileName()).thenReturn(fileName); when(includedModelPath.toURI()).thenReturn(uri); when(moduleService.resolvePackage(includedModelPath)).thenReturn(aPackage); when(importTypesHelper.isDMN(includedModelPath)).thenReturn(true); when(importTypesHelper.isPMML(includedModelPath)).thenReturn(false); when(dmnDiagramHelper.getDiagramByPath(includedModelPath)).thenReturn(diagram); when(dmnDiagramHelper.getNamespace(diagram)).thenReturn(NAMESPACE); when(dmnDiagramHelper.getNodes(diagram)).thenReturn(asList(mock(DRGElement.class), mock(DRGElement.class))); when(dmnDiagramHelper.getItemDefinitions(diagram)).thenReturn(asList(mock(ItemDefinition.class), mock(ItemDefinition.class), mock(ItemDefinition.class))); when(pathsHelper.getRelativeURI(dmnModelPath, includedModelPath)).thenReturn(uri); final IncludedModel includedModel = factory.create(dmnModelPath, includedModelPath); assertTrue(includedModel instanceof DMNIncludedModel); final DMNIncludedModel dmnIncludedModel = (DMNIncludedModel) includedModel; assertEquals(packageName, includedModel.getModelPackage()); assertEquals(fileName, includedModel.getModelName()); assertEquals(uri, includedModel.getPath()); assertEquals(NAMESPACE, dmnIncludedModel.getNamespace()); assertEquals(expectedDrgElementsCount, dmnIncludedModel.getDrgElementsCount()); assertEquals(expectedItemDefinitionsCount, dmnIncludedModel.getItemDefinitionsCount()); }
public IncludedModel create(final Path dmnModelPath, final Path includedModelPath) throws DMNIncludeModelCouldNotBeCreatedException { try { if (importTypesHelper.isDMN(includedModelPath)) { return makeDMNIncludedModel(dmnModelPath, includedModelPath); } else if (importTypesHelper.isPMML(includedModelPath)) { return makePMMLIncludedModel(dmnModelPath, includedModelPath); } else { throw new IllegalArgumentException("Unsupported external model type."); } } catch (final Exception e) { throw new DMNIncludeModelCouldNotBeCreatedException(); } }
IncludedModelFactory { public IncludedModel create(final Path dmnModelPath, final Path includedModelPath) throws DMNIncludeModelCouldNotBeCreatedException { try { if (importTypesHelper.isDMN(includedModelPath)) { return makeDMNIncludedModel(dmnModelPath, includedModelPath); } else if (importTypesHelper.isPMML(includedModelPath)) { return makePMMLIncludedModel(dmnModelPath, includedModelPath); } else { throw new IllegalArgumentException("Unsupported external model type."); } } catch (final Exception e) { throw new DMNIncludeModelCouldNotBeCreatedException(); } } }
IncludedModelFactory { public IncludedModel create(final Path dmnModelPath, final Path includedModelPath) throws DMNIncludeModelCouldNotBeCreatedException { try { if (importTypesHelper.isDMN(includedModelPath)) { return makeDMNIncludedModel(dmnModelPath, includedModelPath); } else if (importTypesHelper.isPMML(includedModelPath)) { return makePMMLIncludedModel(dmnModelPath, includedModelPath); } else { throw new IllegalArgumentException("Unsupported external model type."); } } catch (final Exception e) { throw new DMNIncludeModelCouldNotBeCreatedException(); } } @Inject  IncludedModelFactory(final DMNDiagramHelper diagramHelper,
                                final DMNPathsHelper pathsHelper,
                                final DMNImportTypesHelper importTypesHelper,
                                final PMMLIncludedDocumentFactory pmmlDocumentFactory,
                                final KieModuleService moduleService); }
IncludedModelFactory { public IncludedModel create(final Path dmnModelPath, final Path includedModelPath) throws DMNIncludeModelCouldNotBeCreatedException { try { if (importTypesHelper.isDMN(includedModelPath)) { return makeDMNIncludedModel(dmnModelPath, includedModelPath); } else if (importTypesHelper.isPMML(includedModelPath)) { return makePMMLIncludedModel(dmnModelPath, includedModelPath); } else { throw new IllegalArgumentException("Unsupported external model type."); } } catch (final Exception e) { throw new DMNIncludeModelCouldNotBeCreatedException(); } } @Inject  IncludedModelFactory(final DMNDiagramHelper diagramHelper,
                                final DMNPathsHelper pathsHelper,
                                final DMNImportTypesHelper importTypesHelper,
                                final PMMLIncludedDocumentFactory pmmlDocumentFactory,
                                final KieModuleService moduleService); IncludedModel create(final Path dmnModelPath,
                                final Path includedModelPath); }
IncludedModelFactory { public IncludedModel create(final Path dmnModelPath, final Path includedModelPath) throws DMNIncludeModelCouldNotBeCreatedException { try { if (importTypesHelper.isDMN(includedModelPath)) { return makeDMNIncludedModel(dmnModelPath, includedModelPath); } else if (importTypesHelper.isPMML(includedModelPath)) { return makePMMLIncludedModel(dmnModelPath, includedModelPath); } else { throw new IllegalArgumentException("Unsupported external model type."); } } catch (final Exception e) { throw new DMNIncludeModelCouldNotBeCreatedException(); } } @Inject  IncludedModelFactory(final DMNDiagramHelper diagramHelper,
                                final DMNPathsHelper pathsHelper,
                                final DMNImportTypesHelper importTypesHelper,
                                final PMMLIncludedDocumentFactory pmmlDocumentFactory,
                                final KieModuleService moduleService); IncludedModel create(final Path dmnModelPath,
                                final Path includedModelPath);  }