Skip to content

Commit

Permalink
[WELD-892] use case test; TODO fix and enable.
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj committed Nov 16, 2011
1 parent 3ea48e0 commit 9414f8f
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 3 deletions.
@@ -0,0 +1,52 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., 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.weld.environment.servlet.test.lifecycle;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.weld.environment.servlet.test.util.Deployments;
import org.junit.Test;

/**
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
*/
public class HSCycleTestBase {
protected static WebArchive getBaseDeployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class);
war.addPackage(HSCycleTestBase.class.getPackage());
String webXml = Deployments.extendDefaultWebXml(Deployments.toListener(HSListener.class.getName()));
war.setWebXML(new StringAsset(webXml));
war.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}

@Test
public void testNA() throws Exception {
}

public void XtestCycle(Pinger pinger) throws Exception {
pinger.ping();
}
}
@@ -0,0 +1,59 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., 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.weld.environment.servlet.test.lifecycle;

import javax.enterprise.inject.spi.BeanManager;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
*/
public class HSListener implements HttpSessionListener {

private BeanManager getBeanManager() {
Context context = null;
try {
context = new InitialContext();
return (BeanManager) context.lookup("java:comp/env/BeanManager");
} catch (NamingException e) {
throw new RuntimeException(e);
} finally {
if (context != null)
try {
context.close();
} catch (NamingException ignored) {
}
}
}

public void sessionCreated(HttpSessionEvent se) {
getBeanManager().fireEvent(se.getSession());
}

public void sessionDestroyed(HttpSessionEvent se) {
}
}
@@ -0,0 +1,39 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., 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.weld.environment.servlet.test.lifecycle;

import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.servlet.http.HttpSession;

/**
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
*/
public class Observer {
@Inject
Pinger pinger;

public void newSession(@Observes HttpSession s) {
pinger.ping();
}
}
@@ -0,0 +1,35 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., 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.weld.environment.servlet.test.lifecycle;

import javax.enterprise.context.SessionScoped;
import java.io.Serializable;

/**
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
*/
@SessionScoped
public class Pinger implements Serializable {
public void ping() {
}
}
Expand Up @@ -6,7 +6,9 @@
import org.jboss.shrinkwrap.api.spec.WebArchive;

public class Deployments {
public static final String DEFAULT_WEB_XML_PREFIX = "<web-app> <listener><listener-class>org.jboss.weld.environment.servlet.Listener</listener-class></listener> <resource-env-ref><resource-env-ref-name>BeanManager</resource-env-ref-name><resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type></resource-env-ref> ";
public static final String DEFAULT_WEB_XML_START = "<web-app>";
public static final String DEFAULT_WEB_XML_BODY = toListener("org.jboss.weld.environment.servlet.Listener") + "<resource-env-ref><resource-env-ref-name>BeanManager</resource-env-ref-name><resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type></resource-env-ref> ";
public static final String DEFAULT_WEB_XML_PREFIX = DEFAULT_WEB_XML_START + DEFAULT_WEB_XML_BODY;
public static final String DEFAULT_WEB_XML_SUFFIX = "</web-app>";

public static final Asset DEFAULT_WEB_XML = new ByteArrayAsset((DEFAULT_WEB_XML_PREFIX + DEFAULT_WEB_XML_SUFFIX).getBytes());
Expand All @@ -31,11 +33,15 @@ public static WebArchive baseDeployment(Asset webXml) {
return baseDeployment(new BeansXml(), webXml);
}

public static String toListener(String listenerClassName) {
return "<listener><listener-class>" + listenerClassName + "</listener-class></listener>";
}

/**
* Inserts the extension into the end of the default web.xml (just before closing web-app)
*
* @param extension
* @return
* @param extension the extension
* @return extended web xml
*/
public static String extendDefaultWebXml(String extension) {
return DEFAULT_WEB_XML_PREFIX + extension + DEFAULT_WEB_XML_SUFFIX;
Expand Down
@@ -0,0 +1,43 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., 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.weld.environment.servlet.test.lifecycle;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.weld.environment.servlet.test.util.TomcatDeployments;
import org.junit.runner.RunWith;

/**
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
*/
@RunWith(Arquillian.class)
public class HSCycleTest extends HSCycleTestBase {
@Deployment
public static WebArchive getDeployment() {
WebArchive war = getBaseDeployment();
war.add(TomcatDeployments.CONTEXT_XML, "META-INF/context.xml");
System.out.println(war.toString(true));
return war;
}
}

0 comments on commit 9414f8f

Please sign in to comment.