Package org.drools.io.impl

Examples of org.drools.io.impl.UrlResource


        assertNotNull( resourceAdapter );

        Resource resource = resourceAdapter.getDroolsResource();
        assertTrue( resource instanceof UrlResource );

        UrlResource ur = (UrlResource) resource;

        assertEquals( "enabled",
                      ur.getBasicAuthentication() );
        assertEquals( "someUser",
                      ur.getUsername() );
        assertEquals( "somePassword",
                      ur.getPassword() );

        //Insecure Resource
        resourceAdapter = (DroolsResourceAdapter) context.getBean( "insecureResource" );
        assertNotNull( resourceAdapter );

        resource = resourceAdapter.getDroolsResource();
        assertTrue( resource instanceof UrlResource );

        ur = (UrlResource) resource;

        assertEquals( "disabled",
                      ur.getBasicAuthentication() );
        assertEquals( "",
                      ur.getUsername() );
        assertEquals( "",
                      ur.getPassword() );
    }
View Full Code Here


        InternalResource resource = null;
       
        if ( src.trim().startsWith( "classpath:" ) ) {
            resource = new ClassPathResource( src.substring( src.indexOf( ':' ) + 1 ), parser.getClassLoader() );
        } else {
            resource = new UrlResource( src );
        }
       
        resource.setResourceType( ResourceType.getResourceType( type ) );
       
        return resource;
View Full Code Here


    @Test
    public void testWithCache() throws Exception {
        URL url = new URL("http://localhost:"+this.getPort()+"/rule1.drl");
        UrlResource ur = new UrlResource(url);
        File cacheDir = new File("target/test-tmp/cache");
        cacheDir.mkdirs();
        UrlResource.CACHE_DIR = cacheDir;

        File f1 = fileManager.newFile( "rule1.drl" );
        System.err.println("target file: " + f1.getAbsolutePath());
        Writer output = new BufferedWriter( new FileWriter( f1 ) );
        output.write( "Some data" );
        output.close();

        long lm = ur.getLastModified();
        assertTrue(lm > 0);

        InputStream ins = ur.getInputStream();
        assertNotNull(ins);

        server.stop();

        assertNotNull(ur.getInputStream());

        assertTrue(ur.getLastModified() > 0);

        assertTrue(ur.getInputStream() instanceof FileInputStream);


        //now write some more stuff
        Thread.sleep(1000);
        f1.delete();
        output = new BufferedWriter( new FileWriter( f1 ) );
        output.write( "More data..." );
        output.close();

        server.start();

        url = new URL("http://localhost:"+this.getPort()+"/rule1.drl");
        ur = new UrlResource(url);

        assertNotNull(ur.getInputStream());
        assertFalse(ur.getInputStream() instanceof FileInputStream);
        long lm_ = ur.getLastModified();
        System.err.println("lm_ : " + lm_ + " lm : " + lm );

        assertTrue(lm_ > lm);

        InputStream in_= ur.getInputStream();
        BufferedReader rdr = new BufferedReader(new InputStreamReader(in_));
        String line = rdr.readLine();
        assertEquals("More data...", line);

        server.stop();

        Thread.sleep(1000);
        f1.delete();
        output = new BufferedWriter( new FileWriter( f1 ) );
        output.write( "Finally.." );
        output.close();

        //now it should be cached, so using old copy still... (server has stopped serving it up)
        ur = new UrlResource(url);
        in_= ur.getInputStream();
        rdr = new BufferedReader(new InputStreamReader(in_));
        line = rdr.readLine();
        assertEquals("More data...", line);

        Thread.sleep(1000);
        server.start();

        url = new URL("http://localhost:"+this.getPort()+"/rule1.drl");
        ur = new UrlResource(url);

        ur = new UrlResource(url);
        //server is started, so should have latest...
        in_= ur.getInputStream();
        rdr = new BufferedReader(new InputStreamReader(in_));
        line = rdr.readLine();
        assertEquals("Finally..", line);

View Full Code Here

    }

    @Test
    public void testWithoutCache() throws Exception {
        UrlResource ur = new UrlResource(new URL("http://localhost:"+this.getPort()+"/rule1.drl"));
        UrlResource.CACHE_DIR = null;

        File f1 = fileManager.newFile( "rule1.drl" );
        System.err.println("target file: " + f1.getAbsolutePath());
        Writer output = new BufferedWriter( new FileWriter( f1 ) );
        output.write( "Some data" );
        output.close();

        long lm = ur.getLastModified();
        assertTrue(lm > 0);

        InputStream ins = ur.getInputStream();
        assertNotNull(ins);

        server.stop();
        assertEquals(0, ur.getLastModified());




View Full Code Here

        StringReader reader = new StringReader( str );
        ChangeSet changeSet = xmlReader.read( reader );

        assertEquals( 2,
                      changeSet.getResourcesAdded().size() );
        UrlResource resource = ( UrlResource ) ((List)changeSet.getResourcesAdded()).get( 0 );
        assertNull( resource.getConfiguration() );
        assertEquals( "http://www.domain.com/test.drl",
                      resource.getURL().toString() );
        assertEquals( ResourceType.DRL,
                      resource.getResourceType() );

        resource =  ( UrlResource ) ((List)changeSet.getResourcesAdded()).get( 1 );
       
        assertEquals( "http://www.domain.com/test.xls",
                      resource.getURL().toString() );
        assertEquals( ResourceType.DTABLE,
                      resource.getResourceType() );
        DecisionTableConfiguration dtConf = (DecisionTableConfiguration) resource.getConfiguration();
        assertEquals( DecisionTableInputType.XLS,
                      dtConf.getInputType() );
    }
