summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2012-11-24 14:56:08 (EST)
committer Steffen Pingel2012-11-26 15:54:45 (EST)
commit451c428570d3084341a5bce7f6ff96428b70ab2a (patch)
treeb26e5d9af7ec42e7a9a4725c954cda1cb18887fe
parent4d291ecbc4dc9bb3b693a09c0226c6df7c96b25b (diff)
downloadorg.eclipse.mylyn.commons-451c428570d3084341a5bce7f6ff96428b70ab2a.zip
org.eclipse.mylyn.commons-451c428570d3084341a5bce7f6ff96428b70ab2a.tar.gz
org.eclipse.mylyn.commons-451c428570d3084341a5bce7f6ff96428b70ab2a.tar.bz2
394053: services provisioned by puppet should be discoverable remotelyrefs/changes/43/8843/2
Change-Id: Ie1e49d10adf0567610e6d831745f5c49907b533b Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=394053
-rw-r--r--org.eclipse.mylyn.commons.sdk.util/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/FixtureConfiguration.java70
-rw-r--r--org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/TestConfiguration.java76
3 files changed, 148 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.commons.sdk.util/META-INF/MANIFEST.MF b/org.eclipse.mylyn.commons.sdk.util/META-INF/MANIFEST.MF
index 96aa3ba..afd5ed1 100644
--- a/org.eclipse.mylyn.commons.sdk.util/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.commons.sdk.util/META-INF/MANIFEST.MF
@@ -12,6 +12,7 @@ Require-Bundle: org.junit,
org.eclipse.ui,
org.eclipse.mylyn.commons.core,
org.eclipse.mylyn.commons.repositories.core,
- org.eclipse.mylyn.commons.net
+ org.eclipse.mylyn.commons.net,
+ com.google.gson;bundle-version="2.1.0"
Export-Package: org.eclipse.mylyn.commons.sdk.util;x-internal:=true
Bundle-Vendor: Eclipse Mylyn
diff --git a/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/FixtureConfiguration.java b/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/FixtureConfiguration.java
new file mode 100644
index 0000000..47a7cc8
--- /dev/null
+++ b/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/FixtureConfiguration.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.sdk.util;
+
+import java.util.Map;
+
+/**
+ * @author Steffen Pingel
+ */
+public class FixtureConfiguration {
+
+ String type;
+
+ String url;
+
+ String version;
+
+ String info;
+
+ Map<String, String> properties;
+
+ public FixtureConfiguration() {
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getInfo() {
+ return info;
+ }
+
+ public void setInfo(String info) {
+ this.info = info;
+ }
+
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/TestConfiguration.java b/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/TestConfiguration.java
index 3cd36a9..b34a0f0 100644
--- a/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/TestConfiguration.java
+++ b/org.eclipse.mylyn.commons.sdk.util/src/org/eclipse/mylyn/commons/sdk/util/TestConfiguration.java
@@ -11,15 +11,30 @@
package org.eclipse.mylyn.commons.sdk.util;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.reflect.Constructor;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.EnumSet;
+import java.util.List;
import org.eclipse.core.runtime.Assert;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+
/**
* @author Steffen Pingel
*/
public class TestConfiguration {
+ private static final String URL_SERVICES_LOCALHOST = "http://localhost:2080";
+
+ private static final String URL_SERVICES_DEFAULT = "http://mylyn.org";
+
public enum TestKind {
UNIT, COMPONENT, INTEGRATION, SYSTEM
};
@@ -97,4 +112,65 @@ public class TestConfiguration {
this.localOnly = localOnly;
}
+ public <T> List<T> discover(Class<T> clazz, String fixtureType) {
+ List<T> fixtures = discover(URL_SERVICES_LOCALHOST, clazz, fixtureType);
+ if (fixtures != null) {
+ return fixtures;
+ }
+
+ fixtures = discover(URL_SERVICES_LOCALHOST, clazz, fixtureType);
+ if (fixtures != null) {
+ if (isDefaultOnly()) {
+ return Collections.singletonList(fixtures.get(0));
+ } else {
+ return fixtures;
+ }
+ }
+ return fixtures;
+ }
+
+ public static <T> List<T> discover(String url, Class<T> clazz, String fixtureType) {
+ Assert.isNotNull(fixtureType);
+ List<FixtureConfiguration> configurations = getConfigurations(url + "/cgi-bin/services");
+ if (configurations != null) {
+ for (FixtureConfiguration configuration : configurations) {
+ configuration.setUrl(url + configuration.getUrl());
+ }
+ return loadFixtures(configurations, clazz, fixtureType);
+ }
+ return Collections.emptyList();
+ }
+
+ private static <T> List<T> loadFixtures(List<FixtureConfiguration> configurations, Class<T> clazz,
+ String fixtureType) {
+ List<T> result = new ArrayList<T>();
+ for (FixtureConfiguration configuration : configurations) {
+ if (fixtureType.equals(configuration.getType())) {
+ try {
+ Constructor<T> constructor = clazz.getConstructor(FixtureConfiguration.class);
+ result.add(constructor.newInstance(configuration));
+ } catch (Exception e) {
+ throw new RuntimeException("Unexpected error creating test fixture", e);
+ }
+ }
+ }
+ return result;
+ }
+
+ private static List<FixtureConfiguration> getConfigurations(String url) {
+ try {
+ URLConnection connection = new URL(url).openConnection();
+ InputStreamReader in = new InputStreamReader(connection.getInputStream());
+ try {
+ TypeToken<List<FixtureConfiguration>> type = new TypeToken<List<FixtureConfiguration>>() {
+ };
+ return new Gson().fromJson(in, type.getType());
+ } finally {
+ in.close();
+ }
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
}