View Javadoc

1   /*
2    * $Id: AtomEventTest.java 19980 2010-10-21 11:27:14Z rossmason $
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.module.client.MuleClient;
13  import org.mule.tck.FunctionalTestCase;
14  
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import javax.jcr.Node;
19  import javax.jcr.NodeIterator;
20  import javax.jcr.PathNotFoundException;
21  import javax.jcr.Repository;
22  import javax.jcr.Session;
23  import javax.jcr.SimpleCredentials;
24  
25  import org.apache.abdera.model.Document;
26  import org.apache.abdera.model.Entry;
27  import org.apache.abdera.model.Feed;
28  import org.apache.abdera.protocol.client.AbderaClient;
29  import org.apache.abdera.protocol.client.ClientResponse;
30  
31  public class AtomEventTest extends FunctionalTestCase
32  {
33      private Repository repository;
34  
35      @Override
36      protected String getConfigResources()
37      {
38          return "atom-builder-conf.xml";
39      }
40  
41      public void testCustomerProvider() throws Exception
42      {
43          repository = (Repository) muleContext.getRegistry().lookupObject("jcrRepository");
44  
45          MuleClient client = new MuleClient(muleContext);
46  
47          Map props = new HashMap();
48          props.put("title", "Foo Bar");
49  
50          client.send("vm://in", "Mmm feeding", props);
51  
52          Thread.sleep(1000);
53  
54          AbderaClient aClient = new AbderaClient();
55          ClientResponse res = aClient.get("http://localhost:9003/events");
56  
57          Document<Feed> doc = res.getDocument();
58          Feed feed = doc.getRoot();
59  
60          assertEquals(1, feed.getEntries().size());
61          Entry e = feed.getEntries().get(0);
62  
63          assertEquals("Mmm feeding", e.getContent());
64          assertEquals("Foo Bar", e.getTitle());
65          //TODO author not getting saved See: MULE-4905
66          //assertEquals("Ross Mason", e.getAuthor().getName());
67  
68      }
69  
70      @Override
71      protected void doTearDown() throws Exception
72      {
73          clearJcrRepository();
74  
75          super.doTearDown();
76      }
77  
78      private void clearJcrRepository()
79      {
80          try
81          {
82              if (repository == null)
83              {
84                  return;
85              }
86              Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()));
87  
88              Node node = session.getRootNode();
89  
90              for (NodeIterator itr = node.getNodes(); itr.hasNext();)
91              {
92                  Node child = itr.nextNode();
93                  if (!child.getName().equals("jcr:system"))
94                  {
95                      child.remove();
96                  }
97              }
98              session.save();
99              session.logout();
100         }
101         catch (PathNotFoundException t)
102         {
103         }
104         catch (Throwable t)
105         {
106             t.printStackTrace();
107         }
108     }
109 
110 }