Merge pull request #5 from myrle-krantz/develop

Fixing eureka/ribbon configuration.
diff --git a/src/main/java/io/mifos/core/test/servicestarter/ExtraProperties.java b/src/main/java/io/mifos/core/test/servicestarter/ExtraProperties.java
deleted file mode 100644
index d0e2ec2..0000000
--- a/src/main/java/io/mifos/core/test/servicestarter/ExtraProperties.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2017 The Mifos Initiative.
- *
- * 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 io.mifos.core.test.servicestarter;
-
-import java.util.Hashtable;
-
-/**
- * @author Myrle Krantz
- */
-public class ExtraProperties extends Hashtable<String, String> {
-  @SuppressWarnings("unused")
-  public synchronized String setProperty (String key, String value ) {
-      return put(key, value);
-  }
-}
diff --git a/src/main/java/io/mifos/core/test/servicestarter/InitializedMicroservice.java b/src/main/java/io/mifos/core/test/servicestarter/InitializedMicroservice.java
index 9f10a9c..e3ce24c 100644
--- a/src/main/java/io/mifos/core/test/servicestarter/InitializedMicroservice.java
+++ b/src/main/java/io/mifos/core/test/servicestarter/InitializedMicroservice.java
@@ -16,6 +16,7 @@
 package io.mifos.core.test.servicestarter;
 
 import io.mifos.anubis.test.v1.TenantApplicationSecurityEnvironmentTestRule;
+import io.mifos.core.test.env.ExtraProperties;
 import org.eclipse.aether.resolution.ArtifactResolutionException;
 
 import java.io.IOException;
diff --git a/src/main/java/io/mifos/core/test/servicestarter/IntegrationTestEnvironment.java b/src/main/java/io/mifos/core/test/servicestarter/IntegrationTestEnvironment.java
index a9a7bb9..267db7b 100644
--- a/src/main/java/io/mifos/core/test/servicestarter/IntegrationTestEnvironment.java
+++ b/src/main/java/io/mifos/core/test/servicestarter/IntegrationTestEnvironment.java
@@ -81,7 +81,7 @@
     properties.setProperty(MARIADB_USER_PROPERTY, MARIADB_USER_DEFAULT);
     properties.setProperty(MARIADB_PASSWORD_PROPERTY, MARIADB_PASSWORD_DEFAULT);
     properties.setProperty(HYSTRIX_ENABLED_PROPERTY, HYSTRIX_ENABLED_DEFAULT);
-    properties.setProperty(RIBBON_USES_EUREKA_PROPERTY, RIBBON_USES_EUREKA_DEFAULT);
+    properties.setProperty(RIBBON_USES_EUREKA_PROPERTY, "true");
     this.keyPairHolder = RsaKeyPairFactory.createKeyPair();
     properties.setProperty(SYSTEM_PUBLIC_KEY_TIMESTAMP_PROPERTY, this.keyPairHolder.getTimestamp());
     properties.setProperty(SYSTEM_PUBLIC_KEY_MODULUS_PROPERTY, this.keyPairHolder.publicKey().getModulus().toString());
diff --git a/src/main/java/io/mifos/core/test/servicestarter/Microservice.java b/src/main/java/io/mifos/core/test/servicestarter/Microservice.java
index 34245f8..2fc6c43 100644
--- a/src/main/java/io/mifos/core/test/servicestarter/Microservice.java
+++ b/src/main/java/io/mifos/core/test/servicestarter/Microservice.java
@@ -16,17 +16,20 @@
 package io.mifos.core.test.servicestarter;
 
 import io.mifos.core.api.util.ApiFactory;
+import io.mifos.core.test.env.ExtraProperties;
 import io.mifos.core.test.env.TestEnvironment;
 import org.eclipse.aether.resolution.ArtifactResolutionException;
 import org.junit.rules.ExternalResource;
+import org.springframework.cloud.client.ServiceInstance;
+import org.springframework.cloud.client.discovery.DiscoveryClient;
 import org.springframework.cloud.netflix.feign.FeignClient;
 import org.springframework.core.annotation.AnnotatedElementUtils;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
-
-import static io.mifos.core.test.env.TestEnvironment.SPRING_CLOUD_DISCOVERY_ENABLED_PROPERTY;
+import java.util.stream.Stream;
 
 /**
  * @author Myrle Krantz
@@ -60,7 +63,7 @@
     //https://github.com/spring-cloud/spring-cloud-netflix/issues/373
     //http://blog.abhijitsarkar.org/technical/netflix-eureka/
     processEnvironment.setProperty("eureka.client.serviceUrl.defaultZone", EurekaForTest.DEFAULT_ZONE);
-    processEnvironment.setProperty(SPRING_CLOUD_DISCOVERY_ENABLED_PROPERTY, "true");
+    processEnvironment.setProperty(TestEnvironment.SPRING_CLOUD_DISCOVERY_ENABLED_PROPERTY, "true");
     processEnvironment.setProperty("eureka.instance.hostname", "localhost");
     processEnvironment.setProperty("eureka.client.fetchRegistry", "true");
     processEnvironment.setProperty("eureka.registration.enabled", "true");
@@ -69,6 +72,8 @@
     processEnvironment.setProperty("eureka.client.instanceInfoReplicationIntervalSeconds", "1");
     processEnvironment.setProperty("activemq.brokerUrl", ActiveMQForTest.BIND_ADDRESS);
 
+    processEnvironment.setProperty(TestEnvironment.RIBBON_USES_EUREKA_PROPERTY, "true");
+
     this.integrationTestEnvironment = integrationTestEnvironment;
   }
 
@@ -78,6 +83,19 @@
     return this;
   }
 
+  public void waitTillRegistered(final DiscoveryClient discoveryClient, final Microservice... dependentOnServices) {
+    if (discoveryClient != null) {
+      Stream.concat(Stream.of(applicationName), Stream.of(dependentOnServices).map(Microservice::name))
+              .forEach(x -> {
+                boolean found = false;
+                while (!found) {
+                  final List<ServiceInstance> thisApp = discoveryClient.getInstances(x);
+                  found = !thisApp.isEmpty();
+                }
+              });
+    }
+  }
+
   @Override
   protected void before() throws InterruptedException, IOException, ArtifactResolutionException {
     start();