KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > xslt > test > ScopedXalanUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.xslt.test;
23
24 import java.util.Hashtable JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import javax.management.ObjectName JavaDoc;
29
30 import junit.framework.Test;
31
32 import org.jboss.test.JBossTestCase;
33
34 /**
35  * Test an mbean deployment using a legacy xalan version using scoping
36  *
37  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
38  * @version $Revision: 37406 $
39  */

40 public class ScopedXalanUnitTestCase extends JBossTestCase
41 {
42    public static Test suite() throws Exception JavaDoc
43    {
44       return getDeploySetup(ScopedXalanUnitTestCase.class, "xalan-check-default.sar,xalan-check-scoped.sar");
45    }
46    
47    public ScopedXalanUnitTestCase(String JavaDoc name)
48    {
49       super(name);
50    }
51
52    public void testScopedXalanDeployment() throws Exception JavaDoc
53    {
54       getLog().info("+++ testScopedXalanDeployment");
55       
56       // log the xalan environment seeing by the default deployment
57
ObjectName JavaDoc defaultTarget = new ObjectName JavaDoc("jboss.test:service=XalanCheckDefault");
58       Hashtable JavaDoc defaultHashtable = (Hashtable JavaDoc)getServer().invoke(defaultTarget, "fetchXalanEnvironmentHash", new Object JavaDoc[] {}, new String JavaDoc[] {});
59       logHashtable("XalanCheckDefault", defaultHashtable);
60       
61       // get the xalan version of the default deployment
62
String JavaDoc defaultVersion = (String JavaDoc)getServer().getAttribute(defaultTarget, "XalanVersion");
63       
64       // check if Bug15140 exists in the default deployment
65
boolean defaultXalan25Bug15140;
66       try
67       {
68          getServer().invoke(defaultTarget, "testXalan25Bug15140", new Object JavaDoc[] {}, new String JavaDoc[] {});
69          defaultXalan25Bug15140 = false;
70       }
71       catch (Exception JavaDoc e)
72       {
73          defaultXalan25Bug15140 = true;
74       }
75       
76       // log the xalan environment seeing by the scoped deployment
77
ObjectName JavaDoc scopedTarget = new ObjectName JavaDoc("jboss.test:service=XalanCheckScoped");
78       Hashtable JavaDoc scopedHashtable = (Hashtable JavaDoc)getServer().invoke(scopedTarget, "fetchXalanEnvironmentHash", new Object JavaDoc[] {}, new String JavaDoc[] {});
79       logHashtable("XalanCheckScoped", scopedHashtable);
80       
81       // get the xalan version of the scoped deployment
82
String JavaDoc scopedVersion = (String JavaDoc)getServer().getAttribute(scopedTarget, "XalanVersion");
83       
84       // check if Bug15140 exists in the scoped deployment
85
boolean scopedXalan25Bug15140;
86       try
87       {
88          getServer().invoke(scopedTarget, "testXalan25Bug15140", new Object JavaDoc[] {}, new String JavaDoc[] {});
89          scopedXalan25Bug15140 = false;
90       }
91       catch (Exception JavaDoc e)
92       {
93          scopedXalan25Bug15140 = true;
94       }
95       
96       getLog().info("*******************************************************");
97       getLog().info("Default deployment uses xalan version: " + defaultVersion);
98       getLog().info("Default deployment sees xalan v2.5.2 bug 15140: " + defaultXalan25Bug15140);
99       getLog().info("Scoped deployment uses xalan version : " + scopedVersion);
100       getLog().info("Scoped deployment sees xalan v2.5.2 bug 15140: " + scopedXalan25Bug15140);
101       getLog().info("*******************************************************");
102       
103       // We expect to be seeing the scoped version
104
assertTrue("Expected scoped deployment using xalan version 'Xalan Java 2.5.2'", scopedVersion.equals("Xalan Java 2.5.2") == true);
105       // This can be verified by the presence of the 15140 xalan bug
106
assertTrue("Expected scoped deployment to have the xalan v2.5.2 bug 15140", scopedXalan25Bug15140 == true);
107       // This happens if you move xalan.jar from lib/endorsed to server/default/lib, under jdk1.4
108
assertTrue("Expected default deployment NOT to see jdk1.4 xalan v2.4.1", defaultVersion.equals("Xalan Java 2.4.1") == false);
109       // This is true, because we don't use 2.5.2
110
assertTrue("Expected default deployment NOT to have the xalan v2.5.2 bug 15140", defaultXalan25Bug15140 == false);
111    }
112    
113    private void logHashtable(String JavaDoc name, Hashtable JavaDoc htab)
114    {
115       getLog().info("***" + name + "***");
116       Iterator JavaDoc i = htab.entrySet().iterator();
117       while (i.hasNext())
118       {
119          Map.Entry JavaDoc entry = (Map.Entry JavaDoc)i.next();
120          getLog().info(entry.getKey().toString() + '=' + entry.getValue());
121       }
122    }
123  
124 }
125
Popular Tags