View Javadoc

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