@Test
public void testPutDomainMeta() {

    TopLevelDomain dom1 = createTopLevelDomainObject("MetaDom1",
            "Test Domain1", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1);
    Domain resDom1 = zms.getDomain(mockDomRsrcCtx, "MetaDom1");
    assertNotNull(resDom1);
    assertEquals(resDom1.getDescription(), "Test Domain1");
    assertEquals(resDom1.getOrg(), "testorg");
    assertTrue(resDom1.getEnabled());
    assertFalse(resDom1.getAuditEnabled());
    assertNull(resDom1.getServiceCertExpiryMins());
    assertNull(resDom1.getRoleCertExpiryMins());
    assertNull(resDom1.getMemberExpiryDays());
    assertNull(resDom1.getServiceExpiryDays());
    assertNull(resDom1.getGroupExpiryDays());
    assertNull(resDom1.getTokenExpiryMins());
    DomainMeta meta = createDomainMetaObject("Test2 Domain", "NewOrg",
            true, true, "12345", 1001);
    meta.setCertDnsDomain("YAHOO.cloud");
    meta.setServiceCertExpiryMins(100);
    meta.setRoleCertExpiryMins(200);
    meta.setSignAlgorithm("ec");
    zms.putDomainMeta(mockDomRsrcCtx, "MetaDom1", auditRef, meta);
    zms.putDomainSystemMeta(mockDomRsrcCtx, "MetaDom1", "auditenabled", auditRef, meta);
    zms.putDomainSystemMeta(mockDomRsrcCtx, "MetaDom1", "account", auditRef, meta);
    zms.putDomainSystemMeta(mockDomRsrcCtx, "MetaDom1", "certdnsdomain", auditRef, meta);
    setupPrincipalSystemMetaDelete(zms, mockDomRsrcCtx.principal().getFullName(), "metadom1", "productid", "org", "certdnsdomain");
    zms.putDomainSystemMeta(mockDomRsrcCtx, "MetaDom1", "org", auditRef, meta);
    zms.putDomainSystemMeta(mockDomRsrcCtx, "MetaDom1", "productid", auditRef, meta);
    Domain resDom3 = zms.getDomain(mockDomRsrcCtx, "MetaDom1");
    assertNotNull(resDom3);
    assertEquals(resDom3.getDescription(), "Test2 Domain");
    assertEquals(resDom3.getOrg(), "neworg");
    assertTrue(resDom3.getEnabled());
    assertTrue(resDom3.getAuditEnabled());
    assertEquals(resDom3.getAccount(), "12345");
    assertEquals(Integer.valueOf(1001), resDom3.getYpmId());
    assertEquals(resDom3.getCertDnsDomain(), "yahoo.cloud");
    assertEquals(resDom3.getServiceCertExpiryMins(), Integer.valueOf(100));
    assertEquals(resDom3.getRoleCertExpiryMins(), Integer.valueOf(200));
    assertNull(resDom3.getMemberExpiryDays());
    assertNull(resDom3.getServiceExpiryDays());
    assertNull(resDom3.getGroupExpiryDays());
    assertNull(resDom3.getTokenExpiryMins());
    assertEquals(resDom3.getSignAlgorithm(), "ec");
    // put the meta data using same product id
    meta = createDomainMetaObject("just a new desc", "organs",
            true, true, "12345", 1001);
    meta.setMemberExpiryDays(300);
    meta.setServiceExpiryDays(350);
    meta.setGroupExpiryDays(375);
    meta.setTokenExpiryMins(400);
    zms.putDomainMeta(mockDomRsrcCtx, "MetaDom1", auditRef, meta);
    resDom3 = zms.getDomain(mockDomRsrcCtx, "MetaDom1");
    assertNotNull(resDom3);
    assertEquals(resDom3.getDescription(), "just a new desc");
    //org is system attr. so it wont be changed by putdomainmeta call
    assertEquals(resDom3.getOrg(), "neworg");
    assertTrue(resDom3.getEnabled());
    assertTrue(resDom3.getAuditEnabled());
    assertEquals(resDom3.getAccount(), "12345");
    assertEquals(Integer.valueOf(1001), resDom3.getYpmId());
    assertEquals(resDom3.getServiceCertExpiryMins(), Integer.valueOf(100));
    assertEquals(resDom3.getRoleCertExpiryMins(), Integer.valueOf(200));
    assertEquals(resDom3.getMemberExpiryDays(), Integer.valueOf(300));
    assertEquals(resDom3.getServiceExpiryDays(), Integer.valueOf(350));
    assertEquals(resDom3.getGroupExpiryDays(), Integer.valueOf(375));
    assertEquals(resDom3.getTokenExpiryMins(), Integer.valueOf(400));
    zms.putDomainSystemMeta(mockDomRsrcCtx, "MetaDom1", "org", auditRef, meta);
    resDom3 = zms.getDomain(mockDomRsrcCtx, "MetaDom1");
    assertNotNull(resDom3);
    assertEquals(resDom3.getOrg(), "organs");
    // put the meta data using new product
    meta = createDomainMetaObject("just a new desc", "organs",
            true, true, "12345", 1001);
    Integer newProductId = getRandomProductId();
    meta.setYpmId(newProductId);
    meta.setServiceCertExpiryMins(5);
    meta.setRoleCertExpiryMins(0);
    meta.setMemberExpiryDays(15);
    meta.setServiceExpiryDays(17);
    meta.setGroupExpiryDays(18);
    meta.setTokenExpiryMins(20);
    meta.setSignAlgorithm("rsa");
    zms.putDomainMeta(mockDomRsrcCtx, "MetaDom1", auditRef, meta);
    zms.putDomainSystemMeta(mockDomRsrcCtx, "MetaDom1", "productid", auditRef, meta);
    resDom3 = zms.getDomain(mockDomRsrcCtx, "MetaDom1");
    assertNotNull(resDom3);
    assertEquals(resDom3.getDescription(), "just a new desc");
    assertEquals(resDom3.getOrg(), "organs");
    assertTrue(resDom3.getEnabled());
    assertTrue(resDom3.getAuditEnabled());
    assertEquals(resDom3.getAccount(), "12345");
    assertEquals(newProductId, resDom3.getYpmId());
    assertEquals(resDom3.getServiceCertExpiryMins(), Integer.valueOf(5));
    assertNull(resDom3.getRoleCertExpiryMins());
    assertEquals(resDom3.getMemberExpiryDays(), Integer.valueOf(15));
    assertEquals(resDom3.getServiceExpiryDays(), Integer.valueOf(17));
    assertEquals(resDom3.getGroupExpiryDays(), Integer.valueOf(18));
    assertEquals(resDom3.getTokenExpiryMins(), Integer.valueOf(20));
    assertEquals(resDom3.getSignAlgorithm(), "rsa");
    cleanupPrincipalSystemMetaDelete(zms);
    zms.deleteTopLevelDomain(mockDomRsrcCtx, "MetaDom1", auditRef);
}