KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > ejbconf > test > MetaDataUnitTestCase


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.ejbconf.test;
23
24 import java.net.URL JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import junit.framework.Test;
29 import junit.framework.TestCase;
30 import junit.framework.TestSuite;
31
32 import org.jboss.invocation.InvocationType;
33 import org.jboss.metadata.ApplicationMetaData;
34 import org.jboss.metadata.BeanMetaData;
35 import org.jboss.metadata.MethodMetaData;
36 import org.jboss.metadata.XmlFileLoader;
37 import org.jboss.security.SimplePrincipal;
38
39 import org.w3c.dom.Document JavaDoc;
40 import org.w3c.dom.Element JavaDoc;
41
42 /** Tests of ejb-jar.xml metadata parsing.
43  *
44  * @author Scott.Stark@jboss.org
45  * @version $Revision: 37406 $
46  */

47 public class MetaDataUnitTestCase extends TestCase
48 {
49    public MetaDataUnitTestCase(String JavaDoc name)
50    {
51       super(name);
52    }
53
54    public static Test suite() throws Exception JavaDoc
55    {
56       TestSuite suite = new TestSuite(MetaDataUnitTestCase.class);
57       return suite;
58    }
59
60    public void testMethodPermissions() throws Exception JavaDoc
61    {
62       URL JavaDoc configURL = getClass().getResource("/ejbconf/ejb-jar-permission.xml");
63       if( configURL == null )
64          throw new Exception JavaDoc("Failed to find /ejbconf/ejb-jar-permission.xml");
65       Document JavaDoc configDoc = XmlFileLoader.getDocument(configURL, true);
66       ApplicationMetaData appData = new ApplicationMetaData();
67       appData.importEjbJarXml(configDoc.getDocumentElement());
68
69       SimplePrincipal echo = new SimplePrincipal("Echo");
70       SimplePrincipal echoLocal = new SimplePrincipal("EchoLocal");
71       SimplePrincipal internal = new SimplePrincipal("InternalRole");
72
73       BeanMetaData ss = appData.getBeanByEjbName("StatelessSession");
74       Class JavaDoc[] sig = {};
75       Set JavaDoc perms = ss.getMethodPermissions("create", sig, InvocationType.HOME);
76       assertTrue("Echo can invoke StatelessSessionHome.create", perms.contains(echo));
77       assertTrue("EchoLocal cannot invoke StatelessSessionHome.create", perms.contains(echoLocal) == false);
78
79       perms = ss.getMethodPermissions("create", sig, InvocationType.LOCALHOME);
80       assertTrue("Echo can invoke StatelessSessionLocalHome.create", perms.contains(echo));
81       assertTrue("EchoLocal can invoke StatelessSessionLocalHome.create", perms.contains(echoLocal));
82    }
83
84 }
85
Popular Tags