Fix broken test.

parent 93cd1e7a
......@@ -9,7 +9,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.DataCenterInfo;
import com.netflix.appinfo.InstanceInfo;
......@@ -22,67 +21,69 @@ import org.junit.Test;
import com.netflix.eureka.util.StatusInfo;
public class EurekaControllerReplicasTest {
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 authList2 = authList1+",http://user2:pwd2@test2.com";
String authList2 = authList1 + ",http://user2:pwd2@test2.com";
String empty = new String();
private ApplicationInfoManager original;
private InstanceInfo instanceInfo;
@Before
public void setup() throws Exception {
this.original = ApplicationInfoManager.getInstance();
setInstance(mock(ApplicationInfoManager.class));
instanceInfo = mock(InstanceInfo.class);
}
@After
public void teardown() throws Exception {
setInstance(this.original);
instanceInfo = null;
}
@Test
public void testFilterReplicasNoAuth() throws Exception {
Map<String, Object> model=new HashMap<String, Object>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().
add("registered-replicas", empty).
add("available-replicas",noAuthList1).
add("unavailable-replicas",noAuthList2).
build();
Map<String, Object> model = new HashMap<>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
.add("registered-replicas", empty)
.add("available-replicas", noAuthList1)
.add("unavailable-replicas", noAuthList2)
.withInstanceInfo(this.instanceInfo).build();
EurekaController controller = new EurekaController(null);
controller.filterReplicas(model,statusInfo);
controller.filterReplicas(model, statusInfo);
@SuppressWarnings("unchecked")
Map<String,String> results = (Map<String, String>) model.get("applicationStats");
assertEquals(empty,results.get("registered-replicas"));
assertEquals(noAuthList1,results.get("available-replicas"));
assertEquals(noAuthList2,results.get("unavailable-replicas"));
Map<String, String> results = (Map<String, String>) model.get("applicationStats");
assertEquals(empty, results.get("registered-replicas"));
assertEquals(noAuthList1, results.get("available-replicas"));
assertEquals(noAuthList2, results.get("unavailable-replicas"));
}
@Test
public void testFilterReplicasAuth() throws Exception {
Map<String, Object> model=new HashMap<String, Object>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().
add("registered-replicas", authList2).
add("available-replicas",authList1).
add("unavailable-replicas",empty).
build();
Map<String, Object> model = new HashMap<>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder()
.add("registered-replicas", authList2)
.add("available-replicas", authList1)
.add("unavailable-replicas", empty)
.withInstanceInfo(instanceInfo).build();
EurekaController controller = new EurekaController(null);
controller.filterReplicas(model,statusInfo);
controller.filterReplicas(model, statusInfo);
@SuppressWarnings("unchecked")
Map<String,String> results = (Map<String, String>) model.get("applicationStats");
assertEquals(empty,results.get("unavailable-replicas"));
assertEquals(noAuthList1,results.get("available-replicas"));
assertEquals(noAuthList2,results.get("registered-replicas"));
Map<String, String> results = (Map<String, String>) model.get("applicationStats");
assertEquals(empty, results.get("unavailable-replicas"));
assertEquals(noAuthList1, results.get("available-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