Search in sources :

Example 1 with XLSConversionResult

use of org.drools.workbench.screens.guided.dtable.shared.XLSConversionResult in project drools-wb by kiegroup.

the class GuidedDecisionTableEditorPresenterTest method showConversionMessage.

@Test
public void showConversionMessage() {
    doReturn(new XLSConversionResult("failed")).when(dtService).convert(any());
    presenter.onConvert();
    verify(view, never()).showConversionSuccess(anySet());
    verify(view).showConversionErrorMessage("failed");
}
Also used : XLSConversionResult(org.drools.workbench.screens.guided.dtable.shared.XLSConversionResult) Test(org.junit.Test)

Example 2 with XLSConversionResult

use of org.drools.workbench.screens.guided.dtable.shared.XLSConversionResult in project drools-wb by kiegroup.

the class DecisionTableGuidedToDecisionTableXLSConverterTest method failureOnConversion.

@Test
public void failureOnConversion() throws IOException {
    final Path path = PathFactory.newPath("file.gdst", "file:///contextpath/file.gdst");
    final GuidedDecisionTable52 table52 = new GuidedDecisionTable52();
    final AttributeCol52 attributeCol52 = new AttributeCol52();
    attributeCol52.setAttribute(Attribute.NEGATE_RULE.getAttributeName());
    table52.getAttributeCols().add(attributeCol52);
    doReturn(mock(PackageDataModelOracle.class)).when(dataModelService).getDataModel(any());
    doReturn(table52).when(guidedDecisionTableEditorService).load(path);
    final XLSConversionResult convert = converter.convert(path);
    assertNotNull(convert);
    verify(decisionTableXLSService, never()).create(any(), any(ByteArrayInputStream.class), any(), any());
    assertFalse(convert.isConverted());
}
Also used : Path(org.uberfire.backend.vfs.Path) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ByteArrayInputStream(java.io.ByteArrayInputStream) XLSConversionResult(org.drools.workbench.screens.guided.dtable.shared.XLSConversionResult) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 3 with XLSConversionResult

use of org.drools.workbench.screens.guided.dtable.shared.XLSConversionResult in project drools-wb by kiegroup.

the class DecisionTableGuidedToDecisionTableXLSConverterTest method fileExists.

@Test
public void fileExists() throws IOException {
    final Path path = PathFactory.newPath("file.gdst", "file:///contextpath/file.gdst");
    final GuidedDecisionTable52 table52 = new GuidedDecisionTable52();
    doReturn(mock(PackageDataModelOracle.class)).when(dataModelService).getDataModel(any());
    doReturn(table52).when(guidedDecisionTableEditorService).load(path);
    doReturn("id").when(sessionInfo).getId();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final org.uberfire.java.nio.file.Path proposedPath = (org.uberfire.java.nio.file.Path) invocation.getArguments()[0];
            return Objects.equals("file.gdst export.xls", Paths.convert(proposedPath).getFileName());
        }
    }).when(ioService).exists(any());
    final XLSConversionResult convert = converter.convert(path);
    assertNotNull(convert);
    verify(decisionTableXLSService).create(pathArgumentCaptor.capture(), any(ByteArrayInputStream.class), any(), any());
    final Path value = pathArgumentCaptor.getValue();
    assertEquals("file.gdst export (1).xls", value.getFileName());
}
Also used : Path(org.uberfire.backend.vfs.Path) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) XLSConversionResult(org.drools.workbench.screens.guided.dtable.shared.XLSConversionResult) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 4 with XLSConversionResult

use of org.drools.workbench.screens.guided.dtable.shared.XLSConversionResult in project drools-wb by kiegroup.

the class DecisionTableGuidedToDecisionTableXLSConverterTest method convertEmptyTable.

@Test
public void convertEmptyTable() throws IOException {
    final Path path = PathFactory.newPath("file.gdst", "file:///contextpath/file.gdst");
    final GuidedDecisionTable52 table52 = new GuidedDecisionTable52();
    doReturn(mock(PackageDataModelOracle.class)).when(dataModelService).getDataModel(any());
    doReturn(table52).when(guidedDecisionTableEditorService).load(path);
    doReturn("id").when(sessionInfo).getId();
    final XLSConversionResult convert = converter.convert(path);
    assertNotNull(convert);
    verify(decisionTableXLSService).create(any(), any(ByteArrayInputStream.class), eq("id"), eq("Converted from file.gdst"));
}
Also used : Path(org.uberfire.backend.vfs.Path) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ByteArrayInputStream(java.io.ByteArrayInputStream) XLSConversionResult(org.drools.workbench.screens.guided.dtable.shared.XLSConversionResult) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 5 with XLSConversionResult

use of org.drools.workbench.screens.guided.dtable.shared.XLSConversionResult in project drools-wb by kiegroup.

the class XLSBuilder method build.

public BuildResult build() {
    try {
        checkHitPolicy();
        makeRuleSet();
        makeImports();
        makeDeclare();
        makeTable();
    } catch (final UnsupportedOperationException e) {
        return new BuildResult(workbook, new XLSConversionResult(e.getMessage()));
    } catch (final Exception e) {
        return new BuildResult(workbook, new XLSConversionResult(e.toString() + " : " + e.getMessage()));
    }
    final XLSConversionResult conversionResult = new XLSConversionResult();
    for (final XLSConversionResultMessage notification : notifications) {
        conversionResult.addInfoMessage(notification);
    }
    return new BuildResult(workbook, conversionResult);
}
Also used : XLSConversionResult(org.drools.workbench.screens.guided.dtable.shared.XLSConversionResult) XLSConversionResultMessage(org.drools.workbench.screens.guided.dtable.shared.XLSConversionResultMessage)

Aggregations

XLSConversionResult (org.drools.workbench.screens.guided.dtable.shared.XLSConversionResult)6 Test (org.junit.Test)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)3 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)3 Path (org.uberfire.backend.vfs.Path)3 AttributeCol52 (org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52)1 XLSConversionResultMessage (org.drools.workbench.screens.guided.dtable.shared.XLSConversionResultMessage)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1