View Javadoc

1   /*
2    * $Id: SimpleServiceBuilderTestCase.java 22772 2011-08-27 15:20:15Z dfeist $
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.construct.builder;
12  
13  import static org.junit.Assert.assertEquals;
14  
15  import org.mule.component.AbstractJavaComponent;
16  import org.mule.component.DefaultJavaComponent;
17  import org.mule.component.SimpleCallableJavaComponent;
18  import org.mule.component.simple.EchoComponent;
19  import org.mule.construct.SimpleService;
20  import org.mule.construct.SimpleService.Type;
21  import org.mule.exception.DefaultMessagingExceptionStrategy;
22  import org.mule.tck.junit4.AbstractMuleContextTestCase;
23  import org.mule.tck.services.SimpleMathsComponent;
24  import org.mule.transformer.compression.GZipCompressTransformer;
25  import org.mule.transformer.simple.ObjectToByteArray;
26  import org.mule.transformer.simple.StringAppendTransformer;
27  
28  import org.junit.Test;
29  
30  public class SimpleServiceBuilderTestCase extends AbstractMuleContextTestCase
31  {
32      @Test
33      public void testFullConfiguration() throws Exception
34      {
35          SimpleService simpleService = new SimpleServiceBuilder().name("test-simple-service-full")
36              .inboundAddress("test://foo")
37              .transformers(new StringAppendTransformer("bar"))
38              .responseTransformers(new ObjectToByteArray(), new GZipCompressTransformer())
39              .component(EchoComponent.class)
40              .type(Type.DIRECT)
41              .exceptionStrategy(new DefaultMessagingExceptionStrategy(muleContext))
42              .build(muleContext);
43  
44          assertEquals("test-simple-service-full", simpleService.getName());
45          assertEquals(EchoComponent.class,
46              ((AbstractJavaComponent) simpleService.getComponent()).getObjectType());
47      }
48  
49      @Test
50      public void testShortConfiguration() throws Exception
51      {
52          SimpleService simpleService = new SimpleServiceBuilder().name("test-simple-service-short")
53              .inboundEndpoint(getTestInboundEndpoint("test"))
54              .component(new EchoComponent())
55              .build(muleContext);
56  
57          assertEquals("test-simple-service-short", simpleService.getName());
58          assertEquals(EchoComponent.class,
59              ((SimpleCallableJavaComponent) simpleService.getComponent()).getObjectType());
60      }
61  
62      @Test
63      public void testPojoComponentConfiguration() throws Exception
64      {
65          SimpleMathsComponent pojoComponent = new SimpleMathsComponent();
66  
67          SimpleService simpleService = new SimpleServiceBuilder().name("test-simple-service-pojo-component")
68              .inboundEndpoint(getTestInboundEndpoint("test"))
69              .component(pojoComponent)
70              .build(muleContext);
71  
72          assertEquals("test-simple-service-pojo-component", simpleService.getName());
73          assertEquals(pojoComponent, ((DefaultJavaComponent) simpleService.getComponent()).getObjectFactory()
74              .getInstance(muleContext));
75      }
76  }