Package org.drools.guvnor.server.files

Examples of org.drools.guvnor.server.files.FileManagerUtils


    }

    @Test
    public void testClassicDRLImport() throws Exception {
        FileManagerUtils fm = getFileManagerUtils();
        String drl = "package testClassicDRLImport\n import blah \n rule 'ola' \n when \n then \n end \n rule 'hola' \n when \n then \n end";
        InputStream in = new ByteArrayInputStream( drl.getBytes() );
        fm.importClassicDRL( in,
                             null );

        PackageItem pkg = fm.getRepository().loadPackage( "testClassicDRLImport" );
        assertNotNull( pkg );

        List<AssetItem> rules = iteratorToList( pkg.getAssets() );
        assertEquals( 3,
                      rules.size() );

        AssetItem pkgConf = rules.get( 0 );
        assertEquals( "drools",
                      pkgConf.getName() );
        rules.remove( 0 );

        final AssetItem rule1 = rules.get( 0 );
        assertEquals( "ola",
                      rule1.getName() );
        assertNotNull( rule1.getContent() );
        assertEquals( AssetFormats.DRL,
                      rule1.getFormat() );
        assertTrue( rule1.getContent().indexOf( "when" ) > -1 );

        final AssetItem rule2 = rules.get( 1 );
        assertEquals( "hola",
                      rule2.getName() );
        assertNotNull( rule2.getContent() );
        assertEquals( AssetFormats.DRL,
                      rule2.getFormat() );
        assertTrue( rule2.getContent().indexOf( "when" ) > -1 );

        assertNotNull( DroolsHeader.getDroolsHeader( pkg ) );
        assertTrue( DroolsHeader.getDroolsHeader( pkg ).indexOf( "import" ) > -1 );

        // now lets import an existing thing
        drl = "package testClassicDRLImport\n import should not see \n rule 'ola2' \n when \n then \n end \n rule 'hola' \n when \n then \n end";
        in = new ByteArrayInputStream( drl.getBytes() );
        fm.importClassicDRL( in,
                             null );

        pkg = fm.getRepository().loadPackage( "testClassicDRLImport" );
        assertNotNull( pkg );

        // it should not overwrite this.
        String hdr = DroolsHeader.getDroolsHeader( pkg );
        assertTrue( hdr.indexOf( "import should not see" ) > -1 );
        assertTrue( hdr.indexOf( "import blah" ) > -1 );
        assertTrue( hdr.indexOf( "import should not see" ) > hdr.indexOf( "import blah" ) );

        rules = iteratorToList( pkg.getAssets() );
        assertEquals( 4,
                      rules.size() );

        // now we will import a change, check that it appears. a change to the
        // "ola" rule
        AssetItem assetOriginal = fm.getRepository().loadPackage( "testClassicDRLImport" ).loadAsset( "ola" );
        long ver = assetOriginal.getVersionNumber();

        drl = "package testClassicDRLImport\n import blah \n rule 'ola' \n when CHANGED\n then \n end \n rule 'hola' \n when \n then \n end";
        in = new ByteArrayInputStream( drl.getBytes() );
        fm.importClassicDRL( in,
                             null );
        pkg = fm.getRepository().loadPackage( "testClassicDRLImport" );
        AssetItem asset = pkg.loadAsset( "ola" );

        assertTrue( asset.getContent().indexOf( "CHANGED" ) > 0 );
        assertEquals( ver + 1,
                      asset.getVersionNumber() );
View Full Code Here


    }

    @Test
    public void testDRLImportWithoutPackageName() throws Exception {
        FileManagerUtils fm = getFileManagerUtils();
        String drl = "import blah \n rule 'ola' \n when \n then \n end \n rule 'hola' \n when \n then \n end";
        InputStream in = new ByteArrayInputStream( drl.getBytes() );

        try {
            fm.importClassicDRL( in,
                                 null );
        } catch ( IllegalArgumentException e ) {
            assertEquals( "Missing package name.",
                          e.getMessage() );
        }

        in = new ByteArrayInputStream( drl.getBytes() );
        fm.importClassicDRL( in,
                             "testDRLImportWithoutPackageName" );

        PackageItem pkg = fm.getRepository().loadPackage( "testDRLImportWithoutPackageName" );
        assertNotNull( pkg );

        List<AssetItem> rules = iteratorToList( pkg.getAssets() );
        assertEquals( 3,
                      rules.size() );
View Full Code Here

    }

    @Test
    public void testDRLImportOverrideExistingPackageName() throws Exception {
        FileManagerUtils fm = getFileManagerUtils();
        String drl = "package thisIsNeverUsed \n import blah \n rule 'ola' \n when \n then \n end \n rule 'hola' \n when \n then \n end";
        InputStream in = new ByteArrayInputStream( drl.getBytes() );

        in = new ByteArrayInputStream( drl.getBytes() );
        fm.importClassicDRL( in,
                             "testDRLImportOverrideExistingPackageName" );

        PackageItem pkg = fm.getRepository().loadPackage( "testDRLImportOverrideExistingPackageName" );
        assertNotNull( pkg );

        List<AssetItem> rules = iteratorToList( pkg.getAssets() );
        assertEquals( 3,
                      rules.size() );
View Full Code Here

    }

    @Test
    public void testClassicDRLImportWithDSL() throws Exception {
        FileManagerUtils fm = getFileManagerUtils();
        String drl = "package testClassicDRLImportDSL\n import blah \n expander goo \n rule 'ola' \n when \n then \n end \n rule 'hola' \n when \n then \n end";
        InputStream in = new ByteArrayInputStream( drl.getBytes() );
        fm.importClassicDRL( in,
                             null );

        PackageItem pkg = fm.getRepository().loadPackage( "testClassicDRLImportDSL" );
        assertNotNull( pkg );

        List<AssetItem> rules = iteratorToList( pkg.getAssets() );
        assertEquals( 3,
                      rules.size() ); //its 3 cause there is the drools.package file
View Full Code Here

        int iterations = 0;

        int maxIteration = 1; //pick a large number to do a stress test
        while ( iterations < maxIteration ) {
            iterations++;
            FileManagerUtils fm = getFileManagerUtils();

            if ( iterations % 50 == 0 ) {
                updatePackage( "testHeadOOME" );
            }

            //fm.setRepository( new RulesRepository(TestEnvironmentSessionHelper.getSession()));
            fm.getLastModified( "testHeadOOME",
                                "LATEST" );
            //fm.getRepository().logout();
            System.err.println( "Number " + iterations + " free mem : " + Runtime.getRuntime().freeMemory() );
        }
    }
