Fix broken test.

parent 93cd1e7a
...@@ -9,7 +9,6 @@ import java.util.Collections; ...@@ -9,7 +9,6 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.netflix.appinfo.ApplicationInfoManager; import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.DataCenterInfo; import com.netflix.appinfo.DataCenterInfo;
import com.netflix.appinfo.InstanceInfo; import com.netflix.appinfo.InstanceInfo;
...@@ -22,67 +21,69 @@ import org.junit.Test; ...@@ -22,67 +21,69 @@ import org.junit.Test;
import com.netflix.eureka.util.StatusInfo; import com.netflix.eureka.util.StatusInfo;
public class EurekaControllerReplicasTest { public class EurekaControllerReplicasTest {
String noAuthList1 = "http://test1.com"; String noAuthList1 = "http://test1.com";
String noAuthList2 = noAuthList1+",http://test2.com"; String noAuthList2 = noAuthList1 + ",http://test2.com";
String authList1 = "http://user:pwd@test1.com"; String authList1 = "http://user:pwd@test1.com";
String authList2 = authList1+",http://user2:pwd2@test2.com"; String authList2 = authList1 + ",http://user2:pwd2@test2.com";
String empty = new String(); String empty = new String();
private ApplicationInfoManager original; private ApplicationInfoManager original;
private InstanceInfo instanceInfo;
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
this.original = ApplicationInfoManager.getInstance(); this.original = ApplicationInfoManager.getInstance();
setInstance(mock(ApplicationInfoManager.class)); setInstance(mock(ApplicationInfoManager.class));
instanceInfo = mock(InstanceInfo.class);
} }
@After @After
public void teardown() throws Exception { public void teardown() throws Exception {
setInstance(this.original); setInstance(this.original);
instanceInfo = null;
} }
@Test @Test
public void testFilterReplicasNoAuth() throws Exception { public void testFilterReplicasNoAuth() throws Exception {
Map<String, Object> model=new HashMap<String, Object>(); Map<String, Object> model = new HashMap<>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder(). StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
add("registered-replicas", empty). .add("registered-replicas", empty)
add("available-replicas",noAuthList1). .add("available-replicas", noAuthList1)
add("unavailable-replicas",noAuthList2). .add("unavailable-replicas", noAuthList2)
build(); .withInstanceInfo(this.instanceInfo).build();
EurekaController controller = new EurekaController(null); EurekaController controller = new EurekaController(null);
controller.filterReplicas(model,statusInfo); controller.filterReplicas(model, statusInfo);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String,String> results = (Map<String, String>) model.get("applicationStats"); Map<String, String> results = (Map<String, String>) model.get("applicationStats");
assertEquals(empty,results.get("registered-replicas")); assertEquals(empty, results.get("registered-replicas"));
assertEquals(noAuthList1,results.get("available-replicas")); assertEquals(noAuthList1, results.get("available-replicas"));
assertEquals(noAuthList2,results.get("unavailable-replicas")); assertEquals(noAuthList2, results.get("unavailable-replicas"));
} }
@Test @Test
public void testFilterReplicasAuth() throws Exception { public void testFilterReplicasAuth() throws Exception {
Map<String, Object> model=new HashMap<String, Object>(); Map<String, Object> model = new HashMap<>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder(). StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
add("registered-replicas", authList2). .add("registered-replicas", authList2)
add("available-replicas",authList1). .add("available-replicas", authList1)
add("unavailable-replicas",empty). .add("unavailable-replicas", empty)
build(); .withInstanceInfo(instanceInfo).build();
EurekaController controller = new EurekaController(null); EurekaController controller = new EurekaController(null);
controller.filterReplicas(model,statusInfo); controller.filterReplicas(model, statusInfo);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String,String> results = (Map<String, String>) model.get("applicationStats"); Map<String, String> results = (Map<String, String>) model.get("applicationStats");
assertEquals(empty,results.get("unavailable-replicas")); assertEquals(empty, results.get("unavailable-replicas"));
assertEquals(noAuthList1,results.get("available-replicas")); assertEquals(noAuthList1, results.get("available-replicas"));
assertEquals(noAuthList2,results.get("registered-replicas")); assertEquals(noAuthList2, results.get("registered-replicas"));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment