Package freenet.crypt

Examples of freenet.crypt.MultiHashInputStream$Digester


    public void testFactoryCreateRule()
        throws Exception
    {

        // test passing object create
        Digester digester = new Digester();
        ObjectCreationFactoryTestImpl factory = new ObjectCreationFactoryTestImpl();
        digester.addFactoryCreate( "root", factory, ignoreCreateExceptions );
        String xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
        digester.parse( new StringReader( xml ) );

        assertEquals( "Object create not called(1)[" + ignoreCreateExceptions + "]", factory.called, true );
        assertEquals( "Attribute not passed (1)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
                      "good" );
        assertEquals( "Attribute not passed (2)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
                      "bad" );
        assertEquals( "Attribute not passed (3)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
                      "ugly" );

        digester = new Digester();
        digester.addFactoryCreate( "root", "org.apache.commons.digester3.ObjectCreationFactoryTestImpl",
                                   ignoreCreateExceptions );
        digester.addSetNext( "root", "add" );
        xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
        List<ObjectCreationFactoryTestImpl> list = new ArrayList<ObjectCreationFactoryTestImpl>();
        digester.push( list );
        digester.parse( new StringReader( xml ) );

        assertEquals( "List should contain only the factory object", list.size(), 1 );
        factory = list.get( 0 );
        assertEquals( "Object create not called(2)[" + ignoreCreateExceptions + "]", factory.called, true );
        assertEquals( "Attribute not passed (4)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
                      "good" );
        assertEquals( "Attribute not passed (5)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
                      "bad" );
        assertEquals( "Attribute not passed (6)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
                      "ugly" );

        digester = new Digester();
        digester.addFactoryCreate( "root", "org.apache.commons.digester3.ObjectCreationFactoryTestImpl", "override",
                                   ignoreCreateExceptions );
        digester.addSetNext( "root", "add" );
        xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
        list = new ArrayList<ObjectCreationFactoryTestImpl>();
        digester.push( list );
        digester.parse( new StringReader( xml ) );

        assertEquals( "List should contain only the factory object", list.size(), 1 );
        factory = list.get( 0 );
        assertEquals( "Object create not called(3)[" + ignoreCreateExceptions + "]", factory.called, true );
        assertEquals( "Attribute not passed (7)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
                      "good" );
        assertEquals( "Attribute not passed (8)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
                      "bad" );
        assertEquals( "Attribute not passed (8)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
                      "ugly" );

        digester = new Digester();
        digester.addFactoryCreate( "root", "org.apache.commons.digester3.ObjectCreationFactoryTestImpl", "override",
                                   ignoreCreateExceptions );
        digester.addSetNext( "root", "add" );
        xml =
            new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly' "
                + " override='org.apache.commons.digester3.OtherTestObjectCreationFactory' >" + "<element/></root>" );
        list = new ArrayList<ObjectCreationFactoryTestImpl>();
        digester.push( list );
        digester.parse( new StringReader( xml ) );

        assertEquals( "List should contain only the factory object", list.size(), 1 );
        factory = list.get( 0 );
        assertEquals( "Attribute Override Failed (1)", factory.getClass().getName(),
                      "org.apache.commons.digester3.OtherTestObjectCreationFactory" );
        assertEquals( "Object create not called(4)[" + ignoreCreateExceptions + "]", factory.called, true );
        assertEquals( "Attribute not passed (10)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
                      "good" );
        assertEquals( "Attribute not passed (11)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
                      "bad" );
        assertEquals( "Attribute not passed (12)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
                      "ugly" );

        digester = new Digester();
        digester.addFactoryCreate( "root", ObjectCreationFactoryTestImpl.class, "override", ignoreCreateExceptions );
        digester.addSetNext( "root", "add" );
        xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
        list = new ArrayList<ObjectCreationFactoryTestImpl>();
        digester.push( list );
        digester.parse( new StringReader( xml ) );

        assertEquals( "List should contain only the factory object", list.size(), 1 );
        factory = list.get( 0 );
        assertEquals( "Object create not called(5)[" + ignoreCreateExceptions + "]", factory.called, true );
        assertEquals( "Attribute not passed (13)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
                      "good" );
        assertEquals( "Attribute not passed (14)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
                      "bad" );
        assertEquals( "Attribute not passed (15)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
                      "ugly" );

        digester = new Digester();
        digester.addFactoryCreate( "root", ObjectCreationFactoryTestImpl.class, "override", ignoreCreateExceptions );
        digester.addSetNext( "root", "add" );
        xml =
            new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly' "
                + " override='org.apache.commons.digester3.OtherTestObjectCreationFactory' >" + "<element/></root>" );
        list = new ArrayList<ObjectCreationFactoryTestImpl>();
        digester.push( list );
        digester.parse( new StringReader( xml ) );

        assertEquals( "List should contain only the factory object", list.size(), 1 );
        factory = list.get( 0 );
        assertEquals( "Attribute Override Failed (2)", factory.getClass().getName(),
                      "org.apache.commons.digester3.OtherTestObjectCreationFactory" );
