This repository has been archived by the owner on Nov 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
444 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.project | ||
.classpath | ||
.settings | ||
.idea | ||
*.iml | ||
target | ||
|
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,15 @@ | ||
## GateIn Extension for Arquillian | ||
|
||
### What is this? | ||
|
||
The **GateIn Extension** is an implementation of the [Arquillian Extension for Portals](https://github.com/arquillian/arquillian-extension-portal) | ||
that enables the GateIn Portlet Container to be used on different containers for testing portlets. | ||
|
||
Using **GateIn Extension** in your project for testing requires that a version of pc-embed be added as a dependency so that this extension can access it. | ||
For that, we need the following dependency: | ||
|
||
<dependency> | ||
<groupId>org.gatein.pc</groupId> | ||
<artifactId>pc-embed</artifactId> | ||
<version>2.4.0.Final</version> | ||
</dependency> |
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,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<!-- Parent --> | ||
<parent> | ||
<groupId>org.jboss.portletbridge.testing.gatein</groupId> | ||
<artifactId>gatein-testing-parent</artifactId> | ||
<version>1.0.0.Final-SNAPSHOT</version> | ||
</parent> | ||
|
||
<!-- Model Version --> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<!-- Artifact Configuration --> | ||
<artifactId>gatein-arquillian-extension</artifactId> | ||
<packaging>jar</packaging> | ||
<name>GateIn Arquillian Extension</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.shrinkwrap.resolver</groupId> | ||
<artifactId>shrinkwrap-resolver-api-maven</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.arquillian.extension</groupId> | ||
<artifactId>arquillian-portal-spi</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.arquillian.container</groupId> | ||
<artifactId>arquillian-container-test-spi</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.shrinkwrap.descriptors</groupId> | ||
<artifactId>shrinkwrap-descriptors-impl-javaee</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
47 changes: 47 additions & 0 deletions
47
...in-arquillian-extension/src/main/java/org/gatein/pc/arquillian/GateInPortalExtension.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,47 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2012, 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.gatein.pc.arquillian; | ||
|
||
import org.gatein.pc.arquillian.deployment.GateInDeploymentEnricher; | ||
import org.gatein.pc.arquillian.enricher.resource.GateInURLProvider; | ||
import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; | ||
import org.jboss.arquillian.core.spi.LoadableExtension; | ||
import org.jboss.arquillian.portal.spi.enricher.resource.PortalURLProvider; | ||
|
||
/** | ||
* @author <a href="mailto:ken@kenfinnigan.me">Ken Finnigan</a> | ||
*/ | ||
public class GateInPortalExtension implements LoadableExtension { | ||
|
||
/** | ||
* @see org.jboss.arquillian.core.spi.LoadableExtension#register(org.jboss.arquillian.core.spi.LoadableExtension.ExtensionBuilder) | ||
*/ | ||
@Override | ||
public void register(ExtensionBuilder builder) { | ||
// Deployment enrichment | ||
builder.service(ApplicationArchiveProcessor.class, GateInDeploymentEnricher.class); | ||
|
||
// Portal URL enrichment | ||
builder.service(PortalURLProvider.class, GateInURLProvider.class); | ||
} | ||
|
||
} |
123 changes: 123 additions & 0 deletions
123
...extension/src/main/java/org/gatein/pc/arquillian/deployment/GateInDeploymentEnricher.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,123 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2012, 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. | ||
* | ||
* Licensed 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.gatein.pc.arquillian.deployment; | ||
|
||
import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; | ||
import org.jboss.arquillian.portal.api.PortalTest; | ||
import org.jboss.arquillian.test.spi.TestClass; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ArchivePath; | ||
import org.jboss.shrinkwrap.api.ArchivePaths; | ||
import org.jboss.shrinkwrap.api.Node; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.shrinkwrap.descriptor.api.Descriptors; | ||
import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor; | ||
import org.jboss.shrinkwrap.descriptor.api.webfragment30.WebFragmentDescriptor; | ||
import org.jboss.shrinkwrap.resolver.api.maven.Maven; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* @author <a href="http://community.jboss.org/people/kenfinni">Ken Finnigan</a> | ||
*/ | ||
public class GateInDeploymentEnricher implements ApplicationArchiveProcessor { | ||
|
||
public static final String EMBED_PATH = "embed"; | ||
|
||
private static final String EMBED_SERVLET_NAME = "EmbedServlet"; | ||
private static final String EMBED_SERVLET_CLASS = "org.gatein.pc.embed.EmbedServlet"; | ||
|
||
private static final ArchivePath WEB_XML_PATH = ArchivePaths.create("WEB-INF/web.xml"); | ||
|
||
/** | ||
* @see org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor#process(org.jboss.shrinkwrap.api.Archive, org.jboss.arquillian.test.spi.TestClass) | ||
*/ | ||
@Override | ||
public void process(Archive<?> applicationArchive, TestClass testClass) { | ||
if (testClass.isAnnotationPresent(PortalTest.class)) { | ||
if (applicationArchive instanceof WebArchive) { | ||
WebArchive webArchive = (WebArchive) applicationArchive; | ||
|
||
// Add GateIn PC Embed and Deps to WEB-INF/lib | ||
File[] files = Maven.resolver() | ||
.loadPomFromFile("pom.xml") | ||
.resolve("org.gatein.pc:pc-embed") | ||
.withTransitivity() | ||
.as(File.class); | ||
webArchive.addAsLibraries(files); | ||
|
||
files = Maven.resolver() | ||
.loadPomFromFile("pom.xml") | ||
.resolve("javax.portlet:portlet-api") | ||
.withoutTransitivity() | ||
.as(File.class); | ||
webArchive.addAsLibraries(files); | ||
|
||
// Add EmbedServlet to web.xml | ||
addEmbed(webArchive); | ||
} | ||
} | ||
} | ||
|
||
private void addEmbed(WebArchive webArchive) { | ||
Node webXmlNode = webArchive.get(WEB_XML_PATH); | ||
if (null != webXmlNode) { | ||
WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(webXmlNode.getAsset().openStream()); | ||
|
||
// SHRINKWRAP-187, too eager on not allowing overrides, delete it first | ||
webArchive.delete(WEB_XML_PATH); | ||
|
||
webArchive.setWebXML(new StringAsset(addEmbedToDescriptor(webXml).exportAsString())); | ||
} else { | ||
// No web.xml present so add Embed Servlet to web fragment | ||
WebFragmentDescriptor webFrag = Descriptors.create(WebFragmentDescriptor.class); | ||
JavaArchive jar = ShrinkWrap.create(JavaArchive.class); | ||
jar.addAsManifestResource(new StringAsset(addEmbedToFragment(webFrag).exportAsString()), "web-fragment.xml"); | ||
webArchive.addAsLibrary(jar); | ||
} | ||
} | ||
|
||
private WebFragmentDescriptor addEmbedToFragment(WebFragmentDescriptor webFragment) { | ||
webFragment.createServlet() | ||
.servletName(EMBED_SERVLET_NAME) | ||
.servletClass(EMBED_SERVLET_CLASS) | ||
.loadOnStartup(0) | ||
.up() | ||
.createServletMapping() | ||
.servletName(EMBED_SERVLET_NAME) | ||
.urlPattern("/" + EMBED_PATH + "/*") | ||
.up(); | ||
return webFragment; | ||
} | ||
|
||
private WebAppDescriptor addEmbedToDescriptor(WebAppDescriptor webXml) { | ||
webXml.createServlet() | ||
.servletName(EMBED_SERVLET_NAME) | ||
.servletClass(EMBED_SERVLET_CLASS) | ||
.loadOnStartup(0) | ||
.up() | ||
.createServletMapping() | ||
.servletName(EMBED_SERVLET_NAME) | ||
.urlPattern("/" + EMBED_PATH + "/*") | ||
.up(); | ||
return webXml; | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...extension/src/main/java/org/gatein/pc/arquillian/enricher/resource/GateInURLProvider.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,54 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2012, 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.gatein.pc.arquillian.enricher.resource; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
|
||
import org.gatein.pc.arquillian.deployment.GateInDeploymentEnricher; | ||
import org.jboss.arquillian.portal.spi.enricher.resource.PortalURLProvider; | ||
|
||
/** | ||
* @author <a href="mailto:ken@kenfinnigan.me">Ken Finnigan</a> | ||
*/ | ||
public class GateInURLProvider implements PortalURLProvider { | ||
|
||
/** | ||
* @throws URISyntaxException | ||
* @throws MalformedURLException | ||
* @see org.jboss.arquillian.portal.spi.enricher.resource.PortalURLProvider#customizeURL(java.net.URL, String...) | ||
*/ | ||
@Override | ||
public URL customizeURL(URL archiveURL, String... portlets) throws Exception { | ||
StringBuilder portletPath = new StringBuilder(150); | ||
for (String portlet : portlets) { | ||
if (null != portlet && portlet.length() > 0) { | ||
portletPath.append("/"); | ||
portletPath.append(portlet); | ||
} | ||
} | ||
URL url = archiveURL.toURI().resolve(GateInDeploymentEnricher.EMBED_PATH + portletPath.toString()).toURL(); | ||
return url; | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...sion/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
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 @@ | ||
org.gatein.pc.arquillian.GateInPortalExtension |
Oops, something went wrong.