[jboss-cvs] JBossAS SVN: r74964 - in projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test: ejbthree1150 and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 24 05:30:59 EDT 2008
Author: wolfc
Date: 2008-06-24 05:30:59 -0400 (Tue, 24 Jun 2008)
New Revision: 74964
Added:
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/AnnotatedWebServiceContextInjectedBean.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/OverrideWebServiceContextInjectedBean.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/WebServiceContextInjected.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/WebServiceContextInjectedBean.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/unit/
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/unit/WebServiceContextInjectionTestCase.java
Log:
EJBTHREE-1150: unit test
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/AnnotatedWebServiceContextInjectedBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/AnnotatedWebServiceContextInjectedBean.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/AnnotatedWebServiceContextInjectedBean.java 2008-06-24 09:30:59 UTC (rev 74964)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1150;
+
+import javax.annotation.Resource;
+import javax.ejb.Stateless;
+import javax.xml.ws.WebServiceContext;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+public class AnnotatedWebServiceContextInjectedBean extends WebServiceContextInjectedBean
+{
+ @Resource
+ private WebServiceContext wsContext;
+
+ protected WebServiceContext getWebServiceContext()
+ {
+ return wsContext;
+ }
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/OverrideWebServiceContextInjectedBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/OverrideWebServiceContextInjectedBean.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/OverrideWebServiceContextInjectedBean.java 2008-06-24 09:30:59 UTC (rev 74964)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1150;
+
+import javax.ejb.Stateless;
+import javax.xml.ws.WebServiceContext;
+
+/**
+ * Injection by meta data.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+public class OverrideWebServiceContextInjectedBean extends WebServiceContextInjectedBean
+{
+ // injected through meta data
+ private WebServiceContext wsContext;
+
+ protected WebServiceContext getWebServiceContext()
+ {
+ return wsContext;
+ }
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/WebServiceContextInjected.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/WebServiceContextInjected.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/WebServiceContextInjected.java 2008-06-24 09:30:59 UTC (rev 74964)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1150;
+
+import javax.ejb.Local;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Local
+public interface WebServiceContextInjected
+{
+ void checkWebServiceContext();
+}
\ No newline at end of file
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/WebServiceContextInjectedBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/WebServiceContextInjectedBean.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/WebServiceContextInjectedBean.java 2008-06-24 09:30:59 UTC (rev 74964)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1150;
+
+import javax.annotation.PostConstruct;
+import javax.xml.ws.WebServiceContext;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class WebServiceContextInjectedBean implements WebServiceContextInjected
+{
+ public void checkWebServiceContext()
+ {
+ try
+ {
+ getWebServiceContext().getMessageContext();
+ throw new RuntimeException("Should have thrown an IllegalStateException for wsContext (See WebServiceContext.getMessageContext())");
+ }
+ catch(IllegalStateException e)
+ {
+ // Good
+ }
+ }
+
+ protected abstract WebServiceContext getWebServiceContext();
+
+ @PostConstruct
+ public void postConstruct()
+ {
+ if(getWebServiceContext() == null)
+ throw new IllegalStateException("wsContext was not injected");
+ }
+}
Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/unit/WebServiceContextInjectionTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/unit/WebServiceContextInjectionTestCase.java (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree1150/unit/WebServiceContextInjectionTestCase.java 2008-06-24 09:30:59 UTC (rev 74964)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.core.test.ejbthree1150.unit;
+
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+
+import javax.naming.InitialContext;
+import javax.xml.ws.WebServiceContext;
+
+import org.jboss.aop.Domain;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.core.test.ejbthree1150.AnnotatedWebServiceContextInjectedBean;
+import org.jboss.ejb3.core.test.ejbthree1150.OverrideWebServiceContextInjectedBean;
+import org.jboss.ejb3.core.test.ejbthree1150.WebServiceContextInjected;
+import org.jboss.ejb3.stateless.StatelessContainer;
+import org.jboss.ejb3.test.cachepassivation.MockDeploymentUnit;
+import org.jboss.ejb3.test.cachepassivation.MockEjb3Deployment;
+import org.jboss.ejb3.test.common.MetaDataHelper;
+import org.jboss.metadata.ejb.jboss.JBossEnvironmentRefsGroupMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.javaee.spec.ResourceEnvironmentReferenceMetaData;
+import org.jboss.metadata.javaee.spec.ResourceEnvironmentReferencesMetaData;
+import org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class WebServiceContextInjectionTestCase extends AbstractEJB3TestCase
+{
+ @Test
+ public void testCheckWebServiceContext() throws Exception
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Class<?> beanClass = AnnotatedWebServiceContextInjectedBean.class;
+ String beanClassname = beanClass.getName();
+ String ejbName = beanClass.getSimpleName();
+ Domain domain = getDomain("Stateless Bean");
+ Hashtable<?,?> ctxProperties = null;
+ Ejb3Deployment deployment = new MockEjb3Deployment(new MockDeploymentUnit(), null);
+ JBossSessionBeanMetaData beanMetaData = MetaDataHelper.getMetadataFromBeanImplClass(beanClass);
+ StatelessContainer container = new StatelessContainer(cl, beanClassname, ejbName, domain, ctxProperties, deployment, beanMetaData);
+
+ // TODO: wickedness
+ container.instantiated();
+
+ container.processMetadata();
+
+ // Register the Container in ObjectStore (MC)
+ String containerName = container.getName();
+ Ejb3RegistrarLocator.locateRegistrar().bind(containerName, container);
+
+ InitialContext ctx = new InitialContext();
+ System.out.println("ctx = " + ctx);
+ //System.out.println(" " + container.getInitialContext().list("MyStatelessBean").next());
+ WebServiceContextInjected bean = (WebServiceContextInjected) ctx.lookup("AnnotatedWebServiceContextInjectedBean/local");
+
+ bean.checkWebServiceContext();
+
+ getBootstrap().getKernel().getController().uninstall(containerName);
+ }
+
+ @Test
+ public void testCheckWebServiceContextWithOverride() throws Exception
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Class<?> beanClass = OverrideWebServiceContextInjectedBean.class;
+ String beanClassname = beanClass.getName();
+ String ejbName = beanClass.getSimpleName();
+ Domain domain = getDomain("Stateless Bean");
+ Hashtable<?,?> ctxProperties = null;
+ Ejb3Deployment deployment = new MockEjb3Deployment(new MockDeploymentUnit(), null);
+ JBossSessionBeanMetaData beanMetaData = MetaDataHelper.getMetadataFromBeanImplClass(beanClass);
+
+ // add an override
+
+ ResourceInjectionTargetMetaData injectionTarget = new ResourceInjectionTargetMetaData();
+ injectionTarget.setInjectionTargetClass(OverrideWebServiceContextInjectedBean.class.getName());
+ injectionTarget.setInjectionTargetName("wsContext");
+
+ Set<ResourceInjectionTargetMetaData> injectionTargets = new HashSet<ResourceInjectionTargetMetaData>();
+ injectionTargets.add(injectionTarget);
+
+ ResourceEnvironmentReferenceMetaData resEnvRef = new ResourceEnvironmentReferenceMetaData();
+ resEnvRef.setName("wsContext");
+ resEnvRef.setType(WebServiceContext.class.getName());
+ resEnvRef.setInjectionTargets(injectionTargets);
+
+ if(beanMetaData.getJndiEnvironmentRefsGroup() == null)
+ beanMetaData.setJndiEnvironmentRefsGroup(new JBossEnvironmentRefsGroupMetaData());
+ if(beanMetaData.getResourceEnvironmentReferences() == null)
+ ((JBossEnvironmentRefsGroupMetaData) beanMetaData.getJndiEnvironmentRefsGroup()).setResourceEnvironmentReferences(new ResourceEnvironmentReferencesMetaData());
+ beanMetaData.getResourceEnvironmentReferences().add(resEnvRef);
+ //
+
+ StatelessContainer container = new StatelessContainer(cl, beanClassname, ejbName, domain, ctxProperties, deployment, beanMetaData);
+
+ // TODO: wickedness
+ container.instantiated();
+
+ container.processMetadata();
+
+ // Register the Container in ObjectStore (MC)
+ String containerName = container.getName();
+ Ejb3RegistrarLocator.locateRegistrar().bind(containerName, container);
+
+ InitialContext ctx = new InitialContext();
+ System.out.println("ctx = " + ctx);
+ //System.out.println(" " + container.getInitialContext().list("MyStatelessBean").next());
+ WebServiceContextInjected bean = (WebServiceContextInjected) ctx.lookup("OverrideWebServiceContextInjectedBean/local");
+
+ bean.checkWebServiceContext();
+
+ getBootstrap().getKernel().getController().uninstall(containerName);
+ }
+}
More information about the jboss-cvs-commits
mailing list