View Full Code Here

        Contexts.getSessionContext().set( "fileManager",
                                          getFileManagerUtils() );
    }

    protected FileManagerUtils getFileManagerUtils() {
        FileManagerUtils fileManager = new FileManagerUtils();
        fileManager.setRepository( getRulesRepository() );
        return fileManager;
    }
View Full Code Here

                                          "com.billasurf.manufacturing.plant",
                                          AssetFormats.MODEL );
        InputStream file = this.getClass().getResourceAsStream( "/billasurf.jar" );
        assertNotNull( file );

        FileManagerUtils fm = new FileManagerUtils();
        fm.setRepository( repo );

        fm.attachFileToAsset( uuid,
                              file,
                              "billasurf.jar" );

        AssetItem item = repo.loadAssetByUUID( uuid );
        assertNotNull( item.getBinaryContentAsBytes() );
View Full Code Here

public class FileManagerUtilsTest extends GuvnorTestBase {

    @Test
    public void testAttachFile() throws Exception {

        FileManagerUtils uploadHelper = getFileManagerUtils();

        ServiceImplementation impl = getServiceImplementation();
        RulesRepository repo = impl.getRulesRepository();

        AssetItem item = repo.loadDefaultPackage().addAsset( "testUploadFile",
                                                             "description" );
        item.updateFormat( "drl" );
        FormData upload = new FormData();

        upload.setFile( new MockFile() );
        upload.setUuid( item.getUUID() );

        uploadHelper.attachFile( upload );

        AssetItem item2 = repo.loadDefaultPackage().loadAsset( "testUploadFile" );
        byte[] data = item2.getBinaryContentAsBytes();

        assertNotNull( data );
View Full Code Here

        repo.save();

        assertTrue( pkg.isBinaryUpToDate() );
        assertEquals( "",
                      DroolsHeader.getDroolsHeader( pkg ) );
        FileManagerUtils fm = getFileManagerUtils();

        fm.attachFileToAsset( asset.getUUID(),
                              this.getClass().getResourceAsStream( "/billasurf.jar" ),
                              "billasurf.jar" );

        pkg = repo.loadPackage( "testAttachModelImports" );

        assertFalse( pkg.isBinaryUpToDate() );
        assertNotNull( DroolsHeader.getDroolsHeader( pkg ) );
        assertTrue( DroolsHeader.getDroolsHeader( pkg ).indexOf( "import com.billasurf.Board" ) > -1 );
        assertTrue( DroolsHeader.getDroolsHeader( pkg ).indexOf( "import com.billasurf.Person" ) > -1 );

        DroolsHeader.updateDroolsHeader( "goo wee",
                                                  pkg );
        pkg.checkin( "" );

        fm.attachFileToAsset( asset.getUUID(),
                              this.getClass().getResourceAsStream( "/billasurf.jar" ),
                              "billasurf.jar" );
        pkg = repo.loadPackage( "testAttachModelImports" );
        assertEquals( "goo wee\nimport com.billasurf.Board\nimport com.billasurf.Person\n",
                      DroolsHeader.getDroolsHeader( pkg ) );
View Full Code Here

    }

    @Test
    public void testGetFilebyUUID() throws Exception {
        FileManagerUtils uploadHelper = getFileManagerUtils();

        ServiceImplementation impl = getServiceImplementation();
        RulesRepository repo = impl.getRulesRepository();

        AssetItem item = repo.loadDefaultPackage().addAsset( "testGetFilebyUUID",
                                                             "description" );
        item.updateFormat( "drl" );
        FormData upload = new FormData();

        upload.setFile( new MockFile() );
        upload.setUuid( item.getUUID() );
        uploadHelper.attachFile( upload );

        ByteArrayOutputStream out = new ByteArrayOutputStream();

        String filename = uploadHelper.loadFileAttachmentByUUID( item.getUUID(),
                                                                 out );

        assertNotNull( out.toByteArray() );
        assertEquals( "foo bar",
                      new String( out.toByteArray() ) );
View Full Code Here

TOP

Related Classes of org.drools.guvnor.server.files.FileManagerUtils

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.