@BeforeMethod public void setUpAgain() throws Exception { m_dummyInputStream = new FileInputStream(m_dummyFile); DownloadResult downloadResult = addTestMock(DownloadResult.class); expect(downloadResult.isComplete()).andReturn(true).anyTimes(); expect(downloadResult.getInputStream()).andReturn(m_dummyInputStream).anyTimes(); Future<DownloadResult> future = addTestMock(Future.class); expect(future.get()).andReturn(downloadResult).anyTimes(); DownloadHandle downloadHandle = addTestMock(DownloadHandle.class); expect(downloadHandle.start(isNull(DownloadProgressListener.class))).andReturn(future).anyTimes(); DeploymentHandler deploymentHandler = addTestMock(DeploymentHandler.class); expect(deploymentHandler.getInstalledVersion()).andReturn(m_version2).anyTimes(); expect(deploymentHandler.getAvailableVersions()).andReturn(m_availableVersions).anyTimes(); expect(deploymentHandler.getDownloadHandle(eq(m_version3), eq(true))).andReturn(downloadHandle).once(); deploymentHandler.install(notNull(InputStream.class)); expectLastCall().once(); m_agentContext = mockAgentContext(); m_agentContext.setHandler(DeploymentHandler.class, deploymentHandler); replayTestMocks(); m_agentContext.start(); m_agentControl = new AgentControlImpl(m_agentContext); }
/** * Called by our {@link DependencyTrackerImpl} when all dependencies are satisfied. */ public void componentStarted(BundleContext context) throws Exception { final File bundleDataArea = context.getDataFile(""); m_agentContext = new AgentContextImpl(bundleDataArea); m_agentContext.setHandler(LoggingHandler.class, new LoggingHandlerImpl(context)); m_agentContext.setHandler(ConfigurationHandler.class, new ConfigurationHandlerImpl(context)); m_agentContext.setHandler(EventsHandler.class, new EventsHandlerImpl(context)); m_agentContext.setHandler(ScheduledExecutorService.class, m_executorService); m_agentContext.setHandler(DownloadHandler.class, new DownloadHandlerImpl(bundleDataArea)); m_agentContext.setHandler(DeploymentHandler.class, new DeploymentHandlerImpl(context, m_packageAdmin)); m_agentContext.setHandler(AgentUpdateHandler.class, new AgentUpdateHandlerImpl(context)); m_agentContext.setHandler(FeedbackHandler.class, new FeedbackHandlerImpl()); IdentificationHandler identificationHandler = (m_identificationHandler != null) ? m_identificationHandler : new IdentificationHandlerImpl(); m_agentContext.setHandler(IdentificationHandler.class, identificationHandler); DiscoveryHandler discoveryHandler = (m_discoveryHandler != null) ? m_discoveryHandler : new DiscoveryHandlerImpl(); m_agentContext.setHandler(DiscoveryHandler.class, discoveryHandler); ConnectionHandler connectionHandler = (m_connectionHandler != null) ? m_connectionHandler : new ConnectionHandlerImpl(); m_agentContext.setHandler(ConnectionHandler.class, connectionHandler); m_agentContext.addComponent(new EventLoggerImpl(context)); // Lastly, inject the (custom) controller for this agent... m_agentContext.setController(m_controller); m_agentContext.start(); m_agentControlRegistration = context.registerService(AgentControl.class.getName(), new AgentControlImpl(m_agentContext), null); }