001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.test.dd.unit;
023:
024: import java.net.URL;
025: import java.util.Iterator;
026:
027: import junit.framework.Test;
028: import junit.framework.TestCase;
029: import junit.framework.TestSuite;
030:
031: import org.jboss.ejb3.metamodel.ApplicationClientDD;
032: import org.jboss.ejb3.metamodel.ApplicationClientDDObjectFactory;
033: import org.jboss.ejb3.metamodel.LifecycleCallback;
034: import org.jboss.metamodel.descriptor.EnvEntry;
035:
036: /**
037: * Comment
038: *
039: * @author <a href="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
040: * @version $Revision: $
041: */
042: public class ApplicationClientXmlTestCase extends TestCase {
043: public void testUnmarshalDDXsd() throws Exception {
044: URL xmlUrl = getResourceUrl("dd/application-client-test1.xml");
045: assertNotNull(xmlUrl);
046: ApplicationClientDD dd = ApplicationClientDDObjectFactory
047: .parse(xmlUrl);
048: assertNotNull(dd);
049:
050: assertEquals("Test1", dd.getDisplayName());
051: //assertEquals("application client dd test", dd.getDescription());
052:
053: assertEquals(1, dd.getEnvEntries().size());
054:
055: {
056: Iterator<EnvEntry> i = dd.getEnvEntries().iterator();
057:
058: EnvEntry ee = i.next();
059: assertEquals("envTest", ee.getEnvEntryName());
060: assertEquals("java.lang.String", ee.getEnvEntryType());
061: assertEquals("Hello world", ee.getEnvEntryValue());
062: }
063:
064: assertEquals(1, dd.getPostConstructs().size());
065:
066: {
067: Iterator<LifecycleCallback> i = dd.getPostConstructs()
068: .iterator();
069: LifecycleCallback lc = i.next();
070: assertNull(lc.getLifecycleCallbackClass());
071: assertEquals("postConstruct", lc
072: .getLifecycleCallbackMethod());
073: }
074:
075: assertEquals(1, dd.getPreDestroys().size());
076:
077: {
078: Iterator<LifecycleCallback> i = dd.getPreDestroys()
079: .iterator();
080: LifecycleCallback lc = i.next();
081: assertNull(lc.getLifecycleCallbackClass());
082: assertEquals("preDestroy", lc.getLifecycleCallbackMethod());
083: }
084: }
085:
086: private static URL getResourceUrl(String name) {
087: URL url = Thread.currentThread().getContextClassLoader()
088: .getResource(name);
089: if (url == null) {
090: throw new IllegalStateException("Resource not found: "
091: + name);
092: }
093: return url;
094: }
095:
096: public static Test suite() throws Exception {
097: return new TestSuite(ApplicationClientXmlTestCase.class);
098: }
099:
100: }
|