Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
Add basic test for kernel life cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Jun 25, 2013
1 parent 1f6e072 commit 8786276
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
17 changes: 17 additions & 0 deletions portal/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@
<version>${juzu.version}</version>
</dependency>

<!-- -->
<dependency>
<groupId>org.juzu</groupId>
<artifactId>juzu-bom-arquillian</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.juzu</groupId>
<artifactId>juzu-bom-arquillian-tomcat7</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-impl-javaee</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2012 eXo Platform SAS.
*
* 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.gatein.portal.common.kernel;

import java.net.HttpURLConnection;
import java.net.URL;

import org.exoplatform.container.PortalContainer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptors;
import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;

/**
* @author Julien Viet
*/
@RunWith(Arquillian.class)
public class KernelLifeCycleTestCase {

@Deployment
public static WebArchive getDeployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class);
WebAppDescriptor desc = Descriptors.create(WebAppDescriptor.class).
displayName("portal").
createFilter().filterName("KernelLifeCycle").filterClass(KernelLifeCycle.class.getName()).up().
createFilterMapping().filterName("KernelLifeCycle").servletName("Servlet").up().
createServlet().servletName("Servlet").servletClass(ServletImpl.class.getName()).up().
createServletMapping().urlPattern("/").servletName("Servlet").up();
war.setWebXML(new StringAsset(desc.exportAsString()));
return war;
}

/** . */
public static PortalContainer container;

@ArquillianResource
URL deploymentURL;

@Test
@RunAsClient
public void testContainer() throws Exception {
container = null;
HttpURLConnection conn = (HttpURLConnection) deploymentURL.openConnection();
conn.connect();
assertEquals(200, conn.getResponseCode());
assertNotNull(container);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2012 eXo Platform SAS.
*
* 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.gatein.portal.common.kernel;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.exoplatform.container.PortalContainer;

/**
* @author Julien Viet
*/
public class ServletImpl extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
KernelLifeCycleTestCase.container = KernelLifeCycle.getCurrentContainer();
resp.setStatus(200);
resp.setContentType("text/plain");
resp.getWriter().append("done").close();
}
}

0 comments on commit 8786276

Please sign in to comment.