Java Code Examples for org.easymock.EasyMock#newCapture()
The following examples show how to use
org.easymock.EasyMock#newCapture() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestPlaceServiceLevelDowngradeListener.java From arcusplatform with Apache License 2.0 | 6 votes |
@Test public void testDoOnMessageServiceLevelBasic() { PlatformMessage message = createListenerAndMessage(ServiceLevel.BASIC); //setup mocks EasyMock.expect(mockCache.isServiceLevelChange(message)).andReturn(true); EasyMock.expect(mockVideoDao.countByTag(curPlaceId, VideoConstants.TAG_FAVORITE)).andReturn(5l); Capture<Date> deleteTimeCapture = EasyMock.newCapture(CaptureType.LAST); mockVideoDao.addToPurgePinnedRecording(EasyMock.eq(curPlaceId), EasyMock.capture(deleteTimeCapture)); EasyMock.expectLastCall(); replay(); long now = System.currentTimeMillis(); theListener.onMessage(message); Date deleteTime = deleteTimeCapture.getValue(); int deleteDelay = (int) TimeUnit.MILLISECONDS.toDays(deleteTime.getTime() - now); assertEquals(theListener.getPurgePinnedVideosAfterDays(), deleteDelay); verify(); }
Example 2
Source File: InsertHelperTest.java From fastods with GNU General Public License v3.0 | 6 votes |
@Test public void testInsertImageStream() throws IOException { final SVGRectangle rectangle = SVGRectangle.cm(0, 1, 2, 3); final Capture<DrawFrame> df = EasyMock.newCapture(); PowerMock.resetAll(); this.document.addExtraFile("Pictures/dest1.foo", "image/foo", new byte[0]); this.table.addShape(EasyMock.capture(df)); PowerMock.replayAll(); this.ih.insertImage(this.document, this.table, "frame", new ByteArrayInputStream(new byte[0]), "dest1.foo", rectangle); PowerMock.verifyAll(); TestHelper.assertXMLEquals( "<draw:frame draw:name=\"frame\" draw:z-index=\"0\" svg:x=\"0cm\" svg:y=\"1cm\" svg:width=\"2cm\" svg:height=\"3cm\">" + "<draw:image xlink:href=\"Pictures/dest1.foo\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" + "</draw:frame>", df.getValue()); }
Example 3
Source File: ClientSideSlbTest.java From buck with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testBackgroundHealthCheckIsScheduled() { Capture<Runnable> capture = EasyMock.newCapture(); EasyMock.expect( mockScheduler.scheduleWithFixedDelay( EasyMock.capture(capture), EasyMock.anyLong(), EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class))) .andReturn(mockFuture) .once(); EasyMock.expect(mockFuture.cancel(true)).andReturn(true).once(); EasyMock.expect(mockScheduler.shutdownNow()).andReturn(ImmutableList.of()).once(); EasyMock.expect(dispatcher.executorService().shutdownNow()) .andReturn(ImmutableList.of()) .once(); replayAll(); try (ClientSideSlb slb = new ClientSideSlb(config, mockScheduler, mockClient)) { Assert.assertTrue(capture.hasCaptured()); } verifyAll(); }
Example 4
Source File: TestCallTree.java From arcusplatform with Apache License 2.0 | 6 votes |
private static void initEasyMockVariableSupport(final SubsystemContext<? extends SubsystemModel> context){ // basically this is implementing variable support final Capture<String> nameRef = EasyMock.newCapture(CaptureType.LAST); final Capture<Object> valueRef = EasyMock.newCapture(CaptureType.LAST); EasyMock .expect(context.getVariable(EasyMock.capture(nameRef))) .andAnswer(new IAnswer<LooselyTypedReference>() { @Override public LooselyTypedReference answer() throws Throwable { String json = context.model().getAttribute(TypeMarker.string(), "_subvars:" + nameRef.getValue(), "null"); return JSON.fromJson(json, LooselyTypedReference.class); } }) .anyTimes(); context.setVariable(EasyMock.capture(nameRef), EasyMock.capture(valueRef)); EasyMock .expectLastCall() .andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { context.model().setAttribute("_subvars:" + nameRef.getValue(), JSON.toJson(valueRef.getValue())); return null; } }) .anyTimes(); }
Example 5
Source File: TestAlarmSubsystemSecurity.java From arcusplatform with Apache License 2.0 | 5 votes |
protected Capture<List<IncidentTrigger>> expectAddAlert() { Capture<List<IncidentTrigger>> triggerCapture = EasyMock.newCapture(); EasyMock .expect( incidentService.addAlert(EasyMock.eq(context), EasyMock.eq(SecurityAlarm.NAME), EasyMock.capture(triggerCapture)) ) .andReturn(null); return triggerCapture; }
Example 6
Source File: FilterGrokTest.java From ambari-logsearch with Apache License 2.0 | 5 votes |
public void init(FilterGrokDescriptor filterGrokDescriptor) throws Exception { mockOutputManager = EasyMock.strictMock(OutputManager.class); capture = EasyMock.newCapture(CaptureType.LAST); filterGrok = new FilterGrok(); filterGrok.loadConfig(filterGrokDescriptor); filterGrok.setOutputManager(mockOutputManager); filterGrok.setInput(EasyMock.mock(Input.class)); filterGrok.init(new LogFeederProps()); }
Example 7
Source File: TestDeviceServiceAdd.java From arcusplatform with Apache License 2.0 | 5 votes |
private Capture<Device> expectCreate(Device device) { final Capture<Device> deviceRef = EasyMock.newCapture(); EasyMock .expect(mockDeviceDao.save(EasyMock.capture(deviceRef))) .andAnswer(() -> { Device response = deviceRef.getValue().copy(); response.setCreated(new Date()); response.setModified(new Date() ); return response; }); return deviceRef; }
Example 8
Source File: TestDeviceServiceAdd.java From arcusplatform with Apache License 2.0 | 5 votes |
private Capture<Device> expectDeviceUpdate() { final Capture<Device> deviceRef = EasyMock.newCapture(); EasyMock.expect(mockDeviceDao.save(EasyMock.capture(deviceRef))) .andAnswer(() -> { Device response = deviceRef.getValue().copy(); response.setModified(new Date()); return response; }); return deviceRef; }
Example 9
Source File: TestConsoleUtilities.java From java-license-manager with Apache License 2.0 | 5 votes |
@Test public void testConfigureInterfaceDevice() throws InterruptedException { TextInterfaceDevice textInterfaceDevice = EasyMock.createStrictMock(TextInterfaceDevice.class); Capture<Thread> threadCapture = EasyMock.newCapture(); textInterfaceDevice.registerShutdownHook(EasyMock.capture(threadCapture)); EasyMock.expectLastCall(); textInterfaceDevice.printOutLn(); EasyMock.expectLastCall(); EasyMock.replay(textInterfaceDevice); ConsoleUtilities.configureInterfaceDevice(textInterfaceDevice); Thread captured = threadCapture.getValue(); assertNotNull("The thread should not be null.", captured); captured.start(); int i = 0; while(captured.getState() != Thread.State.TERMINATED && i < 10) { Thread.sleep(100); i++; } assertTrue("The thread took too long to complete.", i < 10); EasyMock.verify(textInterfaceDevice); }
Example 10
Source File: TestPlatformEventSchedulerService.java From arcusplatform with Apache License 2.0 | 5 votes |
protected void expectAndExecuteScheduleAt(Date scheduledTime) { Capture<Runnable> runnable = EasyMock.newCapture(); EasyMock .expect(mockScheduler.scheduleAt(EasyMock.capture(runnable), EasyMock.eq(scheduledTime))) .andAnswer(new RunAndAnswer(runnable)) .once(); }
Example 11
Source File: TestRequestEmailVerificationRESTHandler.java From arcusplatform with Apache License 2.0 | 5 votes |
private Capture<Person> mockSetup(Person curPerson, boolean personExist, boolean principalMatch, String source, int times) { EasyMock.expect(client.getPrincipalId()).andReturn(curPerson.getId()).times(times); EasyMock.expect(request.content()).andReturn(Unpooled.copiedBuffer(generateClientMessage(curPerson.getId(), generateRequest(source)).getBytes())).times(times); EasyMock.expect(ctx.channel()).andReturn(channel).times(times); EasyMock.expect(clientFactory.get(channel)).andReturn(client).times(times); platformMsgCapture = EasyMock.newCapture(CaptureType.ALL); EasyMock.expect(platformBus.send(EasyMock.capture(platformMsgCapture))).andAnswer( () -> { return Futures.immediateFuture(null); } ).anyTimes(); //logout always needs to be called client.logout(); EasyMock.expectLastCall().times(times); EasyMock.expect(authenticator.expireCookie()).andReturn(new DefaultCookie("test", "test")).times(times); if(principalMatch) { EasyMock.expect(client.getPrincipalName()).andReturn(curPerson.getEmail()).times(times); }else{ EasyMock.expect(client.getPrincipalName()).andReturn("[email protected]").times(times); } if(personExist) { EasyMock.expect(personDao.findById(curPerson.getId())).andReturn(curPerson).times(times); }else{ EasyMock.expect(personDao.findById(curPerson.getId())).andReturn(null).times(times); } Capture<Person> personUpdatedCapture = EasyMock.newCapture(CaptureType.ALL); EasyMock.expect(personDao.update(EasyMock.capture(personUpdatedCapture))).andReturn(curPerson).times(times); EasyMock.expect(mockPersonPlaceAssocDAO.findPlaceIdsByPerson(curPerson.getId())).andReturn(ImmutableSet.<UUID>of(curPerson.getCurrPlace())).anyTimes(); return personUpdatedCapture; }
Example 12
Source File: BaseAlarmSubsystemTestCase.java From arcusplatform with Apache License 2.0 | 5 votes |
protected Capture<List<IncidentTrigger>> expectAddPreAlert() { Capture<List<IncidentTrigger>> triggerCapture = EasyMock.newCapture(); EasyMock .expect( incidentService.addPreAlert(EasyMock.eq(context), EasyMock.eq(SecurityAlarm.NAME), EasyMock.isA(Date.class), EasyMock.capture(triggerCapture)) ) .andReturn(Address.platformService(UUID.randomUUID(), AlarmIncidentCapability.NAMESPACE)); return triggerCapture; }
Example 13
Source File: TestAlarmSubsystem_InactiveRequests.java From arcusplatform with Apache License 2.0 | 5 votes |
/** * The only alarm that can go from inactive to alert. */ @Test public void testPanic() { MessageReceivedEvent request = panicRequest(); Capture<List<IncidentTrigger>> triggerCapture = EasyMock.newCapture(); EasyMock .expect( incidentService.addAlert(EasyMock.eq(context), EasyMock.eq(AlarmSubsystemCapability.ACTIVEALERTS_PANIC), EasyMock.capture(triggerCapture)) ) .andReturn(Address.platformService(UUID.randomUUID(), AlarmIncidentCapability.NAMESPACE)); Capture<List<IncidentTrigger>> updateCapture = EasyMock.newCapture(); incidentService.updateIncident(EasyMock.eq(context), EasyMock.capture(triggerCapture)); EasyMock.expectLastCall(); replay(); MessageBody empty = sendRequest(request); assertEquals(MessageBody.emptyMessage(), empty); assertEquals(AlarmCapability.ALERTSTATE_ALERT, AlarmModel.getAlertState(AlarmSubsystemCapability.ACTIVEALERTS_PANIC, model)); assertAlerting(AlarmSubsystemCapability.ACTIVEALERTS_PANIC); List<IncidentTrigger> triggers = triggerCapture.getValue(); assertEquals(1, triggers.size()); IncidentTrigger trigger = triggers.get(0); assertEquals(TriggerEvent.VERIFIED_ALARM.name(), trigger.getEvent()); verify(); }
Example 14
Source File: TestLockDeviceRESTHandler.java From arcusplatform with Apache License 2.0 | 4 votes |
private FullHttpResponse callLockDeviceRequest(String curDeviceId, String curReason, boolean curSuccess, boolean curPersonMatch) throws Exception { EasyMock.expect(client.getPrincipalId()).andReturn(curLoggedPerson.getId()).anyTimes(); EasyMock.expect(request.content()).andReturn(Unpooled.copiedBuffer(generateClientMessage(generateRequest(curDeviceId, curReason)).getBytes())); EasyMock.expect(ctx.channel()).andReturn(channel).anyTimes(); EasyMock.expect(clientFactory.get(channel)).andReturn(client).anyTimes(); Capture<PlatformMessage> platformMsgCapture = EasyMock.newCapture(CaptureType.ALL); EasyMock.expect(platformBus.send(EasyMock.capture(platformMsgCapture))).andAnswer( () -> { return Futures.immediateFuture(null); } ).anyTimes(); MobileDevice mobileDevice = new MobileDevice(); mobileDevice.setDeviceIdentifier(curDeviceId); if(curPersonMatch) { mobileDevice.setPersonId(curLoggedPerson.getId()); mobileDeviceDao.delete(mobileDevice); EasyMock.expectLastCall(); EasyMock.expect(personDao.findById(curLoggedPerson.getId())).andReturn(curLoggedPerson); }else{ mobileDevice.setPersonId(UUID.randomUUID()); } EasyMock.expect(mobileDeviceDao.findWithToken(curDeviceId)).andReturn(mobileDevice); //logout always needs to be called client.logout(); EasyMock.expectLastCall(); EasyMock.expect(authenticator.expireCookie()).andReturn(new DefaultCookie("test", "test")); replay(); FullHttpResponse response = handler.respond(request, ctx); if(curSuccess) { //notification needs to be sent PlatformMessage msg = platformMsgCapture.getValue(); assertNotificationSent(msg); } return response; }
Example 15
Source File: DrawerManagerTest.java From pm-wicket-utils with GNU Lesser General Public License v3.0 | 4 votes |
@Test public void testPushMultipleDrawersWithAJAX() { Capture<Panel> item1 = EasyMock.newCapture(); Capture<Panel> item2 = EasyMock.newCapture(); Capture<Panel> item3 = EasyMock.newCapture(); Capture<String> str1 = EasyMock.newCapture(); Capture<String> str2 = EasyMock.newCapture(); Capture<String> str2a = EasyMock.newCapture(); Capture<String> str2b = EasyMock.newCapture(); Capture<String> str3 = EasyMock.newCapture(); Capture<String> str3a = EasyMock.newCapture(); Capture<String> str3b = EasyMock.newCapture(); DrawerManager m = new DrawerManager("test"); startTest(m); getTarget().add(capture(item1)); getTarget().appendJavaScript(capture(str1)); getTarget().add(capture(item2)); getTarget().appendJavaScript(capture(str2)); getTarget().appendJavaScript(capture(str2a)); getTarget().appendJavaScript(capture(str2b)); getTarget().add(capture(item3)); getTarget().appendJavaScript(capture(str3)); getTarget().appendJavaScript(capture(str3a)); getTarget().appendJavaScript(capture(str3b)); replayAll(); AbstractDrawer d1 = new TestDrawer(); m.push(d1, getTarget()); AbstractDrawer d2 = new TestDrawer(); m.push(d2, getTarget()); AbstractDrawer d3 = new TestDrawer(); m.push(d3, getTarget()); assertEquals(d3, m.getLast(AbstractDrawer.class)); getTester().assertComponent(d3.getPageRelativePath(), TestDrawer.class); verifyAll(); assertEquals(d1.getParent().getParent(), item1.getValue()); assertEquals(d2.getParent().getParent(), item2.getValue()); assertEquals(d3.getParent().getParent(), item3.getValue()); assertEquals("$('#"+d1.getParent().getMarkupId()+"').modaldrawer('show');", str1.getValue()); assertEquals("$('#"+d2.getParent().getMarkupId()+"').modaldrawer('show');", str2.getValue()); assertEquals("$('#"+d1.getParent().getMarkupId()+"').removeClass('shown-modal');", str2a.getValue()); assertEquals("$('#"+d1.getParent().getMarkupId()+"').addClass('hidden-modal');", str2b.getValue()); assertEquals("$('#"+d3.getParent().getMarkupId()+"').modaldrawer('show');", str3.getValue()); assertEquals("$('#"+d2.getParent().getMarkupId()+"').removeClass('shown-modal');", str3a.getValue()); assertEquals("$('#"+d2.getParent().getMarkupId()+"').addClass('hidden-modal');", str3b.getValue()); }
Example 16
Source File: TestConsoleRSAKeyPairGenerator.java From java-license-manager with Apache License 2.0 | 4 votes |
@Test public void testMain02() throws Exception { final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); final PrintStream stream = new PrintStream(byteStream, true, StandardCharsets.UTF_8.name()); final Capture<String> firstErrorCapture = EasyMock.newCapture(); final Capture<String> secondErrorCapture = EasyMock.newCapture(); this.device.registerShutdownHook(EasyMock.anyObject(Thread.class)); EasyMock.expectLastCall().once(); this.device.printErrLn(EasyMock.capture(firstErrorCapture)); EasyMock.expectLastCall().once(); this.device.out(); EasyMock.expectLastCall().andReturn(stream); this.device.exit(1); EasyMock.expectLastCall().andThrow(new ThisExceptionMeansTestSucceededException()); this.device.printErrLn(EasyMock.capture(secondErrorCapture)); EasyMock.expectLastCall().once(); this.device.exit(EasyMock.anyInt()); EasyMock.expectLastCall().anyTimes(); EasyMock.replay(this.generator, this.device); Field consoleField = ConsoleRSAKeyPairGenerator.class.getDeclaredField("TEST_CONSOLE"); consoleField.setAccessible(true); consoleField.set(null, this.device); try { ConsoleRSAKeyPairGenerator.main("-private"); } finally { consoleField.set(null, null); } assertTrue(firstErrorCapture.getValue().contains("private")); assertTrue(secondErrorCapture.getValue().contains("ThisExceptionMeansTestSucceededException")); String output = byteStream.toString(); assertTrue(output, output.toLowerCase().contains("usage")); assertTrue(output, output.contains("ConsoleRSAKeyPairGenerator -help")); }
Example 17
Source File: BaseAlarmSubsystemTestCase.java From arcusplatform with Apache License 2.0 | 4 votes |
protected Capture<List<IncidentTrigger>> expectUpdateIncident() { Capture<List<IncidentTrigger>> triggerCapture = EasyMock.newCapture(); incidentService.updateIncident(EasyMock.eq(context), EasyMock.capture(triggerCapture)); EasyMock.expectLastCall(); return triggerCapture; }
Example 18
Source File: TestRegisterHubV2Handler.java From arcusplatform with Apache License 2.0 | 4 votes |
@Test public void testHubRegisterSuccess() throws Exception { HubRegistration hubReg = HubRegistrationFixtures.createHubRegistration(); hubReg.setState(RegistrationState.APPLYING); hubReg.setDownloadProgress(100); Hub hub = createHubFromHubRegistration(hubReg); EasyMock.expect(kitDao.getKit(hubReg.getId())).andReturn(null); EasyMock.expect(hubDao.findById(hubReg.getId())).andReturn(hub); EasyMock.expect(hubRegDao.findById(hubReg.getId())).andReturn(hubReg); EasyMock.expect(hubDao.findHubForPlace(place.getId())).andReturn(null); //place has no existing hub Capture<Hub> captureSavedHub = EasyMock.newCapture(CaptureType.LAST); Capture<HubRegistration> captureSavedHubReg = EasyMock.newCapture(CaptureType.LAST); EasyMock.expect(hubDao.save(EasyMock.capture(captureSavedHub))).andReturn(hub); EasyMock.expect(hubRegDao.save(EasyMock.capture(captureSavedHubReg))).andReturn(hubReg); EasyMock.expect(hubDao.findHubModel(hubReg.getId())).andAnswer(new IAnswer<ModelEntity>() { @Override public ModelEntity answer() throws Throwable { ModelEntity model = new ModelEntity(); model.setAttribute(HubCapability.ATTR_ID, hub.getId()); return model; } }); replay(); MessageBody msgBody = RegisterHubV2Request.builder().withHubId(hubReg.getId()).build(); try { MessageBody response = handler.handleRequest(place, PlatformMessage.builder().withPayload(msgBody).from(msgSource).create()); assertEquals(RegisterHubV2Response.NAME, response.getMessageType()); assertNotNull(RegisterHubV2Response.getHub(response)); assertEquals(RegisterHubV2Response.STATE_REGISTERED, RegisterHubV2Response.getState(response)); assertEquals(new Integer(100), RegisterHubV2Response.getProgress(response)); Hub savedHub = captureSavedHub.getValue(); assertEquals(HubCapability.REGISTRATIONSTATE_REGISTERED, savedHub.getRegistrationState()); assertEquals(place.getAccount(), savedHub.getAccount()); assertEquals(place.getId(), savedHub.getPlace()); HubRegistration savedHubReg = captureSavedHubReg.getValue(); assertEquals(RegistrationState.REGISTERED, savedHubReg.getState()); } catch(Exception e) { fail(e.getMessage()); } verify(); }
Example 19
Source File: AlarmIncidentServiceTestCase.java From arcusplatform with Apache License 2.0 | 4 votes |
protected Capture<AlarmIncident> expectUpdate() { Capture<AlarmIncident> captor = EasyMock.newCapture(); incidentDao.upsert(EasyMock.capture(captor)); EasyMock.expectLastCall(); return captor; }
Example 20
Source File: ThriftOverHttpServiceTest.java From buck with Apache License 2.0 | 4 votes |
@Test public void testSendValidMessageAndReturnValidResponse() throws IOException, TException { FrontendRequest request = new FrontendRequest(); request.setType(FrontendRequestType.ANNOUNCEMENT); FrontendResponse expectedResponse = new FrontendResponse(); expectedResponse.setType(FrontendRequestType.ANNOUNCEMENT); Capture<Request.Builder> requestBuilder = EasyMock.newCapture(); TSerializer serializer = new TSerializer(config.getThriftProtocol().getFactory()); byte[] responseBuffer = serializer.serialize(expectedResponse); HttpResponse httpResponse = new HttpResponse() { @Override public int statusCode() { return 200; } @Override public String statusMessage() { return "super cool msg"; } @Override public long contentLength() { return responseBuffer.length; } @Override public InputStream getBody() { return new ByteArrayInputStream(responseBuffer); } @Override public String requestUrl() { return "super url"; } @Override public void close() { // do nothing. } }; EasyMock.expect( httpService.makeRequest(EasyMock.eq("/thrift"), EasyMock.capture(requestBuilder))) .andReturn(httpResponse) .times(1); EasyMock.replay(httpService); FrontendResponse actualResponse = new FrontendResponse(); service.makeRequest(request, actualResponse); Assert.assertEquals(expectedResponse, actualResponse); EasyMock.verify(httpService); }