@Test
public void testPutRoleMeta() {

    TopLevelDomain dom1 = createTopLevelDomainObject("rolemetadom1",
            "Role Meta Test Domain1", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1);
    Role role1 = createRoleObject("rolemetadom1", "role1", null,
            "user.john", "user.jane");
    zms.putRole(mockDomRsrcCtx, "rolemetadom1", "role1", auditRef, role1);
    RoleMeta rm = createRoleMetaObject(true);
    rm.setMemberExpiryDays(45);
    rm.setCertExpiryMins(55);
    rm.setServiceExpiryDays(45);
    rm.setGroupExpiryDays(50);
    rm.setTokenExpiryMins(65);
    rm.setMemberReviewDays(70);
    rm.setServiceReviewDays(80);
    rm.setSignAlgorithm("ec");
    zms.putRoleMeta(mockDomRsrcCtx, "rolemetadom1", "role1", auditRef, rm);
    Role resRole1 = zms.getRole(mockDomRsrcCtx, "rolemetadom1", "role1", true, false, false);
    assertNotNull(resRole1);
    assertTrue(resRole1.getSelfServe());
    assertEquals(resRole1.getMemberExpiryDays(), Integer.valueOf(45));
    assertEquals(resRole1.getCertExpiryMins(), Integer.valueOf(55));
    assertEquals(resRole1.getTokenExpiryMins(), Integer.valueOf(65));
    assertEquals(resRole1.getServiceExpiryDays(), Integer.valueOf(45));
    assertEquals(resRole1.getGroupExpiryDays(), Integer.valueOf(50));
    assertEquals(resRole1.getMemberReviewDays(), Integer.valueOf(70));
    assertEquals(resRole1.getServiceReviewDays(), Integer.valueOf(80));
    assertEquals(resRole1.getSignAlgorithm(), "ec");
    // if we pass a null for the expiry days (e.g. old client)
    // then we're not going to modify the value
    RoleMeta rm2 = createRoleMetaObject(false);
    zms.putRoleMeta(mockDomRsrcCtx, "rolemetadom1", "role1", auditRef, rm2);
    resRole1 = zms.getRole(mockDomRsrcCtx, "rolemetadom1", "role1", true, false, false);
    assertNotNull(resRole1);
    assertNull(resRole1.getSelfServe());
    assertEquals(resRole1.getMemberExpiryDays(), Integer.valueOf(45));
    assertEquals(resRole1.getServiceExpiryDays(), Integer.valueOf(45));
    assertEquals(resRole1.getGroupExpiryDays(), Integer.valueOf(50));
    assertEquals(resRole1.getCertExpiryMins(), Integer.valueOf(55));
    assertEquals(resRole1.getTokenExpiryMins(), Integer.valueOf(65));
    assertEquals(resRole1.getMemberReviewDays(), Integer.valueOf(70));
    assertEquals(resRole1.getServiceReviewDays(), Integer.valueOf(80));
    // now let's reset to 0
    RoleMeta rm3 = createRoleMetaObject(false);
    rm3.setMemberExpiryDays(0);
    rm3.setServiceExpiryDays(0);
    rm3.setGroupExpiryDays(0);
    rm3.setCertExpiryMins(0);
    rm3.setTokenExpiryMins(85);
    rm3.setMemberReviewDays(0);
    rm3.setServiceReviewDays(0);
    zms.putRoleMeta(mockDomRsrcCtx, "rolemetadom1", "role1", auditRef, rm3);
    resRole1 = zms.getRole(mockDomRsrcCtx, "rolemetadom1", "role1", true, false, false);
    assertNotNull(resRole1);
    assertNull(resRole1.getSelfServe());
    assertNull(resRole1.getMemberExpiryDays());
    assertNull(resRole1.getServiceExpiryDays());
    assertNull(resRole1.getGroupExpiryDays());
    assertNull(resRole1.getCertExpiryMins());
    assertEquals(resRole1.getTokenExpiryMins(), Integer.valueOf(85));
    assertNull(resRole1.getMemberReviewDays());
    assertNull(resRole1.getServiceReviewDays());
    // invalid negative values
    RoleMeta rm4 = createRoleMetaObject(false);
    rm4.setMemberExpiryDays(-10);
    try {
        zms.putRoleMeta(mockDomRsrcCtx, "rolemetadom1", "role1", auditRef, rm4);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
    }
    rm4.setMemberExpiryDays(10);
    rm4.setServiceExpiryDays(-10);
    try {
        zms.putRoleMeta(mockDomRsrcCtx, "rolemetadom1", "role1", auditRef, rm4);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
    }
    rm4.setMemberExpiryDays(10);
    rm4.setServiceExpiryDays(10);
    rm4.setGroupExpiryDays(-10);
    try {
        zms.putRoleMeta(mockDomRsrcCtx, "rolemetadom1", "role1", auditRef, rm4);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
    }
    rm4.setMemberExpiryDays(10);
    rm4.setServiceExpiryDays(10);
    rm4.setGroupExpiryDays(10);
    rm4.setCertExpiryMins(-10);
    try {
        zms.putRoleMeta(mockDomRsrcCtx, "rolemetadom1", "role1", auditRef, rm4);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
    }
    rm4.setMemberExpiryDays(10);
    rm4.setServiceExpiryDays(10);
    rm4.setCertExpiryMins(10);
    rm4.setTokenExpiryMins(-10);
    try {
        zms.putRoleMeta(mockDomRsrcCtx, "rolemetadom1", "role1", auditRef, rm4);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
    }
    rm4.setMemberExpiryDays(10);
    rm4.setServiceExpiryDays(10);
    rm4.setCertExpiryMins(10);
    rm4.setTokenExpiryMins(10);
    rm4.setMemberReviewDays(-10);
    try {
        zms.putRoleMeta(mockDomRsrcCtx, "rolemetadom1", "role1", auditRef, rm4);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
    }
    rm4.setMemberExpiryDays(10);
    rm4.setServiceExpiryDays(10);
    rm4.setCertExpiryMins(10);
    rm4.setTokenExpiryMins(10);
    rm4.setMemberReviewDays(10);
    rm4.setServiceReviewDays(-10);
    try {
        zms.putRoleMeta(mockDomRsrcCtx, "rolemetadom1", "role1", auditRef, rm4);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
    }
    zms.deleteTopLevelDomain(mockDomRsrcCtx, "rolemetadom1", auditRef);
}