View Full Code Here


                bindRulesFrom( clazz );
            }

        });

        Digester digester = newLoader(modules).newDigester();
        Object actual = digester.parse(input);

        if (input != null) {
            input.close();
        }
View Full Code Here

     */
    @Before
    public void setUp()
    {

        digester = new Digester();

    }
View Full Code Here

    {
        // * tests that a rule can declare custom PluginCreateRules
        // that allow it to plug in instances of itself below
        // itself.

        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules( rc );

        PluginDeclarationRule pdr = new PluginDeclarationRule();
        digester.addRule( "*/plugin", pdr );

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

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

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

            System.err.println( "usage: pipeline config-file" );
            System.exit( -1 );
        }
        String configFile = args[0];

        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules( rc );

        digester.addObjectCreate( "pipeline", Pipeline.class );

        digester.addCallMethod( "pipeline/source", "setSource", 1 );
        digester.addCallParam( "pipeline/source", 0, "file" );

        PluginCreateRule pcr = new PluginCreateRule( Transform.class );
        digester.addRule( "pipeline/transform", pcr );
        digester.addSetNext( "pipeline/transform", "setTransform" );

        digester.addCallMethod( "pipeline/destination", "setDest", 1 );
        digester.addCallParam( "pipeline/destination", 0, "file" );

        Pipeline pipeline = null;
        try
        {
            pipeline = digester.parse( configFile );
        }
        catch ( Exception e )
        {
            System.err.println( "oops exception occurred during parse." );
            e.printStackTrace();
View Full Code Here

        }

        String filename = args[0];

        // Create a Digester instance
        Digester d = new Digester();

        // Prime the digester stack with an object for rules to
        // operate on. Note that it is quite common for "this"
        // to be the object pushed.
        AddressBook book = new AddressBook();
        d.push( book );

        // Add rules to the digester that will be triggered while
        // parsing occurs.
        addRules( d );

        // Process the input file.
        try
        {
            java.io.File srcfile = new java.io.File( filename );
            d.parse( srcfile );
        }
        catch ( java.io.IOException ioe )
        {
            System.out.println( "Error reading input file:" + ioe.getMessage() );
            System.exit( -1 );
View Full Code Here

    return topology;
  }

  private Topology loadTopologyAttempt(File file) throws IOException, SAXException, URISyntaxException {
    Topology topology;
    Digester digester = digesterLoader.newDigester();
    TopologyBuilder topologyBuilder = digester.parse(FileUtils.openInputStream(file));
    topology = topologyBuilder.build();
    topology.setUri(file.toURI());
    topology.setName(FilenameUtils.removeExtension(file.getName()));
    topology.setTimestamp(file.lastModified());
    return topology;
View Full Code Here

  public void tearDown() throws Exception {
  }

  @Test
  public void testParseSimpleTopologyXmlInKnoxFormat() throws IOException, SAXException, URISyntaxException {
    Digester digester = loader.newDigester();
    String name = "org/apache/hadoop/gateway/topology/xml/simple-topology-knox-format.xml";
    URL url = ClassLoader.getSystemResource( name );
    assertThat( "Failed to find URL for resource " + name, url, notNullValue() );
    File file = new File( url.getFile() );
    TopologyBuilder topologyBuilder = digester.parse( url );
    Topology topology = topologyBuilder.build();
    assertThat( "Failed to parse resource " + name, topology, notNullValue() );
    topology.setTimestamp( file.lastModified() );

    assertThat( topology.getName(), is( "topology" ) );
View Full Code Here

    assertThat( provider.getParams().size(), is(5));
  }

  @Test
  public void testParseServiceParamsInKnoxFormat() throws IOException, SAXException {
    Digester digester = loader.newDigester();
    String name = "org/apache/hadoop/gateway/topology/xml/service-param-topology-knox-format.xml";
    URL url = ClassLoader.getSystemResource( name );
    assertThat( "Failed to find URL for resource " + name, url, notNullValue() );
    File file = new File( url.getFile() );
    TopologyBuilder topologyBuilder = digester.parse( url );
    Topology topology = topologyBuilder.build();
    assertThat( "Failed to parse resource " + name, topology, notNullValue() );
    topology.setTimestamp( file.lastModified() );

    assertThat( topology.getName(), is( "test-topology-name" ) );
View Full Code Here

  }


  @Test
  public void testParseSimpleTopologyXmlInHadoopFormat() throws IOException, SAXException, URISyntaxException {
    Digester digester = loader.newDigester();
    String name = "org/apache/hadoop/gateway/topology/xml/simple-topology-ambari-format.conf";
    URL url = ClassLoader.getSystemResource( name );
    assertThat( "Failed to find URL for resource " + name, url, notNullValue() );
    File file = new File( url.getFile() );
    TopologyBuilder topologyBuilder = digester.parse( url );
    Topology topology = topologyBuilder.build();
    assertThat( "Failed to parse resource " + name, topology, notNullValue() );
    topology.setTimestamp( file.lastModified() );

    assertThat( topology.getName(), is( "topology2" ) );
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.