provisionr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From as...@apache.org
Subject [01/21] PROVISIONR-20. Change groupId from com.axemblr.provisionr to org.apache.provisionr
Date Mon, 01 Apr 2013 08:52:24 GMT
Updated Branches:
  refs/heads/master 6559ede8b -> 6ba40c4b2


http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/java/org/apache/provisionr/test/ProvisionrLiveTestSupport.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/org/apache/provisionr/test/ProvisionrLiveTestSupport.java
b/test-support/src/main/java/org/apache/provisionr/test/ProvisionrLiveTestSupport.java
new file mode 100644
index 0000000..4c2cdea
--- /dev/null
+++ b/test-support/src/main/java/org/apache/provisionr/test/ProvisionrLiveTestSupport.java
@@ -0,0 +1,153 @@
+/*
+ * 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 org.apache.provisionr.api.provider.Provider;
+import org.apache.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/org/apache/provisionr/test/TestConstants.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/org/apache/provisionr/test/TestConstants.java b/test-support/src/main/java/org/apache/provisionr/test/TestConstants.java
new file mode 100644
index 0000000..32c29ec
--- /dev/null
+++ b/test-support/src/main/java/org/apache/provisionr/test/TestConstants.java
@@ -0,0 +1,39 @@
+/*
+ * 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.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/resources/com/axemblr/provisionr/test/id_rsa_test
----------------------------------------------------------------------
diff --git a/test-support/src/main/resources/com/axemblr/provisionr/test/id_rsa_test b/test-support/src/main/resources/com/axemblr/provisionr/test/id_rsa_test
deleted file mode 100644
index 5400f3e..0000000
--- a/test-support/src/main/resources/com/axemblr/provisionr/test/id_rsa_test
+++ /dev/null
@@ -1,27 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIEpAIBAAKCAQEAt3VZncmmoOV44eH3n12m8JVdPgdJCeiWXze7Ky1AgITWAWdu
-IhIdpGMjPTKWHPD1+NMOU20bmJdi6NyB/DYKM9aatPygcAmokjXOSnz+ypm1BDYI
-1srFW3vTds72rY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Sic8+a0s+5ffvsQRR5anelaHlSnZtIebJpTM+FxZ
-RQhwstDs06zqzaKMIPrRFMUCgYEAjYNI8umgJoHjNPijm1F8F2UjQ1o8hr2vqC2O
-wKBey668Gd88tSo+Mv/Y1JvUsXVp/RxYbPHfF4HRUEMyMagILHbQCPp8J0b4M5/r
-jFayRbmRxvRNKPROloKDgveOPvppi9loZcC/mKAKRO5Lc/Ey+CY0P4fGss0QeLvD
-Zo0ABqkCgYAIHOnxb32Mf6p2JXdGRx0fwVvTyQgVLYaI1L8HzkgYOqIowzo64Lzs
-Jl+BlvUc/4K3SziYnU+bML7YDJuhTJlJjbWKZHvXeTbfYwCghHpnITmQBzRcz9k3
-7o80fvPxKIb5NuD66CbOEx7QKUTmUhqJiDp6YzFYWTcWTEMqndxwqw==
------END RSA PRIVATE KEY-----

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/resources/com/axemblr/provisionr/test/id_rsa_test.pub
----------------------------------------------------------------------
diff --git a/test-support/src/main/resources/com/axemblr/provisionr/test/id_rsa_test.pub b/test-support/src/main/resources/com/axemblr/provisionr/test/id_rsa_test.pub
deleted file mode 100644
index 9d55fd1..0000000
--- a/test-support/src/main/resources/com/axemblr/provisionr/test/id_rsa_test.pub
+++ /dev/null
@@ -1 +0,0 @@
-ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3dVmdyaag5Xjh4fefXabwlV0+B0kJ6JZfN7srLUCAhNYBZ24iEh2kYyM9MpYc8PX40w5TbRuYl2Lo3IH8Ngoz1pq0/KBwCaiSNc5KfP7KmbUENgjWysVbe9N2zvatggPZxGO7VYK/T2161cVJ2l75TCQYYjmVd1I8fJA9og6HiDaPYLLug37yZuIsmsYBlxjvVMwFi/Kx/JLIwtSbA3mj+j3ud8GbiprDoQ6x6fUHJo3azWKBwvHKe+Nmq00OznpfcVe158Bc61pKQHh9dJOu4c0K5vHsurG7YkqoKxhesM9FRBbw5P9zf71aZiUEyToUn/p8kIvCUQdv3H9sce/J
test@axemblr.com

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/test-support/src/main/resources/features.xml b/test-support/src/main/resources/features.xml
index 34529b4..dd5cd84 100644
--- a/test-support/src/main/resources/features.xml
+++ b/test-support/src/main/resources/features.xml
@@ -21,7 +21,7 @@
 
     <feature name="provisionr-test-support" version="${project.version}">
         <bundle dependency="true">mvn:com.google.guava/guava/${guava.version}</bundle>
-        <bundle>mvn:com.axemblr.provisionr/provisionr-test-support/${project.version}</bundle>
+        <bundle>mvn:org.apache.provisionr/provisionr-test-support/${project.version}</bundle>
     </feature>
 
 </features>

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/resources/org/apache/provisionr/test/id_rsa_test
----------------------------------------------------------------------
diff --git a/test-support/src/main/resources/org/apache/provisionr/test/id_rsa_test b/test-support/src/main/resources/org/apache/provisionr/test/id_rsa_test
new file mode 100644
index 0000000..5400f3e
--- /dev/null
+++ b/test-support/src/main/resources/org/apache/provisionr/test/id_rsa_test
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpAIBAAKCAQEAt3VZncmmoOV44eH3n12m8JVdPgdJCeiWXze7Ky1AgITWAWdu
+IhIdpGMjPTKWHPD1+NMOU20bmJdi6NyB/DYKM9aatPygcAmokjXOSnz+ypm1BDYI
+1srFW3vTds72rYID2cRju1WCv09tetXFSdpe+UwkGGI5lXdSPHyQPaIOh4g2j2Cy
+7oN+8mbiLJrGAZcY71TMBYvysfySyMLUmwN5o/o97nfBm4qaw6EOsen1ByaN2s1i
+gcLxynvjZqtNDs56X3FXtefAXOtaSkB4fXSTruHNCubx7Lqxu2JKqCsYXrDPRUQW
+8OT/c3+9WmYlBMk6FJ/6fJCLwlEHb9x/bHHvyQIDAQABAoIBAQCq4v6FAa7atKVz
+Er9LjTrRYvAltTeNqT9YllscDtzEWffV+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VLYaI1L8HzkgYOqIowzo64Lzs
+Jl+BlvUc/4K3SziYnU+bML7YDJuhTJlJjbWKZHvXeTbfYwCghHpnITmQBzRcz9k3
+7o80fvPxKIb5NuD66CbOEx7QKUTmUhqJiDp6YzFYWTcWTEMqndxwqw==
+-----END RSA PRIVATE KEY-----

http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/test-support/src/main/resources/org/apache/provisionr/test/id_rsa_test.pub
----------------------------------------------------------------------
diff --git a/test-support/src/main/resources/org/apache/provisionr/test/id_rsa_test.pub b/test-support/src/main/resources/org/apache/provisionr/test/id_rsa_test.pub
new file mode 100644
index 0000000..9d55fd1
--- /dev/null
+++ b/test-support/src/main/resources/org/apache/provisionr/test/id_rsa_test.pub
@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3dVmdyaag5Xjh4fefXabwlV0+B0kJ6JZfN7srLUCAhNYBZ24iEh2kYyM9MpYc8PX40w5TbRuYl2Lo3IH8Ngoz1pq0/KBwCaiSNc5KfP7KmbUENgjWysVbe9N2zvatggPZxGO7VYK/T2161cVJ2l75TCQYYjmVd1I8fJA9og6HiDaPYLLug37yZuIsmsYBlxjvVMwFi/Kx/JLIwtSbA3mj+j3ud8GbiprDoQ6x6fUHJo3azWKBwvHKe+Nmq00OznpfcVe158Bc61pKQHh9dJOu4c0K5vHsurG7YkqoKxhesM9FRBbw5P9zf71aZiUEyToUn/p8kIvCUQdv3H9sce/J
test@axemblr.com


Mime
View raw message