forked from aslakknutsen/arquillian-showcase
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Extension Showcase SystemProperties
The Extension will copy all System Preoperties from Client env to Container env based on defined prefix. The Client prefix is removed when in container. Client->Container PRE_my_prop -> my_prop ```xml <extension qualifier="systemproperties"> <property name="prefix">PRE_</property> </extension> ```
- Loading branch information
1 parent
81f95cb
commit a375d7a
Showing
15 changed files
with
800 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
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,33 @@ | ||
AutoDiscover System Properties Extension | ||
======================================================== | ||
|
||
Extension showing how you can filter and copy client side System Properties over to the Container side via a File in the Deployment. | ||
|
||
|
||
```xml | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://jboss.org/schema/arquillian" | ||
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> | ||
|
||
<extension qualifier="systemproperties"> | ||
<property name="prefix">ARQT_</property> | ||
</extension> | ||
</arquillian> | ||
``` | ||
|
||
|
||
Following SPI's are used: | ||
|
||
Client side | ||
------------ | ||
|
||
* org.jboss.arquillian.core.spi.LoadableExtension | ||
* org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor | ||
* org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender | ||
|
||
Container side | ||
--------------- | ||
|
||
* org.jboss.arquillian.container.test.spi.RemoteLoadableExtension | ||
* Core @Observers |
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,165 @@ | ||
<?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"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>arquillian-showcase-parent</artifactId> | ||
<groupId>org.jboss.arquillian.showcase</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../../parent/pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>arquillian-showcase-extension-systemproperties</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Arquillian Showcase Extension: SystemProperties</name> | ||
<description>Examples that demonstrate how to add support for transfering SystemProperties from client to contianer via extension</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.arquillian.core</groupId> | ||
<artifactId>arquillian-core-spi</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.arquillian.test</groupId> | ||
<artifactId>arquillian-test-spi</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.arquillian.container</groupId> | ||
<artifactId>arquillian-container-test-spi</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.shrinkwrap.resolver</groupId> | ||
<artifactId>shrinkwrap-resolver-api-maven</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<version>1.8.3</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.arquillian.junit</groupId> | ||
<artifactId>arquillian-junit-container</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.arquillian.core</groupId> | ||
<artifactId>arquillian-core-impl-base</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.arquillian.core</groupId> | ||
<artifactId>arquillian-core-impl-base</artifactId> | ||
<version>${version.arquillian_core}</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.arquillian.test</groupId> | ||
<artifactId>arquillian-test-impl-base</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.arquillian.test</groupId> | ||
<artifactId>arquillian-test-impl-base</artifactId> | ||
<version>${version.arquillian_core}</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Add support for Servlet Protocol --> | ||
<dependency> | ||
<groupId>org.jboss.arquillian.protocol</groupId> | ||
<artifactId>arquillian-protocol-servlet</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.shrinkwrap.resolver</groupId> | ||
<artifactId>shrinkwrap-resolver-impl-maven</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>arq-jbossas-managed-7</id> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.as</groupId> | ||
<artifactId>jboss-as-arquillian-container-managed</artifactId> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<systemProperties> | ||
<jboss.version>${version.jbossas_7}</jboss.version> | ||
</systemProperties> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>unpack</id> | ||
<phase>process-test-classes</phase> | ||
<goals> | ||
<goal>unpack</goal> | ||
</goals> | ||
<configuration> | ||
<artifactItems> | ||
<artifactItem> | ||
<groupId>org.jboss.as</groupId> | ||
<artifactId>jboss-as-dist</artifactId> | ||
<version>${version.jbossas_7}</version> | ||
<type>zip</type> | ||
<overWrite>false</overWrite> | ||
<outputDirectory>${project.build.directory}/</outputDirectory> | ||
</artifactItem> | ||
</artifactItems> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
<profile> | ||
<id>arq-jbossas-remote-7</id> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.as</groupId> | ||
<artifactId>jboss-as-arquillian-container-remote</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</profile> | ||
</profiles> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<ARQT_ARQ_TEST>ALL_OK</ARQT_ARQ_TEST> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
31 changes: 31 additions & 0 deletions
31
.../main/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemProperties.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,31 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors | ||
* as indicated by the @authors tag. All rights reserved. | ||
* See the copyright.txt 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.jboss.arquillian.showcase.extension.systemproperties; | ||
|
||
/** | ||
* SystemProperties | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
public class SystemProperties | ||
{ | ||
public static final String EXTENSION_NAME = "systemproperties"; | ||
public static final String CONFIG_PREFIX = "prefix"; | ||
public static final String FILE_NAME = "arq_system.properties"; | ||
} |
45 changes: 45 additions & 0 deletions
45
...java/org/jboss/arquillian/showcase/extension/systemproperties/client/ArchiveAppender.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,45 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors | ||
* as indicated by the @authors tag. All rights reserved. | ||
* See the copyright.txt 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.jboss.arquillian.showcase.extension.systemproperties.client; | ||
|
||
import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension; | ||
import org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender; | ||
import org.jboss.arquillian.showcase.extension.systemproperties.SystemProperties; | ||
import org.jboss.arquillian.showcase.extension.systemproperties.container.SystemPropertiesRemoteExtension; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
|
||
/** | ||
* ArchiveAppender | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
public class ArchiveAppender implements AuxiliaryArchiveAppender | ||
{ | ||
@Override | ||
public Archive<?> createAuxiliaryArchive() | ||
{ | ||
return ShrinkWrap.create(JavaArchive.class, "arquillian-systemproperties.jar") | ||
.addPackage(SystemPropertiesRemoteExtension.class.getPackage()) | ||
.addClass(SystemProperties.class) | ||
.addAsServiceProvider(RemoteLoadableExtension.class, SystemPropertiesRemoteExtension.class); | ||
} | ||
|
||
} |
109 changes: 109 additions & 0 deletions
109
...ava/org/jboss/arquillian/showcase/extension/systemproperties/client/ArchiveProcessor.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,109 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors | ||
* as indicated by the @authors tag. All rights reserved. | ||
* See the copyright.txt 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.jboss.arquillian.showcase.extension.systemproperties.client; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import org.jboss.arquillian.config.descriptor.api.ArquillianDescriptor; | ||
import org.jboss.arquillian.config.descriptor.api.ExtensionDef; | ||
import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; | ||
import org.jboss.arquillian.core.api.Instance; | ||
import org.jboss.arquillian.core.api.annotation.Inject; | ||
import org.jboss.arquillian.showcase.extension.systemproperties.SystemProperties; | ||
import org.jboss.arquillian.test.spi.TestClass; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.container.ResourceContainer; | ||
|
||
/** | ||
* ArchiveProcessor | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
public class ArchiveProcessor implements ApplicationArchiveProcessor | ||
{ | ||
@Inject | ||
private Instance<ArquillianDescriptor> descriptor; | ||
|
||
@Override | ||
public void process(Archive<?> applicationArchive, TestClass testClass) | ||
{ | ||
String prefix = getPrefix(); | ||
if(prefix != null) | ||
{ | ||
if(applicationArchive instanceof ResourceContainer) | ||
{ | ||
ResourceContainer<?> container = (ResourceContainer<?>)applicationArchive; | ||
container.addAsResource( | ||
new StringAsset( | ||
toString( | ||
filterSystemProperties(prefix))), SystemProperties.FILE_NAME); | ||
} | ||
} | ||
} | ||
|
||
private String getPrefix() | ||
{ | ||
return getConfiguration().get(SystemProperties.CONFIG_PREFIX); | ||
} | ||
|
||
private Map<String, String> getConfiguration() | ||
{ | ||
for(ExtensionDef def : descriptor.get().getExtensions()) | ||
{ | ||
if(SystemProperties.EXTENSION_NAME.equalsIgnoreCase(def.getExtensionName())) | ||
{ | ||
return def.getExtensionProperties(); | ||
} | ||
} | ||
return new HashMap<String, String>(); | ||
} | ||
|
||
private Properties filterSystemProperties(String prefix) | ||
{ | ||
Properties filteredProps = new Properties(); | ||
Properties sysProps = System.getProperties(); | ||
for (Map.Entry<Object, Object> entry: sysProps.entrySet()) | ||
{ | ||
if(entry.getKey().toString().startsWith(prefix)) | ||
{ | ||
String newKey = entry.getKey().toString().replaceFirst(prefix, ""); | ||
filteredProps.put(newKey, entry.getValue()); | ||
} | ||
} | ||
return filteredProps; | ||
} | ||
|
||
private String toString(Properties props) | ||
{ | ||
try | ||
{ | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
props.store(out, "Arquillian SystemProperties Extension"); | ||
return out.toString(); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new RuntimeException("Could not store properties", e); | ||
} | ||
} | ||
} |
Oops, something went wrong.