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.imports.Import;
 import  org.drools.workbench.models.commons.shared.imports.Imports;
 import org.junit.Test;
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 Globals
public class DataModelGlobalsTest {
    @Test
    public void testGlobal() throws Exception {
        final ProjectDataModelOracle pd = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                .addClassProduct.class )
                .build();
        final PackageDataModelOracle dmo = PackageDataModelOracleBuilder.newPackageOracleBuilder"org.kie.workbench.common.services.datamodel.backend.server.testclasses" )
                .setProjectOraclepd )
                .addGlobals( "global org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product g;" )
                .build();
        assertNotNulldmo );
        assertEquals( 1,
                      dmo.getFactTypes().length );
        assertEquals"Product",
                      dmo.getFactTypes()[ 0 ] );
        assertEquals( 1,
                      dmo.getGlobalVariables().length );
        assertEquals"g",
                      dmo.getGlobalVariables()[ 0 ] );
        assertEquals"Product",
                      dmo.getGlobalVariable( "g" ) );
        final String[] fields = dmo.getFieldCompletions( "Product" );
        assertNotNullfields );
        assertTrue( Arrays.asListfields ).contains"this" ) );
        assertTrue( Arrays.asListfields ).contains"colour" ) );
        assertEquals( 0,
                      dmo.getGlobalCollections().length );
    }
    @Test
    public void testGlobalCollections() throws Exception {
        final ProjectDataModelOracle pd = ProjectDataModelOracleBuilder.newProjectOracleBuilder()
                .addClassjava.util.List.class )
                .build();
        final PackageDataModelOracle dmo = PackageDataModelOracleBuilder.newPackageOracleBuilder"org.kie.workbench.common.services.datamodel.backend.server.testclasses" )
                .setProjectOraclepd )
                .addGlobals( "global java.util.List list;" )
                .build();
        final Imports imports = new Imports();
        imports.addImport( new Import( "java.util.List" ) );
        dmo.filter( imports );
        assertNotNulldmo );
        assertEquals( 1,
                      dmo.getFactTypes().length );
        assertEquals"List",
                      dmo.getFactTypes()[ 0 ] );
        assertEquals( 1,
                      dmo.getGlobalVariables().length );
        assertEquals"list",
                      dmo.getGlobalVariables()[ 0 ] );
        assertEquals"List",
                      dmo.getGlobalVariable( "list" ) );
        assertEquals( 1,
                      dmo.getGlobalCollections().length );
        assertEquals"list",
                      dmo.getGlobalCollections()[ 0 ] );
    }
New to GrepCode? Check out our FAQ X