@Test public void testStartWorkflowParam() { Map<String, Object> input = new HashMap<>(); input.put("1", "abc"); String workflowID = "w112"; when(mockWorkflowService.startWorkflow(anyString(), anyInt(), anyString(), anyMapOf(String.class, Object.class))).thenReturn(workflowID); assertEquals("w112", workflowResource.startWorkflow("test1", 1, "c123", input)); }
@Test public void folder_can_fetch_more_than_10_envelopes() throws MessagingException { when(mockStore.processRequest(anyString(), anyString(), anyString(), anyMapOf(String.class, String.class))) .thenReturn(mockDataSet); List<WebDavMessage> messages = new ArrayList<>(); for (int i = 0; i < 15; i++) { WebDavMessage mockMessage = createWebDavMessage(i); messages.add(mockMessage); } FetchProfile profile = new FetchProfile(); profile.add(FetchProfile.Item.ENVELOPE); folder.fetch(messages, profile, listener); }
@Test public void testStartWorkflowParam() { WorkflowDef workflowDef = new WorkflowDef(); workflowDef.setName("test"); workflowDef.setVersion(1); Map<String, Object> input = new HashMap<>(); input.put("1", "abc"); String workflowID = "w112"; when(mockMetadata.getWorkflowDef(anyString(), anyInt())).thenReturn(workflowDef); when(mockWorkflowExecutor.startWorkflow(anyString(), anyInt(), anyString(), anyMapOf(String.class, Object.class), any(String.class))).thenReturn(workflowID); assertEquals("w112", workflowService.startWorkflow("test", 1, "c123", input)); }
@Test( expected = KettleException.class ) public void testExecService() throws Exception { HttpGet httpGetMock = mock( HttpGet.class ); URI uriMock = new URI( "fake" ); doReturn( uriMock ).when( httpGetMock ).getURI(); doReturn( httpGetMock ).when( slaveServer ).buildExecuteServiceMethod( anyString(), anyMapOf( String.class, String.class ) ); slaveServer.setHostname( "hostNameStub" ); slaveServer.setUsername( "userNAmeStub" ); slaveServer.execService( "wrong_app_name" ); fail( "Incorrect connection details had been used, but no exception was thrown" ); }
@Test public void folder_can_fetch_less_than_10_envelopes() throws MessagingException { when(mockStore.processRequest(anyString(), anyString(), anyString(), anyMapOf(String.class, String.class))) .thenReturn(mockDataSet); List<WebDavMessage> messages = new ArrayList<>(); for (int i = 0; i < 5; i++) { WebDavMessage mockMessage = createWebDavMessage(i); messages.add(mockMessage); } FetchProfile profile = new FetchProfile(); profile.add(FetchProfile.Item.ENVELOPE); folder.fetch(messages, profile, listener); }
@Test public void folder_can_fetch_more_than_20_flags() throws MessagingException { when(mockStore.processRequest(anyString(), anyString(), anyString(), anyMapOf(String.class, String.class))) .thenReturn(mockDataSet); List<WebDavMessage> messages = new ArrayList<>(); for (int i = 0; i < 25; i++) { WebDavMessage mockMessage = createWebDavMessage(i); messages.add(mockMessage); } FetchProfile profile = new FetchProfile(); profile.add(FetchProfile.Item.FLAGS); folder.fetch(messages, profile, listener); }
@Test public void folder_can_fetch_less_than_20_flags() throws MessagingException { when(mockStore.processRequest(anyString(), anyString(), anyString(), anyMapOf(String.class, String.class))) .thenReturn(mockDataSet); List<WebDavMessage> messages = new ArrayList<>(); for (int i = 0; i < 5; i++) { WebDavMessage mockMessage = createWebDavMessage(i); messages.add(mockMessage); } FetchProfile profile = new FetchProfile(); profile.add(FetchProfile.Item.FLAGS); folder.fetch(messages, profile, listener); }
@Test public void testStartWorkflow() { WorkflowDef workflowDef = new WorkflowDef(); workflowDef.setName("test"); workflowDef.setVersion(1); StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest(); startWorkflowRequest.setName("w123"); Map<String, Object> input = new HashMap<>(); input.put("1", "abc"); startWorkflowRequest.setInput(input); String workflowID = "w112"; when(mockMetadata.getWorkflowDef(anyString(), anyInt())).thenReturn(workflowDef); when(mockWorkflowExecutor.startWorkflow(anyString(), anyInt(), anyString(), anyMapOf(String.class, Object.class), any(String.class), any(String.class), anyMapOf(String.class, String.class))).thenReturn(workflowID); assertEquals("w112", workflowService.startWorkflow(startWorkflowRequest)); }
@Test public void folder_does_not_notify_listener_twice_when_fetching_flags_and_bodies() throws MessagingException, IOException, URISyntaxException { setupStoreForMessageFetching(); when(mockStore.processRequest(anyString(), anyString(), anyString(), anyMapOf(String.class, String.class))) .thenReturn(mockDataSet); List<WebDavMessage> messages = setup25MessagesToFetch(); when(mockHttpClient.executeOverride(any(HttpUriRequest.class), nullable(HttpContext.class))).thenAnswer( new Answer<HttpResponse>() { @Override public HttpResponse answer(InvocationOnMock invocation) throws Throwable { HttpResponse httpResponse = mock(HttpResponse.class); StatusLine statusLine = mock(StatusLine.class); when(httpResponse.getStatusLine()).thenReturn(statusLine); when(statusLine.getStatusCode()).thenReturn(200); BasicHttpEntity httpEntity = new BasicHttpEntity(); String body = ""; httpEntity.setContent(new ByteArrayInputStream(body.getBytes("UTF-8"))); when(httpResponse.getEntity()).thenReturn(httpEntity); return httpResponse; } }); FetchProfile profile = new FetchProfile(); profile.add(FetchProfile.Item.FLAGS); profile.add(FetchProfile.Item.BODY); folder.fetch(messages, profile, listener); verify(listener, times(25)).messageStarted(any(String.class), anyInt(), anyInt()); verify(listener, times(25)).messageFinished(any(WebDavMessage.class), anyInt(), anyInt()); }
verify(listListener, times(1)).onAttachedEndpointListChanged(anyMapOf(EndpointAccessToken.class, EndpointKeyHash.class)); } catch (IOException e) { assertTrue("Unexpected exception " + e.getMessage(), false);
/** * Build up workerid-workerlogdir map for the old workers' dirs. */ @Test public void testIdentifyWorkerLogDirs() throws Exception { File port1Dir = new MockDirectoryBuilder().setDirName("/workers-artifacts/topo1/port1").build(); File mockMetaFile = new MockFileBuilder().setFileName("worker.yaml").build(); String expId = "id12345"; SortedSet<File> expected = new TreeSet<>(); expected.add(port1Dir); try { SupervisorUtils mockedSupervisorUtils = mock(SupervisorUtils.class); SupervisorUtils.setInstance(mockedSupervisorUtils); Map<String, Object> stormConf = Utils.readStormConfig(); WorkerLogs workerLogs = new WorkerLogs(stormConf, port1Dir, new StormMetricsRegistry()) { @Override public Optional<File> getMetadataFileForWorkerLogDir(File logDir) throws IOException { return Optional.of(mockMetaFile); } @Override public String getWorkerIdFromMetadataFile(String metaFile) { return expId; } }; when(mockedSupervisorUtils.readWorkerHeartbeatsImpl(anyMapOf(String.class, Object.class))).thenReturn(null); assertEquals(expected, workerLogs.getLogDirs(Collections.singleton(port1Dir), (wid) -> true)); } finally { SupervisorUtils.resetInstance(); } }
private void setUpDecisionService() { decisionEvaluationBuilderMock = mock(DecisionsEvaluationBuilder.class); when(decisionEvaluationBuilderMock.variables(anyMapOf(String.class, Object.class))).thenReturn(decisionEvaluationBuilderMock); decisionServiceMock = mock(DecisionService.class); when(decisionServiceMock.evaluateDecisionById(MockProvider.EXAMPLE_DECISION_DEFINITION_ID)).thenReturn(decisionEvaluationBuilderMock); when(decisionServiceMock.evaluateDecisionByKey(MockProvider.EXAMPLE_DECISION_DEFINITION_KEY)).thenReturn(decisionEvaluationBuilderMock); when(processEngine.getDecisionService()).thenReturn(decisionServiceMock); }
@Before public void setUp() { ParseTestUtils.setTestParseUser(); // Mock ParseAnalyticsController controller = mock(ParseAnalyticsController.class); when(controller.trackEventInBackground( anyString(), anyMapOf(String.class, String.class), anyString())).thenReturn(Task.<Void>forResult(null)); when(controller.trackAppOpenedInBackground( anyString(), anyString())).thenReturn(Task.<Void>forResult(null)); ParseCorePlugins.getInstance().registerAnalyticsController(controller); }
@Test public void testCompleteNonExistingTask() { doThrow(new NotFoundException()) .when(externalTaskService) .complete(any(String.class), any(String.class), anyMapOf(String.class, Object.class), anyMapOf(String.class, Object.class)); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("workerId", "aWorkerId"); given() .contentType(POST_JSON_CONTENT_TYPE) .body(parameters) .pathParam("id", "anExternalTaskId") .then() .expect() .statusCode(Status.NOT_FOUND.getStatusCode()) .body("type", equalTo(RestException.class.getSimpleName())) .body("message", equalTo("External task with id anExternalTaskId does not exist")) .when() .post(COMPLETE_EXTERNAL_TASK_URL); }
@Test public void testHandleBpmnErrorThrowsAuthorizationException() { doThrow(new AuthorizationException("aMessage")) .when(externalTaskService) .handleBpmnError(any(String.class), any(String.class), any(String.class), any(String.class), anyMapOf(String.class, Object.class)); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("workerId", "aWorkerId"); parameters.put("errorCode", "errorCode"); given() .contentType(POST_JSON_CONTENT_TYPE) .body(parameters) .pathParam("id", "anExternalTaskId") .then() .expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .body("type", equalTo(AuthorizationException.class.getSimpleName())) .body("message", equalTo("aMessage")) .when() .post(HANDLE_EXTERNAL_TASK_BPMN_ERROR_URL); }
@Test public void testCompleteThrowsAuthorizationException() { doThrow(new AuthorizationException("aMessage")) .when(externalTaskService) .complete(any(String.class), any(String.class), anyMapOf(String.class, Object.class), anyMapOf(String.class, Object.class)); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("workerId", "aWorkerId"); given() .contentType(POST_JSON_CONTENT_TYPE) .body(parameters) .pathParam("id", "anExternalTaskId") .then() .expect() .statusCode(Status.FORBIDDEN.getStatusCode()) .body("type", equalTo(AuthorizationException.class.getSimpleName())) .body("message", equalTo("aMessage")) .when() .post(COMPLETE_EXTERNAL_TASK_URL); }
@Test public void testCompleteThrowsBadUserRequestException() { doThrow(new BadUserRequestException("aMessage")) .when(externalTaskService) .complete(any(String.class), any(String.class), anyMapOf(String.class, Object.class), anyMapOf(String.class, Object.class)); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("workerId", "aWorkerId"); given() .contentType(POST_JSON_CONTENT_TYPE) .body(parameters) .pathParam("id", "anExternalTaskId") .then() .expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .body("type", equalTo(RestException.class.getSimpleName())) .body("message", equalTo("aMessage")) .when() .post(COMPLETE_EXTERNAL_TASK_URL); }
@Test public void testHandleBpmnErrorNonExistingTask() { doThrow(new NotFoundException()) .when(externalTaskService) .handleBpmnError(any(String.class), any(String.class), any(String.class), any(String.class), anyMapOf(String.class, Object.class)); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("workerId", "aWorkerId"); parameters.put("errorCode", "errorCode"); given() .contentType(POST_JSON_CONTENT_TYPE) .body(parameters) .pathParam("id", "anExternalTaskId") .then() .expect() .statusCode(Status.NOT_FOUND.getStatusCode()) .body("type", equalTo(RestException.class.getSimpleName())) .body("message", equalTo("External task with id anExternalTaskId does not exist")) .when() .post(HANDLE_EXTERNAL_TASK_BPMN_ERROR_URL); }
@Test public void testHandleBpmnErrorThrowsBadUserRequestException() { doThrow(new BadUserRequestException("aMessage")) .when(externalTaskService) .handleBpmnError(any(String.class), any(String.class), any(String.class), any(String.class), anyMapOf(String.class, Object.class)); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("workerId", "aWorkerId"); parameters.put("errorCode", "errorCode"); given() .contentType(POST_JSON_CONTENT_TYPE) .body(parameters) .pathParam("id", "anExternalTaskId") .then() .expect() .statusCode(Status.BAD_REQUEST.getStatusCode()) .body("type", equalTo(RestException.class.getSimpleName())) .body("message", equalTo("aMessage")) .when() .post(HANDLE_EXTERNAL_TASK_BPMN_ERROR_URL); }
@Test public void testLoginWithAsyncWithoutExistingLazyUser() throws ParseException { ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class); when(currentUserController.getAsync(false)).thenReturn(Task.<ParseUser>forResult(null)); when(currentUserController.setAsync(any(ParseUser.class))) .thenReturn(Task.<Void>forResult(null)); ParseUser.State userState = mock(ParseUser.State.class); when(userState.className()).thenReturn("_User"); when(userState.objectId()).thenReturn("1234"); when(userState.isComplete()).thenReturn(true); ParseUserController userController = mock(ParseUserController.class); when(userController.logInAsync(anyString(), anyMapOf(String.class, String.class))) .thenReturn(Task.forResult(userState)); ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController); ParseCorePlugins.getInstance().registerUserController(userController); String authType = "facebook"; Map<String, String> authData = new HashMap<>(); authData.put("token", "123"); ParseUser user = ParseTaskUtils.wait(ParseUser.logInWithInBackground(authType, authData)); verify(currentUserController).getAsync(false); verify(userController).logInAsync(authType, authData); verify(currentUserController).setAsync(user); assertSame(userState, user.getState()); verifyNoMoreInteractions(currentUserController); verifyNoMoreInteractions(userController); }