View Javadoc

1   /*
2    * $Id: RestServiceComponentFlowTestCase.java 22511 2011-07-22 03:27:34Z 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  package org.mule.transport.http.components;
11  
12  import static org.junit.Assert.assertEquals;
13  import static org.junit.Assert.assertNotNull;
14  import static org.junit.Assert.assertTrue;
15  
16  import java.text.MessageFormat;
17  
18  import org.junit.Test;
19  import org.mule.api.component.Component;
20  import org.mule.api.expression.ExpressionManager;
21  import org.mule.construct.Flow;
22  import org.mule.routing.filters.WildcardFilter;
23  import org.mule.routing.filters.logic.NotFilter;
24  import org.mule.tck.junit4.FunctionalTestCase;
25  
26  public class RestServiceComponentFlowTestCase extends FunctionalTestCase
27  {
28  
29      public static final String FLOW_NAME = "WORMS";
30      public static final String FLOW_URL = MessageFormat.format("{0}header:serviceUrl{1}",
31                                                                    ExpressionManager.DEFAULT_EXPRESSION_PREFIX,
32                                                                    ExpressionManager.DEFAULT_EXPRESSION_POSTFIX);
33  
34      @Override
35      protected String getConfigResources()
36      {
37          return "rest-service-component-test-flow.xml";
38      }
39  
40      @Test
41      public void testResetServiceNamespaceHandler() throws Exception
42      {
43          Flow f = (Flow) muleContext.getRegistry().lookupFlowConstruct(FLOW_NAME);
44          
45          Component component = (Component) f.getMessageProcessors().get(0);
46          
47          assertTrue(component instanceof RestServiceWrapper);
48          RestServiceWrapper restServiceWrapper = (RestServiceWrapper) component;
49          assertEquals(restServiceWrapper.getServiceUrl(), FLOW_URL);
50          assertEquals(restServiceWrapper.getHttpMethod(), "POST");
51          assertNotNull(restServiceWrapper.getFilter());
52          assertEquals(NotFilter.class, restServiceWrapper.getFilter().getClass());
53          NotFilter filter = (NotFilter) restServiceWrapper.getFilter();
54          assertEquals(filter.getFilter().getClass(), WildcardFilter.class);
55          WildcardFilter innerFilter = (WildcardFilter) filter.getFilter();
56          assertEquals(innerFilter.getPattern(), "*xyz*");
57          assertNotNull(restServiceWrapper.getPayloadParameterNames());
58          assertEquals(restServiceWrapper.getPayloadParameterNames().size(), 2);
59          assertEquals(restServiceWrapper.getPayloadParameterNames().get(0), "test-property1");
60          assertEquals(restServiceWrapper.getPayloadParameterNames().get(1), "test-property2");
61  
62          assertNotNull(restServiceWrapper.getRequiredParams());
63          assertEquals(restServiceWrapper.getRequiredParams().size(), 2);
64          assertEquals(restServiceWrapper.getRequiredParams().get("r1"), "rv1");
65          assertEquals(restServiceWrapper.getRequiredParams().get("r2"), "rv2");
66  
67          assertNotNull(restServiceWrapper.getOptionalParams());
68          assertEquals(restServiceWrapper.getOptionalParams().size(), 2);
69          assertEquals(restServiceWrapper.getOptionalParams().get("o1"), "ov1");
70          assertEquals(restServiceWrapper.getOptionalParams().get("o2"), "ov2");
71      }
72  }