private void setupCopyResponse(String response) throws MessagingException, IOException { List<ImapResponse> imapResponses = singletonList(createImapResponse(response)); when(imapConnection.executeCommandWithIdSet(eq(Commands.UID_COPY), anyString(), anySetOf(Long.class))) .thenReturn(imapResponses); } }
private void setupUidSearchResponses(String... responses) throws MessagingException, IOException { List<ImapResponse> imapResponses = new ArrayList<>(responses.length); for (String response : responses) { imapResponses.add(createImapResponse(response)); } when(imapConnection.executeSimpleCommand(startsWith("UID SEARCH"))).thenReturn(imapResponses); when(imapConnection.executeCommandWithIdSet(startsWith("UID SEARCH"), anyString(), anySetOf(Long.class))) .thenReturn(imapResponses); }
@Test public void testInstanceRetrievalByListWithEmpty() { ProcessInstanceQuery instanceQuery = mock(ProcessInstanceQuery.class); when(instanceQuery.list()).thenReturn(null); String expectedExceptionMessage = "Set of process instance ids is empty"; doThrow(new ProcessEngineException(expectedExceptionMessage)).when(instanceQuery).processInstanceIds(anySetOf(String.class)); when(processEngine.getRuntimeService().createProcessInstanceQuery()).thenReturn(instanceQuery); String emptyList = ""; given() .queryParam("processInstanceIds", emptyList) .then() .expect() .statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()) .body("type", equalTo(ProcessEngineException.class.getSimpleName())) .body("message", equalTo(expectedExceptionMessage)) .when() .get(PROCESS_INSTANCE_QUERY_URL); }
@Test public void testInstanceRetrievalByListWithEmptyAsPost() { ProcessInstanceQuery instanceQuery = mock(ProcessInstanceQuery.class); when(instanceQuery.list()).thenReturn(null); String expectedExceptionMessage = "Set of process instance ids is empty"; doThrow(new ProcessEngineException(expectedExceptionMessage)).when(instanceQuery).processInstanceIds(anySetOf(String.class)); when(processEngine.getRuntimeService().createProcessInstanceQuery()).thenReturn(instanceQuery); Map<String, Set<String>> params = new HashMap<String, Set<String>>(); params.put("processInstanceIds", new HashSet<String>()); given() .contentType(POST_JSON_CONTENT_TYPE) .body(params) .then() .expect() .statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()) .body("type", equalTo(ProcessEngineException.class.getSimpleName())) .body("message", equalTo(expectedExceptionMessage)) .when() .post(PROCESS_INSTANCE_QUERY_URL); }
verify(connectionQueryServices, notExists ? times(1) : never() ).addColumn(eq(Collections.<Mutation>emptyList()), any(PTable.class), anyMap(), anySetOf(String.class), anyListOf(PColumn.class));
@Before public void setup() { this.service = new RuleNameServiceImpl(queryService, projectService); when(projectService.resolveModule(any(Path.class))).thenReturn(module); when(module.getRootPath()).thenReturn(projectRootPath); when(projectRootPath.toURI()).thenReturn(PROJECT_ROOT_URI); when(queryService.query(eq(FindRulesByModuleQuery.NAME), anySetOf(ValueIndexTerm.class))).thenReturn(getResults()); }
@Test public void testAdminOperation() throws Exception { Mockito.when(mockStore.createRole(anyString(), anyString(), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID)); Mockito.when(mockStore.dropRole(anyString(), anyString(), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 1)); Mockito.when(mockStore.alterRoleAddGroups(anyString(), anyString(), anySetOf(String.class),anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 2)); Mockito.when(mockStore.alterRoleDeleteGroups(anyString(), anyString(),anySetOf(String.class), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 3)); Mockito.when(mockStore.dropPrivilege(anyString(), any(PrivilegeObject.class), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 4)); Mockito.when(mockStore.renamePrivilege(anyString(), anyString(), anyListOf(Authorizable.class), anyListOf(Authorizable.class), anyString())) .thenReturn(new CommitContext(SERVER_UUID, SEQ_ID + 5)); testOperation(ADMIN_USER, Status.OK); }
@Test public void ignore_docker_execution_exceptions_in_rm() throws IOException, InterruptedException { String conflictingContainer = "conflictingContainer"; doThrow(new DockerExecutionException("The name \"" + conflictingContainer + "\" is already in use")) .doNothing() .when(dockerCompose).up(); doThrow(DockerExecutionException.class).when(docker).rm(anySetOf(String.class)); ConflictingContainerRemovingDockerCompose conflictingContainerRemovingDockerCompose = new ConflictingContainerRemovingDockerCompose(dockerCompose, docker); conflictingContainerRemovingDockerCompose.up(); verify(dockerCompose, times(2)).up(); verify(docker).rm(ImmutableSet.of(conflictingContainer)); }
@Test public void fail_on_non_docker_execution_exceptions_in_rm() throws IOException, InterruptedException { String conflictingContainer = "conflictingContainer"; doThrow(new DockerExecutionException("The name \"" + conflictingContainer + "\" is already in use")) .doNothing() .when(dockerCompose).up(); doThrow(RuntimeException.class).when(docker).rm(anySetOf(String.class)); exception.expect(RuntimeException.class); ConflictingContainerRemovingDockerCompose conflictingContainerRemovingDockerCompose = new ConflictingContainerRemovingDockerCompose(dockerCompose, docker); conflictingContainerRemovingDockerCompose.up(); }
public static RMContext createRMContext(Configuration conf) { RMContext mockRmContext = Mockito.spy(new RMContextImpl(null, null, null, null, null, null, new RMContainerTokenSecretManager(conf), new NMTokenSecretManagerInRM(conf), new ClientToAMTokenSecretManagerInRM(), null)); RMNodeLabelsManager nlm = mock(RMNodeLabelsManager.class); when( nlm.getQueueResource(any(String.class), anySetOf(String.class), any(Resource.class))).thenAnswer(new Answer<Resource>() { @Override public Resource answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); return (Resource) args[2]; } }); when(nlm.getResourceByLabel(any(String.class), any(Resource.class))) .thenAnswer(new Answer<Resource>() { @Override public Resource answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); return (Resource) args[1]; } }); mockRmContext.setNodeLabelManager(nlm); return mockRmContext; }
eq(pushOpts.getProj()), eq(pushOpts.getProjectVersion()), any(Resource.class), anySetOf(String.class), anyString())) .thenReturn(running);
public static RMContext createRMContext(Configuration conf) { RMContext mockRmContext = Mockito.spy(new RMContextImpl(null, null, null, null, null, null, new RMContainerTokenSecretManager(conf), new NMTokenSecretManagerInRM(conf), new ClientToAMTokenSecretManagerInRM(), null)); RMNodeLabelsManager nlm = mock(RMNodeLabelsManager.class); when(nlm.getQueueResource(any(String.class), anySetOf(String.class), any(Resource.class))).thenAnswer(new Answer<Resource>() { @Override public Resource answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); return (Resource) args[2]; } }); when(nlm.getResourceByLabel(any(String.class), any(Resource.class))) .thenAnswer(new Answer<Resource>() { @Override public Resource answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); return (Resource) args[1]; } }); mockRmContext.setNodeLabelManager(nlm); mockRmContext .setMultiNodeSortingManager(mock(MultiNodeSortingManager.class)); return mockRmContext; }
@Before public void setUp() { mockStatic(System.class); mockStatic(SystemClock.class); mockStatic(SharedPreferencesManager.class); PowerMockito.doAnswer(new Answer<Void>() { @Override @SuppressWarnings("unchecked") public Void answer(InvocationOnMock invocation) { /* Whenever the new state is persisted, make further calls return the new state. */ String key = (String) invocation.getArguments()[0]; Set<String> value = (Set<String>) invocation.getArguments()[1]; when(SharedPreferencesManager.getStringSet(key)).thenReturn(value); return null; } }).when(SharedPreferencesManager.class); SharedPreferencesManager.putStringSet(anyString(), anySetOf(String.class)); when(SharedPreferencesManager.getStringSet(anyString())).thenReturn(null); SessionContext.unsetInstance(); spendTime(1000); mChannel = mock(Channel.class); mSessionTracker = new SessionTracker(mChannel, TEST_GROUP); }
mSentryGMPrivilege.setRoles(Sets.newHashSet(role)); Mockito.when(mockStore.getRolesByGroups(anyString(), anySetOf(String.class))) .thenReturn(Sets.newHashSet(roleName)); Mockito.when(mockStore.getPrivilegesByProvider(anyString(), anyString(), anySetOf(String.class), anySetOf(String.class), anyListOf(Authorizable.class))) .thenReturn(Sets.newHashSet(queryPrivilege, updatePrivilege)); Mockito.when(mockStore.getGroupsByRoles(anyString(), anySetOf(String.class))) .thenReturn(Sets.newHashSet(groupName)); Mockito.when(mockStore.getPrivilegesByAuthorizable(anyString(), anyString(), anySetOf(String.class), anyListOf(Authorizable.class))) .thenReturn(Sets.newHashSet(mSentryGMPrivilege));
Mockito.when(mockStore.alterRoleAddGroups(anyString(), roleName, anySetOf(String.class),anyString())) .thenThrow(new SentryNoSuchObjectException("Role: " + roleName + " doesn't exist")); Mockito.when(mockStore.alterRoleDeleteGroups(anyString(), roleName, anySetOf(String.class), anyString())) .thenThrow(new SentryNoSuchObjectException("Role: " + roleName + " doesn't exist"));
mSentryGMPrivilege.setRoles(Sets.newHashSet(role)); Mockito.when(mockStore.getRolesByGroups(anyString(), anySetOf(String.class))) .thenReturn(Sets.newHashSet(roleName)); Mockito.when(mockStore.getPrivilegesByProvider(anyString(), anyString(), anySetOf(String.class), anySetOf(String.class), anyListOf(Authorizable.class))) .thenReturn(Sets.newHashSet(queryPrivilege, updatePrivilege)); Mockito.when(mockStore.getGroupsByRoles(anyString(), anySetOf(String.class))) .thenReturn(Sets.newHashSet(groupName)); TSentryRole tSentryRole = new TSentryRole(roleName, Sets.newHashSet(groupName)); mockTRoles.add(tSentryRole); Mockito.when(mockStore.getTSentryRolesByGroupName(anyString(), anySetOf(String.class))) .thenReturn(mockTRoles); Mockito.when(mockStore.getPrivilegesByAuthorizable(anyString(), anyString(), anySetOf(String.class), anyListOf(Authorizable.class))) .thenReturn(Sets.newHashSet(mSentryGMPrivilege));
Mockito.when(mockStore.alterRoleAddGroups(anyString(), roleName, anySetOf(String.class),anyString())) .thenThrow(new SentryNoSuchObjectException("Role: " + roleName)); Mockito.when(mockStore.alterRoleDeleteGroups(anyString(), roleName, anySetOf(String.class), anyString())) .thenThrow(new SentryNoSuchObjectException("Role: " + roleName));