Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.drools.workbench.screens.guided.dtable;
 
 import java.util.Date;
 import java.util.Map;
 
 import org.junit.Test;
 
 import static junit.framework.Assert.*;

Tests for CellValueFactory
 
 public class CellValueFactoryTests {
 
     private PackageDataModelOracle oracle;
     private GuidedDecisionTable52 dt = null;
     private DecisionTableCellValueFactory factory = null;
 
     private AttributeCol52 at1 = null;
     private AttributeCol52 at2 = null;
     private ConditionCol52 c1 = null;
     private ConditionCol52 c2 = null;
     private ConditionCol52 c3 = null;
     private ConditionCol52 c4 = null;
     private ConditionCol52 c5 = null;
     private ConditionCol52 c6 = null;
     private ConditionCol52 c7 = null;
     private ConditionCol52 c8 = null;
     private ConditionCol52 c9 = null;
     private ConditionCol52 c10 = null;
     private ConditionCol52 c11 = null;
     private ActionSetFieldCol52 a1 = null;
     private ActionInsertFactCol52 a2 = null;
 
     @Before
     @SuppressWarnings("serial")
     public void setup() {
         final ProjectDataModelOracle pd = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                 .addFact"MyClass" )
                 .addFieldnew ModelField"bigDecimalField",
                                            Integer.class.getName(),
                                            .,
                                            .,
                                            . ) )
                 .addFieldnew ModelField"bigIntegerField",
                                            Integer.class.getName(),
                                            .,
                                            .,
                                            . ) )
                 .addFieldnew ModelField"byteField",
                                            Integer.class.getName(),
                                            .,
                                            .,
                                            . ) )
                 .addFieldnew ModelField"doubleField",
                                            Integer.class.getName(),
                                            .,
                                            .,
                                            . ) )
                .addFieldnew ModelField"floatField",
                                           Integer.class.getName(),
                                           .,
                                           .,
                                           . ) )
                .addFieldnew ModelField"integerField",
                                           Integer.class.getName(),
                                           .,
                                           .,
                                           . ) )
                .addFieldnew ModelField"longField",
                                           Integer.class.getName(),
                                           .,
                                           .,
                                           . ) )
                .addFieldnew ModelField"shortField",
                                           Integer.class.getName(),
                                           .,
                                           .,
                                           . ) )
                .addFieldnew ModelField"stringField",
                                           String.class.getName(),
                                           .,
                                           .,
                                           . ) )
                .addFieldnew ModelField"dateField",
                                           Boolean.class.getName(),
                                           .,
                                           .,
                                           . ) )
                .addFieldnew ModelField"booleanField",
                                           Boolean.class.getName(),
                                           .,
                                           .,
                                           . ) )
                .end()
                .build();
         = PackageDataModelOracleBuilder.newPackageOracleBuilder().setProjectOraclepd ).build();
         = new GuidedDecisionTable52();
         = new AttributeCol52();
        .setAttribute"salience" );
         = new AttributeCol52();
        .setAttribute"enabled" );
        .getAttributeCols().add );
        .getAttributeCols().add );
        Pattern52 p1 = new Pattern52();
        p1.setBoundName"c1" );
        p1.setFactType"MyClass" );
         = new ConditionCol52();
        .setFactField"stringField" );
        .setOperator"==" );
        p1.getChildColumns().add );
        .getConditions().addp1 );
        Pattern52 p2 = new Pattern52();
        p2.setBoundName"c2" );
        p2.setFactType"MyClass" );
         = new ConditionCol52();
        .setFactField"bigDecimalField" );
        .setOperator"==" );
        p2.getChildColumns().add );
        .getConditions().addp2 );
         = new ConditionCol52();
        .setFactField"bigIntegerField" );
        .setOperator"==" );
        p2.getChildColumns().add );
         = new ConditionCol52();
        .setFactField"byteField" );
        .setOperator"==" );
        p2.getChildColumns().add );
         = new ConditionCol52();
        .setFactField"doubleField" );
        .setOperator"==" );
        p2.getChildColumns().add );
         = new ConditionCol52();
        .setFactField"floatField" );
        .setOperator"==" );
        p2.getChildColumns().add );
         = new ConditionCol52();
        .setFactField"integerField" );
        .setOperator"==" );
        p2.getChildColumns().add );
         = new ConditionCol52();
        .setFactField"longField" );
        .setOperator"==" );
        p2.getChildColumns().add );
         = new ConditionCol52();
        .setFactField"shortField" );
        .setOperator"==" );
        p2.getChildColumns().add );
        Pattern52 p3 = new Pattern52();
        p3.setBoundName"c3" );
        p3.setFactType"MyClass" );
         = new ConditionCol52();
        .setFactField"dateField" );
        .setOperator"==" );
        p3.getChildColumns().add );
        .getConditions().addp3 );
        Pattern52 p4 = new Pattern52();
        p4.setBoundName"c4" );
        p4.setFactType"MyClass" );
         = new ConditionCol52();
        .setFactField"booleanField" );
        .setOperator"==" );
        p4.getChildColumns().add );
        .getConditions().addp4 );
         = new ActionSetFieldCol52();
        .setBoundName"c1" );
        .setFactField"stringField" );
        .getActionCols().add );
         = new ActionInsertFactCol52();
        .setBoundName"a2" );
        .setFactType"MyClass" );
        .setFactField"stringField" );
        .getActionCols().add );
         = new DecisionTableCellValueFactory,
                                                      );
        Map<StringStringpreferences = new HashMap<StringString>();
        preferences.put.,
                         "dd-MMM-yyyy" );
        ApplicationPreferences.setUppreferences );
        DTCellValueUtilities.injectDateConvertor( JVMDateConverter.getInstance() );
    }
    @Test
    public void testDataTypes() {
        Calendar cdob = Calendar.getInstance();
        cdob.clear();
        cdob.set( 2000,
                  0,
                  1 );
        Date dob = cdob.getTime();
        DTCellValue52 dcv1 = new DTCellValue52. );
        DTCellValue52 dcv2 = new DTCellValue52dob );
        DTCellValue52 dcv3 = new DTCellValue52new BigDecimal( 1 ) );
        DTCellValue52 dcv4 = new DTCellValue52new BigInteger"1" ) );
        DTCellValue52 dcv5 = new DTCellValue52new Byte"1" ) );
        DTCellValue52 dcv6 = new DTCellValue52( 1.0d );
        DTCellValue52 dcv7 = new DTCellValue52( 1.0f );
        DTCellValue52 dcv8 = new DTCellValue52new Integer( 1 ) );
        DTCellValue52 dcv9 = new DTCellValue52( 1l );
        DTCellValue52 dcv10 = new DTCellValue52new Short"1" ) );
        DTCellValue52 dcv11 = new DTCellValue52"Smurf" );
        assertEqualsdcv1.getDataType(),
                      .. );
        assertEqualsdcv2.getDataType(),
                      .. );
        assertEqualsdcv3.getDataType(),
                      .. );
        assertEqualsdcv4.getDataType(),
                      .. );
        assertEqualsdcv5.getDataType(),
                      .. );
        assertEqualsdcv6.getDataType(),
                      .. );
        assertEqualsdcv7.getDataType(),
                      .. );
        assertEqualsdcv8.getDataType(),
                      .. );
        assertEqualsdcv9.getDataType(),
                      .. );
        assertEqualsdcv10.getDataType(),
                      .. );
        assertEqualsdcv11.getDataType(),
                      .. );
    }
    @Test
    public void testEmptyCells() {
        CellValue<? extends Comparable<?>> cell1 = .convertModelCellValue,
                                                                                  new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell2 = .convertModelCellValue,
                                                                                  new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell3 = .convertModelCellValue,
                                                                                  new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell4 = .convertModelCellValue,
                                                                                  new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell5 = .convertModelCellValue,
                                                                                  new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell6 = .convertModelCellValue,
                                                                                  new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell7 = .convertModelCellValue,
                                                                                  new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell8 = .convertModelCellValue,
                                                                                  new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell9 = .convertModelCellValue,
                                                                                  new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell10 = .convertModelCellValue,
                                                                                   new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell11 = .convertModelCellValue,
                                                                                   new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell12 = .convertModelCellValue,
                                                                                   new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell13 = .convertModelCellValue,
                                                                                   new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell14 = .convertModelCellValue,
                                                                                   new DTCellValue52() );
        CellValue<? extends Comparable<?>> cell15 = .convertModelCellValue,
                                                                                   new DTCellValue52() );
        assertEqualscell1.getValue(),
                      null );
        assertEqualscell2.getValue(),
                      . );
        assertEqualscell3.getValue(),
                      null );
        assertEqualscell4.getValue(),
                      null );
        assertEqualscell5.getValue(),
                      null );
        assertEqualscell6.getValue(),
                      null );
        assertEqualscell7.getValue(),
                      null );
        assertEqualscell8.getValue(),
                      null );
        assertEqualscell9.getValue(),
                      null );
        assertEqualscell10.getValue(),
                      null );
        assertEqualscell11.getValue(),
                      null );
        assertEqualscell12.getValue(),
                      null );
        assertEqualscell13.getValue(),
                      . );
        assertEqualscell14.getValue(),
                      null );
        assertEqualscell15.getValue(),
                      null );
    }
    @Test
    public void testTypedValues() {
        Calendar cdob = Calendar.getInstance();
        cdob.clear();
        cdob.set( 2000,
                  0,
                  1 );
        Date dob = cdob.getTime();
        DTCellValue52 dcv1 = new DTCellValue52new Integer( 1 ) );
        DTCellValue52 dcv2 = new DTCellValue52. );
        DTCellValue52 dcv3 = new DTCellValue52"Michael" );
        DTCellValue52 dcv4 = new DTCellValue52new BigDecimal( 11 ) );
        DTCellValue52 dcv5 = new DTCellValue52new BigInteger"11" ) );
        DTCellValue52 dcv6 = new DTCellValue52new Byte"11" ) );
        DTCellValue52 dcv7 = new DTCellValue52( 11.0d );
        DTCellValue52 dcv8 = new DTCellValue52( 11.0f );
        DTCellValue52 dcv9 = new DTCellValue52new Integer( 11 ) );
        DTCellValue52 dcv10 = new DTCellValue52( 11l );
        DTCellValue52 dcv11 = new DTCellValue52new Short"11" ) );
        DTCellValue52 dcv12 = new DTCellValue52dob );
        DTCellValue52 dcv13 = new DTCellValue52. );
        DTCellValue52 dcv14 = new DTCellValue52"Mike" );
        DTCellValue52 dcv15 = new DTCellValue52"Mike" );
        CellValue<? extends Comparable<?>> cell1 = .convertModelCellValue,
                                                                                  dcv1 );
        CellValue<? extends Comparable<?>> cell2 = .convertModelCellValue,
                                                                                  dcv2 );
        CellValue<? extends Comparable<?>> cell3 = .convertModelCellValue,
                                                                                  dcv3 );
        CellValue<? extends Comparable<?>> cell4 = .convertModelCellValue,
                                                                                  dcv4 );
        CellValue<? extends Comparable<?>> cell5 = .convertModelCellValue,
                                                                                  dcv5 );
        CellValue<? extends Comparable<?>> cell6 = .convertModelCellValue,
                                                                                  dcv6 );
        CellValue<? extends Comparable<?>> cell7 = .convertModelCellValue,
                                                                                  dcv7 );
        CellValue<? extends Comparable<?>> cell8 = .convertModelCellValue,
                                                                                  dcv8 );
        CellValue<? extends Comparable<?>> cell9 = .convertModelCellValue,
                                                                                  dcv9 );
        CellValue<? extends Comparable<?>> cell10 = .convertModelCellValue,
                                                                                   dcv10 );
        CellValue<? extends Comparable<?>> cell11 = .convertModelCellValue,
                                                                                   dcv11 );
        CellValue<? extends Comparable<?>> cell12 = .convertModelCellValue,
                                                                                   dcv12 );
        CellValue<? extends Comparable<?>> cell13 = .convertModelCellValue,
                                                                                   dcv13 );
        CellValue<? extends Comparable<?>> cell14 = .convertModelCellValue,
                                                                                   dcv14 );
        CellValue<? extends Comparable<?>> cell15 = .convertModelCellValue,
                                                                                   dcv15 );
        assertEqualscell1.getValue(),
                      new Integer( 1 ) );
        assertEqualscell2.getValue(),
                      . );
        assertEqualscell3.getValue(),
                      "Michael" );
        assertEqualscell4.getValue(),
                      new BigDecimal( 11 ) );
        assertEqualscell5.getValue(),
                      new BigInteger"11" ) );
        assertEqualscell6.getValue(),
                      new Byte"11" ) );
        assertEqualscell7.getValue(),
                      11.0d );
        assertEqualscell8.getValue(),
                      11.0f );
        assertEqualscell9.getValue(),
                      new Integer( 11 ) );
        assertEqualscell10.getValue(),
                      11l );
        assertEqualscell11.getValue(),
                      new Short"11" ) );
        assertEqualscell12.getValue(),
                      dob );
        assertEqualscell13.getValue(),
                      . );
        assertEqualscell14.getValue(),
                      "Mike" );
        assertEqualscell15.getValue(),
                      "Mike" );
    }
    @Test
    public void testStringValues() {
        Calendar cdob = Calendar.getInstance();
        cdob.clear();
        cdob.set( 2000,
                  0,
                  1 );
        Date dob = cdob.getTime();
        DTCellValue52 dcv1 = new DTCellValue52"1" );
        DTCellValue52 dcv2 = new DTCellValue52"true" );
        DTCellValue52 dcv3 = new DTCellValue52"Michael" );
        DTCellValue52 dcv4 = new DTCellValue52"11" );
        DTCellValue52 dcv5 = new DTCellValue52"11" );
        DTCellValue52 dcv6 = new DTCellValue52"11" );
        DTCellValue52 dcv7 = new DTCellValue52"11" );
        DTCellValue52 dcv8 = new DTCellValue52"11" );
        DTCellValue52 dcv9 = new DTCellValue52"11" );
        DTCellValue52 dcv10 = new DTCellValue52"11" );
        DTCellValue52 dcv11 = new DTCellValue52"11" );
        DTCellValue52 dcv12 = new DTCellValue52"01-JAN-2000" );
        DTCellValue52 dcv13 = new DTCellValue52"true" );
        DTCellValue52 dcv14 = new DTCellValue52"Mike" );
        DTCellValue52 dcv15 = new DTCellValue52"Mike" );
        CellValue<? extends Comparable<?>> cell1 = .convertModelCellValue,
                                                                                  dcv1 );
        CellValue<? extends Comparable<?>> cell2 = .convertModelCellValue,
                                                                                  dcv2 );
        CellValue<? extends Comparable<?>> cell3 = .convertModelCellValue,
                                                                                  dcv3 );
        CellValue<? extends Comparable<?>> cell4 = .convertModelCellValue,
                                                                                  dcv4 );
        CellValue<? extends Comparable<?>> cell5 = .convertModelCellValue,
                                                                                  dcv5 );
        CellValue<? extends Comparable<?>> cell6 = .convertModelCellValue,
                                                                                  dcv6 );
        CellValue<? extends Comparable<?>> cell7 = .convertModelCellValue,
                                                                                  dcv7 );
        CellValue<? extends Comparable<?>> cell8 = .convertModelCellValue,
                                                                                  dcv8 );
        CellValue<? extends Comparable<?>> cell9 = .convertModelCellValue,
                                                                                  dcv9 );
        CellValue<? extends Comparable<?>> cell10 = .convertModelCellValue,
                                                                                   dcv10 );
        CellValue<? extends Comparable<?>> cell11 = .convertModelCellValue,
                                                                                   dcv11 );
        CellValue<? extends Comparable<?>> cell12 = .convertModelCellValue,
                                                                                   dcv12 );
        CellValue<? extends Comparable<?>> cell13 = .convertModelCellValue,
                                                                                   dcv13 );
        CellValue<? extends Comparable<?>> cell14 = .convertModelCellValue,
                                                                                   dcv14 );
        CellValue<? extends Comparable<?>> cell15 = .convertModelCellValue,
                                                                                   dcv15 );
        assertEqualscell1.getValue(),
                      new Integer( 1 ) );
        assertEqualscell2.getValue(),
                      . );
        assertEqualscell3.getValue(),
                      "Michael" );
        assertEqualscell4.getValue(),
                      new BigDecimal( 11 ) );
        assertEqualscell5.getValue(),
                      new BigInteger"11" ) );
        assertEqualscell6.getValue(),
                      new Byte"11" ) );
        assertEqualscell7.getValue(),
                      11.0d );
        assertEqualscell8.getValue(),
                      11.0f );
        assertEqualscell9.getValue(),
                      new Integer( 11 ) );
        assertEqualscell10.getValue(),
                      11l );
        assertEqualscell11.getValue(),
                      new Short"11" ) );
        assertEqualscell12.getValue(),
                      dob );
        assertEqualscell13.getValue(),
                      . );
        assertEqualscell14.getValue(),
                      "Mike" );
        assertEqualscell15.getValue(),
                      "Mike" );
    }
    @Test
    public void testConversionEmptyValues() {
        DTCellValue52 dcv1 = new DTCellValue52"" );
        DTCellValue52 dcv2 = new DTCellValue52"" );
        DTCellValue52 dcv3 = new DTCellValue52"" );
        DTCellValue52 dcv4 = new DTCellValue52"" );
        DTCellValue52 dcv5 = new DTCellValue52"" );
        DTCellValue52 dcv6 = new DTCellValue52"" );
        DTCellValue52 dcv7 = new DTCellValue52"" );
        DTCellValue52 dcv8 = new DTCellValue52"" );
        DTCellValue52 dcv9 = new DTCellValue52"" );
        DTCellValue52 dcv10 = new DTCellValue52"" );
        DTCellValue52 dcv11 = new DTCellValue52"" );
        DTCellValue52 dcv12 = new DTCellValue52"" );
        DTCellValue52 dcv13 = new DTCellValue52"" );
        DTCellValue52 dcv14 = new DTCellValue52"" );
        DTCellValue52 dcv15 = new DTCellValue52"" );
        CellValue<? extends Comparable<?>> cell1 = .convertModelCellValue,
                                                                                  dcv1 );
        CellValue<? extends Comparable<?>> cell2 = .convertModelCellValue,
                                                                                  dcv2 );
        CellValue<? extends Comparable<?>> cell3 = .convertModelCellValue,
                                                                                  dcv3 );
        CellValue<? extends Comparable<?>> cell4 = .convertModelCellValue,
                                                                                  dcv4 );
        CellValue<? extends Comparable<?>> cell5 = .convertModelCellValue,
                                                                                  dcv5 );
        CellValue<? extends Comparable<?>> cell6 = .convertModelCellValue,
                                                                                  dcv6 );
        CellValue<? extends Comparable<?>> cell7 = .convertModelCellValue,
                                                                                  dcv7 );
        CellValue<? extends Comparable<?>> cell8 = .convertModelCellValue,
                                                                                  dcv8 );
        CellValue<? extends Comparable<?>> cell9 = .convertModelCellValue,
                                                                                  dcv9 );
        CellValue<? extends Comparable<?>> cell10 = .convertModelCellValue,
                                                                                   dcv10 );
        CellValue<? extends Comparable<?>> cell11 = .convertModelCellValue,
                                                                                   dcv11 );
        CellValue<? extends Comparable<?>> cell12 = .convertModelCellValue,
                                                                                   dcv12 );
        CellValue<? extends Comparable<?>> cell13 = .convertModelCellValue,
                                                                                   dcv13 );
        CellValue<? extends Comparable<?>> cell14 = .convertModelCellValue,
                                                                                   dcv14 );
        CellValue<? extends Comparable<?>> cell15 = .convertModelCellValue,
                                                                                   dcv15 );
        assertEqualscell1.getValue(),
                      null );
        assertEqualscell2.getValue(),
                      . );
        assertEqualscell3.getValue(),
                      null );
        assertEqualscell4.getValue(),
                      null );
        assertEqualscell5.getValue(),
                      null );
        assertEqualscell6.getValue(),
                      null );
        assertEqualscell7.getValue(),
                      null );
        assertEqualscell8.getValue(),
                      null );
        assertEqualscell9.getValue(),
                      null );
        assertEqualscell10.getValue(),
                      null );
        assertEqualscell11.getValue(),
                      null );
        assertEqualscell12.getValue(),
                      null );
        assertEqualscell13.getValue(),
                      . );
        assertEqualscell14.getValue(),
                      null );
        assertEqualscell15.getValue(),
                      null );
        assertEqualsdcv1.getDataType(),
                      .. );
        assertEqualsdcv2.getDataType(),
                      .. );
        assertEqualsdcv3.getDataType(),
                      .. );
        assertEqualsdcv4.getDataType(),
                      .. );
        assertEqualsdcv5.getDataType(),
                      .. );
        assertEqualsdcv6.getDataType(),
                      .. );
        assertEqualsdcv7.getDataType(),
                      .. );
        assertEqualsdcv8.getDataType(),
                      .. );
        assertEqualsdcv9.getDataType(),
                      .. );
        assertEqualsdcv10.getDataType(),
                      .. );
        assertEqualsdcv11.getDataType(),
                      .. );
        assertEqualsdcv12.getDataType(),
                      .. );
        assertEqualsdcv13.getDataType(),
                      .. );
        assertEqualsdcv14.getDataType(),
                      .. );
        assertEqualsdcv15.getDataType(),
                      .. );
    }
New to GrepCode? Check out our FAQ X