Examples of FileManagerUtils


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
TOP
Copyright © 2018 www.massapi.com. 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.