This repository has been archived by the owner on Apr 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic test for kernel life cycle
- Loading branch information
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
portal/common/src/test/java/org.gatein.portal.common.kernel/KernelLifeCycleTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
portal/common/src/test/java/org.gatein.portal.common.kernel/ServletImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |