From a375d7aa36b6afd6710c9716efb162590ca0be7c Mon Sep 17 00:00:00 2001 From: Aslak Knutsen Date: Wed, 9 Nov 2011 11:19:39 +0100 Subject: [PATCH] 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 PRE_ ``` --- extensions/pom.xml | 1 + extensions/systemproperties/README.md | 33 ++++ extensions/systemproperties/pom.xml | 165 ++++++++++++++++++ .../systemproperties/SystemProperties.java | 31 ++++ .../client/ArchiveAppender.java | 45 +++++ .../client/ArchiveProcessor.java | 109 ++++++++++++ .../client/SystemPropertiesExtension.java | 39 +++++ .../container/SystemPropertiesLoader.java | 79 +++++++++ .../SystemPropertiesRemoteExtension.java | 36 ++++ ...boss.arquillian.core.spi.LoadableExtension | 1 + .../ArchiveAppenderTestCase.java | 114 ++++++++++++ .../SystemPropertiesIntegrationTestBase.java | 53 ++++++ .../SystemPropertiesJMXTestCase.java | 39 +++++ .../SystemPropertiesServletTestCase.java | 40 +++++ .../src/test/resources/arquillian.xml | 15 ++ 15 files changed, 800 insertions(+) create mode 100644 extensions/systemproperties/README.md create mode 100644 extensions/systemproperties/pom.xml create mode 100644 extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemProperties.java create mode 100644 extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/ArchiveAppender.java create mode 100644 extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/ArchiveProcessor.java create mode 100644 extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/SystemPropertiesExtension.java create mode 100644 extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/container/SystemPropertiesLoader.java create mode 100644 extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/container/SystemPropertiesRemoteExtension.java create mode 100644 extensions/systemproperties/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension create mode 100644 extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/ArchiveAppenderTestCase.java create mode 100644 extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesIntegrationTestBase.java create mode 100644 extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesJMXTestCase.java create mode 100644 extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesServletTestCase.java create mode 100644 extensions/systemproperties/src/test/resources/arquillian.xml diff --git a/extensions/pom.xml b/extensions/pom.xml index 1a81312..7f874db 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -22,6 +22,7 @@ autodiscover lifecycle deploymentscenario + systemproperties weld-servlet diff --git a/extensions/systemproperties/README.md b/extensions/systemproperties/README.md new file mode 100644 index 0000000..41bedde --- /dev/null +++ b/extensions/systemproperties/README.md @@ -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 + + + + + ARQT_ + + +``` + + +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 diff --git a/extensions/systemproperties/pom.xml b/extensions/systemproperties/pom.xml new file mode 100644 index 0000000..223d71f --- /dev/null +++ b/extensions/systemproperties/pom.xml @@ -0,0 +1,165 @@ + + + + 4.0.0 + + + arquillian-showcase-parent + org.jboss.arquillian.showcase + 1.0.0-SNAPSHOT + ../../parent/pom.xml + + + arquillian-showcase-extension-systemproperties + jar + Arquillian Showcase Extension: SystemProperties + Examples that demonstrate how to add support for transfering SystemProperties from client to contianer via extension + + + + org.jboss.arquillian.core + arquillian-core-spi + + + org.jboss.arquillian.test + arquillian-test-spi + + + org.jboss.arquillian.container + arquillian-container-test-spi + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-api-maven + + + org.mockito + mockito-all + 1.8.3 + provided + + + + junit + junit + test + + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.jboss.arquillian.core + arquillian-core-impl-base + test + + + org.jboss.arquillian.core + arquillian-core-impl-base + ${version.arquillian_core} + tests + test + + + org.jboss.arquillian.test + arquillian-test-impl-base + test + + + org.jboss.arquillian.test + arquillian-test-impl-base + ${version.arquillian_core} + tests + test + + + + + org.jboss.arquillian.protocol + arquillian-protocol-servlet + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + test + + + + + + + arq-jbossas-managed-7 + + true + + + + org.jboss.as + jboss-as-arquillian-container-managed + + + + + + maven-surefire-plugin + + + ${version.jbossas_7} + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack + process-test-classes + + unpack + + + + + org.jboss.as + jboss-as-dist + ${version.jbossas_7} + zip + false + ${project.build.directory}/ + + + + + + + + + + + arq-jbossas-remote-7 + + + org.jboss.as + jboss-as-arquillian-container-remote + + + + + + + + maven-surefire-plugin + + + ALL_OK + + + + + + diff --git a/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemProperties.java b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemProperties.java new file mode 100644 index 0000000..6ab49f5 --- /dev/null +++ b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemProperties.java @@ -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 Aslak Knutsen + * @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"; +} diff --git a/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/ArchiveAppender.java b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/ArchiveAppender.java new file mode 100644 index 0000000..e091a5e --- /dev/null +++ b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/ArchiveAppender.java @@ -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 Aslak Knutsen + * @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); + } + +} diff --git a/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/ArchiveProcessor.java b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/ArchiveProcessor.java new file mode 100644 index 0000000..5ed4611 --- /dev/null +++ b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/ArchiveProcessor.java @@ -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 Aslak Knutsen + * @version $Revision: $ + */ +public class ArchiveProcessor implements ApplicationArchiveProcessor +{ + @Inject + private Instance 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 getConfiguration() + { + for(ExtensionDef def : descriptor.get().getExtensions()) + { + if(SystemProperties.EXTENSION_NAME.equalsIgnoreCase(def.getExtensionName())) + { + return def.getExtensionProperties(); + } + } + return new HashMap(); + } + + private Properties filterSystemProperties(String prefix) + { + Properties filteredProps = new Properties(); + Properties sysProps = System.getProperties(); + for (Map.Entry 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); + } + } +} diff --git a/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/SystemPropertiesExtension.java b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/SystemPropertiesExtension.java new file mode 100644 index 0000000..e09f1e7 --- /dev/null +++ b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/client/SystemPropertiesExtension.java @@ -0,0 +1,39 @@ +/* + * 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.client.deployment.ApplicationArchiveProcessor; +import org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender; +import org.jboss.arquillian.core.spi.LoadableExtension; + +/** + * SystemPropertiesExtension + * + * @author Aslak Knutsen + * @version $Revision: $ + */ +public class SystemPropertiesExtension implements LoadableExtension +{ + @Override + public void register(ExtensionBuilder builder) + { + builder.service(ApplicationArchiveProcessor.class, ArchiveProcessor.class) + .service(AuxiliaryArchiveAppender.class, ArchiveAppender.class); + } + +} diff --git a/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/container/SystemPropertiesLoader.java b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/container/SystemPropertiesLoader.java new file mode 100644 index 0000000..597cd9b --- /dev/null +++ b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/container/SystemPropertiesLoader.java @@ -0,0 +1,79 @@ +/* + * 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.container; + +import java.io.InputStream; +import java.util.Map; +import java.util.Properties; + +import org.jboss.arquillian.core.api.annotation.Observes; +import org.jboss.arquillian.showcase.extension.systemproperties.SystemProperties; +import org.jboss.arquillian.test.spi.event.suite.AfterSuite; +import org.jboss.arquillian.test.spi.event.suite.BeforeSuite; + +/** + * SystemPropertiesLoader + * + * @author Aslak Knutsen + * @version $Revision: $ + */ +public class SystemPropertiesLoader +{ + public void setProperties(@Observes BeforeSuite event) + { + Properties props = load(SystemProperties.FILE_NAME); + if(props != null) + { + for(Map.Entry entry : props.entrySet()) + { + System.setProperty(entry.getKey().toString(), entry.getValue().toString()); + } + } + } + + public void unsetProperties(@Observes AfterSuite event) + { + Properties props = load(SystemProperties.FILE_NAME); + if(props != null) + { + for(Map.Entry entry : props.entrySet()) + { + System.clearProperty(entry.getKey().toString()); + } + } + } + + private Properties load(String resource) + { + InputStream propsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource); + if(propsStream != null) + { + Properties props = new Properties(); + try + { + props.load(propsStream); + return props; + } + catch (Exception e) + { + throw new RuntimeException("Could not load properties", e); + } + } + return null; + } +} diff --git a/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/container/SystemPropertiesRemoteExtension.java b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/container/SystemPropertiesRemoteExtension.java new file mode 100644 index 0000000..e97b2d0 --- /dev/null +++ b/extensions/systemproperties/src/main/java/org/jboss/arquillian/showcase/extension/systemproperties/container/SystemPropertiesRemoteExtension.java @@ -0,0 +1,36 @@ +/* + * 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.container; + +import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension; + +/** + * SystemPropertiesRemoteExtension + * + * @author Aslak Knutsen + * @version $Revision: $ + */ +public class SystemPropertiesRemoteExtension implements RemoteLoadableExtension +{ + @Override + public void register(ExtensionBuilder builder) + { + builder.observer(SystemPropertiesLoader.class); + } + +} diff --git a/extensions/systemproperties/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension b/extensions/systemproperties/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension new file mode 100644 index 0000000..0e2fae5 --- /dev/null +++ b/extensions/systemproperties/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension @@ -0,0 +1 @@ +org.jboss.arquillian.showcase.extension.systemproperties.client.SystemPropertiesExtension \ No newline at end of file diff --git a/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/ArchiveAppenderTestCase.java b/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/ArchiveAppenderTestCase.java new file mode 100644 index 0000000..14d22e0 --- /dev/null +++ b/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/ArchiveAppenderTestCase.java @@ -0,0 +1,114 @@ +/* + * 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; + +import java.util.Properties; + +import org.jboss.arquillian.config.descriptor.api.ArquillianDescriptor; +import org.jboss.arquillian.core.api.Injector; +import org.jboss.arquillian.core.api.Instance; +import org.jboss.arquillian.core.api.annotation.ApplicationScoped; +import org.jboss.arquillian.core.api.annotation.Inject; +import org.jboss.arquillian.showcase.extension.systemproperties.client.ArchiveProcessor; +import org.jboss.arquillian.test.spi.TestClass; +import org.jboss.arquillian.test.test.AbstractTestTestBase; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.descriptor.api.Descriptors; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * ArchiveAppenderTestCase + * + * @author Aslak Knutsen + * @version $Revision: $ + */ +public class ArchiveAppenderTestCase extends AbstractTestTestBase +{ + private static final String PREFIX = "ARQ_TEST"; + private static final String PROPERTY_1 = "PROP1"; + private static final String PROPERTY_2 = "PROP2"; + + private static final String VALUE_1 = "VALUE1"; + private static final String VALUE_2 = "VALUE1"; + + @Inject + private Instance injector; + + private ArquillianDescriptor desc; + private Archive archive; + + @Before + public void setup() throws Exception { + desc = Descriptors.create(ArquillianDescriptor.class); + archive = ShrinkWrap.create(JavaArchive.class); + + bind(ApplicationScoped.class, ArquillianDescriptor.class, desc); + } + + @Test + public void shouldNotAddResourceFileIfNoPrefixSet() throws Exception + { + ArchiveProcessor processor = new ArchiveProcessor(); + injector.get().inject(processor); + processor.process(archive, new TestClass(getClass())); + + Assert.assertFalse( + "Verify file was not stored", + archive.contains(SystemProperties.FILE_NAME)); + } + + @Test + public void shouldAddResourceFileWhenPrefixSet() throws Exception + { + desc.extension(SystemProperties.EXTENSION_NAME) + .property(SystemProperties.CONFIG_PREFIX, PREFIX); + + try + { + System.setProperty(PREFIX + PROPERTY_1, VALUE_1); + System.setProperty(PREFIX + PROPERTY_2, VALUE_2); + + ArchiveProcessor processor = new ArchiveProcessor(); + injector.get().inject(processor); + processor.process(archive, new TestClass(getClass())); + + Assert.assertTrue( + "Verify file was stored", + archive.contains(SystemProperties.FILE_NAME)); + + Properties stored = new Properties(); + stored.load(archive.get(SystemProperties.FILE_NAME).getAsset().openStream()); + + Assert.assertEquals( + "Verify correct number of properties were filtered", + 2, stored.size()); + + Assert.assertEquals("Verify correct value stored", stored.getProperty(PROPERTY_1), VALUE_1); + Assert.assertEquals("Verify correct value stored", stored.getProperty(PROPERTY_2), VALUE_2); + } + finally + { + System.clearProperty(PREFIX + PROPERTY_1); + System.clearProperty(PREFIX + PROPERTY_2); + } + } +} diff --git a/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesIntegrationTestBase.java b/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesIntegrationTestBase.java new file mode 100644 index 0000000..0145cee --- /dev/null +++ b/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesIntegrationTestBase.java @@ -0,0 +1,53 @@ +/* + * 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; + +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * SystemPropertiesIntegrationTestCase + * + * @author Aslak Knutsen + * @version $Revision: $ + */ +@RunWith(Arquillian.class) +public abstract class SystemPropertiesIntegrationTestBase +{ + public static String propertyName = "ARQ_TEST"; + public static String propertyValue = "ALL_OK"; + + public static WebArchive createDeployment() + { + return ShrinkWrap.create(WebArchive.class) + .addClass(SystemPropertiesIntegrationTestBase.class); + } + + @Test + public void shouldBeAbleToReadProperty() + { + Object property = System.getProperty(propertyName); + + Assert.assertNotNull("Verify property was found", property); + Assert.assertEquals("Verify property was set correctly", property.toString(), propertyValue); + } +} diff --git a/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesJMXTestCase.java b/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesJMXTestCase.java new file mode 100644 index 0000000..06197b5 --- /dev/null +++ b/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesJMXTestCase.java @@ -0,0 +1,39 @@ +/* + * 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; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.runner.RunWith; + +/** + * SystemPropertiesIntegrationTestCase + * + * @author Aslak Knutsen + * @version $Revision: $ + */ +@RunWith(Arquillian.class) +public class SystemPropertiesJMXTestCase extends SystemPropertiesIntegrationTestBase +{ + @Deployment + public static WebArchive deploy() + { + return createDeployment(); + } +} diff --git a/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesServletTestCase.java b/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesServletTestCase.java new file mode 100644 index 0000000..ff5b20f --- /dev/null +++ b/extensions/systemproperties/src/test/java/org/jboss/arquillian/showcase/extension/systemproperties/SystemPropertiesServletTestCase.java @@ -0,0 +1,40 @@ +/* + * 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; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.OverProtocol; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.runner.RunWith; + +/** + * SystemPropertiesIntegrationTestCase + * + * @author Aslak Knutsen + * @version $Revision: $ + */ +@RunWith(Arquillian.class) +public class SystemPropertiesServletTestCase extends SystemPropertiesIntegrationTestBase +{ + @Deployment @OverProtocol("Servlet 3.0") + public static WebArchive deploy() + { + return createDeployment(); + } +} diff --git a/extensions/systemproperties/src/test/resources/arquillian.xml b/extensions/systemproperties/src/test/resources/arquillian.xml new file mode 100644 index 0000000..d424e6c --- /dev/null +++ b/extensions/systemproperties/src/test/resources/arquillian.xml @@ -0,0 +1,15 @@ + + + + + + target/jboss-as-${jboss.version:7.0.2.Final} + + + + + ARQT_ + +