use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testDeleteDomainDependencyRetryFailure.
@Test
public void testDeleteDomainDependencyRetryFailure() {
String domainName = "deleteDomainDependencyRetryFail1";
String serviceName = "service-retry1";
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.deleteDomainDependency(eq(domainName), eq(serviceName))).thenThrow(new ResourceException(ResourceException.CONFLICT));
Domain domain = new Domain().setName(domainName);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.deleteDomainDependency(mockDomRsrcCtx, domainName, serviceName, auditRef, "deleteDomainDependency");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.CONFLICT);
}
zms.dbService.defaultRetryCount = saveRetryCount;
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeleteDomainRoleMemberRetryException.
@Test
public void testExecuteDeleteDomainRoleMemberRetryException() {
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getPrincipalRoles("user.joe", "dom1")).thenThrow(new ResourceException(410));
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 3;
try {
zms.dbService.executeDeleteDomainRoleMember(mockDomRsrcCtx, "dom1", "user.joe", adminUser, "unittest");
fail();
} catch (ResourceException ex) {
assertEquals(410, ex.getCode());
}
zms.dbService.defaultRetryCount = saveRetryCount;
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutGroupMetaRetry.
@Test
public void testExecutePutGroupMetaRetry() {
final String domainName = "metadomTest1";
final String groupName = "metagroupTest1";
List<String> admins = new ArrayList<>();
admins.add(adminUser);
zms.dbService.makeDomain(mockDomRsrcCtx, ZMSTestUtils.makeDomainObject(domainName, "test desc", "testOrg", false, "", 1234, "", 0), admins, null, auditRef);
Group group = createGroupObject(domainName, groupName, "user.john", "user.jane");
zms.dbService.executePutGroup(mockDomRsrcCtx, domainName, groupName, group, "test");
GroupMeta gm = new GroupMeta();
gm.setSelfServe(true);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
zms.dbService.defaultRetryCount = 2;
Mockito.when(mockObjStore.getConnection(anyBoolean(), anyBoolean())).thenReturn(mockJdbcConn);
ResourceException rex = new ResourceException(409);
Mockito.when(mockJdbcConn.getGroup(eq(domainName), eq(groupName))).thenReturn(group);
Mockito.when(mockJdbcConn.updateGroup(eq(domainName), any(Group.class))).thenThrow(rex);
try {
zms.dbService.executePutGroupMeta(mockDomRsrcCtx, domainName, groupName, gm, auditRef);
fail();
} catch (ResourceException r) {
assertEquals(r.getCode(), 409);
assertTrue(r.getMessage().contains("Conflict"));
}
zms.dbService.store = saveStore;
zms.dbService.defaultRetryCount = 120;
zms.dbService.executeDeleteDomain(mockDomRsrcCtx, domainName, auditRef, "deletedomain");
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testUpdateRoleMetaWithExistingTag.
@Test
public void testUpdateRoleMetaWithExistingTag() {
final String domainName = "sys.auth";
final String initialTagKey = "initial-tag-key";
final List<String> initialTagValues = Collections.singletonList("initial-tag-value");
final String updateRoleMetaTag = "tag-key-update-role-meta-exist-tag";
final List<String> updateRoleMetaTagValues = Collections.singletonList("update-meta-value");
final String roleName = "roleWithTagUpdateMeta";
ObjectStore savedStore = zms.dbService.store;
// initial role with tags
Role role = new Role().setName(roleName).setTags(Collections.singletonMap(initialTagKey, new TagValueList().setList(initialTagValues)));
// role meta with updated tags
RoleMeta rm = new RoleMeta().setTags(Collections.singletonMap(updateRoleMetaTag, new TagValueList().setList(updateRoleMetaTagValues)));
// mock dbService store
ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(conn.updateRole(any(), any())).thenReturn(true);
Mockito.when(conn.deleteRoleTags(anyString(), anyString(), anySet())).thenReturn(true);
Mockito.when(conn.insertRoleTags(anyString(), anyString(), anyMap())).thenReturn(true);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(conn);
zms.dbService.store = mockObjStore;
// update role meta
zms.dbService.executePutRoleMeta(mockDomRsrcCtx, domainName, roleName, role, rm, auditRef, "testUpdateRoleMetaWithoutTag");
// assert tags to removed
ArgumentCaptor<Set<String>> tagCapture = ArgumentCaptor.forClass(Set.class);
ArgumentCaptor<String> roleCapture = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> domainCapture = ArgumentCaptor.forClass(String.class);
Mockito.verify(conn, times(1)).deleteRoleTags(roleCapture.capture(), domainCapture.capture(), tagCapture.capture());
assertEquals(roleName, roleCapture.getValue());
assertEquals(domainName, domainCapture.getValue());
assertTrue(tagCapture.getValue().contains(initialTagKey));
// assert tags to add
ArgumentCaptor<Map<String, TagValueList>> tagInsertCapture = ArgumentCaptor.forClass(Map.class);
Mockito.verify(conn, times(1)).insertRoleTags(roleCapture.capture(), domainCapture.capture(), tagInsertCapture.capture());
assertEquals(roleName, roleCapture.getValue());
assertEquals(domainName, domainCapture.getValue());
Map<String, TagValueList> resultInsertTags = tagInsertCapture.getAllValues().get(0);
TagValueList tagValues = resultInsertTags.get(updateRoleMetaTag);
assertNotNull(tagValues);
assertTrue(tagValues.getList().containsAll(updateRoleMetaTagValues));
zms.dbService.store = savedStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeleteGroupFailure.
@Test
public void testExecuteDeleteGroupFailure() {
final String domainName = "failure-del-groupdomain";
final String groupName = "group1";
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Mockito.when(mockJdbcConn.deleteGroup(domainName, groupName)).thenReturn(false);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executeDeleteGroup(mockDomRsrcCtx, domainName, groupName, auditRef);
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.NOT_FOUND, ex.getCode());
}
zms.dbService.store = saveStore;
}
Aggregations