DecisionTableXLSToDecisionTableGuidedConverter implements DecisionTableXLSConversionService { @Override public ConversionResult convert(final Path path) { ConversionResult result = new ConversionResult(); if (!(xlsDTableType.accept(path) || xlsxDTableType.accept(path))) { result.addMessage("Source Asset must be either a XLS or XLSX Decision Table file.", ConversionMessageType.ERROR); return result; } final PackageDataModelOracle dmo = dataModelService.getDataModel(path); final GuidedDecisionTableGeneratorListener listener = parseAssets(path, result, dmo); final Path context = Paths.convert(Paths.convert(path).getParent()); createNewImports(context, listener.getImports(), result); createNewFunctions(context, listener.getImports(), listener.getFunctions(), result); createNewQueries(context, listener.getImports(), listener.getQueries(), result); makeNewJavaTypes(context, listener.getTypeDeclarations(), result); createNewGlobals(context, listener.getImports(), listener.getGlobals(), result); createNewDecisionTables(context, listener.getImports(), listener.getGuidedDecisionTables(), result); return result; } DecisionTableXLSToDecisionTableGuidedConverter(); @Inject  DecisionTableXLSToDecisionTableGuidedConverter(final @Named("ioStrategy") IOService ioService,
                                                          final DRLTextEditorService drlService,
                                                          final GuidedDecisionTableEditorService guidedDecisionTableService,
                                                          final GlobalsEditorService globalsService,
                                                          final KieModuleService moduleService,
                                                          final ProjectImportsService importsService,
                                                          final MetadataService metadataService,
                                                          final DataModelerService modellerService,
                                                          final DataModelService dataModelService,
                                                          final AppConfigService appConfigService,
                                                          final DecisionTableXLSResourceTypeDefinition xlsDTableType,
                                                          final DecisionTableXLSXResourceTypeDefinition xlsxDTableType,
                                                          final GuidedDTableResourceTypeDefinition guidedDTableType,
                                                          final DRLResourceTypeDefinition drlType,
                                                          final GlobalResourceTypeDefinition globalsType); @PostConstruct void setup(); @Override ConversionResult convert(final Path path);  }
@Test public void testGlobalGeneration() { final InputStream is = this.getClass().getResourceAsStream("BZ1310208.xls"); when(ioService.newInputStream(any(org.uberfire.java.nio.file.Path.class))).thenReturn(is); final ConversionResult result = converter.convert(path); assertNotNull(result); final ArgumentCaptor<GlobalsModel> globalsModelArgumentCaptor = ArgumentCaptor.forClass(GlobalsModel.class); verify(globalsService, times(1)).create(any(Path.class), any(String.class), globalsModelArgumentCaptor.capture(), any(String.class)); assertNotNull(globalsModelArgumentCaptor.getValue()); final GlobalsModel globalsModel = globalsModelArgumentCaptor.getValue(); assertEquals(1, globalsModel.getGlobals().size()); assertEquals("list", globalsModel.getGlobals().get(0).getAlias()); assertEquals("java.util.List", globalsModel.getGlobals().get(0).getClassName()); verify(guidedDecisionTableService, times(1)).create(any(Path.class), any(String.class), any(GuidedDecisionTable52.class), any(String.class)); verify(drlService, never()).create(any(Path.class), any(String.class), any(String.class), any(String.class)); }
@Test public void testImportGeneration() { final InputStream is = this.getClass().getResourceAsStream("GUVNOR-2478.xls"); when(ioService.newInputStream(any(org.uberfire.java.nio.file.Path.class))).thenReturn(is); final ConversionResult result = converter.convert(path); assertNotNull(result); final ArgumentCaptor<Path> projectImportsPathArgumentCaptor = ArgumentCaptor.forClass(Path.class); final ArgumentCaptor<ProjectImports> projectImportsArgumentCaptor = ArgumentCaptor.forClass(ProjectImports.class); verify(importsService, times(1)).save(projectImportsPathArgumentCaptor.capture(), projectImportsArgumentCaptor.capture(), any(Metadata.class), any(String.class)); assertNotNull(projectImportsPathArgumentCaptor.getValue()); final Path actualProjectImportsPath = projectImportsPathArgumentCaptor.getValue(); assertEquals(expectedProjectImportsPath.toURI(), actualProjectImportsPath.toURI()); assertNotNull(projectImportsArgumentCaptor.getValue()); final ProjectImports projectImports = projectImportsArgumentCaptor.getValue(); assertEquals(1, projectImports.getImports().getImports().size()); assertEquals("java.util.List", projectImports.getImports().getImports().get(0).getType()); verify(guidedDecisionTableService, times(1)).create(any(Path.class), any(String.class), any(GuidedDecisionTable52.class), any(String.class)); }
@Test public void checkConversionOfXLSXFiles() { final InputStream is = this.getClass().getResourceAsStream("GUVNOR-2696.xlsx"); when(ioService.newInputStream(any(org.uberfire.java.nio.file.Path.class))).thenReturn(is); final ConversionResult result = converter.convert(path); assertNotNull(result); assertEquals(1, result.getMessages().size()); assertTrue(result.getMessages().get(0).getMessage().startsWith("Created Guided Decision Table 'Weather")); verify(guidedDecisionTableService, times(1)).create(any(Path.class), any(String.class), any(GuidedDecisionTable52.class), any(String.class)); }
@Test(expected = DecisionTableParseException.class) public void checkConversionOfXLSWithInvalidContent() { final InputStream is = this.getClass().getResourceAsStream("wrong_file.xls"); when(ioService.newInputStream(any(org.uberfire.java.nio.file.Path.class))).thenReturn(is); converter.convert(path); }