http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/test/java/org/apache/openejb/PersistenceUnitLinkResolverTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/PersistenceUnitLinkResolverTest.java b/container/openejb-core/src/test/java/org/apache/openejb/PersistenceUnitLinkResolverTest.java index 57ecf5f..4f6b5a2 100644 --- a/container/openejb-core/src/test/java/org/apache/openejb/PersistenceUnitLinkResolverTest.java +++ b/container/openejb-core/src/test/java/org/apache/openejb/PersistenceUnitLinkResolverTest.java @@ -1,44 +1,44 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.openejb; - -import org.apache.openejb.config.AppModule; -import org.apache.openejb.config.PersistenceUnitLinkResolver; -import org.apache.openejb.jee.Application; -import org.apache.openejb.jee.jpa.unit.PersistenceUnit; -import org.apache.openejb.loader.Files; -import org.junit.Test; - -import java.io.File; -import java.net.URI; - -import static org.junit.Assert.assertNull; - -public class PersistenceUnitLinkResolverTest { - @Test - public void resolve() { - final AppModule appModule = new AppModule(Thread.currentThread().getContextClassLoader(), "target/classes/foo", new Application(), false); - - Files.mkdir(new File("target/classes/foo/bar")); - - final PersistenceUnitLinkResolver resolver = new PersistenceUnitLinkResolver(appModule); - resolver.add(URI.create("file:/fake/1"), "foo", new PersistenceUnit()); - resolver.add(URI.create("file:/fake/2"), "foo", new PersistenceUnit()); - - assertNull(resolver.resolveLink("foo", URI.create("bar"))); // can't resolve but doesn't fail - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb; + +import org.apache.openejb.config.AppModule; +import org.apache.openejb.config.PersistenceUnitLinkResolver; +import org.apache.openejb.jee.Application; +import org.apache.openejb.jee.jpa.unit.PersistenceUnit; +import org.apache.openejb.loader.Files; +import org.junit.Test; + +import java.io.File; +import java.net.URI; + +import static org.junit.Assert.assertNull; + +public class PersistenceUnitLinkResolverTest { + @Test + public void resolve() { + final AppModule appModule = new AppModule(Thread.currentThread().getContextClassLoader(), "target/classes/foo", new Application(), false); + + Files.mkdir(new File("target/classes/foo/bar")); + + final PersistenceUnitLinkResolver resolver = new PersistenceUnitLinkResolver(appModule); + resolver.add(URI.create("file:/fake/1"), "foo", new PersistenceUnit()); + resolver.add(URI.create("file:/fake/2"), "foo", new PersistenceUnit()); + + assertNull(resolver.resolveLink("foo", URI.create("bar"))); // can't resolve but doesn't fail + } +}
http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/test/java/org/apache/openejb/activemq/KahaDBSupportTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/KahaDBSupportTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/KahaDBSupportTest.java index 5bc6b58..5664afb 100644 --- a/container/openejb-core/src/test/java/org/apache/openejb/activemq/KahaDBSupportTest.java +++ b/container/openejb-core/src/test/java/org/apache/openejb/activemq/KahaDBSupportTest.java @@ -1,44 +1,44 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.openejb.activemq; - -import org.apache.activemq.broker.BrokerFactory; -import org.apache.activemq.broker.BrokerService; -import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter; -import org.apache.openejb.util.NetworkUtil; -import org.junit.Test; - -import java.io.File; -import java.net.URI; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; - -public class KahaDBSupportTest { - @Test - public void create() throws Exception { - final BrokerService broker = BrokerFactory.createBroker(new URI("openejb:broker:(tcp://localhost:" + NetworkUtil.getNextAvailablePort() + ")?usekahadb=true&kahadb.directory=target/kahatest")); - try { - assertThat(broker.getPersistenceAdapter(), instanceOf(KahaDBPersistenceAdapter.class)); - final KahaDBPersistenceAdapter adapter = KahaDBPersistenceAdapter.class.cast(broker.getPersistenceAdapter()); - assertEquals(new File("target/kahatest"), adapter.getDirectory()); - } finally { - broker.stop(); - } - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.activemq; + +import org.apache.activemq.broker.BrokerFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter; +import org.apache.openejb.util.NetworkUtil; +import org.junit.Test; + +import java.io.File; +import java.net.URI; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; + +public class KahaDBSupportTest { + @Test + public void create() throws Exception { + final BrokerService broker = BrokerFactory.createBroker(new URI("openejb:broker:(tcp://localhost:" + NetworkUtil.getNextAvailablePort() + ")?usekahadb=true&kahadb.directory=target/kahatest")); + try { + assertThat(broker.getPersistenceAdapter(), instanceOf(KahaDBPersistenceAdapter.class)); + final KahaDBPersistenceAdapter adapter = KahaDBPersistenceAdapter.class.cast(broker.getPersistenceAdapter()); + assertEquals(new File("target/kahatest"), adapter.getDirectory()); + } finally { + broker.stop(); + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java b/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java index 6078958..65f8493 100644 --- a/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java +++ b/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java @@ -1,284 +1,284 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.openejb.assembler; - -import org.apache.openejb.OpenEJB; -import org.apache.openejb.OpenEJBException; -import org.apache.openejb.assembler.classic.AppInfo; -import org.apache.openejb.jee.WebApp; -import org.apache.openejb.junit.ApplicationComposer; -import org.apache.openejb.loader.FileUtils; -import org.apache.openejb.loader.Files; -import org.apache.openejb.loader.SystemInstance; -import org.apache.openejb.testing.AppResource; -import org.apache.openejb.testing.Classes; -import org.apache.openejb.testing.Module; -import org.apache.openejb.util.WebArchives; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -import javax.naming.Context; -import javax.naming.NamingException; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicReference; - -@RunWith(ApplicationComposer.class) -public class DeployerEjbTest { - - private static final AtomicReference<String> property = new AtomicReference<String>(null); - private static final AtomicReference<File> warArchive = new AtomicReference<File>(null); - private static final String OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS = "openejb.deployer.save-deployments"; - - @BeforeClass - public static void beforeClass() throws Exception { - - final FileUtils base = SystemInstance.get().getBase(); - final File conf = base.getDirectory("conf", false); - Files.delete(conf); - - final File apps = base.getDirectory("apps", true); - Files.delete(apps); - - base.getDirectory("apps", true); - base.getDirectory("conf", true); - - property.set(System.getProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS)); - System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.TRUE.toString()); - warArchive.set(WebArchives.warArchive(TestClass.class)); - } - - @AfterClass - public static void afterClass() { - - final String s = property.get(); - if (null != s) { - System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, "true"); - } else { - System.clearProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS); - } - - final File file = warArchive.get(); - if (file != null && file.exists()) { - if (!file.delete()) { - file.deleteOnExit(); - } - } - - - final FileUtils base = SystemInstance.get().getBase(); - if (null != base) { - try { - Files.delete(base.getDirectory("apps", false)); - } catch (final Exception e) { - //Ignore - } - try { - Files.delete(base.getDirectory("conf", false)); - } catch (final Exception e) { - //Ignore - } - } - - } - - @Module - @Classes(value = {DeployerEjb.class}) - public WebApp war() { - return new WebApp().contextRoot("/initial"); - } - - @AppResource - private Context context; - - @Before - public void before() throws Exception { - final File deployments = new File(SystemInstance.get().getBase().getDirectory("conf", false), "deployments.xml"); - if (deployments.exists()) { - Files.delete(deployments); - } - System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.TRUE.toString()); - } - - @After - public void after() throws Exception { - System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.FALSE.toString()); - OpenEJB.destroy(); - } - - private Deployer getDeployer() throws NamingException { - return (Deployer) context.lookup("openejb/DeployerRemote"); - } - - @Test - public void testGetUniqueFile() throws Exception { - - final String uniqueFile = getDeployer().getUniqueFile(); - Assert.assertTrue(new File(uniqueFile).exists()); - } - - @Test - public void testGetDeployedApps() throws Exception { - getAppInfos(); - } - - private Collection<AppInfo> getAppInfos() throws Exception { - final Deployer deployer = getDeployer(); - Collection<AppInfo> deployedApps = deployer.getDeployedApps(); - - if (null == deployedApps) { - deployedApps = new ArrayList<AppInfo>(); - } - - if (deployedApps.size() < 1) { - getAppInfo(); - deployedApps.addAll(deployer.getDeployedApps()); - } - - Assert.assertTrue("Found no deployed apps", deployedApps.size() > 0); - return deployedApps; - } - - @Test - public void testDeployWarSave() throws Exception { - - final Collection<AppInfo> deployedApps = getDeployer().getDeployedApps(); - Assert.assertTrue("Found more than one app", deployedApps.size() < 2); - - final File deployments = new File(SystemInstance.get().getBase().getDirectory("conf", false), "deployments.xml"); - Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists()); - - getAppInfo(); - - Assert.assertTrue("Failed to find: " + deployments.getAbsolutePath(), deployments.exists()); - } - - private AppInfo getAppInfo() throws IOException, NamingException, OpenEJBException { - return getAppInfo(null); - } - - private AppInfo getAppInfo(final Properties p) throws IOException, NamingException, OpenEJBException { - - final Deployer deployer = getDeployer(); - - final File war = warArchive.get(); - if (!war.exists()) { - Assert.fail("War file does not exist: " + war.getAbsolutePath()); - } - - return (null != p ? deployer.deploy(war.getAbsolutePath(), p) : deployer.deploy(war.getAbsolutePath())); - } - - @Test - public void testDeployWarNoSave() throws Exception { - final Collection<AppInfo> deployedApps = getDeployer().getDeployedApps(); - Assert.assertTrue("Found more than one app", deployedApps.size() < 2); - - final File deployments = new File(SystemInstance.get().getBase().getDirectory("conf", false), "deployments.xml"); - if (deployments.exists()) { - Files.delete(deployments); - } - - Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists()); - - final Properties p = new Properties(); - p.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.FALSE.toString()); - getAppInfo(p); - - Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists()); - } - - @Test - public void testDeployProperties() throws Exception { - final Properties p = new Properties(); - final String path = warArchive.get().getAbsolutePath(); - - p.setProperty(Deployer.FILENAME, path); - p.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.FALSE.toString()); - - final Deployer deployer = getDeployer(); - final AppInfo appInfo = deployer.deploy(p); - Assert.assertTrue("Paths do not match: " + path + " - " + appInfo.path, path.equals(appInfo.path)); - } - - @Test - public void testUndeploy() throws Exception { - final AppInfo appInfo = getDeployedApp(); - - Assert.assertNotNull("Failed to deploy app", appInfo); - - final Deployer deployer = getDeployer(); - deployer.undeploy(appInfo.path); - - final Collection<AppInfo> appInfos = getAppInfos(); - Assert.assertTrue("Failed to undeploy app", appInfos.size() < 2); - } - - private AppInfo getDeployedApp() throws Exception { - final Collection<AppInfo> appInfos = getAppInfos(); - - AppInfo appInfo = null; - final File file = warArchive.get(); - - if (appInfos.size() < 2) { - appInfo = getAppInfo(); - } else { - - final String name = file.getName().toLowerCase(); - - for (final AppInfo info : appInfos) { - if (name.contains(info.appId.toLowerCase())) { - appInfo = info; - } - } - } - return appInfo; - } - - @Test - public void testReload() throws Exception { - - final AppInfo appInfo = getDeployedApp(); - - final Deployer deployer = getDeployer(); - deployer.reload(appInfo.path); - - final Collection<AppInfo> deployedApps = deployer.getDeployedApps(); - boolean found = false; - for (final AppInfo app : deployedApps) { - if (app.path.equals(appInfo.path)) { - found = true; - } - } - - Assert.assertTrue("Failed to find app after redeploy", found); - } - - public static class TestClass { - public TestClass() { - } - } +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.openejb.assembler; + +import org.apache.openejb.OpenEJB; +import org.apache.openejb.OpenEJBException; +import org.apache.openejb.assembler.classic.AppInfo; +import org.apache.openejb.jee.WebApp; +import org.apache.openejb.junit.ApplicationComposer; +import org.apache.openejb.loader.FileUtils; +import org.apache.openejb.loader.Files; +import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.testing.AppResource; +import org.apache.openejb.testing.Classes; +import org.apache.openejb.testing.Module; +import org.apache.openejb.util.WebArchives; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.naming.Context; +import javax.naming.NamingException; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicReference; + +@RunWith(ApplicationComposer.class) +public class DeployerEjbTest { + + private static final AtomicReference<String> property = new AtomicReference<String>(null); + private static final AtomicReference<File> warArchive = new AtomicReference<File>(null); + private static final String OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS = "openejb.deployer.save-deployments"; + + @BeforeClass + public static void beforeClass() throws Exception { + + final FileUtils base = SystemInstance.get().getBase(); + final File conf = base.getDirectory("conf", false); + Files.delete(conf); + + final File apps = base.getDirectory("apps", true); + Files.delete(apps); + + base.getDirectory("apps", true); + base.getDirectory("conf", true); + + property.set(System.getProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS)); + System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.TRUE.toString()); + warArchive.set(WebArchives.warArchive(TestClass.class)); + } + + @AfterClass + public static void afterClass() { + + final String s = property.get(); + if (null != s) { + System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, "true"); + } else { + System.clearProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS); + } + + final File file = warArchive.get(); + if (file != null && file.exists()) { + if (!file.delete()) { + file.deleteOnExit(); + } + } + + + final FileUtils base = SystemInstance.get().getBase(); + if (null != base) { + try { + Files.delete(base.getDirectory("apps", false)); + } catch (final Exception e) { + //Ignore + } + try { + Files.delete(base.getDirectory("conf", false)); + } catch (final Exception e) { + //Ignore + } + } + + } + + @Module + @Classes(value = {DeployerEjb.class}) + public WebApp war() { + return new WebApp().contextRoot("/initial"); + } + + @AppResource + private Context context; + + @Before + public void before() throws Exception { + final File deployments = new File(SystemInstance.get().getBase().getDirectory("conf", false), "deployments.xml"); + if (deployments.exists()) { + Files.delete(deployments); + } + System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.TRUE.toString()); + } + + @After + public void after() throws Exception { + System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.FALSE.toString()); + OpenEJB.destroy(); + } + + private Deployer getDeployer() throws NamingException { + return (Deployer) context.lookup("openejb/DeployerRemote"); + } + + @Test + public void testGetUniqueFile() throws Exception { + + final String uniqueFile = getDeployer().getUniqueFile(); + Assert.assertTrue(new File(uniqueFile).exists()); + } + + @Test + public void testGetDeployedApps() throws Exception { + getAppInfos(); + } + + private Collection<AppInfo> getAppInfos() throws Exception { + final Deployer deployer = getDeployer(); + Collection<AppInfo> deployedApps = deployer.getDeployedApps(); + + if (null == deployedApps) { + deployedApps = new ArrayList<AppInfo>(); + } + + if (deployedApps.size() < 1) { + getAppInfo(); + deployedApps.addAll(deployer.getDeployedApps()); + } + + Assert.assertTrue("Found no deployed apps", deployedApps.size() > 0); + return deployedApps; + } + + @Test + public void testDeployWarSave() throws Exception { + + final Collection<AppInfo> deployedApps = getDeployer().getDeployedApps(); + Assert.assertTrue("Found more than one app", deployedApps.size() < 2); + + final File deployments = new File(SystemInstance.get().getBase().getDirectory("conf", false), "deployments.xml"); + Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists()); + + getAppInfo(); + + Assert.assertTrue("Failed to find: " + deployments.getAbsolutePath(), deployments.exists()); + } + + private AppInfo getAppInfo() throws IOException, NamingException, OpenEJBException { + return getAppInfo(null); + } + + private AppInfo getAppInfo(final Properties p) throws IOException, NamingException, OpenEJBException { + + final Deployer deployer = getDeployer(); + + final File war = warArchive.get(); + if (!war.exists()) { + Assert.fail("War file does not exist: " + war.getAbsolutePath()); + } + + return (null != p ? deployer.deploy(war.getAbsolutePath(), p) : deployer.deploy(war.getAbsolutePath())); + } + + @Test + public void testDeployWarNoSave() throws Exception { + final Collection<AppInfo> deployedApps = getDeployer().getDeployedApps(); + Assert.assertTrue("Found more than one app", deployedApps.size() < 2); + + final File deployments = new File(SystemInstance.get().getBase().getDirectory("conf", false), "deployments.xml"); + if (deployments.exists()) { + Files.delete(deployments); + } + + Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists()); + + final Properties p = new Properties(); + p.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.FALSE.toString()); + getAppInfo(p); + + Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists()); + } + + @Test + public void testDeployProperties() throws Exception { + final Properties p = new Properties(); + final String path = warArchive.get().getAbsolutePath(); + + p.setProperty(Deployer.FILENAME, path); + p.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.FALSE.toString()); + + final Deployer deployer = getDeployer(); + final AppInfo appInfo = deployer.deploy(p); + Assert.assertTrue("Paths do not match: " + path + " - " + appInfo.path, path.equals(appInfo.path)); + } + + @Test + public void testUndeploy() throws Exception { + final AppInfo appInfo = getDeployedApp(); + + Assert.assertNotNull("Failed to deploy app", appInfo); + + final Deployer deployer = getDeployer(); + deployer.undeploy(appInfo.path); + + final Collection<AppInfo> appInfos = getAppInfos(); + Assert.assertTrue("Failed to undeploy app", appInfos.size() < 2); + } + + private AppInfo getDeployedApp() throws Exception { + final Collection<AppInfo> appInfos = getAppInfos(); + + AppInfo appInfo = null; + final File file = warArchive.get(); + + if (appInfos.size() < 2) { + appInfo = getAppInfo(); + } else { + + final String name = file.getName().toLowerCase(); + + for (final AppInfo info : appInfos) { + if (name.contains(info.appId.toLowerCase())) { + appInfo = info; + } + } + } + return appInfo; + } + + @Test + public void testReload() throws Exception { + + final AppInfo appInfo = getDeployedApp(); + + final Deployer deployer = getDeployer(); + deployer.reload(appInfo.path); + + final Collection<AppInfo> deployedApps = deployer.getDeployedApps(); + boolean found = false; + for (final AppInfo app : deployedApps) { + if (app.path.equals(appInfo.path)) { + found = true; + } + } + + Assert.assertTrue("Failed to find app after redeploy", found); + } + + public static class TestClass { + public TestClass() { + } + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationAppendixInterceptorTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationAppendixInterceptorTest.java b/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationAppendixInterceptorTest.java index daea0d6..b918f0a 100644 --- a/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationAppendixInterceptorTest.java +++ b/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationAppendixInterceptorTest.java @@ -1,204 +1,204 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.openejb.bval; - -import org.apache.openejb.BeanContext; -import org.apache.openejb.jee.EjbJar; -import org.apache.openejb.jee.Empty; -import org.apache.openejb.jee.StatelessBean; -import org.apache.openejb.junit.ApplicationComposer; -import org.apache.openejb.testing.Configuration; -import org.apache.openejb.testing.Module; -import org.junit.Test; -import org.junit.runner.RunWith; - -import javax.ejb.EJB; -import javax.ejb.Local; -import javax.ejb.LocalBean; -import javax.ejb.Remote; -import javax.ejb.Stateless; -import javax.validation.ConstraintViolationException; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotNull; -import java.io.Serializable; -import java.util.Properties; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -@RunWith(ApplicationComposer.class) -public class BeanValidationAppendixInterceptorTest { - @Local - public static interface Manager { - String drive(Person person, @Min(18) int age); - - Person create(@NotNull String name); - } - - @Remote - public static interface ManagerRemote { - String drive(Person person, @Min(16) int age); - - Person create(String name); - } - - public static class Person implements Serializable { - public String name; - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - } - - @Stateless - public static class ManagerBean implements Manager { - public String drive(final Person person, final int age) { - return "vroom"; - } - - public Person create(final String name) { - final Person person = new Person(); - person.setName(name); - return person; - } - } - - @Stateless - public static class ManagerBean2 implements Manager, ManagerRemote { - public String drive(final Person person, final int age) { - return "vroom"; - } - - public Person create(final String name) { - final Person person = new Person(); - person.setName(name); - return person; - } - } - - @Stateless - @LocalBean - public static class ManagerLocalBean { - public void foo(@NotNull final String bar) { - // no-op - } - } - - @Test - public void valid() { - final Person p = mgr.create("foo"); - mgr.drive(p, 18); - } - - @Test - public void notValid() { - Person p = null; - try { - p = mgr.create(null); - fail(); - } catch (final Exception e) { - assertTrue(e.getCause() instanceof ConstraintViolationException); - final ConstraintViolationException cvs = (ConstraintViolationException) e.getCause(); - assertEquals(1, cvs.getConstraintViolations().size()); - } - try { - mgr.drive(p, 17); - fail(); - } catch (final Exception e) { - assertTrue(e.getCause() instanceof ConstraintViolationException); - final ConstraintViolationException cvs = (ConstraintViolationException) e.getCause(); - assertEquals(1, cvs.getConstraintViolations().size()); - } - } - - @Test - public void validRemote() { - final Person p = mgrRemote.create(null); - mgrRemote.drive(p, 26); - mgrRemote.drive(p, 17); - } - - @Test - public void notValidRemote() { - final Person p = mgrRemote.create("bar"); - try { - mgrRemote.drive(p, 15); - fail(); - } catch (final Exception e) { - assertTrue(e.getCause() instanceof ConstraintViolationException); - final ConstraintViolationException cvs = (ConstraintViolationException) e.getCause(); - assertEquals(1, cvs.getConstraintViolations().size()); - } - } - - @Test - public void localBean() { - mgrLB.foo("ok"); - try { - mgrLB.foo(null); - fail(); - } catch (final Exception e) { - assertTrue(e.getCause() instanceof ConstraintViolationException); - final ConstraintViolationException cvs = (ConstraintViolationException) e.getCause(); - assertEquals(1, cvs.getConstraintViolations().size()); - } - } - - @EJB - private Manager mgr; - @EJB - private ManagerRemote mgrRemote; - @EJB - private ManagerLocalBean mgrLB; - - @Configuration - public Properties config() { - final Properties p = new Properties(); - p.put(BeanContext.USER_INTERCEPTOR_KEY, BeanValidationAppendixInterceptor.class.getName()); - return p; - } - - @Module - public EjbJar app() throws Exception { - final EjbJar ejbJar = new EjbJar("bval-interceptor"); - - final StatelessBean bean1 = new StatelessBean(ManagerBean.class); - bean1.addBusinessLocal(Manager.class); - bean1.setLocalBean(new Empty()); - - final StatelessBean bean3 = new StatelessBean(ManagerBean2.class); - bean3.addBusinessRemote(ManagerRemote.class); - bean3.addBusinessLocal(Manager.class); - bean3.setLocalBean(new Empty()); - - final StatelessBean bean2 = new StatelessBean(ManagerLocalBean.class); - bean2.setLocalBean(new Empty()); - - ejbJar.addEnterpriseBean(bean1); - ejbJar.addEnterpriseBean(bean2); - ejbJar.addEnterpriseBean(bean3); - - return ejbJar; - } - -} - +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.bval; + +import org.apache.openejb.BeanContext; +import org.apache.openejb.jee.EjbJar; +import org.apache.openejb.jee.Empty; +import org.apache.openejb.jee.StatelessBean; +import org.apache.openejb.junit.ApplicationComposer; +import org.apache.openejb.testing.Configuration; +import org.apache.openejb.testing.Module; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.ejb.EJB; +import javax.ejb.Local; +import javax.ejb.LocalBean; +import javax.ejb.Remote; +import javax.ejb.Stateless; +import javax.validation.ConstraintViolationException; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(ApplicationComposer.class) +public class BeanValidationAppendixInterceptorTest { + @Local + public static interface Manager { + String drive(Person person, @Min(18) int age); + + Person create(@NotNull String name); + } + + @Remote + public static interface ManagerRemote { + String drive(Person person, @Min(16) int age); + + Person create(String name); + } + + public static class Person implements Serializable { + public String name; + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + } + + @Stateless + public static class ManagerBean implements Manager { + public String drive(final Person person, final int age) { + return "vroom"; + } + + public Person create(final String name) { + final Person person = new Person(); + person.setName(name); + return person; + } + } + + @Stateless + public static class ManagerBean2 implements Manager, ManagerRemote { + public String drive(final Person person, final int age) { + return "vroom"; + } + + public Person create(final String name) { + final Person person = new Person(); + person.setName(name); + return person; + } + } + + @Stateless + @LocalBean + public static class ManagerLocalBean { + public void foo(@NotNull final String bar) { + // no-op + } + } + + @Test + public void valid() { + final Person p = mgr.create("foo"); + mgr.drive(p, 18); + } + + @Test + public void notValid() { + Person p = null; + try { + p = mgr.create(null); + fail(); + } catch (final Exception e) { + assertTrue(e.getCause() instanceof ConstraintViolationException); + final ConstraintViolationException cvs = (ConstraintViolationException) e.getCause(); + assertEquals(1, cvs.getConstraintViolations().size()); + } + try { + mgr.drive(p, 17); + fail(); + } catch (final Exception e) { + assertTrue(e.getCause() instanceof ConstraintViolationException); + final ConstraintViolationException cvs = (ConstraintViolationException) e.getCause(); + assertEquals(1, cvs.getConstraintViolations().size()); + } + } + + @Test + public void validRemote() { + final Person p = mgrRemote.create(null); + mgrRemote.drive(p, 26); + mgrRemote.drive(p, 17); + } + + @Test + public void notValidRemote() { + final Person p = mgrRemote.create("bar"); + try { + mgrRemote.drive(p, 15); + fail(); + } catch (final Exception e) { + assertTrue(e.getCause() instanceof ConstraintViolationException); + final ConstraintViolationException cvs = (ConstraintViolationException) e.getCause(); + assertEquals(1, cvs.getConstraintViolations().size()); + } + } + + @Test + public void localBean() { + mgrLB.foo("ok"); + try { + mgrLB.foo(null); + fail(); + } catch (final Exception e) { + assertTrue(e.getCause() instanceof ConstraintViolationException); + final ConstraintViolationException cvs = (ConstraintViolationException) e.getCause(); + assertEquals(1, cvs.getConstraintViolations().size()); + } + } + + @EJB + private Manager mgr; + @EJB + private ManagerRemote mgrRemote; + @EJB + private ManagerLocalBean mgrLB; + + @Configuration + public Properties config() { + final Properties p = new Properties(); + p.put(BeanContext.USER_INTERCEPTOR_KEY, BeanValidationAppendixInterceptor.class.getName()); + return p; + } + + @Module + public EjbJar app() throws Exception { + final EjbJar ejbJar = new EjbJar("bval-interceptor"); + + final StatelessBean bean1 = new StatelessBean(ManagerBean.class); + bean1.addBusinessLocal(Manager.class); + bean1.setLocalBean(new Empty()); + + final StatelessBean bean3 = new StatelessBean(ManagerBean2.class); + bean3.addBusinessRemote(ManagerRemote.class); + bean3.addBusinessLocal(Manager.class); + bean3.setLocalBean(new Empty()); + + final StatelessBean bean2 = new StatelessBean(ManagerLocalBean.class); + bean2.setLocalBean(new Empty()); + + ejbJar.addEnterpriseBean(bean1); + ejbJar.addEnterpriseBean(bean2); + ejbJar.addEnterpriseBean(bean3); + + return ejbJar; + } + +} + http://git-wip-us.apache.org/repos/asf/tomee/blob/52567075/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java b/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java index 9626ad9..3b0a075 100644 --- a/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java +++ b/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java @@ -1,550 +1,550 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.openejb.config; - -import org.apache.openejb.OpenEJB; -import org.apache.openejb.assembler.classic.AppInfo; -import org.apache.openejb.assembler.classic.Assembler; -import org.apache.openejb.assembler.classic.ClientInfo; -import org.apache.openejb.jee.AssemblyDescriptor; -import org.apache.openejb.jee.ConfigProperty; -import org.apache.openejb.jee.Connector; -import org.apache.openejb.jee.EjbJar; -import org.apache.openejb.jee.EnterpriseBean; -import org.apache.openejb.jee.SessionBean; -import org.apache.openejb.jee.TransactionSupportType; -import org.apache.openejb.jee.WebApp; -import org.apache.xbean.finder.Annotated; -import org.apache.xbean.finder.AnnotationFinder; -import org.apache.xbean.finder.ClassFinder; -import org.apache.xbean.finder.archive.ClassesArchive; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Test; - -import javax.annotation.Resource; -import javax.ejb.ApplicationException; -import javax.ejb.Local; -import javax.ejb.LocalBean; -import javax.ejb.Stateless; -import javax.naming.NamingException; -import javax.naming.Reference; -import javax.resource.Referenceable; -import javax.resource.ResourceException; -import javax.resource.cci.MessageListener; -import javax.resource.cci.Record; -import javax.resource.spi.Activation; -import javax.resource.spi.ActivationSpec; -import javax.resource.spi.AdministeredObject; -import javax.resource.spi.AuthenticationMechanism; -import javax.resource.spi.AuthenticationMechanism.CredentialInterface; -import javax.resource.spi.BootstrapContext; -import javax.resource.spi.ConnectionDefinition; -import javax.resource.spi.ConnectionManager; -import javax.resource.spi.ConnectionRequestInfo; -import javax.resource.spi.InvalidPropertyException; -import javax.resource.spi.ManagedConnection; -import javax.resource.spi.ManagedConnectionFactory; -import javax.resource.spi.ResourceAdapter; -import javax.resource.spi.ResourceAdapterInternalException; -import javax.resource.spi.SecurityPermission; -import javax.resource.spi.TransactionSupport.TransactionSupportLevel; -import javax.resource.spi.endpoint.MessageEndpointFactory; -import javax.resource.spi.work.WorkContext; -import javax.security.auth.Subject; -import javax.transaction.xa.XAResource; -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.Path; -import javax.ws.rs.core.Application; -import java.io.PrintWriter; -import java.io.Serializable; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -/** - * @version $Rev$ $Date$ - */ -public class AnnotationDeployerTest { - - @AfterClass - public static void afterClass() throws Exception { - OpenEJB.destroy(); - } - - @Test - /** - * For http://issues.apache.org/jira/browse/OPENEJB-980 - */ - public void applicationExceptionInheritanceTest() throws Exception { - EjbModule ejbModule = testModule(); - final AnnotationDeployer.DiscoverAnnotatedBeans discvrAnnBeans = new AnnotationDeployer.DiscoverAnnotatedBeans(); - ejbModule = discvrAnnBeans.deploy(ejbModule); - - final AssemblyDescriptor assemblyDescriptor = ejbModule.getEjbJar().getAssemblyDescriptor(); - org.apache.openejb.jee.ApplicationException appEx = - assemblyDescriptor.getApplicationException(BusinessException.class); - assertThat(appEx, notNullValue()); - assertThat(appEx.getExceptionClass(), is(BusinessException.class.getName())); - assertThat(appEx.isRollback(), is(true)); - - //inheritance is now handled at runtime, only explicitly mentioned exceptions are in the assembly descriptor - appEx = assemblyDescriptor.getApplicationException(ValueRequiredException.class); - assertThat(appEx, nullValue()); - } - - private EjbModule testModule() { - final EjbJar ejbJar = new EjbJar("test-classes"); - final EjbModule ejbModule = new EjbModule(ejbJar); - ejbModule.setFinder(new ClassFinder(AnnotationDeployerTest.class, - BusinessException.class, - Exception.class, - GenericInterface.class, - InterceptedSLSBean.class, - MyMainClass.class, - TestLocalBean.class, - ValueRequiredException.class - )); - return ejbModule; - } - - - @Test - public void testSortClasses() throws Exception { - final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(Emerald.class)).link(); - - final List<Annotated<Class<?>>> classes = finder.findMetaAnnotatedClasses(Resource.class); - assertTrue(classes.size() >= 3); - - final List<Annotated<Class<?>>> sorted = AnnotationDeployer.sortClasses(classes); - - assertTrue(sorted.size() >= 3); - - assertEquals(Emerald.class, sorted.get(0).get()); - assertEquals(Green.class, sorted.get(1).get()); - assertEquals(Color.class, sorted.get(2).get()); - } - - @Test - public void testSortMethods() throws Exception { - final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(Emerald.class)).link(); - - final List<Annotated<Method>> classes = finder.findMetaAnnotatedMethods(Resource.class); - assertTrue(classes.size() >= 3); - - final List<Annotated<Method>> sorted = AnnotationDeployer.sortMethods(classes); - - assertTrue(sorted.size() >= 3); - - assertEquals(Emerald.class, sorted.get(0).get().getDeclaringClass()); - assertEquals(Green.class, sorted.get(1).get().getDeclaringClass()); - assertEquals(Color.class, sorted.get(2).get().getDeclaringClass()); - } - - @Test - /** - * For https://issues.apache.org/jira/browse/OPENEJB-1063 - */ - public void badMainClassFormatTest() throws Exception { - final ConfigurationFactory config = new ConfigurationFactory(); - final Assembler assembler = new Assembler(); - - final AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app"); - - final ClientModule clientModule = new ClientModule(null, app.getClassLoader(), app.getJarLocation(), null, null); - - // change "." --> "/" to check that main class is changed by the AnnotationDeployer - final String mainClass = MyMainClass.class.getName().replaceAll("\\.", "/"); - clientModule.setMainClass(mainClass); - - app.getClientModules().add(clientModule); - - final AppInfo appInfo = config.configureApplication(app); - - assembler.createApplication(appInfo); - - final ClientInfo clientInfo = appInfo.clients.get(0); - Assert.assertNotNull(clientInfo); - Assert.assertEquals(MyMainClass.class.getName(), clientInfo.mainClass); - } - - /** - * For https://issues.apache.org/jira/browse/OPENEJB-1128 - */ - @Test - public void interceptingGenericBusinessMethodCalls() throws Exception { - EjbModule ejbModule = testModule(); - final EjbJar ejbJar = ejbModule.getEjbJar(); - - final AnnotationDeployer.DiscoverAnnotatedBeans discvrAnnBeans = new AnnotationDeployer.DiscoverAnnotatedBeans(); - ejbModule = discvrAnnBeans.deploy(ejbModule); - - final EnterpriseBean bean = ejbJar.getEnterpriseBean("InterceptedSLSBean"); - assert bean != null; - } - - /** - * For https://issues.apache.org/jira/browse/OPENEJB-1188 - * - * @throws Exception - */ - @Test - public void testLocalBean() throws Exception { - final EjbModule ejbModule = testModule(); - final EjbJar ejbJar = ejbModule.getEjbJar(); - - AppModule appModule = new AppModule(Thread.currentThread().getContextClassLoader(), "myapp"); - appModule.getEjbModules().add(ejbModule); - - final AnnotationDeployer annotationDeployer = new AnnotationDeployer(); - appModule = annotationDeployer.deploy(appModule); - - EnterpriseBean bean = ejbJar.getEnterpriseBean("TestLocalBean"); - assert bean != null; - assert (((SessionBean) bean).getLocalBean() != null); - - bean = ejbJar.getEnterpriseBean("InterceptedSLSBean"); - assert bean != null; - assert (((SessionBean) bean).getLocalBean() == null); - } - - @Test - public void testResourceAdapter() throws Exception { - final ConnectorModule connectorModule = testConnectorModule(); - final AnnotationDeployer.DiscoverAnnotatedBeans discvrAnnBeans = new AnnotationDeployer.DiscoverAnnotatedBeans(); - discvrAnnBeans.deploy(connectorModule); - - final Connector connector = connectorModule.getConnector(); - Assert.assertEquals("displayName", connector.getDisplayName()); - Assert.assertEquals("description", connector.getDescription()); - Assert.assertEquals("eisType", connector.getEisType()); - Assert.assertEquals("vendorName", connector.getVendorName()); - Assert.assertEquals("version", connector.getResourceAdapterVersion()); - Assert.assertEquals("smallIcon", connector.getIcon().getSmallIcon()); - Assert.assertEquals("largeIcon", connector.getIcon().getLargeIcon()); - Assert.assertEquals("licenseDescription", connector.getLicense().getDescription()); - Assert.assertEquals(true, connector.getLicense().isLicenseRequired()); - - final List<org.apache.openejb.jee.SecurityPermission> securityPermission = connector.getResourceAdapter().getSecurityPermission(); - Assert.assertEquals("description", securityPermission.get(0).getDescription()); - Assert.assertEquals("permissionSpec", securityPermission.get(0).getSecurityPermissionSpec()); - - final List<String> requiredWorkContext = connector.getRequiredWorkContext(); - Assert.assertEquals(TestWorkContext.class.getName(), requiredWorkContext.get(0)); - - final List<org.apache.openejb.jee.AuthenticationMechanism> authenticationMechanism = connector.getResourceAdapter().getOutboundResourceAdapter().getAuthenticationMechanism(); - Assert.assertEquals("authMechanism", authenticationMechanism.get(0).getAuthenticationMechanismType()); - Assert.assertEquals(CredentialInterface.GenericCredential.toString(), authenticationMechanism.get(0).getCredentialInterface()); - Assert.assertEquals("description", authenticationMechanism.get(0).getDescription()); - - Assert.assertEquals(TransactionSupportType.NO_TRANSACTION, connector.getResourceAdapter().getOutboundResourceAdapter().getTransactionSupport()); - Assert.assertEquals(true, connector.getResourceAdapter().getOutboundResourceAdapter().isReauthenticationSupport()); - - Assert.assertEquals(Connection.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionInterface()); - Assert.assertEquals(ConnectionImpl.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionImplClass()); - Assert.assertEquals(ConnectionFactory.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionFactoryInterface()); - Assert.assertEquals(ConnectionFactoryImpl.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionFactoryImplClass()); - - Assert.assertEquals(TestActivation.class.getName(), connector.getResourceAdapter().getInboundResourceAdapter().getMessageAdapter().getMessageListener().get(0).getActivationSpec().getActivationSpecClass()); - Assert.assertEquals(TestMessageListener.class.getName(), connector.getResourceAdapter().getInboundResourceAdapter().getMessageAdapter().getMessageListener().get(0).getMessageListenerType()); - - Assert.assertEquals(TestAdminObject.class.getName(), connector.getResourceAdapter().getAdminObject().get(0).getAdminObjectClass()); - Assert.assertEquals(TestAdminObjectInterface.class.getName(), connector.getResourceAdapter().getAdminObject().get(0).getAdminObjectInterface()); - } - - private ConnectorModule testConnectorModule() { - final Connector connector = new Connector(); - final ConnectorModule connectorModule = new ConnectorModule(connector); - connectorModule.setFinder(new ClassFinder(TestConnector.class, TestManagedConnectionFactory.class, TestActivation.class, TestAdminObject.class)); - return connectorModule; - } - - @Test - public void testConfigProperties() throws Exception { - final ClassFinder finder = new ClassFinder(TestAdminObject.class); - - final List<ConfigProperty> configProperty = new ArrayList<ConfigProperty>(); - - final Object object = new Object() { - public List<ConfigProperty> getConfigProperty() { - return configProperty; - } - }; - - new AnnotationDeployer.DiscoverAnnotatedBeans().process(null, TestAdminObject.class.getName(), object); - Assert.assertEquals(2, configProperty.size()); - Assert.assertEquals("myNumber", configProperty.get(0).getConfigPropertyName()); - Assert.assertEquals("java.lang.Integer", configProperty.get(0).getConfigPropertyType()); - Assert.assertEquals("myProperty", configProperty.get(1).getConfigPropertyName()); - Assert.assertEquals("java.lang.String", configProperty.get(1).getConfigPropertyType()); - Assert.assertEquals("This is a test", configProperty.get(1).getConfigPropertyValue()); - } - - @ApplicationException(rollback = true) - public abstract class BusinessException extends Exception { - } - - public class ValueRequiredException extends BusinessException { - } - - public static final class MyMainClass { - public static void main(final String[] args) { - } - } - - public static interface GenericInterface<T> { - T genericMethod(T t); - } - - @Stateless - @Local(GenericInterface.class) - public static class InterceptedSLSBean implements GenericInterface<String> { - public String genericMethod(final String s) { - return s; - } - } - - @Stateless - @LocalBean - public static class TestLocalBean { - public String echo(final String input) { - return input; - } - } - - @Resource - public static class Color { - @Resource - public void color() { - } - } - - @Resource - public static class Green extends Color { - @Resource - public void green() { - } - } - - @Resource - public static class Emerald extends Green { - @Resource - public void emerald() { - } - } - - @javax.resource.spi.Connector(description = "description", - displayName = "displayName", smallIcon = "smallIcon", - largeIcon = "largeIcon", vendorName = "vendorName", - eisType = "eisType", - version = "version", - licenseDescription = {"licenseDescription"}, - licenseRequired = true, - authMechanisms = {@AuthenticationMechanism(authMechanism = "authMechanism", - credentialInterface = CredentialInterface.GenericCredential, description = {"description"})}, - reauthenticationSupport = true, - securityPermissions = {@SecurityPermission(permissionSpec = "permissionSpec", description = "description")}, - transactionSupport = TransactionSupportLevel.NoTransaction, - requiredWorkContexts = {TestWorkContext.class} - ) - public static class TestConnector implements ResourceAdapter { - - public void endpointActivation(final MessageEndpointFactory mef, final ActivationSpec spec) throws ResourceException { - } - - public void endpointDeactivation(final MessageEndpointFactory mef, final ActivationSpec spec) { - } - - public XAResource[] getXAResources(final ActivationSpec[] specs) throws ResourceException { - return null; - } - - public void start(final BootstrapContext ctx) throws ResourceAdapterInternalException { - } - - public void stop() { - } - } - - @ConnectionDefinition(connection = Connection.class, connectionFactory = ConnectionFactory.class, connectionImpl = ConnectionImpl.class, connectionFactoryImpl = ConnectionFactoryImpl.class) - public static class TestManagedConnectionFactory implements ManagedConnectionFactory { - - public Object createConnectionFactory() throws ResourceException { - return null; - } - - public Object createConnectionFactory(final ConnectionManager connectionManager) throws ResourceException { - return null; - } - - public ManagedConnection createManagedConnection(final Subject subject, final ConnectionRequestInfo connectionRequestInfo) throws ResourceException { - return null; - } - - public PrintWriter getLogWriter() throws ResourceException { - return null; - } - - public ManagedConnection matchManagedConnections(final Set managedConnections, final Subject subject, final ConnectionRequestInfo connectionRequestInfo) throws ResourceException { - return null; - } - - public void setLogWriter(final PrintWriter writer) throws ResourceException { - } - - } - - public static class TestWorkContext implements WorkContext { - public String getDescription() { - return "Description"; - } - - public String getName() { - return "Name"; - } - } - - public static interface Connection { - } - - public static class ConnectionImpl implements Connection { - } - - public static interface ConnectionFactory extends Serializable, Referenceable { - } - - public static class ConnectionFactoryImpl implements ConnectionFactory { - - public void setReference(final Reference reference) { - } - - public Reference getReference() throws NamingException { - return null; - } - } - - @Activation(messageListeners = {TestMessageListener.class}) - public static class TestActivation implements ActivationSpec, Serializable { - - public ResourceAdapter getResourceAdapter() { - return null; - } - - public void setResourceAdapter(final ResourceAdapter arg0) throws ResourceException { - } - - public void validate() throws InvalidPropertyException { - } - } - - public static class TestMessageListener implements MessageListener { - public Record onMessage(final Record arg0) throws ResourceException { - return null; - } - } - - public static interface TestAdminObjectInterface { - } - - public static interface SomeOtherInterface { - } - - @AdministeredObject(adminObjectInterfaces = {TestAdminObjectInterface.class}) - public static class TestAdminObject implements TestAdminObjectInterface, SomeOtherInterface { - private String myProperty = "This is a test"; - - @javax.resource.spi.ConfigProperty(ignore = true) - private int myNumber; - - public String getMyProperty() { - return myProperty; - } - - public void setMyProperty(final String myProperty) { - this.myProperty = myProperty; - } - - public int getMyNumber() { - return myNumber; - } - - public void setMyNumber(final int myNumber) { - this.myNumber = myNumber; - } - } - - @Test - public void findRestClasses() throws Exception { - final WebApp webApp = new WebApp(); - webApp.setContextRoot("/"); - webApp.setId("web"); - webApp.setVersion("2.5"); - WebModule webModule = new WebModule(webApp, webApp.getContextRoot(), Thread.currentThread().getContextClassLoader(), "myapp", webApp.getId()); - webModule.setFinder(new AnnotationFinder(new ClassesArchive(RESTClass.class, RESTMethod.class, RESTApp.class)).link()); - - final AnnotationDeployer annotationDeployer = new AnnotationDeployer(); - webModule = annotationDeployer.deploy(webModule); - - final Set<String> classes = webModule.getRestClasses(); - final Set<String> applications = webModule.getRestApplications(); - - assertEquals(1, classes.size()); - assertTrue(classes.contains(RESTClass.class.getName())); - // assertTrue(classes.contains(RESTMethod.class.getName())); - - assertEquals(1, applications.size()); - assertEquals(RESTApp.class.getName(), applications.iterator().next()); - } - - @Path("/") - public static class RESTClass { - - } - - public static class RESTMethod extends RESTClass { - @Path("/method") - public void noop() { - // no-op - } - } - - @ApplicationPath("/") - public static class RESTApp extends Application { - public java.util.Set<java.lang.Class<?>> getClasses() { - return new HashSet<Class<?>>() {{ - add(RESTClass.class); - add(RESTMethod.class); - }}; - } - - public java.util.Set<java.lang.Object> getSingletons() { - return new HashSet<Object>() {{ - add(new RESTMethod()); - add(new RESTMethod()); - }}; - } - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.config; + +import org.apache.openejb.OpenEJB; +import org.apache.openejb.assembler.classic.AppInfo; +import org.apache.openejb.assembler.classic.Assembler; +import org.apache.openejb.assembler.classic.ClientInfo; +import org.apache.openejb.jee.AssemblyDescriptor; +import org.apache.openejb.jee.ConfigProperty; +import org.apache.openejb.jee.Connector; +import org.apache.openejb.jee.EjbJar; +import org.apache.openejb.jee.EnterpriseBean; +import org.apache.openejb.jee.SessionBean; +import org.apache.openejb.jee.TransactionSupportType; +import org.apache.openejb.jee.WebApp; +import org.apache.xbean.finder.Annotated; +import org.apache.xbean.finder.AnnotationFinder; +import org.apache.xbean.finder.ClassFinder; +import org.apache.xbean.finder.archive.ClassesArchive; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Test; + +import javax.annotation.Resource; +import javax.ejb.ApplicationException; +import javax.ejb.Local; +import javax.ejb.LocalBean; +import javax.ejb.Stateless; +import javax.naming.NamingException; +import javax.naming.Reference; +import javax.resource.Referenceable; +import javax.resource.ResourceException; +import javax.resource.cci.MessageListener; +import javax.resource.cci.Record; +import javax.resource.spi.Activation; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.AdministeredObject; +import javax.resource.spi.AuthenticationMechanism; +import javax.resource.spi.AuthenticationMechanism.CredentialInterface; +import javax.resource.spi.BootstrapContext; +import javax.resource.spi.ConnectionDefinition; +import javax.resource.spi.ConnectionManager; +import javax.resource.spi.ConnectionRequestInfo; +import javax.resource.spi.InvalidPropertyException; +import javax.resource.spi.ManagedConnection; +import javax.resource.spi.ManagedConnectionFactory; +import javax.resource.spi.ResourceAdapter; +import javax.resource.spi.ResourceAdapterInternalException; +import javax.resource.spi.SecurityPermission; +import javax.resource.spi.TransactionSupport.TransactionSupportLevel; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.resource.spi.work.WorkContext; +import javax.security.auth.Subject; +import javax.transaction.xa.XAResource; +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.Path; +import javax.ws.rs.core.Application; +import java.io.PrintWriter; +import java.io.Serializable; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +/** + * @version $Rev$ $Date$ + */ +public class AnnotationDeployerTest { + + @AfterClass + public static void afterClass() throws Exception { + OpenEJB.destroy(); + } + + @Test + /** + * For http://issues.apache.org/jira/browse/OPENEJB-980 + */ + public void applicationExceptionInheritanceTest() throws Exception { + EjbModule ejbModule = testModule(); + final AnnotationDeployer.DiscoverAnnotatedBeans discvrAnnBeans = new AnnotationDeployer.DiscoverAnnotatedBeans(); + ejbModule = discvrAnnBeans.deploy(ejbModule); + + final AssemblyDescriptor assemblyDescriptor = ejbModule.getEjbJar().getAssemblyDescriptor(); + org.apache.openejb.jee.ApplicationException appEx = + assemblyDescriptor.getApplicationException(BusinessException.class); + assertThat(appEx, notNullValue()); + assertThat(appEx.getExceptionClass(), is(BusinessException.class.getName())); + assertThat(appEx.isRollback(), is(true)); + + //inheritance is now handled at runtime, only explicitly mentioned exceptions are in the assembly descriptor + appEx = assemblyDescriptor.getApplicationException(ValueRequiredException.class); + assertThat(appEx, nullValue()); + } + + private EjbModule testModule() { + final EjbJar ejbJar = new EjbJar("test-classes"); + final EjbModule ejbModule = new EjbModule(ejbJar); + ejbModule.setFinder(new ClassFinder(AnnotationDeployerTest.class, + BusinessException.class, + Exception.class, + GenericInterface.class, + InterceptedSLSBean.class, + MyMainClass.class, + TestLocalBean.class, + ValueRequiredException.class + )); + return ejbModule; + } + + + @Test + public void testSortClasses() throws Exception { + final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(Emerald.class)).link(); + + final List<Annotated<Class<?>>> classes = finder.findMetaAnnotatedClasses(Resource.class); + assertTrue(classes.size() >= 3); + + final List<Annotated<Class<?>>> sorted = AnnotationDeployer.sortClasses(classes); + + assertTrue(sorted.size() >= 3); + + assertEquals(Emerald.class, sorted.get(0).get()); + assertEquals(Green.class, sorted.get(1).get()); + assertEquals(Color.class, sorted.get(2).get()); + } + + @Test + public void testSortMethods() throws Exception { + final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(Emerald.class)).link(); + + final List<Annotated<Method>> classes = finder.findMetaAnnotatedMethods(Resource.class); + assertTrue(classes.size() >= 3); + + final List<Annotated<Method>> sorted = AnnotationDeployer.sortMethods(classes); + + assertTrue(sorted.size() >= 3); + + assertEquals(Emerald.class, sorted.get(0).get().getDeclaringClass()); + assertEquals(Green.class, sorted.get(1).get().getDeclaringClass()); + assertEquals(Color.class, sorted.get(2).get().getDeclaringClass()); + } + + @Test + /** + * For https://issues.apache.org/jira/browse/OPENEJB-1063 + */ + public void badMainClassFormatTest() throws Exception { + final ConfigurationFactory config = new ConfigurationFactory(); + final Assembler assembler = new Assembler(); + + final AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app"); + + final ClientModule clientModule = new ClientModule(null, app.getClassLoader(), app.getJarLocation(), null, null); + + // change "." --> "/" to check that main class is changed by the AnnotationDeployer + final String mainClass = MyMainClass.class.getName().replaceAll("\\.", "/"); + clientModule.setMainClass(mainClass); + + app.getClientModules().add(clientModule); + + final AppInfo appInfo = config.configureApplication(app); + + assembler.createApplication(appInfo); + + final ClientInfo clientInfo = appInfo.clients.get(0); + Assert.assertNotNull(clientInfo); + Assert.assertEquals(MyMainClass.class.getName(), clientInfo.mainClass); + } + + /** + * For https://issues.apache.org/jira/browse/OPENEJB-1128 + */ + @Test + public void interceptingGenericBusinessMethodCalls() throws Exception { + EjbModule ejbModule = testModule(); + final EjbJar ejbJar = ejbModule.getEjbJar(); + + final AnnotationDeployer.DiscoverAnnotatedBeans discvrAnnBeans = new AnnotationDeployer.DiscoverAnnotatedBeans(); + ejbModule = discvrAnnBeans.deploy(ejbModule); + + final EnterpriseBean bean = ejbJar.getEnterpriseBean("InterceptedSLSBean"); + assert bean != null; + } + + /** + * For https://issues.apache.org/jira/browse/OPENEJB-1188 + * + * @throws Exception + */ + @Test + public void testLocalBean() throws Exception { + final EjbModule ejbModule = testModule(); + final EjbJar ejbJar = ejbModule.getEjbJar(); + + AppModule appModule = new AppModule(Thread.currentThread().getContextClassLoader(), "myapp"); + appModule.getEjbModules().add(ejbModule); + + final AnnotationDeployer annotationDeployer = new AnnotationDeployer(); + appModule = annotationDeployer.deploy(appModule); + + EnterpriseBean bean = ejbJar.getEnterpriseBean("TestLocalBean"); + assert bean != null; + assert (((SessionBean) bean).getLocalBean() != null); + + bean = ejbJar.getEnterpriseBean("InterceptedSLSBean"); + assert bean != null; + assert (((SessionBean) bean).getLocalBean() == null); + } + + @Test + public void testResourceAdapter() throws Exception { + final ConnectorModule connectorModule = testConnectorModule(); + final AnnotationDeployer.DiscoverAnnotatedBeans discvrAnnBeans = new AnnotationDeployer.DiscoverAnnotatedBeans(); + discvrAnnBeans.deploy(connectorModule); + + final Connector connector = connectorModule.getConnector(); + Assert.assertEquals("displayName", connector.getDisplayName()); + Assert.assertEquals("description", connector.getDescription()); + Assert.assertEquals("eisType", connector.getEisType()); + Assert.assertEquals("vendorName", connector.getVendorName()); + Assert.assertEquals("version", connector.getResourceAdapterVersion()); + Assert.assertEquals("smallIcon", connector.getIcon().getSmallIcon()); + Assert.assertEquals("largeIcon", connector.getIcon().getLargeIcon()); + Assert.assertEquals("licenseDescription", connector.getLicense().getDescription()); + Assert.assertEquals(true, connector.getLicense().isLicenseRequired()); + + final List<org.apache.openejb.jee.SecurityPermission> securityPermission = connector.getResourceAdapter().getSecurityPermission(); + Assert.assertEquals("description", securityPermission.get(0).getDescription()); + Assert.assertEquals("permissionSpec", securityPermission.get(0).getSecurityPermissionSpec()); + + final List<String> requiredWorkContext = connector.getRequiredWorkContext(); + Assert.assertEquals(TestWorkContext.class.getName(), requiredWorkContext.get(0)); + + final List<org.apache.openejb.jee.AuthenticationMechanism> authenticationMechanism = connector.getResourceAdapter().getOutboundResourceAdapter().getAuthenticationMechanism(); + Assert.assertEquals("authMechanism", authenticationMechanism.get(0).getAuthenticationMechanismType()); + Assert.assertEquals(CredentialInterface.GenericCredential.toString(), authenticationMechanism.get(0).getCredentialInterface()); + Assert.assertEquals("description", authenticationMechanism.get(0).getDescription()); + + Assert.assertEquals(TransactionSupportType.NO_TRANSACTION, connector.getResourceAdapter().getOutboundResourceAdapter().getTransactionSupport()); + Assert.assertEquals(true, connector.getResourceAdapter().getOutboundResourceAdapter().isReauthenticationSupport()); + + Assert.assertEquals(Connection.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionInterface()); + Assert.assertEquals(ConnectionImpl.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionImplClass()); + Assert.assertEquals(ConnectionFactory.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionFactoryInterface()); + Assert.assertEquals(ConnectionFactoryImpl.class.getName(), connector.getResourceAdapter().getOutboundResourceAdapter().getConnectionDefinition().get(0).getConnectionFactoryImplClass()); + + Assert.assertEquals(TestActivation.class.getName(), connector.getResourceAdapter().getInboundResourceAdapter().getMessageAdapter().getMessageListener().get(0).getActivationSpec().getActivationSpecClass()); + Assert.assertEquals(TestMessageListener.class.getName(), connector.getResourceAdapter().getInboundResourceAdapter().getMessageAdapter().getMessageListener().get(0).getMessageListenerType()); + + Assert.assertEquals(TestAdminObject.class.getName(), connector.getResourceAdapter().getAdminObject().get(0).getAdminObjectClass()); + Assert.assertEquals(TestAdminObjectInterface.class.getName(), connector.getResourceAdapter().getAdminObject().get(0).getAdminObjectInterface()); + } + + private ConnectorModule testConnectorModule() { + final Connector connector = new Connector(); + final ConnectorModule connectorModule = new ConnectorModule(connector); + connectorModule.setFinder(new ClassFinder(TestConnector.class, TestManagedConnectionFactory.class, TestActivation.class, TestAdminObject.class)); + return connectorModule; + } + + @Test + public void testConfigProperties() throws Exception { + final ClassFinder finder = new ClassFinder(TestAdminObject.class); + + final List<ConfigProperty> configProperty = new ArrayList<ConfigProperty>(); + + final Object object = new Object() { + public List<ConfigProperty> getConfigProperty() { + return configProperty; + } + }; + + new AnnotationDeployer.DiscoverAnnotatedBeans().process(null, TestAdminObject.class.getName(), object); + Assert.assertEquals(2, configProperty.size()); + Assert.assertEquals("myNumber", configProperty.get(0).getConfigPropertyName()); + Assert.assertEquals("java.lang.Integer", configProperty.get(0).getConfigPropertyType()); + Assert.assertEquals("myProperty", configProperty.get(1).getConfigPropertyName()); + Assert.assertEquals("java.lang.String", configProperty.get(1).getConfigPropertyType()); + Assert.assertEquals("This is a test", configProperty.get(1).getConfigPropertyValue()); + } + + @ApplicationException(rollback = true) + public abstract class BusinessException extends Exception { + } + + public class ValueRequiredException extends BusinessException { + } + + public static final class MyMainClass { + public static void main(final String[] args) { + } + } + + public static interface GenericInterface<T> { + T genericMethod(T t); + } + + @Stateless + @Local(GenericInterface.class) + public static class InterceptedSLSBean implements GenericInterface<String> { + public String genericMethod(final String s) { + return s; + } + } + + @Stateless + @LocalBean + public static class TestLocalBean { + public String echo(final String input) { + return input; + } + } + + @Resource + public static class Color { + @Resource + public void color() { + } + } + + @Resource + public static class Green extends Color { + @Resource + public void green() { + } + } + + @Resource + public static class Emerald extends Green { + @Resource + public void emerald() { + } + } + + @javax.resource.spi.Connector(description = "description", + displayName = "displayName", smallIcon = "smallIcon", + largeIcon = "largeIcon", vendorName = "vendorName", + eisType = "eisType", + version = "version", + licenseDescription = {"licenseDescription"}, + licenseRequired = true, + authMechanisms = {@AuthenticationMechanism(authMechanism = "authMechanism", + credentialInterface = CredentialInterface.GenericCredential, description = {"description"})}, + reauthenticationSupport = true, + securityPermissions = {@SecurityPermission(permissionSpec = "permissionSpec", description = "description")}, + transactionSupport = TransactionSupportLevel.NoTransaction, + requiredWorkContexts = {TestWorkContext.class} + ) + public static class TestConnector implements ResourceAdapter { + + public void endpointActivation(final MessageEndpointFactory mef, final ActivationSpec spec) throws ResourceException { + } + + public void endpointDeactivation(final MessageEndpointFactory mef, final ActivationSpec spec) { + } + + public XAResource[] getXAResources(final ActivationSpec[] specs) throws ResourceException { + return null; + } + + public void start(final BootstrapContext ctx) throws ResourceAdapterInternalException { + } + + public void stop() { + } + } + + @ConnectionDefinition(connection = Connection.class, connectionFactory = ConnectionFactory.class, connectionImpl = ConnectionImpl.class, connectionFactoryImpl = ConnectionFactoryImpl.class) + public static class TestManagedConnectionFactory implements ManagedConnectionFactory { + + public Object createConnectionFactory() throws ResourceException { + return null; + } + + public Object createConnectionFactory(final ConnectionManager connectionManager) throws ResourceException { + return null; + } + + public ManagedConnection createManagedConnection(final Subject subject, final ConnectionRequestInfo connectionRequestInfo) throws ResourceException { + return null; + } + + public PrintWriter getLogWriter() throws ResourceException { + return null; + } + + public ManagedConnection matchManagedConnections(final Set managedConnections, final Subject subject, final ConnectionRequestInfo connectionRequestInfo) throws ResourceException { + return null; + } + + public void setLogWriter(final PrintWriter writer) throws ResourceException { + } + + } + + public static class TestWorkContext implements WorkContext { + public String getDescription() { + return "Description"; + } + + public String getName() { + return "Name"; + } + } + + public static interface Connection { + } + + public static class ConnectionImpl implements Connection { + } + + public static interface ConnectionFactory extends Serializable, Referenceable { + } + + public static class ConnectionFactoryImpl implements ConnectionFactory { + + public void setReference(final Reference reference) { + } + + public Reference getReference() throws NamingException { + return null; + } + } + + @Activation(messageListeners = {TestMessageListener.class}) + public static class TestActivation implements ActivationSpec, Serializable { + + public ResourceAdapter getResourceAdapter() { + return null; + } + + public void setResourceAdapter(final ResourceAdapter arg0) throws ResourceException { + } + + public void validate() throws InvalidPropertyException { + } + } + + public static class TestMessageListener implements MessageListener { + public Record onMessage(final Record arg0) throws ResourceException { + return null; + } + } + + public static interface TestAdminObjectInterface { + } + + public static interface SomeOtherInterface { + } + + @AdministeredObject(adminObjectInterfaces = {TestAdminObjectInterface.class}) + public static class TestAdminObject implements TestAdminObjectInterface, SomeOtherInterface { + private String myProperty = "This is a test"; + + @javax.resource.spi.ConfigProperty(ignore = true) + private int myNumber; + + public String getMyProperty() { + return myProperty; + } + + public void setMyProperty(final String myProperty) { + this.myProperty = myProperty; + } + + public int getMyNumber() { + return myNumber; + } + + public void setMyNumber(final int myNumber) { + this.myNumber = myNumber; + } + } + + @Test + public void findRestClasses() throws Exception { + final WebApp webApp = new WebApp(); + webApp.setContextRoot("/"); + webApp.setId("web"); + webApp.setVersion("2.5"); + WebModule webModule = new WebModule(webApp, webApp.getContextRoot(), Thread.currentThread().getContextClassLoader(), "myapp", webApp.getId()); + webModule.setFinder(new AnnotationFinder(new ClassesArchive(RESTClass.class, RESTMethod.class, RESTApp.class)).link()); + + final AnnotationDeployer annotationDeployer = new AnnotationDeployer(); + webModule = annotationDeployer.deploy(webModule); + + final Set<String> classes = webModule.getRestClasses(); + final Set<String> applications = webModule.getRestApplications(); + + assertEquals(1, classes.size()); + assertTrue(classes.contains(RESTClass.class.getName())); + // assertTrue(classes.contains(RESTMethod.class.getName())); + + assertEquals(1, applications.size()); + assertEquals(RESTApp.class.getName(), applications.iterator().next()); + } + + @Path("/") + public static class RESTClass { + + } + + public static class RESTMethod extends RESTClass { + @Path("/method") + public void noop() { + // no-op + } + } + + @ApplicationPath("/") + public static class RESTApp extends Application { + public java.util.Set<java.lang.Class<?>> getClasses() { + return new HashSet<Class<?>>() {{ + add(RESTClass.class); + add(RESTMethod.class); + }}; + } + + public java.util.Set<java.lang.Object> getSingletons() { + return new HashSet<Object>() {{ + add(new RESTMethod()); + add(new RESTMethod()); + }}; + } + } +}
