@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");
    }
  }
  @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));
 }