Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.kie.workbench.common.services.datamodel.backend.server;
  
  import java.util.Arrays;
  import java.util.List;
  
  import  org.drools.core.util.asm.ClassFieldInspector;
  import  org.drools.workbench.models.commons.shared.oracle.model.DataType;
 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 MethodInfo and Parametric types
 
 public class DataModelParametricTypesTest {
 
     @Test
     public void testClassFieldInspector() throws Exception {
         final ClassFieldInspector cfi = new ClassFieldInspector( Purchase.class );
         final Type t1 = cfi.getFieldTypesField().get( "customerName" ).getGenericType();
         final Type t2 = cfi.getFieldTypesField().get( "items" ).getGenericType();
 
         assertNotNullt1 );
         assertNotNullt2 );
 
         assertFalset1 instanceof ParameterizedType );
         assertTruet2 instanceof ParameterizedType );
     }
 
     @Test
     public void testPackageDMOParametricReturnTypes() throws Exception {
         final ProjectDataModelOracle pd = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                 .addClassPurchase.class )
                 .addClassProduct.class )
                 .build();
 
         final PackageDataModelOracle dmo = PackageDataModelOracleBuilder.newPackageOracleBuilder"org.kie.workbench.common.services.datamodel.backend.server.testclasses" ).setProjectOraclepd ).build();
 
         assertNotNulldmo );
 
         assertEquals( 2,
                       dmo.getFactTypes().length );
 
         List<Stringlist = Arrays.asListdmo.getFactTypes() );
 
         assertTruelist.contains"Purchase" ) );
         assertTruelist.contains"Product" ) );
 
         assertEquals"java.util.Collection",
                       dmo.getFieldClassName( "Purchase",
                                              "items" ) );
         assertEquals( DataType.TYPE_COLLECTION,
                       dmo.getFieldType( "Purchase",
                                         "items" ) );
         assertEquals"Product",
                       dmo.getParametricFieldType( "Purchase",
                                                   "items" ) );
 
     }
 
     @Test
     public void testProjectDMOParametricReturnTypes() throws Exception {
         final ProjectDataModelOracle oracle = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                 .addClassPurchase.class )
                 .addClassProduct.class )
                 .build();
 
         assertNotNulloracle );
 
         assertEquals( 2,
                       oracle.getFactTypes().length );
 
         List<Stringlist = Arrays.asListoracle.getFactTypes() );
 
         assertTruelist.contains"org.kie.workbench.common.services.datamodel.backend.server.testclasses.Purchase" ) );
         assertTruelist.contains"org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product" ) );
 
         assertEquals"java.util.Collection",
                       oracle.getFieldClassName( "org.kie.workbench.common.services.datamodel.backend.server.testclasses.Purchase",
                                                 "items" ) );
         assertEquals( DataType.TYPE_COLLECTION,
                       oracle.getFieldType( "org.kie.workbench.common.services.datamodel.backend.server.testclasses.Purchase",
                                            "items" ) );
         assertEquals"org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product",
                       oracle.getParametricFieldType( "org.kie.workbench.common.services.datamodel.backend.server.testclasses.Purchase",
                                                      "items" ) );
 
     }
 
     @Test
     public void testParametricMethod() throws Exception {
        final ProjectDataModelOracle pd = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                .addClassPurchase.class )
                .build();
        final PackageDataModelOracle dmo = PackageDataModelOracleBuilder.newPackageOracleBuilder"org.kie.workbench.common.services.datamodel.backend.server.testclasses" ).setProjectOraclepd ).build();
        assertNotNulldmo );
        assertEquals"Product",
                      dmo.getParametricFieldType( "Purchase",
                                                  "customerPurchased(int)" ) );
    }
New to GrepCode? Check out our FAQ X