View Javadoc

1   /*
2    * $Id: EventTest.java 20054 2010-11-02 21:49:32Z dzapata $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.module.atom.event;
11  
12  import org.mule.tck.FunctionalTestCase;
13  
14  import javax.jcr.Node;
15  import javax.jcr.NodeIterator;
16  import javax.jcr.PathNotFoundException;
17  import javax.jcr.Repository;
18  import javax.jcr.Session;
19  import javax.jcr.SimpleCredentials;
20  
21  import org.apache.abdera.model.Document;
22  import org.apache.abdera.model.Feed;
23  import org.apache.abdera.protocol.client.AbderaClient;
24  import org.apache.abdera.protocol.client.ClientResponse;
25  
26  public class EventTest extends FunctionalTestCase
27  {
28  
29      private Repository repository;
30  
31      @Override
32      protected String getConfigResources()
33      {
34          return "eventqueue-conf.xml";
35      }
36  
37      public void testCustomerProvider() throws Exception
38      {
39          repository = (Repository) muleContext.getRegistry().lookupObject("jcrRepository");
40  
41          Thread.sleep(2000);
42  
43          AbderaClient client = new AbderaClient();
44          ClientResponse res = client.get("http://localhost:9002/events");
45  
46          Document<Feed> doc = res.getDocument();
47          Feed feed = doc.getRoot();
48  
49          assertTrue( feed.getEntries().size() >= 1);
50  
51          assertTrue(EntryReceiver.receivedEntries.get() > 0);
52      }
53  
54      @Override
55      protected void doSetUp() throws Exception
56      {
57          super.doSetUp();
58          EntryReceiver.receivedEntries.set(0);
59      }
60  
61      @Override
62      protected void doTearDown() throws Exception
63      {
64          clearJcrRepository();
65  
66          super.doTearDown();
67      }
68  
69      private void clearJcrRepository()
70      {
71          try
72          {
73              if (repository == null)
74              {
75                  return;
76              }
77              Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()));
78  
79              Node node = session.getRootNode();
80  
81              for (NodeIterator itr = node.getNodes(); itr.hasNext();)
82              {
83                  Node child = itr.nextNode();
84                  if (!child.getName().equals("jcr:system"))
85                  {
86                      child.remove();
87                  }
88              }
89              session.save();
90              session.logout();
91          }
92          catch (PathNotFoundException t)
93          {
94          }
95          catch (Throwable t)
96          {
97              t.printStackTrace();
98          }
99      }
100 
101 }