@Test public void testAvailableVersions() throws Exception { DeploymentHandler deploymentHandler = m_agentContext.getHandler(DeploymentHandler.class); SortedSet<Version> expected = new TreeSet<>(); expected.add(m_version1); expected.add(m_version2); expected.add(m_version3); SortedSet<Version> available = deploymentHandler.getAvailableVersions(); assertNotNull(available); assertFalse(available.isEmpty()); assertEquals(available, expected); }
@Test public void testCurrentVersion() throws Exception { DeploymentHandler deploymentHandler = m_agentContext.getHandler(DeploymentHandler.class); Version current = deploymentHandler.getInstalledVersion(); assertNotNull(current); assertEquals(current, m_version2); }
@Test public void testPackageSize() throws Exception { DeploymentHandler deploymentHandler = m_agentContext.getHandler(DeploymentHandler.class); long packageSize = deploymentHandler.getSize(m_version1, true); assertEquals(packageSize, m_remotePackageSize); }
private void startController(final Object object) { terminateRunningController(); initAgentContextAware(object); // In case of a Runnable, we start a separate thread that executes this task... if (object instanceof Runnable) { ScheduledExecutorService executorService = getHandler(ScheduledExecutorService.class); if (executorService == null || executorService.isShutdown()) { return; } m_future = executorService.submit(new Runnable() { private static final String NAME = "ACE Agent Controller"; @Override public void run() { // Annotate the name of the thread for debugging purposes... Thread.currentThread().setName(NAME); startAgentContextAware(object); ((Runnable) object).run(); stopAgentContextAware(object); } }); } else { // Expect the controller to handle its own execution... startAgentContextAware(object); } }
@Test public void testBasicAuthFORBIDDEN() throws Exception { Map<String, String> props = new HashMap<>(); props.put(AgentConstants.CONFIG_CONNECTION_AUTHTYPE, Types.NONE.name()); ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configurationHandler.putAll(props); ConnectionHandler connectionHandler = m_agentContext.getHandler(ConnectionHandler.class); HttpURLConnection connection = (HttpURLConnection) connectionHandler.getConnection(m_basicAuthURL); assertEquals(connection.getResponseCode(), HttpServletResponse.SC_FORBIDDEN); }
@Test public void testBasicAuthOK() throws Exception { Map<String, String> props = new HashMap<>(); props.put(AgentConstants.CONFIG_CONNECTION_AUTHTYPE, Types.BASIC.name()); props.put(AgentConstants.CONFIG_CONNECTION_USERNAME, USERNAME); props.put(AgentConstants.CONFIG_CONNECTION_PASSWORD, PASSWORD); ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configurationHandler.putAll(props); ConnectionHandler connectionHandler = m_agentContext.getHandler(ConnectionHandler.class); HttpURLConnection connection = (HttpURLConnection) connectionHandler.getConnection(m_basicAuthURL); assertEquals(connection.getResponseCode(), HttpServletResponse.SC_OK); } }
@Test public void testSingleFeedbackChannelConfig() throws Exception { ConfigurationHandler configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, CONFIG_FEEDBACK_CHANNELS, AUDITLOG); FeedbackHandler feedbackHandler = m_agentContextImpl.getHandler(FeedbackHandler.class); assertFeedbackChannelNames(feedbackHandler, AUDITLOG); assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG); }
@Test public void testDeployPackage() throws Exception { DeploymentHandler deploymentHandler = m_agentContext.getHandler(DeploymentHandler.class); InputStream inputStream = deploymentHandler.getInputStream(m_version3, true); try { deploymentHandler.install(inputStream); } finally { inputStream.close(); } } }
@SuppressWarnings("deprecation") @Test public void testWriteEvent() throws Exception { FrameworkEvent event = new FrameworkEvent(32, new Object()); m_eventLogger.frameworkEvent(event); FeedbackHandler feedbackHandler = m_agentContext.getHandler(FeedbackHandler.class); TestFeedbackChannel channel = (TestFeedbackChannel) feedbackHandler.getChannel("auditlog"); assertEquals(channel.getLastTtype(), 1001); }
@Test public void testConfigClean() throws Exception { ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl(m_context); resetConfigurationHandler(configurationHandler); configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class); assertEquals(configurationHandler.get("key1", "default1"), "default1"); // should be persisted configurationHandler = new ConfigurationHandlerImpl(m_context); resetConfigurationHandler(configurationHandler); configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class); assertEquals(configurationHandler.get("key1", "default1"), "default1"); }
@Test public void testDownloadOk() throws Exception { DownloadHandler downloadHandler = m_agentContext.getHandler(DownloadHandler.class); DownloadResult downloadResult; Future<DownloadResult> future; final DownloadHandle handle = downloadHandler.getHandle(m_testContentURL); future = handle.start(null); downloadResult = future.get(5, TimeUnit.SECONDS); assertTrue(downloadResult.isComplete()); File file = ((DownloadHandleImpl) handle).getDownloadFile(); long fileLength = file.length(); assertTrue(file.exists(), file.getName() + " does not exist?!"); assertTrue(fileLength > 0 && fileLength == m_contentLength, "Nothing downloaded yet for " + file.getName() + "?"); // Verify the contents of the downloaded file is what we expect... assertEquals(getDigest(file), m_digest); }
@Test public void testCreateDownloadHandleGeneratesSameTemporaryFilenameOk() throws Exception { DownloadHandler downloadHandler = m_agentContext.getHandler(DownloadHandler.class); DownloadHandleImpl handle; handle = (DownloadHandleImpl) downloadHandler.getHandle(m_testContentURL); String tempFilename = handle.getDownloadFile().getAbsolutePath(); handle = (DownloadHandleImpl) downloadHandler.getHandle(m_testContentURL); assertEquals(handle.getDownloadFile().getAbsolutePath(), tempFilename); handle = (DownloadHandleImpl) downloadHandler.getHandle(m_testContentURL); assertEquals(handle.getDownloadFile().getAbsolutePath(), tempFilename); }
@SuppressWarnings("deprecation") @Test public void testExcludeEvent() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, AgentConstants.CONFIG_LOGGING_EXCLUDE_EVENTS, "1001,1002"); FrameworkEvent event = new FrameworkEvent(32, new Object()); FeedbackHandler feedbackHandler = m_agentContext.getHandler(FeedbackHandler.class); TestFeedbackChannel channel = (TestFeedbackChannel) feedbackHandler.getChannel("auditlog"); // make sure the configuration is written to the channel assertEquals(channel.getLastTtype(), 2000); m_eventLogger.frameworkEvent(event); // make sure nothing is written to the channel assertEquals(channel.getLastTtype(), 2000); } }
/** * Tests that there is always a default channel registered when starting the agent. */ @Test public void testDefaultFeedbackChannelPresent() throws Exception { FeedbackHandler feedbackHandler = m_agentContextImpl.getHandler(FeedbackHandler.class); assertFeedbackChannelNames(feedbackHandler, AUDITLOG); assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG); assertFeedbackChannelsNotPresent(feedbackHandler, NON_EXISTING_CHANNEL); }
@Test public void testConfigLongProps() throws Exception { ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl(m_context); resetConfigurationHandler(configurationHandler); configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, "long1", "42", "long2", "4"); assertEquals(configurationHandler.getLong("long1", 0l), 42); assertEquals(configurationHandler.getLong("long2", 0l), 4l); assertEquals(configurationHandler.getLong("longX", 42l), 42l); }
@Test public void testConfigBooleanProps() throws Exception { ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl(m_context); resetConfigurationHandler(configurationHandler); configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, "boolean1", "true", "boolean2", "false"); assertEquals(configurationHandler.getBoolean("boolean1", false), true); assertEquals(configurationHandler.getBoolean("boolean2", true), false); assertEquals(configurationHandler.getBoolean("booleanX", true), true); assertEquals(configurationHandler.getBoolean("booleanY", false), false); }
private void resetConfigurationHandler(ConfigurationHandler configurationHandler) throws Exception { ConfigurationHandler oldConfigurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class); if (oldConfigurationHandler instanceof ComponentBase) { ((ComponentBase) oldConfigurationHandler).stop(); } m_agentContextImpl.setHandler(ConfigurationHandler.class, configurationHandler); m_agentContextImpl.start(); } }
@Test public void testUpdateConfigRemoveFeedbackChannel() throws Exception { ConfigurationHandler configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, CONFIG_FEEDBACK_CHANNELS, AUDITLOG_AND_CUSTOMCHANNEL); FeedbackHandler feedbackHandler = m_agentContextImpl.getHandler(FeedbackHandler.class); assertFeedbackChannelNames(feedbackHandler, AUDITLOG, CUSTOMCHANNEL); assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG, CUSTOMCHANNEL); configureAgent(configurationHandler, CONFIG_FEEDBACK_CHANNELS, AUDITLOG); assertFeedbackChannelNames(feedbackHandler, AUDITLOG); assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG); assertFeedbackChannelsNotPresent(feedbackHandler, CUSTOMCHANNEL); }
@Test public void testUpdateConfigAddFeedbackChannel() throws Exception { ConfigurationHandler configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, CONFIG_FEEDBACK_CHANNELS, AUDITLOG); FeedbackHandler feedbackHandler = m_agentContextImpl.getHandler(FeedbackHandler.class); assertFeedbackChannelNames(feedbackHandler, AUDITLOG); assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG); assertFeedbackChannelsNotPresent(feedbackHandler, CUSTOMCHANNEL); configureAgent(configurationHandler, CONFIG_FEEDBACK_CHANNELS, AUDITLOG_AND_CUSTOMCHANNEL); assertFeedbackChannelNames(feedbackHandler, AUDITLOG, CUSTOMCHANNEL); assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG, CUSTOMCHANNEL); }
@BeforeMethod(alwaysRun = true) public void reset() throws Exception { // create a new eventlogger for every test m_eventLogger = new EventLoggerImpl(mockBundleContext()); m_eventLogger.init(m_agentContext); m_eventsHandler.addListener(m_eventLogger); m_eventLogger.start(m_agentContext); // reset the previously logged data in our mock feedbackchannel. No need to create a new one here FeedbackHandler feedbackHandler = m_agentContext.getHandler(FeedbackHandler.class); TestFeedbackChannel channel = (TestFeedbackChannel) feedbackHandler.getChannel("auditlog"); channel.reset(); }