Package org.mule.module.atom.event

Source Code of org.mule.module.atom.event.EventTest

/*
* $Id: EventTest.java 21075 2011-01-24 17:51:12Z dirk.olmes $
* --------------------------------------------------------------------------------------
* Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
*
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.module.atom.event;

import org.mule.tck.DynamicPortTestCase;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.apache.abdera.model.Document;
import org.apache.abdera.model.Feed;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;

public class EventTest extends DynamicPortTestCase
{
    private Repository repository;

    @Override
    protected void doSetUp() throws Exception
    {
        super.doSetUp();
        EntryReceiver component = (EntryReceiver)getComponent("eventConsumer");
        component.getReceivedEntries().set(0);
    }

    @Override
    protected String getConfigResources()
    {
        return "eventqueue-conf.xml";
    }

    @Override
    protected int getNumPortsToFind()
    {
        return 1;
    }

    @Override
    protected void doTearDown() throws Exception
    {
        clearJcrRepository();
        super.doTearDown();
    }

    public void testCustomerProvider() throws Exception
    {
        repository = (Repository) muleContext.getRegistry().lookupObject("jcrRepository");

        Thread.sleep(5000);

        AbderaClient client = new AbderaClient();
        ClientResponse res = client.get("http://localhost:" + getPorts().get(0) + "/events");

        Document<Feed> doc = res.getDocument();
        // see if this helps with intermittent failures
        doc.complete();
        Feed feed = doc.getRoot();
        // see if this helps with intermittent failures
        feed.complete();
        assertNotNull("feed is null", feed);
        assertTrue( feed.getEntries().size() >= 1);
        EntryReceiver component = (EntryReceiver)getComponent("eventConsumer");

        assertTrue(component.getCount() > 0);
    }

    private void clearJcrRepository()
    {
        try
        {
            if (repository == null)
            {
                return;
            }
            Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()));

            Node node = session.getRootNode();

            for (NodeIterator itr = node.getNodes(); itr.hasNext();)
            {
                Node child = itr.nextNode();
                if (!child.getName().equals("jcr:system"))
                {
                    child.remove();
                }
            }
            session.save();
            session.logout();
        }
        catch (PathNotFoundException t)
        {
            // do nothing
        }
        catch (Throwable t)
        {
            // do nothing
        }
    }
}
TOP

Related Classes of org.mule.module.atom.event.EventTest

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.