Package org.drools.guvnor.server.files

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


        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

        RepositoryPackageService repoPackageService = getRepositoryPackageService();

        long before = System.currentTimeMillis();
        Thread.sleep( 20 );
        FileManagerUtils uploadHelper = getFileManagerUtils();

        PackageItem pkg = repo.createPackage( "testGetBinaryPackageServlet",
                                              "" );
        DroolsHeader.updateDroolsHeader( "import java.util.List",
                                                  pkg );
        pkg.updateCompiledPackage( new ByteArrayInputStream( "foo".getBytes() ) );
        pkg.checkin( "" );

        assertTrue( before < uploadHelper.getLastModified( pkg.getName(),
                                                           "LATEST" ) );

        repoPackageService.createPackageSnapshot( pkg.getName(),
                                    "SNAPPY 1",
                                    false,
                                    "" );

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        String fileName = uploadHelper.loadBinaryPackage( pkg.getName(),
                                                          Snapshot.LATEST_SNAPSHOT,
                                                          true,
                                                          out );
        assertEquals( "testGetBinaryPackageServlet.pkg",
                      fileName );
        byte[] file = out.toByteArray();
        assertNotNull( file );
        assertEquals( "foo",
                      new String( file ) );

        out = new ByteArrayOutputStream();
        String drlName = uploadHelper.loadSourcePackage( pkg.getName(),
                                                         Snapshot.LATEST_SNAPSHOT,
                                                         true,
                                                         out );
        String drl = new String( out.toByteArray() );
        assertEquals( pkg.getName() + ".drl",
                      drlName );
        assertNotNull( drl );
        assertTrue( drl.indexOf( "import java.util.List" ) > -1 );

        out = new ByteArrayOutputStream();
        fileName = uploadHelper.loadBinaryPackage( pkg.getName(),
                                                   "SNAPPY 1",
                                                   false,
                                                   out );
        assertEquals( "testGetBinaryPackageServlet_SNAPPY+1.pkg",
                      fileName );
        file = out.toByteArray();
        assertNotNull( file );
        assertEquals( "foo",
                      new String( file ) );

        out = new ByteArrayOutputStream();
        fileName = uploadHelper.loadSourcePackage( pkg.getName(),
                                                   "SNAPPY 1",
                                                   false,
                                                   out );
        assertEquals( "testGetBinaryPackageServlet_SNAPPY+1.drl",
                      fileName );
        drl = new String( out.toByteArray() );
        assertTrue( drl.indexOf( "import java.util.List" ) > -1 );

        Thread.sleep( 100 );
        repoPackageService.createPackageSnapshot( pkg.getName(),
                                    "SNAPX",
                                    false,
                                    "" );

        long lastMod = uploadHelper.getLastModified( pkg.getName(),
                                                     "SNAPPY 1" );
        assertTrue( pkg.getLastModified().getTimeInMillis() < lastMod );

        Thread.sleep( 100 );

        repoPackageService.createPackageSnapshot( pkg.getName(),
                                    "SNAPX",
                                    true,
                                    "yeah" );

        long lastMod2 = uploadHelper.getLastModified( pkg.getName(),
                                                      "SNAPX" );
        assertTrue( lastMod < lastMod2 );

    }
View Full Code Here

     * Tests importing when an archived package with the same name exists.
     */

    @Test
    public void testImportArchivedPackage() throws Exception {
        FileManagerUtils fm = getFileManagerUtils();

        // Import package
        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 );
        assertFalse( pkg.isArchived() );

        // Archive it
        pkg.archiveItem( true );

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

        // Import it again
        InputStream in2 = new ByteArrayInputStream( drl.getBytes() );
        fm.importClassicDRL( in2,
                             null );

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

    }
View Full Code Here

    }

    @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

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.