provisionr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject [02/21] PROVISIONR-20. Change groupId from com.axemblr.provisionr to org.apache.provisionr
Date Mon, 01 Apr 2013 08:52:25 GMT
http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/CloudStackActivityLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/CloudStackActivityLiveTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/CloudStackActivityLiveTest.java
new file mode 100644
index 0000000..2cd33d2
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/CloudStackActivityLiveTest.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.activities;
+
+import org.apache.provisionr.api.provider.Provider;
+import org.apache.provisionr.cloudstack.CloudStackProvisionr;
+import org.apache.provisionr.cloudstack.ProviderOptions;
+import org.apache.provisionr.cloudstack.core.SecurityGroups;
+import org.apache.provisionr.test.Generics;
+import org.apache.provisionr.test.ProvisionrLiveTestSupport;
+import com.google.common.base.Throwables;
+import java.util.Set;
+import java.util.UUID;
+import org.jclouds.cloudstack.CloudStackAsyncClient;
+import org.jclouds.cloudstack.CloudStackClient;
+import org.jclouds.cloudstack.domain.Network;
+import org.jclouds.cloudstack.domain.SecurityGroup;
+import org.jclouds.cloudstack.domain.SshKeyPair;
+import org.jclouds.cloudstack.domain.VirtualMachine;
+import org.jclouds.rest.RestContext;
+import org.junit.After;
+import org.junit.Before;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Helper base class for CloudStack Live tests.
+ */
+public class CloudStackActivityLiveTest<T extends CloudStackActivity> extends ProvisionrLiveTestSupport {
+
+    public CloudStackActivityLiveTest() {
+        super(CloudStackProvisionr.ID);
+    }
+
+    private static final Logger LOG = LoggerFactory.getLogger(CloudStackActivityLiveTest.class);
+
+    protected final String BUSINESS_KEY = "j-" + UUID.randomUUID().toString();
+    /**
+     * Cloud provider credentials collected from system properties.
+     */
+    protected Provider provider;
+    /**
+     * Instance of CloudStackActivity being tested. Automatically created from the
+     * generic type class argument.
+     */
+    protected CloudStackActivity activity;
+
+    protected RestContext<CloudStackClient, CloudStackAsyncClient> context;
+
+    public CloudStackActivityLiveTest(String provisionrId) {
+        super(provisionrId);
+    }
+
+    protected T createCloudStackActivitiInstance() {
+        try {
+            return getCloudStackActivityClass().newInstance();
+        } catch (Exception e) {
+            throw Throwables.propagate(e);
+        }
+    }
+
+    protected Class<T> getCloudStackActivityClass() {
+        return Generics.getTypeParameter(getClass(), CloudStackActivity.class);
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        provider = collectProviderCredentialsFromSystemProperties()
+            .option(ProviderOptions.ZONE_ID, getProviderProperty(ProviderOptions.ZONE_ID))
+            .option(ProviderOptions.NETWORK_OFFERING_ID, getProviderProperty(ProviderOptions.NETWORK_OFFERING_ID))
+            .createProvider();
+        LOG.info("Using provider {}", provider);
+
+        activity = createCloudStackActivitiInstance();
+        context = activity.newCloudStackClient(provider);
+    }
+
+
+    @After
+    public void tearDown() throws Exception {
+        context.close();
+    }
+
+    protected void logSecurityGroupDetails() {
+        Set<SecurityGroup> securityGroups = SecurityGroups.getAll(context.getApi());
+        LOG.info("Security Group count is {}", securityGroups.size());
+        for (SecurityGroup securityGroup : securityGroups) {
+            LOG.info("\tSecurity Group {}", securityGroup.getName());
+        }
+    }
+
+    protected void logKeyPairs() {
+        Set<SshKeyPair> keys = context.getApi().getSSHKeyPairClient().listSSHKeyPairs();
+        LOG.info("Access Key count is {}", keys.size());
+        for (SshKeyPair keyPair : keys) {
+            LOG.info("\tKey {}", keyPair.getName());
+        }
+    }
+
+    protected void logVirtualMachines() {
+        Set<VirtualMachine> vms = context.getApi().getVirtualMachineClient().listVirtualMachines();
+        LOG.info("Virtual machines count is {}", vms.size());
+        for (VirtualMachine vm : vms) {
+            LOG.info("\tVirtual machine {}", vm.toString());
+        }
+    }
+
+    protected void logNetworks() {
+        Set<Network> networks = context.getApi().getNetworkClient().listNetworks();
+        LOG.info("Networks count is {}", networks.size());
+        for (Network network : networks) {
+            LOG.info("{}\n", network.toString());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/DeleteKeyPairLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/DeleteKeyPairLiveTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/DeleteKeyPairLiveTest.java
new file mode 100644
index 0000000..70604f0
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/DeleteKeyPairLiveTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.activities;
+
+import org.activiti.engine.delegate.DelegateExecution;
+import org.apache.provisionr.api.access.AdminAccess;
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.cloudstack.core.KeyPairs;
+import org.apache.provisionr.core.CoreProcessVariables;
+import static org.fest.assertions.api.Assertions.assertThat;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DeleteKeyPairLiveTest extends CloudStackActivityLiveTest<DeleteKeyPair> {
+
+    private final String KEYPAIR_NAME = KeyPairs.formatNameFromBusinessKey(BUSINESS_KEY);
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        logKeyPairs();
+        context.getApi().getSSHKeyPairClient().registerSSHKeyPair(KEYPAIR_NAME, getResourceAsString("keys/test.pub"));
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+        context.getApi().getSSHKeyPairClient().deleteSSHKeyPair(KEYPAIR_NAME);
+        logKeyPairs();
+        super.tearDown();
+    }
+
+    @Test
+    public void testDeleteKeyPair() throws Exception {
+        final AdminAccess adminAccess = AdminAccess.builder()
+            .username("admin")
+            .publicKey(getResourceAsString("keys/test.pub"))
+            .privateKey(getResourceAsString("keys/test"))
+            .createAdminAccess();
+
+        DelegateExecution execution = mock(DelegateExecution.class);
+        Pool pool = mock(Pool.class);
+
+        when(pool.getAdminAccess()).thenReturn(adminAccess);
+        when(pool.getProvider()).thenReturn(provider);
+
+        when(execution.getProcessBusinessKey()).thenReturn(BUSINESS_KEY);
+        when(execution.getVariable(CoreProcessVariables.POOL)).thenReturn(pool);
+
+        activity.execute(execution);
+        assertKeyNotFound(KEYPAIR_NAME);
+        /* the second call should just do nothing */
+        activity.execute(execution);
+    }
+
+    private void assertKeyNotFound(String keyName) {
+        assertThat(context.getApi().getSSHKeyPairClient().getSSHKeyPair(keyName)).isNull();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/DeleteSecurityGroupLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/DeleteSecurityGroupLiveTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/DeleteSecurityGroupLiveTest.java
new file mode 100644
index 0000000..7662abe
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/DeleteSecurityGroupLiveTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.activities;
+
+import java.util.NoSuchElementException;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.apache.provisionr.api.network.Network;
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.cloudstack.core.SecurityGroups;
+import org.apache.provisionr.core.CoreProcessVariables;
+import org.junit.After;
+import static org.junit.Assert.fail;
+import org.junit.Before;
+import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DeleteSecurityGroupLiveTest extends CloudStackActivityLiveTest<DeleteSecurityGroup> {
+
+    private final Logger LOG = LoggerFactory.getLogger(DeleteSecurityGroupLiveTest.class);
+    private final String SECURITY_GROUP_NAME = SecurityGroups.formatNameFromBusinessKey(BUSINESS_KEY);
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        logSecurityGroupDetails();
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+        logSecurityGroupDetails();
+        super.tearDown();
+    }
+
+    @Test
+    public void testDeleteSecurityGroup() throws Exception {
+        DelegateExecution execution = mock(DelegateExecution.class);
+        final Network network = Network.builder().createNetwork();
+
+        Pool pool = mock(Pool.class);
+
+        when(pool.getProvider()).thenReturn(provider);
+        when(pool.getNetwork()).thenReturn(network);
+
+        when(execution.getVariable(CoreProcessVariables.POOL)).thenReturn(pool);
+        when(execution.getProcessBusinessKey()).thenReturn(BUSINESS_KEY);
+
+        SecurityGroups.createSecurityGroup(context.getApi(), SECURITY_GROUP_NAME);
+
+        activity.execute(execution);
+
+        try {
+            SecurityGroups.getByName(context.getApi(), SECURITY_GROUP_NAME);
+            fail("Does not throw Exception as it should have");
+        } catch (NoSuchElementException e) {
+            LOG.info("Exception thrown. Test passed.");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureKeyPairExistsLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureKeyPairExistsLiveTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureKeyPairExistsLiveTest.java
new file mode 100644
index 0000000..12fbb67
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureKeyPairExistsLiveTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.activities;
+
+import java.io.IOException;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.apache.provisionr.api.access.AdminAccess;
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.cloudstack.core.KeyPairs;
+import org.apache.provisionr.core.CoreProcessVariables;
+import static org.fest.assertions.api.Assertions.assertThat;
+import org.jclouds.cloudstack.domain.SshKeyPair;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class EnsureKeyPairExistsLiveTest extends CloudStackActivityLiveTest<EnsureKeyPairExists> {
+
+    public static final String TEST_KEY_FINGERPRINT = "15:0b:a4:43:dd:58:19:9e:84:ca:db:31:a8:6b:b6:c3";
+    private final String KEYPAIR_NAME = KeyPairs.formatNameFromBusinessKey(BUSINESS_KEY);
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        logKeyPairs();
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+        context.getApi().getSSHKeyPairClient().deleteSSHKeyPair(KEYPAIR_NAME);
+        logKeyPairs();
+        super.tearDown();
+    }
+
+    @Test
+    public void testEnsureKeyPairExists() throws Exception {
+        final AdminAccess adminAccess = AdminAccess.builder()
+            .username("admin")
+            .publicKey(getResourceAsString("keys/test.pub"))
+            .privateKey(getResourceAsString("keys/test"))
+            .createAdminAccess();
+
+        DelegateExecution execution = mock(DelegateExecution.class);
+        Pool pool = mock(Pool.class);
+
+        when(pool.getProvider()).thenReturn(provider);
+        when(pool.getAdminAccess()).thenReturn(adminAccess);
+
+        when(execution.getProcessBusinessKey()).thenReturn(BUSINESS_KEY);
+        when(execution.getVariable(CoreProcessVariables.POOL)).thenReturn(pool);
+
+        activity.execute(execution);
+        assertKeyPairWasImportedAsExpected();
+
+        /* the second call should just re-import the key */
+        activity.execute(execution);
+        assertKeyPairWasImportedAsExpected();
+    }
+
+    private void assertKeyPairWasImportedAsExpected() throws IOException {
+        SshKeyPair pair = context.getApi().getSSHKeyPairClient().getSSHKeyPair(KEYPAIR_NAME);
+        assertThat(pair.getFingerprint()).isEqualTo(TEST_KEY_FINGERPRINT);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureNetworkExistsLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureNetworkExistsLiveTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureNetworkExistsLiveTest.java
new file mode 100644
index 0000000..b9329e0
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureNetworkExistsLiveTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.activities;
+
+import java.util.NoSuchElementException;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.cloudstack.NetworkOptions;
+import org.apache.provisionr.cloudstack.ProcessVariables;
+import org.apache.provisionr.cloudstack.core.Networks;
+import org.apache.provisionr.core.CoreProcessVariables;
+import org.apache.provisionr.test.ProcessVariablesCollector;
+import static org.fest.assertions.api.Assertions.assertThat;
+import org.jclouds.cloudstack.CloudStackClient;
+import org.jclouds.cloudstack.domain.Network;
+import org.jclouds.cloudstack.features.NetworkClient;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EnsureNetworkExistsLiveTest extends CloudStackActivityLiveTest<EnsureNetworkExists> {
+
+    private final static Logger LOG = LoggerFactory.getLogger(EnsureNetworkExistsLiveTest.class);
+    private final String networkName = Networks.formatNameFromBusinessKey(BUSINESS_KEY);
+    private DelegateExecution execution;
+    private Pool pool;
+    private ProcessVariablesCollector collector;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        logNetworks();
+        initMocks();
+    }
+
+    private void initMocks() {
+        execution = mock(DelegateExecution.class);
+        pool = mock(Pool.class);
+
+        when(pool.getProvider()).thenReturn(provider);
+        when(execution.getVariable(CoreProcessVariables.POOL)).thenReturn(pool);
+        when(execution.getProcessBusinessKey()).thenReturn(BUSINESS_KEY);
+        when(pool.getNetwork()).thenReturn(org.apache.provisionr.api.network.Network.builder()
+            .type("provided")
+            .createNetwork());
+        collector = new ProcessVariablesCollector();
+        collector.install(execution);
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+        deleteNetworkIfExists();
+        logNetworks();
+        super.tearDown();
+    }
+
+    private void deleteNetworkIfExists() {
+        try {
+            Network network = Networks.getByName(context.getApi(), networkName);
+            // this will not wait for the network to be deleted. operation will fail if network is used.
+            context.getApi().getNetworkClient().deleteNetwork(network.getId());
+        } catch (NoSuchElementException e) {
+            LOG.info("Network {} does not exist", networkName);
+        }
+    }
+
+    @Test
+    public void testEnsureNetworkExistsByCreatingTheNetwork() throws Exception {
+        activity.execute(execution);
+
+        assertThat(collector.getVariable(ProcessVariables.NETWORK_ID)).isNotNull();
+
+        Network network = Networks.getByName(context.getApi(), networkName);
+        assertThat(network.getName()).isEqualToIgnoringCase(networkName);
+        String networkId = network.getId();
+        // second run should not create a new network
+        activity.execute(execution);
+
+        when(execution.getProcessBusinessKey()).thenReturn(BUSINESS_KEY);
+        network = Networks.getByName(context.getApi(), networkName);
+        assertThat(network.getId()).isEqualTo(networkId);
+    }
+
+    @Test
+    public void testEnsureNetworkExistsWithProvidedExistingNetwork() throws Exception {
+        final String networkId = "network-id-0123";
+        final CloudStackClient mockClient = mock(CloudStackClient.class);
+        final NetworkClient mockNetworkClient = mock(NetworkClient.class);
+        final Network mockNetwork = mock(Network.class);
+        final org.apache.provisionr.api.network.Network network = org.apache.provisionr.api.network.Network.builder()
+            .option(NetworkOptions.EXISTING_NETWORK_ID, networkId).createNetwork();
+
+        execution.setVariable(ProcessVariables.NETWORK_ID, networkId);
+
+        when(pool.getNetwork()).thenReturn(network);
+        when(mockClient.getNetworkClient()).thenReturn(mockNetworkClient);
+        when(mockNetworkClient.getNetwork(networkId)).thenReturn(mockNetwork);
+        when(mockNetwork.getId()).thenReturn(networkId);
+
+        activity.execute(mockClient, pool, execution);
+        assertThat(collector.getVariable(ProcessVariables.NETWORK_ID)).isEqualTo(networkId);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureSecurityGroupExistsLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureSecurityGroupExistsLiveTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureSecurityGroupExistsLiveTest.java
new file mode 100644
index 0000000..569b84a
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/EnsureSecurityGroupExistsLiveTest.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.activities;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import java.util.NoSuchElementException;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.apache.provisionr.api.network.Network;
+import org.apache.provisionr.api.network.Rule;
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.cloudstack.core.ConvertIngressRuleToRule;
+import org.apache.provisionr.cloudstack.core.SecurityGroups;
+import org.apache.provisionr.core.CoreProcessVariables;
+import static org.fest.assertions.api.Assertions.assertThat;
+import org.jclouds.cloudstack.domain.SecurityGroup;
+import static org.jclouds.cloudstack.options.ListSecurityGroupsOptions.Builder.named;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EnsureSecurityGroupExistsLiveTest extends CloudStackActivityLiveTest<EnsureSecurityGroupExists> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(EnsureSecurityGroupExistsLiveTest.class);
+
+    private final String SECURITY_GROUP_NAME = "network-" + BUSINESS_KEY;
+
+    private final ImmutableSet<Rule> ingressRules = ImmutableSet.of(
+        Rule.builder().anySource().icmp().createRule(),
+        Rule.builder().anySource().tcp().port(22).createRule(),
+        Rule.builder().anySource().udp().port(53).createRule());
+
+    private final Network network = Network.builder().ingress(ingressRules).createNetwork();
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        logSecurityGroupDetails();
+        deleteSecurityGroupIfExists();
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+        deleteSecurityGroupIfExists();
+        logSecurityGroupDetails();
+        super.tearDown();
+    }
+
+    private void deleteSecurityGroupIfExists() {
+        try {
+            SecurityGroup securityGroup = Iterables.getOnlyElement(context.getApi()
+                .getSecurityGroupClient()
+                .listSecurityGroups(named(SECURITY_GROUP_NAME)));
+
+            context.getApi().getSecurityGroupClient().deleteSecurityGroup(securityGroup.getId());
+        } catch (NoSuchElementException e) {
+            LOG.info("Security group {} was not found", SECURITY_GROUP_NAME);
+        } catch (Exception e2) {
+            LOG.error("Exception deleting security group {}", e2);
+        }
+    }
+
+    @Test
+    public void testCreateSecurityGroup() throws Exception {
+        DelegateExecution execution = mock(DelegateExecution.class);
+        Pool pool = mock(Pool.class);
+
+        when(pool.getProvider()).thenReturn(provider);
+        when(pool.getNetwork()).thenReturn(network);
+
+        when(execution.getVariable(CoreProcessVariables.POOL)).thenReturn(pool);
+        when(execution.getProcessBusinessKey()).thenReturn(BUSINESS_KEY);
+
+        activity.execute(execution);
+        assertSecurityGroupExistsWithRules(SecurityGroups.getByName(
+            context.getApi(), SECURITY_GROUP_NAME), ingressRules);
+    }
+
+    @Test
+    public void testCreateSecurityGroupWithExistingSecurityGroup() throws Exception {
+        DelegateExecution execution = mock(DelegateExecution.class);
+        Pool pool = mock(Pool.class);
+
+        when(pool.getProvider()).thenReturn(provider);
+
+        when(execution.getVariable(CoreProcessVariables.POOL)).thenReturn(pool);
+        when(execution.getProcessBusinessKey()).thenReturn(BUSINESS_KEY);
+
+        // create the SecurityGroup with an extra Network Rule, then call the activity
+        when(pool.getNetwork()).thenReturn(network.toBuilder().addRules(
+            Rule.builder().anySource().tcp().port(80).createRule()).createNetwork());
+
+        activity.execute(execution);
+        // call the process again with the old network rules and check the rules
+        when(pool.getNetwork()).thenReturn(network);
+
+        activity.execute(execution);
+
+        assertSecurityGroupExistsWithRules(SecurityGroups.getByName(context.getApi(),
+            SECURITY_GROUP_NAME), ingressRules);
+    }
+
+    private void assertSecurityGroupExistsWithRules(SecurityGroup securityGroup, ImmutableSet<Rule> ingressRules) {
+        assertThat(ingressRules).containsAll(Iterables.transform(securityGroup.getIngressRules(),
+            ConvertIngressRuleToRule.FUNCTION));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/RunInstancesLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/RunInstancesLiveTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/RunInstancesLiveTest.java
new file mode 100644
index 0000000..514a038
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/activities/RunInstancesLiveTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.activities;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.apache.provisionr.api.access.AdminAccess;
+import org.apache.provisionr.api.hardware.Hardware;
+import org.apache.provisionr.api.network.Network;
+import org.apache.provisionr.api.network.Rule;
+import org.apache.provisionr.api.pool.Pool;
+import org.apache.provisionr.api.software.Software;
+import org.apache.provisionr.cloudstack.ProviderOptions;
+import org.apache.provisionr.cloudstack.core.VirtualMachines;
+import org.apache.provisionr.core.CoreProcessVariables;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RunInstancesLiveTest extends CloudStackActivityLiveTest<RunInstances> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RunInstancesLiveTest.class);
+
+    private DelegateExecution execution;
+    private Pool pool;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        logSecurityGroupDetails();
+        logKeyPairs();
+        logVirtualMachines();
+        execution = mock(DelegateExecution.class);
+        pool = mock(Pool.class);
+
+        final AdminAccess adminAccess = AdminAccess.builder()
+            .username("admin")
+            .publicKey(getResourceAsString("keys/test.pub"))
+            .privateKey(getResourceAsString("keys/test"))
+            .createAdminAccess();
+
+        final Network network = Network.builder().addRules(
+            Rule.builder().anySource().tcp().port(22).createRule()).createNetwork();
+
+        final Hardware hardware = Hardware.builder().type(getProviderProperty("serviceOffering")).createHardware();
+        final Software software = Software.builder()
+            .imageId(getProviderProperty("templateId"))
+            .createSoftware();
+
+        Map<String, String> options = ImmutableMap.of(ProviderOptions.ZONE_ID,
+            getProviderProperty("zoneId"));
+
+        when(pool.getProvider()).thenReturn(provider);
+        when(pool.getAdminAccess()).thenReturn(adminAccess);
+        when(pool.getNetwork()).thenReturn(network);
+        when(pool.getHardware()).thenReturn(hardware);
+        when(pool.getSoftware()).thenReturn(software);
+        when(pool.getOptions()).thenReturn(options);
+
+        when(execution.getProcessBusinessKey()).thenReturn(BUSINESS_KEY);
+        when(execution.getVariable(CoreProcessVariables.POOL)).thenReturn(pool);
+
+        new EnsureSecurityGroupExists().execute(execution);
+        new EnsureKeyPairExists().execute(execution);
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+        new DeleteKeyPair().execute(execution);
+        new DeleteSecurityGroup().execute(execution);
+
+        logSecurityGroupDetails();
+        logKeyPairs();
+        logVirtualMachines();
+        VirtualMachines.destroyAllVirtualMachineByName(context.getApi(), BUSINESS_KEY);
+        logVirtualMachines();
+        super.tearDown();
+    }
+
+    @Test
+    @Ignore
+    public void test() throws Exception {
+        activity.execute(execution);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/CommandTestSupport.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/CommandTestSupport.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/CommandTestSupport.java
new file mode 100644
index 0000000..d8d44d2
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/CommandTestSupport.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.commands;
+
+import org.apache.provisionr.api.provider.Provider;
+import org.apache.provisionr.cloudstack.DefaultProviderConfig;
+import com.google.common.base.Optional;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import org.jclouds.cloudstack.CloudStackClient;
+import org.junit.Before;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Support class for CloudStack Karaf Command tests.
+ */
+public class CommandTestSupport {
+
+    protected DefaultProviderConfig defaultProviderConfig;
+    protected ByteArrayOutputStream byteArrayOutputStream;
+    protected PrintStream out;
+    protected CloudStackClient client;
+
+    @Before
+    public void setUp() throws Exception {
+        defaultProviderConfig = mock(DefaultProviderConfig.class);
+        byteArrayOutputStream = new ByteArrayOutputStream();
+        out = new PrintStream(byteArrayOutputStream);
+        client = mock(CloudStackClient.class);
+        when(defaultProviderConfig.createProvider()).thenReturn(Optional.of(mock(Provider.class)));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/OfferingsCommandTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/OfferingsCommandTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/OfferingsCommandTest.java
new file mode 100644
index 0000000..bec3041
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/OfferingsCommandTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.commands;
+
+import com.google.common.collect.Sets;
+import java.util.Set;
+import static org.fest.assertions.api.Assertions.assertThat;
+import org.jclouds.cloudstack.domain.DiskOffering;
+import org.jclouds.cloudstack.domain.NetworkOffering;
+import org.jclouds.cloudstack.domain.ServiceOffering;
+import org.jclouds.cloudstack.features.OfferingClient;
+import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class OfferingsCommandTest extends CommandTestSupport {
+
+    final Set<ServiceOffering> serviceOfferings = Sets.newHashSet(ServiceOffering.builder()
+        .id("service-1")
+        .name("service-one")
+        .build());
+
+    final Set<DiskOffering> diskOfferings = Sets.newHashSet(DiskOffering.builder()
+        .id("disk-1")
+        .name("disk-one")
+        .build());
+
+    final Set<NetworkOffering> networkOfferings = Sets.newHashSet(NetworkOffering.builder()
+        .id("network-1")
+        .name("network-one")
+        .build());
+
+    @Test
+    public void testOfferingCommandWithNoOptionSpecified() throws Exception {
+        final OfferingsCommand offeringsCommand = new OfferingsCommand(defaultProviderConfig);
+        offeringsCommand.doExecuteWithContext(client, out);
+        out.close();
+        assertThat(byteArrayOutputStream.toString()).contains("No option specified");
+    }
+
+    @Test
+    public void testOfferingCommandsPrintsServiceOfferings() throws Exception {
+        final OfferingClient offeringClient = mock(OfferingClient.class);
+        when(client.getOfferingClient()).thenReturn(offeringClient);
+        when(offeringClient.listServiceOfferings()).thenReturn(serviceOfferings);
+
+        final OfferingsCommand offeringsCommand = new OfferingsCommand(defaultProviderConfig);
+        offeringsCommand.setServiceOffering(true);
+        offeringsCommand.doExecuteWithContext(client, out);
+        out.close();
+
+        assertThat(byteArrayOutputStream.toString())
+            .contains("service-1")
+            .contains("service-one")
+            .doesNotContain("No option");
+    }
+
+    @Test
+    public void testOfferingsCommandWithAllOptions() throws Exception {
+        final OfferingClient offeringClient = mock(OfferingClient.class);
+
+        when(client.getOfferingClient()).thenReturn(offeringClient);
+        when(offeringClient.listServiceOfferings()).thenReturn(serviceOfferings);
+        when(offeringClient.listDiskOfferings()).thenReturn(diskOfferings);
+        when(offeringClient.listNetworkOfferings()).thenReturn(networkOfferings);
+
+        final OfferingsCommand offeringsCommand = new OfferingsCommand(defaultProviderConfig);
+
+        offeringsCommand.setServiceOffering(true);
+        offeringsCommand.setDiskOffering(true);
+        offeringsCommand.setNetworkOffering(true);
+
+        offeringsCommand.doExecuteWithContext(client, out);
+
+        out.close();
+
+        assertThat(byteArrayOutputStream.toString())
+            .contains("service-1")
+            .contains("service-one")
+            .contains("disk-1")
+            .contains("network-1")
+            .doesNotContain("No option");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/TemplatesCommandTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/TemplatesCommandTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/TemplatesCommandTest.java
new file mode 100644
index 0000000..9375853
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/TemplatesCommandTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.commands;
+
+import com.google.common.collect.Sets;
+import java.util.Set;
+import static org.fest.assertions.api.Assertions.assertThat;
+import org.jclouds.cloudstack.domain.Template;
+import org.jclouds.cloudstack.features.TemplateClient;
+import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class TemplatesCommandTest extends CommandTestSupport {
+
+    final Set<Template> templates = Sets.newHashSet(Template.builder()
+        .id("template-1")
+        .name("template-one")
+        .build());
+
+    @Test
+    public void testTemplatesCommandPrintsTheTemplates() throws Exception {
+        final TemplatesCommand templatesCommand = new TemplatesCommand(defaultProviderConfig);
+        final TemplateClient templateClient = mock(TemplateClient.class);
+
+        when(client.getTemplateClient()).thenReturn(templateClient);
+        when(templateClient.listTemplates()).thenReturn(templates);
+
+        templatesCommand.doExecuteWithContext(client, out);
+        out.close();
+        assertThat(byteArrayOutputStream.toString()).contains("template-1").contains("template-one");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/ZonesCommandTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/ZonesCommandTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/ZonesCommandTest.java
new file mode 100644
index 0000000..b422dd6
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/commands/ZonesCommandTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.commands;
+
+import com.google.common.collect.Sets;
+import java.util.Set;
+import static org.fest.assertions.api.Assertions.assertThat;
+import org.jclouds.cloudstack.domain.Zone;
+import org.jclouds.cloudstack.features.ZoneClient;
+import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ZonesCommandTest extends CommandTestSupport {
+
+    private final Set<Zone> zones = Sets.newHashSet(Zone.builder()
+        .id("zone-1")
+        .name("zone-one")
+        .securityGroupsEnabled(false)
+        .build());
+
+    @Test
+    public void testZonesCommandPrintsZones() throws Exception {
+        final ZonesCommand zonesCommand = new ZonesCommand(defaultProviderConfig);
+        final ZoneClient zoneClient = mock(ZoneClient.class);
+        when(client.getZoneClient()).thenReturn(zoneClient);
+        when(zoneClient.listZones()).thenReturn(zones);
+
+        zonesCommand.doExecuteWithContext(client, out);
+        out.close();
+
+        final String result = byteArrayOutputStream.toString();
+
+        assertThat(result)
+            .contains("zone-1")
+            .contains("zone-one")
+            .contains("false");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/core/ConversionsTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/core/ConversionsTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/core/ConversionsTest.java
new file mode 100644
index 0000000..8c08a9b
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/core/ConversionsTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.core;
+
+import org.apache.provisionr.api.network.Protocol;
+import org.apache.provisionr.api.network.Rule;
+import static org.fest.assertions.api.Assertions.assertThat;
+import org.jclouds.cloudstack.domain.IngressRule;
+import org.junit.Test;
+
+public class ConversionsTest {
+
+    @Test
+    public void testConvertIngressRuleToRuleICMP() throws Exception {
+        final IngressRule ingressRule = IngressRule.builder()
+            .id("rule1")
+            .protocol("icmp")
+            .ICMPCode(SecurityGroups.DEFAULT_ICMP_CODE)
+            .ICMPType(SecurityGroups.DEFAULT_ICMP_TYPE)
+            .CIDR("10.0.0.0/24")
+            .build();
+
+        Rule rule = ConvertIngressRuleToRule.FUNCTION.apply(ingressRule);
+        assertThat(rule.getProtocol()).isEqualTo(Protocol.ICMP);
+        assertThat(rule.getCidr()).isEqualTo(ingressRule.getCIDR());
+    }
+
+    @Test
+    public void testConvertSinglePortRangeIngressRuleToRule() throws Exception {
+        final IngressRule ingressRule = IngressRule.builder()
+            .id("rule1")
+            .protocol("tcp")
+            .startPort(22)
+            .endPort(22)
+            .CIDR("0.0.0.1/24")
+            .build();
+
+        Rule rule = ConvertIngressRuleToRule.FUNCTION.apply(ingressRule);
+        assertThat(rule.getProtocol()).isEqualTo(Protocol.TCP);
+        assertThat(rule.getCidr()).isEqualTo(ingressRule.getCIDR());
+        assertThat(rule.getPorts().lowerEndpoint()).isEqualTo(ingressRule.getStartPort());
+        assertThat(rule.getPorts().upperEndpoint()).isEqualTo(ingressRule.getEndPort());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/core/SecurityGroupsTest.java
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/core/SecurityGroupsTest.java b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/core/SecurityGroupsTest.java
new file mode 100644
index 0000000..cbc911b
--- /dev/null
+++ b/providers/cloudstack/src/test/java/org/apache/provisionr/cloudstack/core/SecurityGroupsTest.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.cloudstack.core;
+
+import static org.fest.assertions.api.Assertions.assertThat;
+import org.junit.Test;
+
+public class SecurityGroupsTest {
+
+    @Test
+    public void testSecurityNameFromBusinessProcessKey() throws Exception {
+        assertThat(SecurityGroups.formatNameFromBusinessKey("test")).isEqualTo("network-test");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/providers/cloudstack/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/providers/cloudstack/src/test/resources/logback.xml b/providers/cloudstack/src/test/resources/logback.xml
index 379a09b..8018ecc 100644
--- a/providers/cloudstack/src/test/resources/logback.xml
+++ b/providers/cloudstack/src/test/resources/logback.xml
@@ -58,7 +58,7 @@
         <level value="debug"/>
     </root>
 
-    <logger name="com.axemblr">
+    <logger name="org.apache.provisionr">
         <level value="info"/>
         <appender-ref ref="STDOUT"/>
     </logger>

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/scripts/deploy.sh
----------------------------------------------------------------------
diff --git a/scripts/deploy.sh b/scripts/deploy.sh
index 30bfffb..4d0f4d5 100755
--- a/scripts/deploy.sh
+++ b/scripts/deploy.sh
@@ -6,7 +6,7 @@ if [ $# -ne 2 ]; then
 	exit 0
 fi
 rm -rf $1/provisionr
-archive=$(basename "../karaf/assembly/target/com.axemblr.provisionr-$2-SNAPSHOT.tar.gz") 
+archive=$(basename "../karaf/assembly/target/org.apache.provisionr-$2-SNAPSHOT.tar.gz") 
 cp karaf/assembly/target/$archive $1 && cd $1
 tar xvzf $archive && rm $archive
 mv "${archive%.*.*}" provisionr
@@ -14,5 +14,5 @@ cd provisionr/
 for w in "secretKey" "accessKey"
 do
         key=$(grep -E -m 1 -o "<.*amazon.*$w>(.*)</.*amazon.*$w>" ~/.m2/settings.xml | sed -e 's,.*<*.>\([^<]*\)</.*>.*,\1,g')
-        sed -i -e "s/$w = .*$/$w = $key/g" ~/provisionr/system/com/axemblr/provisionr/provisionr-amazon/0.4.0-SNAPSHOT/provisionr-amazon-0.4.0-SNAPSHOT-defaults.cfg
+        sed -i -e "s/$w = .*$/$w = $key/g" ~/provisionr/system/org/apache/provisionr/provisionr-amazon/0.4.0-SNAPSHOT/provisionr-amazon-0.4.0-SNAPSHOT-defaults.cfg
 done
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/pom.xml
----------------------------------------------------------------------
diff --git a/test-support/pom.xml b/test-support/pom.xml
index 4ca5340..837b196 100644
--- a/test-support/pom.xml
+++ b/test-support/pom.xml
@@ -18,18 +18,18 @@
 <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/xsd/maven-4.0.0.xsd">
     <parent>
         <artifactId>provisionr-parent</artifactId>
-        <groupId>com.axemblr.provisionr</groupId>
+        <groupId>org.apache.provisionr</groupId>
         <version>0.4.0-SNAPSHOT</version>
         <relativePath>../parent/pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
-    <name>Axemblr Provisionr :: Test Support</name>
+    <name>Apache Provisionr :: Test Support</name>
     <artifactId>provisionr-test-support</artifactId>
     <packaging>bundle</packaging>
 
     <properties>
-        <osgi.export>com.axemblr.provisionr.test*</osgi.export>
+        <osgi.export>org.apache.provisionr.test*</osgi.export>
         <osgi.import>
             org.mockito*;resolution:=optional,
             *
@@ -42,7 +42,7 @@
             <artifactId>org.osgi.core</artifactId>
         </dependency>
         <dependency>
-            <groupId>com.axemblr.provisionr</groupId>
+            <groupId>org.apache.provisionr</groupId>
             <artifactId>provisionr-api</artifactId>
         </dependency>
         <dependency>
@@ -168,7 +168,7 @@
                 </configuration>
             </plugin>
             <!--
-             features:addurl mvn:com.axemblr.provisionr/provisionr-features/0.0.1-SNAPSHOT/xml/features
+             features:addurl mvn:org.apache.provisionr/provisionr-features/0.0.1-SNAPSHOT/xml/features
              features:install <feature-name>
              -->
             <plugin>

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/java/com/axemblr/provisionr/test/Generics.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/com/axemblr/provisionr/test/Generics.java b/test-support/src/main/java/com/axemblr/provisionr/test/Generics.java
deleted file mode 100644
index ce44e97..0000000
--- a/test-support/src/main/java/com/axemblr/provisionr/test/Generics.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * 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 com.axemblr.provisionr.test;
-
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Helper methods for class type parameters.
- *
- * @see <a href="https://github.com/codahale/dropwizard/blob/master/dropwizard-core/src/main/java/com/yammer/dropwizard/util/Generics.java">Generics in Codahale Dropwizard</a>
- * @see <a href="http://gafter.blogspot.com/2006/12/super-type-tokens.html">Super Type Tokens</a>
- */
-public class Generics {
-    private Generics() { /* singleton */ }
-
-    /**
-     * Finds the type parameter for the given class which is assignable to the bound class.
-     *
-     * @param klass a parameterized class
-     * @param bound the type bound
-     * @param <T>   the type bound
-     * @return the class's type parameter
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> Class<T> getTypeParameter(Class<?> klass, Class<? super T> bound) {
-        Type t = checkNotNull(klass);
-        while (t instanceof Class<?>) {
-            t = ((Class<?>) t).getGenericSuperclass();
-        }
-        /* This is not guaranteed to work for all cases with convoluted piping
-         * of type parameters: but it can at least resolve straight-forward
-         * extension with single type parameter (as per [Issue-89]).
-         * And when it fails to do that, will indicate with specific exception.
-         */
-        if (t instanceof ParameterizedType) {
-            // should typically have one of type parameters (first one) that matches:
-            for (Type param : ((ParameterizedType) t).getActualTypeArguments()) {
-                if (param instanceof Class<?>) {
-                    final Class<?> cls = (Class<?>) param;
-                    if (bound.isAssignableFrom(cls)) {
-                        return (Class<T>) cls;
-                    }
-                }
-            }
-        }
-        throw new IllegalStateException("Cannot figure out type parameterization for " + klass.getName());
-    }
-
-    /**
-     * Finds the type parameter for the given class.
-     *
-     * @param klass a parameterized class
-     * @return the class's type parameter
-     */
-    public static Class<?> getTypeParameter(Class<?> klass) {
-        return getTypeParameter(klass, Object.class);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/java/com/axemblr/provisionr/test/KarafTests.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/com/axemblr/provisionr/test/KarafTests.java b/test-support/src/main/java/com/axemblr/provisionr/test/KarafTests.java
deleted file mode 100644
index 4e5bdf0..0000000
--- a/test-support/src/main/java/com/axemblr/provisionr/test/KarafTests.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * 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 com.axemblr.provisionr.test;
-
-import java.io.File;
-import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.karafDistributionConfiguration;
-import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.keepRuntimeFolder;
-import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.logLevel;
-import org.apache.karaf.tooling.exam.options.LogLevelOption;
-import static org.ops4j.pax.exam.CoreOptions.junitBundles;
-import static org.ops4j.pax.exam.CoreOptions.maven;
-import static org.ops4j.pax.exam.CoreOptions.scanFeatures;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import org.ops4j.pax.exam.MavenUtils;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
-import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
-import org.ops4j.pax.exam.options.SystemPropertyOption;
-import org.ops4j.pax.exam.options.extra.FeaturesScannerProvisionOption;
-
-/**
- * Helper methods for Karaf integration tests
- */
-public class KarafTests {
-
-    public static final String KARAF_GROUP_ID = "org.apache.karaf";
-    public static final String KARAF_ARTIFACT_ID = "apache-karaf";
-
-    private KarafTests() {
-    }
-
-    /**
-     * Use the same Karaf version from the project for integration testing with Pax Exam
-     */
-    public static DefaultCompositeOption useDefaultKarafAsInProjectWithJunitBundles() {
-        String karafVersion = getKarafVersionAsInProject();
-
-        MavenArtifactUrlReference karafUrl = maven().groupId(KARAF_GROUP_ID)
-            .artifactId(KARAF_ARTIFACT_ID)
-            .version(karafVersion)
-            .type("tar.gz");
-
-        return new DefaultCompositeOption()
-            .add(karafDistributionConfiguration()
-                .frameworkUrl(karafUrl)
-                .karafVersion(karafVersion)
-                .name("Apache Karaf")
-                .unpackDirectory(new File("target/exam")))
-            .add(keepRuntimeFolder())
-            .add(junitBundles())
-            .add(logLevel(LogLevelOption.LogLevel.INFO));
-    }
-
-    public static String getKarafVersionAsInProject() {
-        return MavenUtils.asInProject().getVersion(KARAF_GROUP_ID, KARAF_ARTIFACT_ID);
-    }
-
-    /**
-     * Make sure all system properties with a given prefix are also available inside the container
-     */
-    public static DefaultCompositeOption passThroughAllSystemPropertiesWithPrefix(String prefix) {
-        DefaultCompositeOption options = new DefaultCompositeOption();
-        for (String name : System.getProperties().stringPropertyNames()) {
-            if (name.startsWith(prefix)) {
-                options.add(systemProperty(name).value(System.getProperty(name)));
-            }
-        }
-        return options;
-    }
-
-    /**
-     * Set the project version as a Karaf system property
-     * <p/>
-     * This method assumes that the test-support bundle has the same
-     * version as the code being tested
-     */
-    public static SystemPropertyOption projectVersionAsSystemProperty() {
-        String version = MavenUtils.asInProject()
-            .getVersion("com.axemblr.provisionr", "provisionr-test-support");
-        return systemProperty("project.version").value(version);
-    }
-
-    /**
-     * Create an option to install the test support bundle inside the PAX Exam container
-     */
-    public static FeaturesScannerProvisionOption installProvisionrTestSupportBundle() {
-        return scanFeatures(
-            maven().groupId("com.axemblr.provisionr").artifactId("provisionr-test-support")
-                .type("xml").classifier("features").versionAsInProject(),
-            "provisionr-test-support"
-        );
-    }
-
-    /**
-     * Create an option to install all the requested Provisionr features inside the PAX Exam container
-     */
-    public static FeaturesScannerProvisionOption installProvisionrFeatures(String... features) {
-        return scanFeatures(
-            maven().groupId("com.axemblr.provisionr").artifactId("provisionr-features")
-                .type("xml").classifier("features").versionAsInProject(),
-            features
-        );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/java/com/axemblr/provisionr/test/ProcessVariablesCollector.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/com/axemblr/provisionr/test/ProcessVariablesCollector.java b/test-support/src/main/java/com/axemblr/provisionr/test/ProcessVariablesCollector.java
deleted file mode 100644
index 6ac7e02..0000000
--- a/test-support/src/main/java/com/axemblr/provisionr/test/ProcessVariablesCollector.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * 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 com.axemblr.provisionr.test;
-
-import com.google.common.collect.Maps;
-import java.util.Arrays;
-import java.util.Map;
-import org.activiti.engine.delegate.DelegateExecution;
-import org.mockito.Matchers;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doAnswer;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ProcessVariablesCollector implements Answer<Void> {
-
-    public static final Logger LOG = LoggerFactory.getLogger(ProcessVariablesCollector.class);
-
-    private Map<String, Object> variables = Maps.newConcurrentMap();
-
-    /**
-     * Install the collector on the setVariable class
-     */
-    public void install(DelegateExecution execution) {
-        doAnswer(this).when(execution).setVariable(Matchers.<String>any(), any());
-    }
-
-    @Override
-    public Void answer(InvocationOnMock invocation) throws Throwable {
-        Object[] arguments = invocation.getArguments();
-        LOG.info("Got method call {} with arguments {}",
-            invocation.getMethod().getName(), Arrays.toString(arguments));
-
-        variables.put((String) arguments[0], arguments[1]);
-        return null;
-    }
-
-    public Object getVariable(String name) {
-        return variables.get(name);
-    }
-
-    @Override
-    public String toString() {
-        return "ProcessVariablesCollector{" +
-            "variables=" + variables +
-            '}';
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/java/com/axemblr/provisionr/test/ProvisionrLiveTestSupport.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/com/axemblr/provisionr/test/ProvisionrLiveTestSupport.java b/test-support/src/main/java/com/axemblr/provisionr/test/ProvisionrLiveTestSupport.java
deleted file mode 100644
index 9d7a7d7..0000000
--- a/test-support/src/main/java/com/axemblr/provisionr/test/ProvisionrLiveTestSupport.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
- *
- * 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 com.axemblr.provisionr.test;
-
-import com.axemblr.provisionr.api.provider.Provider;
-import com.axemblr.provisionr.api.provider.ProviderBuilder;
-import com.google.common.base.Charsets;
-import com.google.common.base.Optional;
-import static com.google.common.base.Preconditions.checkNotNull;
-import com.google.common.base.Stopwatch;
-import com.google.common.io.Resources;
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import javax.inject.Inject;
-import org.activiti.engine.ProcessEngine;
-import org.activiti.engine.repository.ProcessDefinition;
-import org.activiti.engine.runtime.ProcessInstance;
-import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ProvisionrLiveTestSupport {
-
-    private static final Logger LOG = LoggerFactory.getLogger(ProvisionrLiveTestSupport.class);
-
-    @Inject
-    protected BundleContext bundleContext;
-
-    protected final String provisionrId;
-
-    /**
-     * Supply the provisionrId to acquire proper credentials from System Properties.
-     *
-     * @param provisionrId
-     */
-    public ProvisionrLiveTestSupport(String provisionrId) {
-        this.provisionrId = checkNotNull(provisionrId, "provisionrId is null");
-    }
-
-    /**
-     * Retrieve a reference to an OSGi service using the class name
-     */
-    protected <T> T getOsgiService(Class<T> klass, int timeoutInMilliseconds) throws InterruptedException {
-        ServiceTracker tracker = new ServiceTracker(bundleContext,
-            klass.getCanonicalName(), null);
-        tracker.open(true);
-
-        try {
-            return (T) checkNotNull(tracker.waitForService(timeoutInMilliseconds),
-                "OSGi Service not available " + klass.getCanonicalName());
-        } finally {
-            tracker.close();
-        }
-    }
-
-    /**
-     * Collect the provider connection details from system properties
-     */
-    protected ProviderBuilder collectProviderCredentialsFromSystemProperties() {
-        return Provider.builder().id(provisionrId)
-            .accessKey(getProviderProperty("accessKey"))
-            .secretKey(getProviderProperty("secretKey"))
-            .endpoint(Optional.fromNullable(getProviderProperty("endpoint")));
-    }
-
-    /**
-     * Get a provider configuration property from system properties
-     */
-    protected String getProviderProperty(String property) {
-        return System.getProperty(String.format("test.%s.provider.%s", provisionrId, property));
-    }
-
-    /**
-     * @see #getProviderProperty
-     */
-    protected String getProviderProperty(String property, String defaultValue) {
-        return Optional.fromNullable(getProviderProperty(property)).or(defaultValue);
-    }
-
-    public String getResourceAsString(String resource) throws IOException {
-        return Resources.toString(Resources.getResource(resource), Charsets.UTF_8);
-    }
-
-    /**
-     * Must be called inside a test method to be able to access OSGi infrastructure,
-     *
-     * @param processKey
-     * @throws InterruptedException
-     */
-    public void waitForProcessDeployment(String processKey) throws InterruptedException, TimeoutException {
-        ProcessEngine engine = getOsgiService(ProcessEngine.class, 5000);
-        int iteration = 0;
-        while (iteration < 5) {
-            ProcessDefinition definition = engine.getRepositoryService()
-                .createProcessDefinitionQuery()
-                .processDefinitionKey(processKey).singleResult();
-            if (definition != null) {
-                break;
-            }
-            iteration++;
-            TimeUnit.MILLISECONDS.sleep(500);
-        }
-        if (iteration == 5) {
-            throw new TimeoutException("No process found with key: " + processKey);
-        }
-    }
-
-    public void waitForProcessEnd(String processInstanceId) throws Exception {
-        waitForProcessEnd(processInstanceId, 60000 /* milliseconds */);
-    }
-
-    public void waitForProcessEnd(final String processInstanceId, int timeoutInMilliseconds) throws Exception {
-        Stopwatch stopwatch = new Stopwatch().start();
-        while (isProcessNotEnded(processInstanceId)) {
-            if (stopwatch.elapsedMillis() > timeoutInMilliseconds) {
-                throw new TimeoutException(String.format("Process %s not ended in %d milliseconds.",
-                    processInstanceId, timeoutInMilliseconds));
-            }
-            LOG.info(String.format("Process instance %s not ended. Waiting 1s.", processInstanceId));
-            TimeUnit.SECONDS.sleep(1);
-        }
-        LOG.info(String.format("Process instance %s ended as expected in less than %d milliseconds",
-            processInstanceId, timeoutInMilliseconds));
-    }
-
-    private boolean isProcessNotEnded(final String processInstanceId) throws InterruptedException {
-        ProcessInstance localInstance = getProcessInstanceById(processInstanceId);
-        return localInstance != null && !localInstance.isEnded();
-    }
-
-    private ProcessInstance getProcessInstanceById(final String processInstanceId) throws InterruptedException {
-        ProcessEngine engine = getOsgiService(ProcessEngine.class, 5000);
-        return engine.getRuntimeService().createProcessInstanceQuery()
-            .processInstanceId(processInstanceId)
-            .singleResult();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/java/com/axemblr/provisionr/test/TestConstants.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/com/axemblr/provisionr/test/TestConstants.java b/test-support/src/main/java/com/axemblr/provisionr/test/TestConstants.java
deleted file mode 100644
index 35c3c84..0000000
--- a/test-support/src/main/java/com/axemblr/provisionr/test/TestConstants.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L
- *
- * 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 com.axemblr.provisionr.test;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Throwables;
-import com.google.common.io.Resources;
-import java.io.IOException;
-
-public class TestConstants {
-
-    static final String PUBLIC_KEY_FILE_NAME = "id_rsa_test.pub";
-    static final String PRIVATE_KEY_FILE_NAME = "id_rsa_test";
-
-    public static final String PUBLIC_KEY = loadResource(PUBLIC_KEY_FILE_NAME);
-    public static final String PRIVATE_KEY = loadResource(PRIVATE_KEY_FILE_NAME);
-
-    private static String loadResource(String fileName) {
-        try {
-            return Resources.toString(Resources.getResource(TestConstants.class, fileName), Charsets.UTF_8);
-        } catch (IOException e) {
-            throw Throwables.propagate(e);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/java/org/apache/provisionr/test/Generics.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/org/apache/provisionr/test/Generics.java b/test-support/src/main/java/org/apache/provisionr/test/Generics.java
new file mode 100644
index 0000000..248fc87
--- /dev/null
+++ b/test-support/src/main/java/org/apache/provisionr/test/Generics.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.test;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Helper methods for class type parameters.
+ *
+ * @see <a href="https://github.com/codahale/dropwizard/blob/master/dropwizard-core/src/main/java/com/yammer/dropwizard/util/Generics.java">Generics in Codahale Dropwizard</a>
+ * @see <a href="http://gafter.blogspot.com/2006/12/super-type-tokens.html">Super Type Tokens</a>
+ */
+public class Generics {
+    private Generics() { /* singleton */ }
+
+    /**
+     * Finds the type parameter for the given class which is assignable to the bound class.
+     *
+     * @param klass a parameterized class
+     * @param bound the type bound
+     * @param <T>   the type bound
+     * @return the class's type parameter
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> Class<T> getTypeParameter(Class<?> klass, Class<? super T> bound) {
+        Type t = checkNotNull(klass);
+        while (t instanceof Class<?>) {
+            t = ((Class<?>) t).getGenericSuperclass();
+        }
+        /* This is not guaranteed to work for all cases with convoluted piping
+         * of type parameters: but it can at least resolve straight-forward
+         * extension with single type parameter (as per [Issue-89]).
+         * And when it fails to do that, will indicate with specific exception.
+         */
+        if (t instanceof ParameterizedType) {
+            // should typically have one of type parameters (first one) that matches:
+            for (Type param : ((ParameterizedType) t).getActualTypeArguments()) {
+                if (param instanceof Class<?>) {
+                    final Class<?> cls = (Class<?>) param;
+                    if (bound.isAssignableFrom(cls)) {
+                        return (Class<T>) cls;
+                    }
+                }
+            }
+        }
+        throw new IllegalStateException("Cannot figure out type parameterization for " + klass.getName());
+    }
+
+    /**
+     * Finds the type parameter for the given class.
+     *
+     * @param klass a parameterized class
+     * @return the class's type parameter
+     */
+    public static Class<?> getTypeParameter(Class<?> klass) {
+        return getTypeParameter(klass, Object.class);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/java/org/apache/provisionr/test/KarafTests.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/org/apache/provisionr/test/KarafTests.java b/test-support/src/main/java/org/apache/provisionr/test/KarafTests.java
new file mode 100644
index 0000000..c8ba29a
--- /dev/null
+++ b/test-support/src/main/java/org/apache/provisionr/test/KarafTests.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.test;
+
+import java.io.File;
+import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.karafDistributionConfiguration;
+import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.keepRuntimeFolder;
+import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.logLevel;
+import org.apache.karaf.tooling.exam.options.LogLevelOption;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.CoreOptions.scanFeatures;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import org.ops4j.pax.exam.MavenUtils;
+import org.ops4j.pax.exam.options.DefaultCompositeOption;
+import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
+import org.ops4j.pax.exam.options.SystemPropertyOption;
+import org.ops4j.pax.exam.options.extra.FeaturesScannerProvisionOption;
+
+/**
+ * Helper methods for Karaf integration tests
+ */
+public class KarafTests {
+
+    public static final String KARAF_GROUP_ID = "org.apache.karaf";
+    public static final String KARAF_ARTIFACT_ID = "apache-karaf";
+
+    private KarafTests() {
+    }
+
+    /**
+     * Use the same Karaf version from the project for integration testing with Pax Exam
+     */
+    public static DefaultCompositeOption useDefaultKarafAsInProjectWithJunitBundles() {
+        String karafVersion = getKarafVersionAsInProject();
+
+        MavenArtifactUrlReference karafUrl = maven().groupId(KARAF_GROUP_ID)
+            .artifactId(KARAF_ARTIFACT_ID)
+            .version(karafVersion)
+            .type("tar.gz");
+
+        return new DefaultCompositeOption()
+            .add(karafDistributionConfiguration()
+                .frameworkUrl(karafUrl)
+                .karafVersion(karafVersion)
+                .name("Apache Karaf")
+                .unpackDirectory(new File("target/exam")))
+            .add(keepRuntimeFolder())
+            .add(junitBundles())
+            .add(logLevel(LogLevelOption.LogLevel.INFO));
+    }
+
+    public static String getKarafVersionAsInProject() {
+        return MavenUtils.asInProject().getVersion(KARAF_GROUP_ID, KARAF_ARTIFACT_ID);
+    }
+
+    /**
+     * Make sure all system properties with a given prefix are also available inside the container
+     */
+    public static DefaultCompositeOption passThroughAllSystemPropertiesWithPrefix(String prefix) {
+        DefaultCompositeOption options = new DefaultCompositeOption();
+        for (String name : System.getProperties().stringPropertyNames()) {
+            if (name.startsWith(prefix)) {
+                options.add(systemProperty(name).value(System.getProperty(name)));
+            }
+        }
+        return options;
+    }
+
+    /**
+     * Set the project version as a Karaf system property
+     * <p/>
+     * This method assumes that the test-support bundle has the same
+     * version as the code being tested
+     */
+    public static SystemPropertyOption projectVersionAsSystemProperty() {
+        String version = MavenUtils.asInProject()
+            .getVersion("org.apache.provisionr", "provisionr-test-support");
+        return systemProperty("project.version").value(version);
+    }
+
+    /**
+     * Create an option to install the test support bundle inside the PAX Exam container
+     */
+    public static FeaturesScannerProvisionOption installProvisionrTestSupportBundle() {
+        return scanFeatures(
+            maven().groupId("org.apache.provisionr").artifactId("provisionr-test-support")
+                .type("xml").classifier("features").versionAsInProject(),
+            "provisionr-test-support"
+        );
+    }
+
+    /**
+     * Create an option to install all the requested Provisionr features inside the PAX Exam container
+     */
+    public static FeaturesScannerProvisionOption installProvisionrFeatures(String... features) {
+        return scanFeatures(
+            maven().groupId("org.apache.provisionr").artifactId("provisionr-features")
+                .type("xml").classifier("features").versionAsInProject(),
+            features
+        );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/java/org/apache/provisionr/test/ProcessVariablesCollector.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/org/apache/provisionr/test/ProcessVariablesCollector.java b/test-support/src/main/java/org/apache/provisionr/test/ProcessVariablesCollector.java
new file mode 100644
index 0000000..6e5e5f0
--- /dev/null
+++ b/test-support/src/main/java/org/apache/provisionr/test/ProcessVariablesCollector.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L
+ *
+ * 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.apache.provisionr.test;
+
+import com.google.common.collect.Maps;
+import java.util.Arrays;
+import java.util.Map;
+import org.activiti.engine.delegate.DelegateExecution;
+import org.mockito.Matchers;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ProcessVariablesCollector implements Answer<Void> {
+
+    public static final Logger LOG = LoggerFactory.getLogger(ProcessVariablesCollector.class);
+
+    private Map<String, Object> variables = Maps.newConcurrentMap();
+
+    /**
+     * Install the collector on the setVariable class
+     */
+    public void install(DelegateExecution execution) {
+        doAnswer(this).when(execution).setVariable(Matchers.<String>any(), any());
+    }
+
+    @Override
+    public Void answer(InvocationOnMock invocation) throws Throwable {
+        Object[] arguments = invocation.getArguments();
+        LOG.info("Got method call {} with arguments {}",
+            invocation.getMethod().getName(), Arrays.toString(arguments));
+
+        variables.put((String) arguments[0], arguments[1]);
+        return null;
+    }
+
+    public Object getVariable(String name) {
+        return variables.get(name);
+    }
+
+    @Override
+    public String toString() {
+        return "ProcessVariablesCollector{" +
+            "variables=" + variables +
+            '}';
+    }
+}


Mime
View raw message