Search in sources :

Example 11 with DecisionTableParseException

use of org.drools.template.parser.DecisionTableParseException in project drools by kiegroup.

the class RuleWorksheetParseTest method testDuplicatePackageAttribute.

/**
 * Duplicate package level attribute
 */
@Test
public void testDuplicatePackageAttribute() {
    try {
        makeRuleSet();
        // B3, C3
        makeAttribute("agenda-group", "agroup");
        // B3. B4
        makeAttribute("agenda-group", "bgroup");
        makeRuleTable();
        makeRow(11, "C", "A", "P");
        makeRow(12, "Foo", "Foo");
        makeRow(13, "attr == $param", "x");
        makeRow(15, "1", "show()", "10");
        listener.finishSheet();
        Package p = listener.getRuleSet();
        DRLOutput dout = new DRLOutput();
        p.renderDRL(dout);
        String drl = dout.getDRL();
        // System.out.println( drl );
        fail("should have failed");
    } catch (DecisionTableParseException e) {
        System.err.println(e.getMessage());
        assertTrue(e.getMessage().contains("C3, C4"));
    }
}
Also used : DRLOutput(org.drools.template.model.DRLOutput) DecisionTableParseException(org.drools.template.parser.DecisionTableParseException) Package(org.drools.template.model.Package) Test(org.junit.Test)

Example 12 with DecisionTableParseException

use of org.drools.template.parser.DecisionTableParseException in project drools-wb by kiegroup.

the class GuidedDecisionTableLHSBuilder method getValueBuilder.

private ParameterizedValueBuilder getValueBuilder(final String content) {
    // Work out the type of "template":-
    // age                     ---> SnippetType.SINGLE
    // age ==                  ---> SnippetType.SINGLE
    // age == $param           ---> SnippetType.PARAM
    // age == $1 || age == $2  ---> SnippetType.INDEXED
    // forall{age < $}{,}      ---> SnippetType.FORALL
    String template = content.trim();
    SnippetType type = SnippetBuilder.getType(template);
    if (type == SnippetType.SINGLE) {
        type = SnippetType.PARAM;
        boolean hasExplicitOperator = false;
        for (String op : operators) {
            if (template.endsWith(op)) {
                hasExplicitOperator = true;
                break;
            }
        }
        if (!hasExplicitOperator) {
            template = template + " ==";
        }
        template = template + " \"";
        template = template + SnippetBuilder.PARAM_STRING + "\"";
    }
    // Make a ValueBuilder for the template
    switch(type) {
        case INDEXED:
            return new IndexedParametersValueBuilder(template, parameterUtilities, ParameterizedValueBuilder.Part.LHS);
        case PARAM:
            return new SingleParameterValueBuilder(template, parameterUtilities, ParameterizedValueBuilder.Part.LHS);
        case SINGLE:
            return new LiteralValueBuilder(template);
    }
    throw new DecisionTableParseException("SnippetBuilder.SnippetType '" + type.toString() + "' is not supported. The column will not be added.");
}
Also used : SnippetType(org.drools.template.model.SnippetBuilder.SnippetType) DecisionTableParseException(org.drools.template.parser.DecisionTableParseException)

Example 13 with DecisionTableParseException

use of org.drools.template.parser.DecisionTableParseException in project drools-wb by kiegroup.

the class DecisionTableXLSServiceImplTest method testInvalidTable.

private void testInvalidTable(Consumer<DecisionTableXLSServiceImpl> serviceConsumer) throws IOException {
    this.service = getServiceWithValidationOverride((tempFile) -> {
        // mock an invalid file
        Throwable t = new Throwable("testing invalid xls dt creation");
        throw new DecisionTableParseException("DecisionTableParseException: " + t.getMessage(), t);
    });
    mockStatic(IOUtils.class);
    when(IOUtils.copy(any(InputStream.class), any(OutputStream.class))).thenReturn(0);
    try {
        serviceConsumer.accept(service);
    } catch (RuntimeException e) {
    // this is expected correct behavior
    }
    verify(ioService, never()).newOutputStream(any(org.uberfire.java.nio.file.Path.class), any(CommentedOption.class));
    verifyStatic(never());
}
Also used : PowerMockito.mockStatic(org.powermock.api.mockito.PowerMockito.mockStatic) Mock(org.mockito.Mock) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) Captor(org.mockito.Captor) ArgumentCaptor(org.mockito.ArgumentCaptor) CommentedOptionFactory(org.guvnor.common.services.backend.util.CommentedOptionFactory) Matchers.eq(org.mockito.Matchers.eq) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Matchers.anyObject(org.mockito.Matchers.anyObject) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) RenameService(org.uberfire.ext.editor.commons.service.RenameService) Path(org.uberfire.backend.vfs.Path) DeleteService(org.uberfire.ext.editor.commons.service.DeleteService) Before(org.junit.Before) OutputStream(java.io.OutputStream) Event(javax.enterprise.event.Event) PowerMockito.verifyStatic(org.powermock.api.mockito.PowerMockito.verifyStatic) Assert.assertNotNull(org.junit.Assert.assertNotNull) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) DecisionTableXLSConversionService(org.drools.workbench.screens.dtablexls.service.DecisionTableXLSConversionService) Mockito.when(org.mockito.Mockito.when) AuthenticationService(org.jboss.errai.security.shared.service.AuthenticationService) ResourceOpenedEvent(org.uberfire.workbench.events.ResourceOpenedEvent) File(java.io.File) GenericValidator(org.guvnor.common.services.backend.validation.GenericValidator) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Matchers.any(org.mockito.Matchers.any) IOUtils(org.apache.commons.io.IOUtils) Mockito.never(org.mockito.Mockito.never) User(org.jboss.errai.security.shared.api.identity.User) DecisionTableParseException(org.drools.template.parser.DecisionTableParseException) IOService(org.uberfire.io.IOService) CopyService(org.uberfire.ext.editor.commons.service.CopyService) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) CommentedOptionFactoryImpl(org.guvnor.common.services.backend.util.CommentedOptionFactoryImpl) Path(org.uberfire.backend.vfs.Path) DecisionTableParseException(org.drools.template.parser.DecisionTableParseException) InputStream(java.io.InputStream) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream)

Aggregations

DecisionTableParseException (org.drools.template.parser.DecisionTableParseException)13 Test (org.junit.Test)4 Package (org.drools.template.model.Package)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 DRLOutput (org.drools.template.model.DRLOutput)2 Global (org.drools.template.model.Global)2 Rule (org.drools.template.model.Rule)2 SnippetBuilder (org.drools.template.model.SnippetBuilder)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 Consumer (java.util.function.Consumer)1 Event (javax.enterprise.event.Event)1 IOUtils (org.apache.commons.io.IOUtils)1