[jboss-dev-forums] [Deployers on JBoss (Deployers/JBoss)] - Re: Ordering of .ear subdeployments

vickyk do-not-reply at jboss.com
Thu Jul 27 06:12:45 EDT 2006


I have been in a process of writing a test case for the change but there seems to be some more changes to be made if we need the automated test case . Here are my  analysis 
1)  The DeploymentInfo needs to have a field as 
public ArrayList actualEarlierDeployements ; 
which will be set during the initi of the MainDeployer
2) The init of the MainDeployer have 
// Changes for the JBAB-2904
		 ArrayList actualEarlierSortedSubs = new ArrayList(deployment.subDeployments);
		 Collections.sort(actualEarlierSortedSubs, infoSorter);
		 deployment.actualEarlierDeployements = actualEarlierSortedSubs;
		 boolean isSorted = deployment.getSortedSubDeployments();
		 if(!isSorted){
			Collections.sort(sortedSubs, infoSorter);
		 }
 // Changes for the JBAB-2904
3) The additional actualEarlierDeployements  from the DeploymentInfo can be used in the UnitTest to see the variation in the ordering .

If we dont keep the UnitTest then we dont need to make the changes in the DeploymentInfo object . 
Here is the UnitTest Code I have been in process of writing 

  | /*
  |  * JBoss, the OpenSource J2EE webOS
  |  * 
  |  * Distributable under LGPL license.
  |  * See terms of license at gnu.org.
  |  */
  | package org.jboss.test.deployers.ear.jbas2904;
  | 
  | import java.util.ArrayList;
  | import java.util.Collection;
  | import java.util.HashSet;
  | import java.util.Iterator;
  | import java.util.Set;
  | import java.util.StringTokenizer;
  | 
  | import java.net.JarURLConnection;
  | import java.net.URL;
  | 
  | import java.io.InputStream;
  | import java.io.File;
  | import java.io.FileInputStream;
  | 
  | import junit.framework.Test;
  | import junit.framework.TestSuite;
  | 
  | import org.jboss.deployment.DeploymentInfo;
  | import org.jboss.deployment.EARDeployer;
  | import org.jboss.test.deployers.AbstractDeploymentTest;
  | 
  | import org.w3c.dom.Element;
  | import org.w3c.dom.Node;
  | import org.w3c.dom.NodeList;
  | 
  | import org.jboss.metadata.XmlFileLoader;
  | 
  | /**
  |  * A test that tests the JBAB2904
  |  * 
  |  * build compile-classes-only
  |  * build -Dtest=org.jboss.test.deployers.ear.jbas2904.EARDeploymentUnitTestCase one-test
  |  * @author <a href="vicky.kak at jboss.com">Vicky Kak</a>
  |  * @version $Revision: 1.0 $
  |  */
  | public class EARDeploymentUnitTestCase extends AbstractDeploymentTest
  | {
  |  
  |    public EARDeploymentUnitTestCase(String test)
  |    {
  |       super(test);
  |    }
  | 
  |    public static Test suite() throws Exception
  |    {
  | 	   return getDeploySetup(EARDeploymentUnitTestCase.class, ear1Deployment);
  |    }
  | 
  |    public void testEARDeployment() throws Exception{
  | 	   //Expected Deployment Ordering 
  | 	   DeploymentInfo topInfo = assertDeployed(ear1Deployment);
  | 	   ArrayList expectedList = new ArrayList();
  | 	   String urltoread = (topInfo.url).toString();
  | 	   URL applicationUrl = new URL("jar:"+urltoread+"!/META-INF/application.xml");
  | 	   JarURLConnection jarConnection = (JarURLConnection)applicationUrl.openConnection();
  | 	   InputStream is = jarConnection.getInputStream();
  | 	   System.out.println("Expected Ordering ------->");
  | 	   expectedList = getExpectedDeployedModules(is,"application.xml");
  | 	   is.close();
  | 	   applicationUrl = new URL("jar:"+urltoread+"!/META-INF/jboss-app.xml");
  | 	   jarConnection = (JarURLConnection)applicationUrl.openConnection();
  | 	   is = jarConnection.getInputStream();
  | 	   ArrayList expectedList1 = getExpectedDeployedModules(is,"jboss-app.xml");
  | 	   expectedList.addAll(expectedList1);
  | 	   is.close();
  | 	   Object expectedModules[] = expectedList.toArray();
  | 
  | 	   //Actual Results	
  | 	   //Set subDeployments = topInfo.subDeployments;
  | 	   ArrayList subDeployments = topInfo.actualEarlierDeployements;
  | 	   //System.out.println("subDeployments : "+subDeployments.size());
  | 	   System.out.println("Actual Ordering -------->");
  | 	   ArrayList deployedModuleNames = new ArrayList(subDeployments.size());
  | 	   int index = 0;
  |        if (subDeployments != null )
  | 	   {
  |          //for (Iterator i = subDeployments.iterator(); i.hasNext(); )
  | 		 for(int count = 0;count<subDeployments.size();count++)
  |          {
  |             //DeploymentInfo child = (DeploymentInfo) i.next();
  | 			DeploymentInfo child = (DeploymentInfo)subDeployments.get(count);
  | 			URL url = child.url;
  | 			String moduleName = getModuleDeployed(url.toString());
  | 			deployedModuleNames.add(moduleName);
  | 			System.out.println(getModuleDeployed(url.toString()));
  | 			//assertEquals(((String)expectedModules[index]),moduleName);
  | 			index++;
  | 		 }
  | 	   }
  |    }
  | 
  |    private String getModuleDeployed(String tempUrl){
  | 	   StringTokenizer st = new StringTokenizer(tempUrl,"/");
  | 	   String moduleName = "";
  | 	   while (st.hasMoreTokens()) {
  | 		 moduleName = st.nextToken();
  |          //System.out.println(moduleName);
  | 	   }
  | 	   return moduleName;
  |    }
  | 
  |    private ArrayList getExpectedDeployedModules(InputStream in,String xmlDDFileName) throws Exception{
  | 	    
  | 	    XmlFileLoader xfl = new XmlFileLoader(false);
  | 	    Element application = xfl.getDocument(in, xmlDDFileName).getDocumentElement();
  | 		NodeList jeemoduleList = application.getElementsByTagName("module");
  | 		int jeemoduleListCount = jeemoduleList.getLength();
  | 		ArrayList list = new ArrayList(jeemoduleListCount);
  | 		//System.out.println(" jeemoduleListCount :"+jeemoduleListCount);
  | 		for(int count=0;count<jeemoduleListCount;count++)
  | 				{
  | 					Node node = jeemoduleList.item(count);
  | 					if(node.getNodeType()== Node.ELEMENT_NODE)
  | 					{
  | 						String module = node.getNodeValue();
  | 						Element mod = (Element) node;						
  | 						NodeList jeeNodeList = mod.getElementsByTagName("java");
  | 						//System.out.println("Modules are >>>>-->"+jeeNodeList.getLength());
  | 						int nodescount = jeeNodeList.getLength();
  | 						if(nodescount==0)
  | 						{
  | 							jeeNodeList = mod.getElementsByTagName("ejb");
  | 							nodescount = jeeNodeList.getLength();
  | 						}
  | 						if(nodescount==0)
  | 						{
  | 							jeeNodeList = mod.getElementsByTagName("web-uri");
  | 							nodescount = jeeNodeList.getLength();
  | 
  | 						}
  | 						if(nodescount==0)
  | 						{
  | 							jeeNodeList = mod.getElementsByTagName("connector");
  | 							nodescount = jeeNodeList.getLength();
  | 						}			
  | 						if(nodescount==0)
  | 						{
  | 							jeeNodeList = mod.getElementsByTagName("service");
  | 							nodescount = jeeNodeList.getLength();
  | 						}			
  | 						Node checkNode = jeeNodeList.item(0);
  | 						if(checkNode!=null){
  | 							String nodeName = checkNode.getFirstChild().getNodeValue();
  | 							System.out.println(nodeName);
  | 							list.add(nodeName);
  | 						}
  | 					}
  | 				}
  | 	    return list;
  |   }
  | }
  | 
  | 

Any inputs here ?

Regards
Vicky

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961226#3961226

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961226



More information about the jboss-dev-forums mailing list