@Test
  public void testBadRegistrationOfDataCenterInfo() throws Exception {
    try {
      // test 400 when configured to return client error
      ConfigurationManager.getConfigInstance()
          .setProperty("eureka.experimental.registration.validation.dataCenterInfoId", "true");
      InstanceInfo instanceInfo = spy(InstanceInfoGenerator.takeOne());
      when(instanceInfo.getDataCenterInfo()).thenReturn(new TestDataCenterInfo());
      Response response = applicationResource.addInstance(instanceInfo, false + "");
      assertThat(response.getStatus(), is(400));

      // test backfill of data for AmazonInfo
      ConfigurationManager.getConfigInstance()
          .setProperty("eureka.experimental.registration.validation.dataCenterInfoId", "false");
      instanceInfo = spy(InstanceInfoGenerator.takeOne());
      assertThat(instanceInfo.getDataCenterInfo(), instanceOf(AmazonInfo.class));
      ((AmazonInfo) instanceInfo.getDataCenterInfo())
          .getMetadata()
          .remove(AmazonInfo.MetaDataKey.instanceId.getName()); // clear the Id
      response = applicationResource.addInstance(instanceInfo, false + "");
      assertThat(response.getStatus(), is(204));

    } finally {
      ConfigurationManager.getConfigInstance()
          .clearProperty("eureka.experimental.registration.validation.dataCenterInfoId");
    }
  }
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();
    InstanceInfoGenerator instanceInfos = InstanceInfoGenerator.newBuilder(6, 1).build();
    testApplication = instanceInfos.toApplications().getRegisteredApplications().get(0);

    applicationResource =
        new ApplicationResource(
            testApplication.getName(),
            serverContext.getServerConfig(),
            serverContext.getRegistry());

    for (InstanceInfo instanceInfo : testApplication.getInstances()) {
      registry.register(instanceInfo, false);
    }
  }
Example #3
0
 public static InstanceInfo newInstanceInfo(int index) {
   Iterator<InstanceInfo> instanceGenerator =
       InstanceInfoGenerator.newBuilder(10, 10).withMetaData(true).build().serviceIterator();
   // Skip to the requested index
   for (int i = 0; i < index; i++) {
     instanceGenerator.next();
   }
   return instanceGenerator.next();
 }
  @Test
  public void testBadRegistration() throws Exception {
    InstanceInfo instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getId()).thenReturn(null);
    Response response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));

    instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getHostName()).thenReturn(null);
    response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));

    instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getAppName()).thenReturn("");
    response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));

    instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getAppName()).thenReturn(applicationResource.getName() + "extraExtra");
    response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));

    instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getDataCenterInfo()).thenReturn(null);
    response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));

    instanceInfo = spy(InstanceInfoGenerator.takeOne());
    when(instanceInfo.getDataCenterInfo())
        .thenReturn(
            new DataCenterInfo() {
              @Override
              public Name getName() {
                return null;
              }
            });
    response = applicationResource.addInstance(instanceInfo, false + "");
    assertThat(response.getStatus(), is(400));
  }
 @Test
 public void testGoodRegistration() throws Exception {
   InstanceInfo noIdInfo = InstanceInfoGenerator.takeOne();
   Response response = applicationResource.addInstance(noIdInfo, false + "");
   assertThat(response.getStatus(), is(204));
 }