Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.kie.workbench.common.services.datamodel.backend.server;
  
  import java.util.Date;
  import java.util.List;
  
  import  org.drools.workbench.models.commons.shared.oracle.model.DataType;
  import  org.drools.workbench.models.commons.shared.oracle.model.FieldAccessorsAndMutators;
  import  org.drools.workbench.models.commons.shared.oracle.model.ModelField;
  import  org.drools.workbench.models.datamodel.oracle.CEPOracle;
 import  org.drools.workbench.models.commons.shared.oracle.PackageDataModelOracle;
 import  org.drools.workbench.models.commons.shared.oracle.ProjectDataModelOracle;
 import org.junit.Test;
 
 import static org.junit.Assert.*;

Tests for the ProjectDataModelOracle CEP completions
 
 
     @Test
     public void testCEPCompletions() {
         final ProjectDataModelOracle pd = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                 .addFact"NotAnEvent" )
                 .addFieldnew ModelField( "dateField",
                                            Date.class.getName(),
                                            ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                            ModelField.FIELD_ORIGIN.DECLARED,
                                            FieldAccessorsAndMutators.BOTH,
                                            DataType.TYPE_DATE ) )
                 .end()
                 .addFact( "AnEvent",
                           true )
                 .addField( new ModelField( "this",
                                            Object.class.getName(),
                                            ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                            ModelField.FIELD_ORIGIN.SELF,
                                            FieldAccessorsAndMutators.BOTH,
                                            "AnEvent" ) )
                 .addField( new ModelField( "dateField",
                                            Date.class.getName(),
                                            ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                            ModelField.FIELD_ORIGIN.DECLARED,
                                            FieldAccessorsAndMutators.BOTH,
                                            DataType.TYPE_DATE ) )
                 .end()
                 .build();
 
         final PackageDataModelOracle dmo = PackageDataModelOracleBuilder.newPackageOracleBuilder().setProjectOraclepd ).build();
 
         //Check completions
         String[] types = dmo.getFactTypes();
         assertEquals( 2,
                       types.length );
         DataModelOracleTestUtils.assertContains"NotAnEvent",
                                                  types );
         DataModelOracleTestUtils.assertContains"AnEvent",
                                                  types );
 
         String[] notAnEventDateFieldOperators = dmo.getOperatorCompletions( "NotAnEvent",
                                                                             "dateField" );
         assertEquals( 13,
                       notAnEventDateFieldOperators.length );
         assertEqualsnotAnEventDateFieldOperators[ 0 ],
                       "==" );
         assertEqualsnotAnEventDateFieldOperators[ 1 ],
                       "!=" );
         assertEqualsnotAnEventDateFieldOperators[ 2 ],
                       "<" );
         assertEqualsnotAnEventDateFieldOperators[ 3 ],
                       ">" );
         assertEqualsnotAnEventDateFieldOperators[ 4 ],
                       "<=" );
         assertEqualsnotAnEventDateFieldOperators[ 5 ],
                       ">=" );
         assertEqualsnotAnEventDateFieldOperators[ 6 ],
                       "== null" );
         assertEqualsnotAnEventDateFieldOperators[ 7 ],
                       "!= null" );
         assertEqualsnotAnEventDateFieldOperators[ 8 ],
                       "in" );
         assertEqualsnotAnEventDateFieldOperators[ 9 ],
                       "not in" );
         assertEqualsnotAnEventDateFieldOperators[ 10 ],
                       "after" );
         assertEqualsnotAnEventDateFieldOperators[ 11 ],
                       "before" );
         assertEqualsnotAnEventDateFieldOperators[ 12 ],
                       "coincides" );
 
         String[] anEventThisOperators = dmo.getOperatorCompletions( "AnEvent",
                                                                     "this" );
         assertEquals( 17,
                       anEventThisOperators.length );
         assertEqualsanEventThisOperators[ 0 ],
                       "==" );
         assertEqualsanEventThisOperators[ 1 ],
                      "!=" );
        assertEqualsanEventThisOperators[ 2 ],
                      "== null" );
        assertEqualsanEventThisOperators[ 3 ],
                      "!= null" );
        assertEqualsanEventThisOperators[ 4 ],
                      "after" );
        assertEqualsanEventThisOperators[ 5 ],
                      "before" );
        assertEqualsanEventThisOperators[ 6 ],
                      "coincides" );
        assertEqualsanEventThisOperators[ 7 ],
                      "during" );
        assertEqualsanEventThisOperators[ 8 ],
                      "finishes" );
        assertEqualsanEventThisOperators[ 9 ],
                      "finishedby" );
        assertEqualsanEventThisOperators[ 10 ],
                      "includes" );
        assertEqualsanEventThisOperators[ 11 ],
                      "meets" );
        assertEqualsanEventThisOperators[ 12 ],
                      "metby" );
        assertEqualsanEventThisOperators[ 13 ],
                      "overlaps" );
        assertEqualsanEventThisOperators[ 14 ],
                      "overlappedby" );
        assertEqualsanEventThisOperators[ 15 ],
                      "starts" );
        assertEqualsanEventThisOperators[ 16 ],
                      "startedby" );
    }
    @Test
    @SuppressWarnings("serial")
    public void testCEPParameterCompletions() {
        List<Integerc = CEPOracle.getCEPOperatorParameterSets("after");
        assertEquals( 3,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        assertEquals( 2,
                      c.get( 2 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "before" );
        assertEquals( 3,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        assertEquals( 2,
                      c.get( 2 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "coincides" );
        assertEquals( 3,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        assertEquals( 2,
                      c.get( 2 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "during" );
        assertEquals( 4,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        assertEquals( 2,
                      c.get( 2 ).intValue() );
        assertEquals( 4,
                      c.get( 3 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "finishes" );
        assertEquals( 2,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "finishedby" );
        assertEquals( 2,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "includes" );
        assertEquals( 4,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        assertEquals( 2,
                      c.get( 2 ).intValue() );
        assertEquals( 4,
                      c.get( 3 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "meets" );
        assertEquals( 2,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "metby" );
        assertEquals( 2,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "overlaps" );
        assertEquals( 3,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        assertEquals( 2,
                      c.get( 2 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "overlappedby" );
        assertEquals( 3,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        assertEquals( 2,
                      c.get( 2 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "starts" );
        assertEquals( 2,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
        c = CEPOracle.getCEPOperatorParameterSets( "startedby" );
        assertEquals( 2,
                      c.size() );
        assertEquals( 0,
                      c.get( 0 ).intValue() );
        assertEquals( 1,
                      c.get( 1 ).intValue() );
    }
    @Test
    public void testCEPOperatorValidation() {
        assertFalse( CEPOracle.isCEPOperator( "==" ) );
        assertFalse( CEPOracle.isCEPOperator( "!=" ) );
        assertFalse( CEPOracle.isCEPOperator( "<" ) );
        assertFalse( CEPOracle.isCEPOperator( ">" ) );
        assertFalse( CEPOracle.isCEPOperator( "<=" ) );
        assertFalse( CEPOracle.isCEPOperator( ">=" ) );
        assertFalse( CEPOracle.isCEPOperator( "== null" ) );
        assertFalse( CEPOracle.isCEPOperator( "!= null" ) );
        assertTrue( CEPOracle.isCEPOperator( "after" ) );
        assertTrue( CEPOracle.isCEPOperator( "before" ) );
        assertTrue( CEPOracle.isCEPOperator( "coincides" ) );
        assertTrue( CEPOracle.isCEPOperator( "during" ) );
        assertTrue( CEPOracle.isCEPOperator( "finishes" ) );
        assertTrue( CEPOracle.isCEPOperator( "finishedby" ) );
        assertTrue( CEPOracle.isCEPOperator( "includes" ) );
        assertTrue( CEPOracle.isCEPOperator( "meets" ) );
        assertTrue( CEPOracle.isCEPOperator( "metby" ) );
        assertTrue( CEPOracle.isCEPOperator( "overlaps" ) );
        assertTrue( CEPOracle.isCEPOperator( "overlappedby" ) );
        assertTrue( CEPOracle.isCEPOperator( "starts" ) );
        assertTrue( CEPOracle.isCEPOperator( "startedby" ) );
    }
    @Test
    public void testCEPWindowOperators() {
        List<Stringoperators = CEPOracle.getCEPWindowOperators();
        assertEquals( 2,
                      operators.size() );
        assertEquals"over window:time",
                      operators.get( 0 ) );
        assertEquals"over window:length",
                      operators.get( 1 ) );
    }
New to GrepCode? Check out our FAQ X