View Full Code Here

        StringReader reader = new StringReader( str );
        ChangeSet changeSet = xmlReader.read( reader );

        assertEquals( 1,
                      changeSet.getResourcesAdded().size() );
        UrlResource resource = ( UrlResource ) ((List)changeSet.getResourcesAdded()).get( 0 );
        assertNull( resource.getConfiguration() );
        assertEquals( "http://localhost:8081/jboss-brms/org.drools.guvnor.Guvnor/package/defaultPackage/LATEST",
                      resource.getURL().toString() );
        assertEquals( "enabled", resource.getBasicAuthentication() );
        assertEquals( "admin", resource.getUsername() );
        assertEquals( "pwd", resource.getPassword() );
        assertEquals( ResourceType.PKG,
                      resource.getResourceType() );
    }
View Full Code Here

    public void setResource(String resource) {
        if ( resource.trim().startsWith( "classpath:" ) ) {
            this.resource = new ClassPathResource( resource.substring( resource.indexOf( ':' ) + 1 ),
                                                   ClassPathResource.class.getClassLoader() );
        } else {
            this.resource = new UrlResource( resource );
        }
    }
View Full Code Here

        InternalResource resource = null;
       
        if ( src.trim().startsWith( "classpath:" ) ) {
            resource = new ClassPathResource( src.substring( src.indexOf( ':' ) + 1 ), parser.getClassLoader() );
        } else {
            resource = new UrlResource( src );
            ((UrlResource)resource).setBasicAuthentication(basicAuthentication);
            ((UrlResource)resource).setUsername(username);
            ((UrlResource)resource).setPassword(password);
        }
       
View Full Code Here

        InternalResource resource = null;
       
        if ( src.trim().startsWith( "classpath:" ) ) {
            resource = new ClassPathResource( src.substring( src.indexOf( ':' ) + 1 ), parser.getClassLoader() );
        } else {
            resource = new UrlResource( src );
        }
       
        resource.setResourceType( ResourceType.valueOf( type ) );
       
        return resource;
View Full Code Here

        InternalResource resource = null;
       
        if ( src.trim().startsWith( "classpath:" ) ) {
            resource = new ClassPathResource( src.substring( src.indexOf( ':' ) + 1 ), ( Class ) parser.getMetaData().get( "clazz" ), parser.getClassLoader() );
        } else {
            resource = new UrlResource( src );
            ((UrlResource)resource).setBasicAuthentication(basicAuthentication);
            ((UrlResource)resource).setUsername(username);
            ((UrlResource)resource).setPassword(password);          
        }
       
View Full Code Here

TOP

Related Classes of org.drools.io.impl.UrlResource

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.