protected void setup() throws Exception { mockApp = mock(App.class); Field f = App.class.getDeclaredField("INST"); f.setAccessible(true); f.set(null, mockApp); mockJobManager = mock(AppJobManager.class); mockEventBus = mock(EventBus.class); when(mockApp.jobManager()).thenReturn(mockJobManager); when(mockApp.eventBus()).thenReturn(mockEventBus); mockAppConfig = mock(AppConfig.class); when(mockAppConfig.possibleControllerClass(argThat(new StartsWith("testapp.controller.")))).thenReturn(true); mockActionContext = mock(ActionContext.class); when(mockActionContext.app()).thenReturn(mockApp); when(mockActionContext.config()).thenReturn(mockAppConfig); mockRouter = mock(Router.class); when(mockApp.config()).thenReturn(mockAppConfig); when(mockApp.router()).thenReturn(mockRouter); when(mockApp.getInstance(any(Class.class))).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); return $.newInstance((Class)args[0]); } }); mockReq = mock(H.Request.class); mockResp = mock(H.Response.class); }
protected void setup() throws Exception { initActMetricPlugin(); mockApp = mock(App.class); Field f = App.class.getDeclaredField("INST"); f.setAccessible(true); f.set(null, mockApp); mockSingletonRegistry = mock(SingletonRegistry.class); //when(mockApp.singletonRegistry()).thenReturn(mockSingletonRegistry); mockJobManager = mock(JobManager.class); when(mockApp.jobManager()).thenReturn(mockJobManager); mockEventBus = mock(EventBus.class); when(mockApp.eventBus()).thenReturn(mockEventBus); mockAppConfig = mock(AppConfig.class); when(mockAppConfig.possibleControllerClass(argThat(new StartsWith("testapp.controller.")))).thenReturn(true); mockActionContext = mock(ActionContext.class); when(mockActionContext.app()).thenReturn(mockApp); when(mockActionContext.config()).thenReturn(mockAppConfig); mockRouter = mock(Router.class); when(mockApp.config()).thenReturn(mockAppConfig); when(mockApp.router()).thenReturn(mockRouter); when(mockApp.router(Matchers.same(""))).thenReturn(mockRouter); when(mockApp.getInstance(any(Class.class))).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); Class<?> cls = (Class) args[0]; if (SessionManager.class == cls) { return new SessionManager(mockAppConfig); } return $.newInstance((Class)args[0]); } }); mockReq = mock(H.Request.class); mockResp = mock(ActResponse.class); when(mockReq.method()).thenReturn(H.Method.GET); }
@Test(dataProvider = "prefs") public void shouldExportContentsAsFile(String p) throws Exception { mvc.perform(get(p).param("export", "file")) .andExpect(status().is(200)) .andExpect(content().contentType(APPLICATION_XML)) .andExpect(header().string("Content-Disposition", new StartsWith("attachment;"))); }
@Test @RunAsClient public void masterpage_is_served_without_trailing_slash(@ArquillianResource URL baseUrl) { String url = baseUrl.toString(); url = url.substring(0, url.length() - 1); given() .auth().basic("ThePoltergeist", "bouh") .header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML) .expect() .statusCode(200) .header(HttpHeaders.CONTENT_TYPE, new StartsWith(MediaType.TEXT_HTML)) .when() .get(url); }
@Test @RunAsClient public void masterpage_is_served_with_trailing_slash(@ArquillianResource URL baseUrl) { given() .auth().basic("ThePoltergeist", "bouh") .header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML) .expect() .statusCode(200) .header(HttpHeaders.CONTENT_TYPE, new StartsWith(MediaType.TEXT_HTML)) .when() .get(baseUrl.toString()); }
@Test @RunAsClient public void json_home_is_served_on_rest_root(@ArquillianResource URL baseUrl) { given() .auth().basic("ThePoltergeist", "bouh") .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON) .expect() .statusCode(200) .header(HttpHeaders.CONTENT_TYPE, new StartsWith(MediaType.APPLICATION_JSON)) .when() .get(baseUrl.toString() + "rest/"); }
@Test @RunAsClient public void masterpage_is_correctly_served(@ArquillianResource URL baseUrl) { given() .auth().basic("ThePoltergeist", "bouh") .header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML) .expect() .statusCode(200) .header(HttpHeaders.CONTENT_TYPE, new StartsWith(MediaType.TEXT_HTML)) .when() .get(baseUrl.toString()); }
@Test @RunAsClient public void redirection_to_masterpage_is_working(@ArquillianResource URL baseUrl) { given() .auth().basic("ThePoltergeist", "bouh") .header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML) .expect() .statusCode(200) .header(HttpHeaders.CONTENT_TYPE, new StartsWith(MediaType.TEXT_HTML)) .when() .get(baseUrl.toString() + "subpage"); }
@Test public void headerTest() throws JMSException, UnknownHostException { TextMessage msg = Mockito.mock(TextMessage.class); Mockito.when(session.createTextMessage(Matchers.anyString())).thenReturn(msg); EventServiceBindingDescriptor eventServiceBindingDescriptor = Mockito.mock(EventServiceBindingDescriptor.class); Mockito.when(eventServiceBindingDescriptor.getServiceVersion()).thenReturn(new ServiceVersion(1, 0)); cut.marshallEvent(eventServiceBindingDescriptor, new ExpectedEvent("bob", "100 chancellors"), session); String thisHost = InetAddress.getLocalHost().getCanonicalHostName(); Mockito.verify(msg).setStringProperty(Matchers.eq(JMSPropertyConstants.MESSAGE_ID_FIELD_NAME), Matchers.anyString()); Mockito.verify(msg).setStringProperty(Matchers.eq(JMSPropertyConstants.MESSAGE_ROUTING_FIELD_NAME), Matchers.argThat(new StartsWith(thisHost))); }
private void testStopTaskInNonStopeableState(PipelineExecutorTask.Status notStopeableStatus) throws PipelineExecutorException { PipelineExecutorTaskImpl task = mock(PipelineExecutorTaskImpl.class); when(task.getId()).thenReturn(TASK_ID); when(task.getPipelineStatus()).thenReturn(notStopeableStatus); PipelineExecutorTaskManagerImpl.TaskEntry taskEntry = mock(PipelineExecutorTaskManagerImpl.TaskEntry.class); when(taskEntry.isAsync()).thenReturn(true); when(taskEntry.getTask()).thenReturn(task); taskManager.currentTasks.put(TASK_ID, taskEntry); taskManager.init(); expectedException.expectMessage(new StartsWith("A PipelineExecutorTask in status: " + notStopeableStatus.name() + " can not be stopped. Stop operation is available for the following status set:")); taskManager.stop(TASK_ID); }
@Test public void testDeleteActiveTask() throws Exception { PipelineExecutorTaskManagerImpl.TaskEntry taskEntry = mock(PipelineExecutorTaskManagerImpl.TaskEntry.class); taskManager.currentTasks.put(TASK_ID, taskEntry); expectedException.expectMessage(new StartsWith("An active PipelineExecutorTask was found for taskId: " + TASK_ID)); taskManager.delete(TASK_ID); }
private void testDeleteTaskInNonStopeableState(PipelineExecutorTask.Status nonStopeableStatus) throws Exception { PipelineExecutorTask task = mock(PipelineExecutorTask.class); when(task.getPipelineStatus()).thenReturn(nonStopeableStatus); PipelineExecutorTrace trace = mock(PipelineExecutorTrace.class); when(trace.getTask()).thenReturn(task); when(pipelineExecutorRegistry.getExecutorTrace(TASK_ID)).thenReturn(trace); expectedException.expectMessage(new StartsWith("A PipelineExecutorTask in status: " + nonStopeableStatus + " can not" + " be deleted. Delete operation is available for the following status set:")); taskManager.delete(TASK_ID); }
@Test public void test_index() throws Exception { mvc.perform(get("/")).andExpect(status().isOk()).andExpect( content().string(new Contains("<label>Say what ever:</label>"))).andExpect( content().string(new StartsWith("<!DOCTYPE html>"))); }