Package freenet.crypt

Examples of freenet.crypt.MultiHashInputStream$Digester


        throws IOException
    {

        String xml = "<root alpha='${attr1}'/>";
        StringReader input = new StringReader( xml );
        Digester digester = new Digester();

        // Configure the digester as required
        MultiVariableExpander expander = new MultiVariableExpander();
        expander.addSource( "$", new HashMap<String, Object>() );
        digester.setSubstitutor( new VariableSubstitutor( expander ) );

        digester.addObjectCreate( "root", SimpleTestBean.class );
        digester.addSetProperties( "root" );

        // Parse our test input.
        try
        {
            digester.parse( input );
            fail( "Exception expected due to unknown variable." );
        }
        catch ( SAXException e )
        {
            // expected, due to reference to undefined variable
View Full Code Here


    public void testExpansionWithMutableSource()
        throws SAXException, IOException
    {
        String xml = "<root>" + "<property name='attr' value='prop.value'/>" + "<bean alpha='${attr}'/>" + "</root>";
        StringReader input = new StringReader( xml );
        Digester digester = createDigesterThatCanDoAnt();

        simpleTestBeans.clear();
        digester.push( this );
        digester.parse( input );

        assertEquals( 1, simpleTestBeans.size() );
        SimpleTestBean bean = simpleTestBeans.get( 0 );
        assertEquals( "prop.value", bean.getAlpha() );
    }
View Full Code Here

    {
        String xml =
            "<root>" + "<property name='attr1' value='prop.value1'/>"
                + "<property name='attr2' value='substituted-${attr1}'/>" + "<bean alpha='${attr2}'/>" + "</root>";
        StringReader input = new StringReader( xml );
        Digester digester = createDigesterThatCanDoAnt();

        simpleTestBeans.clear();
        digester.push( this );
        digester.parse( input );

        assertEquals( 1, simpleTestBeans.size() );
        SimpleTestBean bean = simpleTestBeans.get( 0 );
        assertEquals( "substituted-prop.value1", bean.getAlpha() );
    }
View Full Code Here

        if ( rules == null )
        {
            throw new DigesterLoadingException( "Impossible to create a new Digester with null Rules" );
        }

        Digester digester = new Digester( reader );
        digester.setRules( rules );
        digester.setSubstitutor( substitutor );
        digester.registerAll( entityValidator );
        digester.setEntityResolver( entityResolver );
        digester.setStackAction( stackAction );
        digester.setNamespaceAware( isNamespaceAware() );
        digester.setExecutorService( executorService );

        addRules( digester );

        return digester;
    }
View Full Code Here

        throws Exception
    {
        // * tests that when a PluginCreateRule is defined with a default
        // class, that the default class is instantiated when no class
        // or id is specified in the xml file.
        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules( rc );

        PluginCreateRule pcr = new PluginCreateRule( Widget.class, TextLabel.class );
        digester.addRule( "root/widget", pcr );
        digester.addSetNext( "root/widget", "addChild" );

        Container root = new Container();
        digester.push( root );

        try
        {
            digester.parse( Utils.getInputStream( this, "test2.xml" ) );
        }
        catch ( Exception e )
        {
            throw e;
        }
View Full Code Here

    public void testDefaultPlugins2()
        throws Exception
    {
        // * tests that when there is no default plugin, it is an error
        // not to have one of plugin-class or plugin-id specified
        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules( rc );

        PluginCreateRule pcr = new PluginCreateRule( Widget.class );
        digester.addRule( "root/widget", pcr );
        digester.addSetNext( "root/widget", "addChild" );

        Container root = new Container();
        digester.push( root );

        Exception exception = null;
        Log oldLog = digester.getLogger();
        try
        {
            digester.setLogger( new NoOpLog() );
            digester.parse( Utils.getInputStream( this, "test2.xml" ) );
        }
        catch ( Exception e )
        {
            exception = e;
        }
        finally
        {
            digester.setLogger( oldLog );
        }

        assertNotNull( exception );
        assertEquals( SAXParseException.class, exception.getClass() );
        assertEquals( PluginInvalidInputException.class, ( (SAXParseException) exception ).getException().getClass() );
View Full Code Here

     */
    @Before
    public void setUp()
    {

        digester = new Digester();
        digester.setRules( new RulesBase() );

    }
View Full Code Here

    public void testDefaultPlugins3()
        throws Exception
    {
        // * tests that the default plugin must implement or extend the
        // plugin base class.
        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules( rc );

        PluginCreateRule pcr = new PluginCreateRule( Widget.class, Object.class );
        digester.addRule( "root/widget", pcr );
        digester.addSetNext( "root/widget", "addChild" );

        Container root = new Container();
        digester.push( root );

        Exception exception = null;
        Log oldLog = digester.getLogger();
        try
        {
            digester.setLogger( new NoOpLog() );
            digester.parse( Utils.getInputStream( this, "test2.xml" ) );
        }
        catch ( Exception e )
        {
            exception = e;
        }
        finally
        {
            digester.setLogger( oldLog );
        }

        assertNotNull( exception );
        assertEquals( SAXParseException.class, exception.getClass() );
        assertEquals( PluginConfigurationException.class, ( (SAXParseException) exception ).getException().getClass() );
View Full Code Here

                this.body = text;
            }
        }

        TestSubRule tsr = new TestSubRule();
        Digester digester = new Digester();
        digester.addRule( "alpha/beta", tsr );

        // it's not easy to transform dirty harry into the mighty circus - but let's give it a try
        String xml =
            "<?xml version='1.0'?><alpha><beta forname='Dirty' surname='Harry'>Do you feel luck punk?</beta></alpha>";
        InputSource in = new InputSource( new StringReader( xml ) );

        digester.parse( in );

        assertEquals( "Unsubstituted body text", "Do you feel luck punk?", tsr.body );
        assertEquals( "Unsubstituted number of attributes", 2, tsr.attributes.getLength() );
        assertEquals( "Unsubstituted forname attribute value", "Dirty", tsr.attributes.getValue( "forname" ) );
        assertEquals( "Unsubstituted surname attribute value", "Harry", tsr.attributes.getValue( "surname" ) );

        digester.setSubstitutor( new Substitutor()
        {
            @Override
            public Attributes substitute( Attributes attributes )
            {
                AttributesImpl results = new AttributesImpl();
                results.addAttribute( "", "python", "python", "CDATA", "Cleese" );
                return results;
            }

            @Override
            public String substitute( String bodyText )
            {
                return "And now for something completely different...";
            }
        } );

        // now transform into the full monty
        in = new InputSource( new StringReader( xml ) );
        digester.parse( in );

        assertEquals( "Substituted body text", "And now for something completely different...", tsr.body );
        assertEquals( "Substituted number of attributes", 1, tsr.attributes.getLength() );
        assertEquals( "Substituted python attribute value", "Cleese", tsr.attributes.getValue( "", "python" ) );
    }
View Full Code Here

    public void testNamedStackPushPeekPop()
        throws Exception
    {
        BigDecimal archimedesAveragePi = new BigDecimal( "3.1418" );
        String testStackName = "org.apache.commons.digester3.tests.testNamedStackPushPeekPop";
        Digester digester = new Digester();
        assertTrue( "Stack starts empty:", digester.isEmpty( testStackName ) );
        digester.push( testStackName, archimedesAveragePi );
        assertEquals( "Peeked value:", archimedesAveragePi, digester.peek( testStackName ) );
        assertEquals( "Popped value:", archimedesAveragePi, digester.pop( testStackName ) );
        assertTrue( "Stack ends empty:", digester.isEmpty( testStackName ) );

        digester.push( testStackName, "1" );
        digester.push( testStackName, "2" );
        digester.push( testStackName, "3" );

        assertEquals( "Peek#1", "1", digester.peek( testStackName, 2 ) );
        assertEquals( "Peek#2", "2", digester.peek( testStackName, 1 ) );
        assertEquals( "Peek#3", "3", digester.peek( testStackName, 0 ) );
        assertEquals( "Peek#3a", "3", digester.peek( testStackName ) );

        try
        {
            // peek beyond stack
            digester.peek( testStackName, 3 );
            fail( "Peek#4 failed to throw an exception." );
        }
        catch ( EmptyStackException ex )
        {
            // ok, expected
        }

        try
        {
            // peek a nonexistent named stack
            digester.peek( "no.such.stack", 0 );
            fail( "Peeking a non-existent stack failed to throw an exception." );
        }
        catch ( EmptyStackException ex )
        {
            // ok, expected
View Full Code Here

TOP

Related Classes of freenet.crypt.MultiHashInputStream$Digester

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.