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.components.script.refreshable;
8   
9   
10  import org.junit.Test;
11  
12  public class GroovyRefreshableBeanTestCase extends AbstractRefreshableBeanTestCase
13  {
14  
15      public static final String RECEIVED = "Received";
16      public static final String RECEIVED2 = "Received2";
17      public static final String PAYLOAD = "Test:";
18      public static final String NAME_CALLABLE = "groovy-dynamic-script-callable.groovy";
19      public static final String NAME_BEAN = "groovy-dynamic-script-bean.groovy";
20      public static final String NAME_CHANGE_INTERFACE = "groovy-dynamic-script.groovy";
21      public static final String ON_CALL_RECEIVED = "import org.mule.api.MuleEventContext; import org.mule.api.lifecycle.Callable; public class GroovyDynamicScript implements Callable { public Object onCall(MuleEventContext eventContext) throws Exception{ return eventContext.getMessage().getPayloadAsString() + \"" + RECEIVED + "\"; }}";
22      public static final String ON_CALL_RECEIVED2 = ON_CALL_RECEIVED.replaceAll(RECEIVED, RECEIVED2);
23      public static final String RECEIVE_RECEIVED = "public class GroovyDynamicScript { public String receive(String src) { return src + \"" + RECEIVED + "\"; }}";
24      public static final String RECEIVE_RECEIVED2 = RECEIVE_RECEIVED.replaceAll(RECEIVED, RECEIVED2);
25  
26      @Override
27      protected String getConfigResources()
28      {
29          return "groovy-refreshable-config.xml";
30      }
31  
32      @Test
33      public void testFirstOnCallRefresh() throws Exception
34      {
35          runScriptTest(ON_CALL_RECEIVED, NAME_CALLABLE, "vm://groovy_refresh_callable", PAYLOAD, RECEIVED);
36      }
37      
38      @Test
39      public void testCallFirstTest() throws Exception
40      {
41          testFirstOnCallRefresh();
42      }
43      
44      @Test
45      public void testSecondOnCallRefresh() throws Exception
46      {
47          runScriptTest(ON_CALL_RECEIVED2, NAME_CALLABLE, "vm://groovy_refresh_callable", PAYLOAD, RECEIVED2);
48      }
49  
50      @Test
51      public void testFirstPojoRefresh() throws Exception
52      {
53          runScriptTest(RECEIVE_RECEIVED, NAME_BEAN, "vm://groovy_refresh_bean", PAYLOAD, RECEIVED);
54      }
55      
56      @Test
57      public void testSecondPojoRefresh() throws Exception
58      {
59          runScriptTest(RECEIVE_RECEIVED2, NAME_BEAN, "vm://groovy_refresh_bean", PAYLOAD, RECEIVED2);
60      }
61      
62      @Test
63      public void testFirstChangeInterfaces() throws Exception
64      {
65          runScriptTest(ON_CALL_RECEIVED, NAME_CHANGE_INTERFACE, "vm://groovy_refresh_changeInterfaces", PAYLOAD, RECEIVED);
66      }
67      
68      @Test
69      public void testSecondChangeInterfaces() throws Exception
70      {
71          runScriptTest(RECEIVE_RECEIVED2, NAME_CHANGE_INTERFACE, "vm://groovy_refresh_changeInterfaces", PAYLOAD, RECEIVED2);
72      }
73  
74  }
75  
76  
77