View Javadoc

1   /*
2    * $Id: MuleTestNamespaceFunctionalTestCase.java 22421 2011-07-15 05:05:06Z dirk.olmes $
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  
11  package org.mule.test.integration.tck;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.AbstractServiceAndFlowTestCase;
16  import org.mule.util.ExceptionUtils;
17  
18  import java.io.FileNotFoundException;
19  import java.util.Arrays;
20  import java.util.Collection;
21  
22  import org.junit.Test;
23  import org.junit.runners.Parameterized.Parameters;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNotNull;
27  import static org.junit.Assert.assertNull;
28  import static org.junit.Assert.assertTrue;
29  
30  public class MuleTestNamespaceFunctionalTestCase extends AbstractServiceAndFlowTestCase
31  {
32      @Parameters
33      public static Collection<Object[]> parameters()
34      {
35          return Arrays.asList(new Object[][]{
36              {ConfigVariant.SERVICE, "org/mule/test/integration/tck/test-namespace-config-service.xml"},
37              {ConfigVariant.FLOW, "org/mule/test/integration/tck/test-namespace-config-flow.xml"}});
38      }
39  
40      public MuleTestNamespaceFunctionalTestCase(ConfigVariant variant, String configResources)
41      {
42          super(variant, configResources);
43      }
44  
45      @Test
46      public void testService1() throws Exception
47      {
48          MuleClient client = new MuleClient(muleContext);
49          MuleMessage message = client.send("vm://service1", "foo", null);
50          assertNotNull(message);
51          assertNull(message.getExceptionPayload());
52          assertEquals("Foo Bar Car Jar", message.getPayloadAsString());
53      }
54  
55      @Test
56      public void testService2() throws Exception
57      {
58          String result = loadResourceAsString("org/mule/test/integration/tck/test-data.txt");
59          MuleClient client = new MuleClient(muleContext);
60          MuleMessage message = client.send("vm://service2", "foo", null);
61          assertNotNull(message);
62          assertNull(message.getExceptionPayload());
63          assertEquals(result, message.getPayloadAsString());
64      }
65  
66      @Test
67      public void testService3() throws Exception
68      {
69          MuleClient client = new MuleClient(muleContext);
70          MuleMessage message = client.send("vm://service3", "foo", null);
71          assertNotNull(message);
72          assertNull(message.getExceptionPayload());
73          assertEquals("foo received in testService3", message.getPayloadAsString());
74      }
75  
76      @Test
77      public void testService4() throws Exception
78      {
79          try
80          {
81              muleContext.getClient().send("vm://service4", "foo", null);
82          }
83          catch (Exception e)
84          {
85              // expected
86          }
87      }
88  
89      @Test
90      public void testService5() throws Exception
91      {
92          try
93          {
94              muleContext.getClient().send("vm://service5", "foo", null);
95          }
96          catch (Exception e)
97          {
98              assertTrue(ExceptionUtils.getRootCause(e) instanceof FileNotFoundException);
99          }
100     }
101 }