1   /*******************************************************************************
2    *  Copyright (c) 2005, 2006, 2007 Imola Informatica.
3    *  All rights reserved. This program and the accompanying materials
4    *  are made available under the terms of the LGPL License v2.1
5    *  which accompanies this distribution, and is available at
6    *  http://www.gnu.org/licenses/lgpl.html
7    *******************************************************************************/
8   package it.imolinfo.jbi4ejb.test.deploy;
9   
10  import it.imolinfo.jbi4ejb.jbi.component.Jbi4EjbRuntime;
11  import it.imolinfo.jbi4ejb.jbi.component.Jbi4EjbSUManager;
12  import it.imolinfo.jbi4ejb.jbi.endpoint.Jbi4EjbEndpoint;
13  import it.imolinfo.jbi4ejb.test.TestUtils;
14  
15  import java.io.File;
16  import java.util.List;
17  
18  import javax.jbi.management.DeploymentException;
19  import javax.xml.namespace.QName;
20  
21  import junit.framework.TestCase;
22  
23  /**
24   * Tests the SU deploy, copiying the deploy files in the src/test/etc/test-sus/<su-name> directory in 
25   * a temporary directory and trying to deploy. At the end, removes the temporary directory.
26   * 
27   * @author marco 
28   */
29  public class WSDLDeployTest extends TestCase {
30  
31  
32      // Where the test SUS (wsdl and jbi.xml) are
33      public static final String SUS_TEST_DIR = "src/test/etc/test-sus";
34  
35      // The test working path
36      public static final String WORKING_PATH = "target/test-deploy";
37  
38      public WSDLDeployTest() {}
39  
40      public WSDLDeployTest(String name) {
41          super(name);
42      }
43  
44      public void setUp() {
45          // Creates the working path directory
46          File dirTemp = new File(WORKING_PATH);        
47          dirTemp.mkdir();        
48      }
49  
50      /**
51       * Tests the <code>su-complex</code> SU deploy.
52       */
53      public void testSuComplexDeployTest() {        
54          String serviceUnitName = "su-complex";
55          String suWorkingPath = WORKING_PATH + File.separator + serviceUnitName;
56          try {                 
57              Jbi4EjbSUManager suManager = getTestSUManager(serviceUnitName, suWorkingPath);
58              
59              try {
60                  suManager.deploy(serviceUnitName, suWorkingPath);
61                  suManager.init(serviceUnitName, suWorkingPath);
62              } catch (DeploymentException e) {      
63                  fail(e.getMessage());
64              }
65                          
66              List<Jbi4EjbEndpoint> endpoints = suManager.getDeployedEndpoints();
67              assertEquals(1, endpoints.size());
68              assertEquals(endpoints.get(0).getServiceName(), new QName("http://complex.test14.imolinfo.it","TestComplexSessionRemote"));
69              assertEquals(endpoints.get(0).getEndpointName(), "TestComplexSessionRemotePort");
70    
71          } catch (Exception ex) {
72              ex.printStackTrace();
73              fail(ex.getMessage());
74          }
75  
76          // TODO assert the  enpoint loaded
77      }      
78      
79      /**
80       * Tests the <code>su-complex</code> SU deploy.
81       */
82      public void testSuSimpleDeployTest() {        
83          String serviceUnitName = "su-simple";
84          String suWorkingPath = WORKING_PATH + File.separator + serviceUnitName;
85          try {                 
86              Jbi4EjbSUManager suManager = getTestSUManager(serviceUnitName, suWorkingPath);
87              
88              try {
89                  suManager.deploy(serviceUnitName, suWorkingPath);
90                  suManager.init(serviceUnitName, suWorkingPath);
91              } catch (DeploymentException e) {      
92                  fail(e.getMessage());
93              }
94              
95              List<Jbi4EjbEndpoint> endpoints = suManager.getDeployedEndpoints();
96              assertEquals(1, endpoints.size());
97              assertEquals(endpoints.get(0).getServiceName(), new QName("http://test14.imolinfo.it","TestSessionRemote"));
98              assertEquals(endpoints.get(0).getEndpointName(), "TestSessionRemotePort");
99              
100         } catch (Exception ex) {
101             ex.printStackTrace();
102             fail(ex.getMessage()); 
103         }
104         // TODO assert the  enpoint loaded
105     }  
106 
107 
108     /**
109      * Create the <code>Jbi4EjbSUManager</code> of the given SU and inits the component context (with a Mock).
110      * @param suName
111      */
112     private Jbi4EjbSUManager getTestSUManager(String suName, String suWorkingPath) throws Exception {
113         File susTestDirFile = new File(SUS_TEST_DIR + File.separator + suName);
114         File suDeployFile = new File(suWorkingPath);        
115         System.out.println("Copying files from: " + susTestDirFile.getAbsolutePath() + " to :" + suDeployFile.getAbsolutePath());
116         TestUtils.copyDirectory(susTestDirFile, suDeployFile);        
117         Jbi4EjbRuntime ejbComponent = new Jbi4EjbRuntime();          
118         Jbi4EjbSUManager suManager = new Jbi4EjbSUManager(ejbComponent);      
119         return suManager;
120     }
121 
122     /**
123      * Remove all the created files in the working path.
124      */
125     public void tearDown() {
126         System.out.println("Removing the directory:" + WORKING_PATH);
127         File dir = new File(WORKING_PATH);
128         TestUtils.deleteDir(dir);
129     }    
130     
131 
132 }
133