use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeleteQuotaFailureRetry.
@Test
public void testExecuteDeleteQuotaFailureRetry() {
String domainName = "putquota";
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.deleteQuota(domainName)).thenThrow(new ResourceException(ResourceException.CONFLICT, "conflict"));
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.executeDeleteQuota(mockDomRsrcCtx, domainName, auditRef, "deleteQuota");
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.CONFLICT, 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 testExecutePutAssertionConditions.
@Test
public void testExecutePutAssertionConditions() {
ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
String domain = "assertion-conditions-dom";
String policy = "assertion-conditions-pol";
ObjectStore savedStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
Domain dom = new Domain().setName(domain);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(conn);
Mockito.when(conn.getDomain(anyString())).thenReturn(dom);
Map<String, AssertionConditionData> m1 = new HashMap<>();
AssertionConditionData cd11 = new AssertionConditionData().setOperator(AssertionConditionOperator.EQUALS).setValue("host1");
m1.put("instances", cd11);
AssertionConditionData cd12 = new AssertionConditionData().setOperator(AssertionConditionOperator.EQUALS).setValue("ENFORCE");
m1.put("enforcementState", cd12);
AssertionCondition c1 = new AssertionCondition().setId(1).setConditionsMap(m1);
Map<String, AssertionConditionData> m2 = new HashMap<>();
AssertionConditionData cd21 = new AssertionConditionData().setOperator(AssertionConditionOperator.EQUALS).setValue("host2");
m2.put("instances", cd21);
AssertionConditionData cd22 = new AssertionConditionData().setOperator(AssertionConditionOperator.EQUALS).setValue("REPORT");
m2.put("enforcementState", cd22);
AssertionCondition c2 = new AssertionCondition().setId(2).setConditionsMap(m2);
AssertionConditions ac1 = new AssertionConditions().setConditionsList(new ArrayList<>());
ac1.getConditionsList().add(c1);
ac1.getConditionsList().add(c2);
Mockito.when(conn.insertAssertionConditions(1, ac1)).thenReturn(true).thenReturn(false).thenThrow(new ResourceException(ResourceException.CONFLICT));
int savedRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.executePutAssertionConditions(mockDomRsrcCtx, domain, policy, 1L, ac1, auditRef, "PutAssertionConditions");
} catch (ResourceException ignored) {
fail();
}
try {
zms.dbService.executePutAssertionConditions(mockDomRsrcCtx, domain, policy, 1L, ac1, auditRef, "PutAssertionConditions");
fail();
} catch (ResourceException re) {
assertEquals(re.getCode(), ResourceException.BAD_REQUEST);
}
try {
zms.dbService.executePutAssertionConditions(mockDomRsrcCtx, domain, policy, 1L, ac1, auditRef, "PutAssertionConditions");
fail();
} catch (ResourceException re) {
assertEquals(re.getCode(), ResourceException.CONFLICT);
}
zms.dbService.defaultRetryCount = savedRetryCount;
zms.dbService.store = savedStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testProcessDomainWithSameTagsUpdate.
@Test
public void testProcessDomainWithSameTagsUpdate() {
ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
ObjectStore savedStore = zms.dbService.store;
Map<String, TagValueList> domainTags = Collections.singletonMap("tagKey", new TagValueList().setList(Arrays.asList("val1", "val2")));
Domain domain = new Domain().setName("newDomainTagsUpdate").setTags(domainTags);
Mockito.when(conn.insertDomain(domain)).thenReturn(true);
Mockito.when(conn.insertDomainTags("newDomainTagsUpdate", domainTags)).thenReturn(true);
Mockito.when(conn.insertRole(anyString(), any(Role.class))).thenReturn(true);
Mockito.when(conn.insertRoleMember(any(), any(), any(), any(), any())).thenReturn(true);
Mockito.when(conn.insertPolicy(any(), any())).thenReturn(true);
Mockito.when(conn.insertAssertion(any(), any(), any(), any())).thenReturn(true);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(conn).thenReturn(conn).thenReturn(conn).thenReturn(conn).thenReturn(conn).thenReturn(conn);
zms.dbService.store = mockObjStore;
Domain createdDomain = zms.dbService.makeDomain(mockDomRsrcCtx, domain, Collections.singletonList(adminUser), null, auditRef);
assertEquals(createdDomain.getTags(), domainTags);
// same tags tags
Map<String, TagValueList> newDomainTags = Collections.singletonMap("tagKey", new TagValueList().setList(Arrays.asList("val1", "val2")));
Mockito.when(conn.updateDomain(any(Domain.class))).thenReturn(true);
Mockito.when(conn.deleteDomainTags(anyString(), anySet())).thenReturn(true);
Mockito.when(conn.insertDomainTags(anyString(), anyMap())).thenReturn(true);
Mockito.when(conn.getDomain("newDomainTagsUpdate")).thenReturn(domain);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(conn).thenReturn(conn).thenReturn(conn).thenReturn(conn);
// update domain meta
DomainMeta meta = new DomainMeta().setTags(newDomainTags);
zms.dbService.executePutDomainMeta(mockDomRsrcCtx, domain, meta, null, false, auditRef, "putDomainMeta");
// assert tags to remove is empty
ArgumentCaptor<Set<String>> tagCapture = ArgumentCaptor.forClass(Set.class);
ArgumentCaptor<String> domainCapture = ArgumentCaptor.forClass(String.class);
Mockito.verify(conn, times(0)).deleteDomainTags(domainCapture.capture(), tagCapture.capture());
// assert tags to add is empty
ArgumentCaptor<Map<String, TagValueList>> tagInsertCapture = ArgumentCaptor.forClass(Map.class);
Mockito.verify(conn, times(1)).insertDomainTags(domainCapture.capture(), tagInsertCapture.capture());
// assert first tag insertion
Map<String, TagValueList> resultFirstInsertTags = tagInsertCapture.getAllValues().get(0);
assertEquals(resultFirstInsertTags, Collections.singletonMap("tagKey", new TagValueList().setList(Arrays.asList("val1", "val2"))));
zms.dbService.store = savedStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutGroupFailure.
@Test
public void testExecutePutGroupFailure() {
final String domainName = "put-group-failure";
final String groupName = "group1";
Group group = createGroupObject(domainName, groupName, "user.user2", "user.user3");
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.insertGroup(anyString(), any(Group.class))).thenReturn(false);
Domain domain = new Domain().setName(domainName);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executePutGroup(mockDomRsrcCtx, domainName, groupName, group, auditRef);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.INTERNAL_SERVER_ERROR);
}
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testGetPendingMembershipNotificationsTimestampUpdateFailed.
@Test
public void testGetPendingMembershipNotificationsTimestampUpdateFailed() {
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.updatePendingRoleMembersNotificationTimestamp(anyString(), anyLong(), anyInt())).thenReturn(false);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
Set<String> recipientsRes = zms.dbService.getPendingMembershipApproverRoles(0);
assertNull(recipientsRes);
zms.dbService.store = saveStore;
}
Aggregations