View Javadoc

1   /*
2    * $Id: RestServiceComponentServiceTestCase.java 22488 2011-07-21 09:23:32Z justin.calleja $
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 org.mule.api.component.Component;
13  import org.mule.api.expression.ExpressionManager;
14  import org.mule.routing.filters.WildcardFilter;
15  import org.mule.routing.filters.logic.NotFilter;
16  import org.mule.tck.junit4.FunctionalTestCase;
17  
18  import java.text.MessageFormat;
19  
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertTrue;
25  
26  public class RestServiceComponentServiceTestCase extends FunctionalTestCase
27  {
28  
29      public static final String SERVICE_NAME = "WORMS";
30      public static final String SERVICE_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-service.xml";
38      }
39  
40      @Test
41      public void testResetServiceNamespaceHandler() throws Exception
42      {
43          Component component = muleContext.getRegistry().lookupService(SERVICE_NAME).getComponent();
44          assertTrue(component instanceof RestServiceWrapper);
45          RestServiceWrapper restServiceWrapper = (RestServiceWrapper) component;
46          assertEquals(restServiceWrapper.getServiceUrl(), SERVICE_URL);
47          assertEquals(restServiceWrapper.getHttpMethod(), "POST");
48          assertNotNull(restServiceWrapper.getFilter());
49          assertEquals(NotFilter.class, restServiceWrapper.getFilter().getClass());
50          NotFilter filter = (NotFilter) restServiceWrapper.getFilter();
51          assertEquals(filter.getFilter().getClass(), WildcardFilter.class);
52          WildcardFilter innerFilter = (WildcardFilter) filter.getFilter();
53          assertEquals(innerFilter.getPattern(), "*xyz*");
54          assertNotNull(restServiceWrapper.getPayloadParameterNames());
55          assertEquals(restServiceWrapper.getPayloadParameterNames().size(), 2);
56          assertEquals(restServiceWrapper.getPayloadParameterNames().get(0), "test-property1");
57          assertEquals(restServiceWrapper.getPayloadParameterNames().get(1), "test-property2");
58  
59          assertNotNull(restServiceWrapper.getRequiredParams());
60          assertEquals(restServiceWrapper.getRequiredParams().size(), 2);
61          assertEquals(restServiceWrapper.getRequiredParams().get("r1"), "rv1");
62          assertEquals(restServiceWrapper.getRequiredParams().get("r2"), "rv2");
63  
64          assertNotNull(restServiceWrapper.getOptionalParams());
65          assertEquals(restServiceWrapper.getOptionalParams().size(), 2);
66          assertEquals(restServiceWrapper.getOptionalParams().get("o1"), "ov1");
67          assertEquals(restServiceWrapper.getOptionalParams().get("o2"), "ov2");
68      }
69  }