View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.http.components;
8   
9   import org.mule.api.component.Component;
10  import org.mule.api.expression.ExpressionManager;
11  import org.mule.routing.filters.WildcardFilter;
12  import org.mule.routing.filters.logic.NotFilter;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  
15  import java.text.MessageFormat;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.assertTrue;
22  
23  public class RestServiceComponentTestCase extends FunctionalTestCase
24  {
25  
26      public static final String SERVICE_NAME = "WORMS";
27      public static final String SERVICE_URL = MessageFormat.format("{0}header:serviceUrl{1}",
28                                                                    ExpressionManager.DEFAULT_EXPRESSION_PREFIX,
29                                                                    ExpressionManager.DEFAULT_EXPRESSION_POSTFIX);
30  
31      @Override
32      protected String getConfigResources()
33      {
34          return "rest-service-component-test.xml";
35      }
36  
37      @Test
38      public void testResetServiceNamespaceHandler() throws Exception
39      {
40          Component component = muleContext.getRegistry().lookupService(SERVICE_NAME).getComponent();
41          assertTrue(component instanceof RestServiceWrapper);
42          RestServiceWrapper restServiceWrapper = (RestServiceWrapper) component;
43          assertEquals(restServiceWrapper.getServiceUrl(), SERVICE_URL);
44          assertEquals(restServiceWrapper.getHttpMethod(), "POST");
45          assertNotNull(restServiceWrapper.getFilter());
46          assertEquals(NotFilter.class, restServiceWrapper.getFilter().getClass());
47          NotFilter filter = (NotFilter) restServiceWrapper.getFilter();
48          assertEquals(filter.getFilter().getClass(), WildcardFilter.class);
49          WildcardFilter innerFilter = (WildcardFilter) filter.getFilter();
50          assertEquals(innerFilter.getPattern(), "*xyz*");
51          assertNotNull(restServiceWrapper.getPayloadParameterNames());
52          assertEquals(restServiceWrapper.getPayloadParameterNames().size(), 2);
53          assertEquals(restServiceWrapper.getPayloadParameterNames().get(0), "test-property1");
54          assertEquals(restServiceWrapper.getPayloadParameterNames().get(1), "test-property2");
55  
56          assertNotNull(restServiceWrapper.getRequiredParams());
57          assertEquals(restServiceWrapper.getRequiredParams().size(), 2);
58          assertEquals(restServiceWrapper.getRequiredParams().get("r1"), "rv1");
59          assertEquals(restServiceWrapper.getRequiredParams().get("r2"), "rv2");
60  
61          assertNotNull(restServiceWrapper.getOptionalParams());
62          assertEquals(restServiceWrapper.getOptionalParams().size(), 2);
63          assertEquals(restServiceWrapper.getOptionalParams().get("o1"), "ov1");
64          assertEquals(restServiceWrapper.getOptionalParams().get("o2"), "ov2");
65      }
66  }