Start line:  
End line:  

Snippet Preview

Snippet HTML Code

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

Tests for the ProjectDataModelOracle completions
 
 
     @Test
     public void testFactsAndFields() {
         final ProjectDataModelOracle pd = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                 .addFact"Person" )
                 .addFieldnew ModelField( "age",
                                            Integer.class.getName(),
                                            ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                            ModelField.FIELD_ORIGIN.DECLARED,
                                            FieldAccessorsAndMutators.BOTH,
                                            DataType.TYPE_NUMERIC_INTEGER ) )
                 .addField( new ModelField( "sex",
                                            String.class.getName(),
                                            ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                            ModelField.FIELD_ORIGIN.DECLARED,
                                            FieldAccessorsAndMutators.BOTH,
                                            DataType.TYPE_STRING ) )
                 .end()
                 .build();
 
         final PackageDataModelOracle dmo = PackageDataModelOracleBuilder.newPackageOracleBuilder().setProjectOraclepd ).build();
 
         assertEquals( DataType.TYPE_NUMERIC_INTEGER,
                       dmo.getFieldType( "Person",
                                         "age" ) );
         assertEquals( DataType.TYPE_STRING,
                       dmo.getFieldType( "Person",
                                         "sex" ) );
     }
 
     @Test
     public void testFactCompletions() {
         final ProjectDataModelOracle pd = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                 .addFact"Person" )
                 .addFieldnew ModelField( "age",
                                            Integer.class.getName(),
                                            ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                            ModelField.FIELD_ORIGIN.DECLARED,
                                            FieldAccessorsAndMutators.BOTH,
                                            DataType.TYPE_NUMERIC_INTEGER ) )
                 .addField( new ModelField( "rank",
                                            Integer.class.getName(),
                                            ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                            ModelField.FIELD_ORIGIN.DECLARED,
                                            FieldAccessorsAndMutators.BOTH,
                                            DataType.TYPE_COMPARABLE ) )
                 .addField( new ModelField( "name",
                                            String.class.getName(),
                                            ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                            ModelField.FIELD_ORIGIN.DECLARED,
                                            FieldAccessorsAndMutators.BOTH,
                                            DataType.TYPE_STRING ) )
                 .end()
                 .addFact( "Vehicle" )
                 .addField( new ModelField( "make",
                                            String.class.getName(),
                                            ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                            ModelField.FIELD_ORIGIN.DECLARED,
                                            FieldAccessorsAndMutators.BOTH,
                                            DataType.TYPE_STRING ) )
                 .addField( new ModelField( "type",
                                            String.class.getName(),
                                            ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                            ModelField.FIELD_ORIGIN.DECLARED,
                                            FieldAccessorsAndMutators.BOTH,
                                            DataType.TYPE_STRING ) )
                 .end()
                 .build();
 
         final PackageDataModelOracle dmo = PackageDataModelOracleBuilder.newPackageOracleBuilder().setProjectOraclepd ).build();
 
         String[] types = dmo.getFactTypes();
         assertEquals( 2,
                       types.length );
         DataModelOracleTestUtils.assertContains"Person",
                                                  types );
         DataModelOracleTestUtils.assertContains"Vehicle",
                                                  types );
     }
 
     @Test
     public void testFactFieldCompletions() {
        final ProjectDataModelOracle pd = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                .addFact"Person" )
                .addFieldnew ModelField( "age",
                                           Integer.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_NUMERIC_INTEGER ) )
                .addField( new ModelField( "rank",
                                           Integer.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_COMPARABLE ) )
                .addField( new ModelField( "name",
                                           String.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_STRING ) )
                .end()
                .build();
        final PackageDataModelOracle dmo = PackageDataModelOracleBuilder.newPackageOracleBuilder().setProjectOraclepd ).build();
        String[] personFields = dmo.getFieldCompletions( "Person" );
        assertEquals( 4,
                      personFields.length );
        assertEquals"this",
                      personFields[ 0 ] );
        assertEquals"age",
                      personFields[ 1 ] );
        assertEquals"rank",
                      personFields[ 2 ] );
        assertEquals"name",
                      personFields[ 3 ] );
    }
    @Test
    public void testFactFieldOperatorCompletions() {
        final ProjectDataModelOracle pd = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                .addFact"Person" )
                .addFieldnew ModelField( "age",
                                           Integer.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_NUMERIC_INTEGER ) )
                .addField( new ModelField( "rank",
                                           Integer.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_COMPARABLE ) )
                .addField( new ModelField( "name",
                                           String.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_STRING ) )
                .end()
                .build();
        final PackageDataModelOracle dmo = PackageDataModelOracleBuilder.newPackageOracleBuilder().setProjectOraclepd ).build();
        String[] personThisOperators = dmo.getOperatorCompletions( "Person",
                                                                   "this" );
        assertEquals( 4,
                      personThisOperators.length );
        assertEqualspersonThisOperators[ 0 ],
                      "==" );
        assertEqualspersonThisOperators[ 1 ],
                      "!=" );
        assertEqualspersonThisOperators[ 2 ],
                      "== null" );
        assertEqualspersonThisOperators[ 3 ],
                      "!= null" );
        String[] personAgeOperators = dmo.getOperatorCompletions( "Person",
                                                                  "age" );
        assertEquals( 10,
                      personAgeOperators.length );
        assertEqualspersonAgeOperators[ 0 ],
                      "==" );
        assertEqualspersonAgeOperators[ 1 ],
                      "!=" );
        assertEqualspersonAgeOperators[ 2 ],
                      "<" );
        assertEqualspersonAgeOperators[ 3 ],
                      ">" );
        assertEqualspersonAgeOperators[ 4 ],
                      "<=" );
        assertEqualspersonAgeOperators[ 5 ],
                      ">=" );
        assertEqualspersonAgeOperators[ 6 ],
                      "== null" );
        assertEqualspersonAgeOperators[ 7 ],
                      "!= null" );
        assertEqualspersonAgeOperators[ 8 ],
                      "in" );
        assertEqualspersonAgeOperators[ 9 ],
                      "not in" );
        String[] personRankOperators = dmo.getOperatorCompletions( "Person",
                                                                   "rank" );
        assertEquals( 8,
                      personRankOperators.length );
        assertEqualspersonRankOperators[ 0 ],
                      "==" );
        assertEqualspersonRankOperators[ 1 ],
                      "!=" );
        assertEqualspersonRankOperators[ 2 ],
                      "<" );
        assertEqualspersonRankOperators[ 3 ],
                      ">" );
        assertEqualspersonRankOperators[ 4 ],
                      "<=" );
        assertEqualspersonRankOperators[ 5 ],
                      ">=" );
        assertEqualspersonRankOperators[ 6 ],
                      "== null" );
        assertEqualspersonRankOperators[ 7 ],
                      "!= null" );
        String[] personNameOperators = dmo.getOperatorCompletions( "Person",
                                                                   "name" );
        assertEquals( 12,
                      personNameOperators.length );
        assertEquals"==",
                      personNameOperators[ 0 ] );
        assertEquals"!=",
                      personNameOperators[ 1 ] );
        assertEquals"<",
                      personNameOperators[ 2 ] );
        assertEquals">",
                      personNameOperators[ 3 ] );
        assertEquals"<=",
                      personNameOperators[ 4 ] );
        assertEquals">=",
                      personNameOperators[ 5 ] );
        assertEquals"matches",
                      personNameOperators[ 6 ] );
        assertEquals"soundslike",
                      personNameOperators[ 7 ] );
        assertEquals"== null",
                      personNameOperators[ 8 ] );
        assertEquals"!= null",
                      personNameOperators[ 9 ] );
        assertEquals"in",
                      personNameOperators[ 10 ] );
        assertEquals"not in",
                      personNameOperators[ 11 ] );
    }
    @Test
        final ProjectDataModelOracle pd = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                .addFact"Person" )
                .addFieldnew ModelField( "age",
                                           Integer.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_NUMERIC_INTEGER ) )
                .addField( new ModelField( "rank",
                                           Integer.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_COMPARABLE ) )
                .addField( new ModelField( "name",
                                           String.class.getName(),
                                           ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS,
                                           ModelField.FIELD_ORIGIN.DECLARED,
                                           FieldAccessorsAndMutators.BOTH,
                                           DataType.TYPE_STRING ) )
                .end()
                .build();
        final PackageDataModelOracle dmo = PackageDataModelOracleBuilder.newPackageOracleBuilder().setProjectOraclepd ).build();
        String[] personThisConnectiveOperators = dmo.getConnectiveOperatorCompletions( "Person",
                                                                                       "this" );
        assertEquals( 3,
                      personThisConnectiveOperators.length );
        assertEqualspersonThisConnectiveOperators[ 0 ],
                      "|| ==" );
        assertEqualspersonThisConnectiveOperators[ 1 ],
                      "|| !=" );
        assertEqualspersonThisConnectiveOperators[ 2 ],
                      "&& !=" );
        String[] personAgeConnectiveOperators = dmo.getConnectiveOperatorCompletions( "Person",
                                                                                      "age" );
        assertEquals( 11,
                      personAgeConnectiveOperators.length );
        assertEqualspersonAgeConnectiveOperators[ 0 ],
                      "|| ==" );
        assertEqualspersonAgeConnectiveOperators[ 1 ],
                      "|| !=" );
        assertEqualspersonAgeConnectiveOperators[ 2 ],
                      "&& !=" );
        assertEqualspersonAgeConnectiveOperators[ 3 ],
                      "&& >" );
        assertEqualspersonAgeConnectiveOperators[ 4 ],
                      "&& <" );
        assertEqualspersonAgeConnectiveOperators[ 5 ],
                      "|| >" );
        assertEqualspersonAgeConnectiveOperators[ 6 ],
                      "|| <" );
        assertEqualspersonAgeConnectiveOperators[ 7 ],
                      "&& >=" );
        assertEqualspersonAgeConnectiveOperators[ 8 ],
                      "&& <=" );
        assertEqualspersonAgeConnectiveOperators[ 9 ],
                      "|| <=" );
        assertEqualspersonAgeConnectiveOperators[ 10 ],
                      "|| >=" );
        String[] personRankConnectiveOperators = dmo.getConnectiveOperatorCompletions( "Person",
                                                                                       "rank" );
        assertEquals( 11,
                      personRankConnectiveOperators.length );
        assertEqualspersonRankConnectiveOperators[ 0 ],
                      "|| ==" );
        assertEqualspersonRankConnectiveOperators[ 1 ],
                      "|| !=" );
        assertEqualspersonRankConnectiveOperators[ 2 ],
                      "&& !=" );
        assertEqualspersonRankConnectiveOperators[ 3 ],
                      "&& >" );
        assertEqualspersonRankConnectiveOperators[ 4 ],
                      "&& <" );
        assertEqualspersonRankConnectiveOperators[ 5 ],
                      "|| >" );
        assertEqualspersonRankConnectiveOperators[ 6 ],
                      "|| <" );
        assertEqualspersonRankConnectiveOperators[ 7 ],
                      "&& >=" );
        assertEqualspersonRankConnectiveOperators[ 8 ],
                      "&& <=" );
        assertEqualspersonRankConnectiveOperators[ 9 ],
                      "|| <=" );
        assertEqualspersonRankConnectiveOperators[ 10 ],
                      "|| >=" );
        String[] personNameConnectiveOperators = dmo.getConnectiveOperatorCompletions( "Person",
                                                                                       "name" );
        assertEquals( 13,
                      personNameConnectiveOperators.length );
        assertEqualspersonNameConnectiveOperators[ 0 ],
                      "|| ==" );
        assertEqualspersonNameConnectiveOperators[ 1 ],
                      "|| !=" );
        assertEqualspersonNameConnectiveOperators[ 2 ],
                      "&& !=" );
        assertEqualspersonNameConnectiveOperators[ 3 ],
                      "&& >" );
        assertEqualspersonNameConnectiveOperators[ 4 ],
                      "&& <" );
        assertEqualspersonNameConnectiveOperators[ 5 ],
                      "|| >" );
        assertEqualspersonNameConnectiveOperators[ 6 ],
                      "|| <" );
        assertEqualspersonNameConnectiveOperators[ 7 ],
                      "&& >=" );
        assertEqualspersonNameConnectiveOperators[ 8 ],
                      "&& <=" );
        assertEqualspersonNameConnectiveOperators[ 9 ],
                      "|| <=" );
        assertEqualspersonNameConnectiveOperators[ 10 ],
                      "|| >=" );
        assertEqualspersonNameConnectiveOperators[ 11 ],
                      "&& matches" );
        assertEqualspersonNameConnectiveOperators[ 12 ],
                      "|| matches" );
    }
New to GrepCode? Check out our FAQ X