@Test
public void testPostInstanceRegisterInformation() throws IOException {

    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root",
            privateKey, "0");
    
    DataStore store = new DataStore(structStore, null);
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    
    SignedDomain providerDomain = signedAuthorizedProviderDomain();
    store.processDomain(providerDomain, false);
    
    SignedDomain tenantDomain = signedBootstrapTenantDomain("athenz.provider", "athenz", "production");
    store.processDomain(tenantDomain, false);
    
    Path path = Paths.get("src/test/resources/athenz.instanceid.csr");
    String certCsr = new String(Files.readAllBytes(path));
    InstanceProviderManager instanceProviderManager = Mockito.mock(InstanceProviderManager.class);
    InstanceProvider providerClient = Mockito.mock(InstanceProvider.class);
    Mockito.when(providerClient.getProviderScheme()).thenReturn(InstanceProvider.Scheme.CLASS);
    Map<String, String> attrs = new HashMap<>();
    attrs.put("certSSH", "true");
    InstanceConfirmation confirmation = new InstanceConfirmation()
            .setDomain("athenz").setService("production").setProvider("athenz.provider")
            .setAttributes(attrs);
    InstanceCertManager instanceManager = Mockito.spy(ztsImpl.instanceCertManager);
    Mockito.when(instanceProviderManager.getProvider(eq("athenz.provider"), Mockito.any())).thenReturn(providerClient);
    Mockito.when(providerClient.confirmInstance(Mockito.any())).thenReturn(confirmation);
    Mockito.when(instanceManager.insertX509CertRecord(Mockito.any())).thenReturn(true);
    path = Paths.get("src/test/resources/athenz.instanceid.pem");
    String pem = new String(Files.readAllBytes(path));
    
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.production")
            .setX509Certificate(pem);
    Mockito.doReturn(identity).when(instanceManager).generateIdentity(Mockito.any(),
            Mockito.any(), Mockito.any(), Mockito.anyInt());
    
    ztsImpl.instanceProviderManager = instanceProviderManager;
    ztsImpl.instanceCertManager = instanceManager;
    
    InstanceRegisterInformation info = new InstanceRegisterInformation()
            .setAttestationData("attestationData").setCsr(certCsr)
            .setDomain("athenz").setService("production")
            .setProvider("athenz.provider").setToken(true);
    ResourceContext context = createResourceContext(null);
    Response response = ztsImpl.postInstanceRegisterInformation(context, info);
    assertEquals(response.getStatus(), 201);
    InstanceIdentity resIdentity = (InstanceIdentity) response.getEntity();
    assertNotNull(resIdentity.getX509Certificate());
}