ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1524332 - /ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/FeedbackHandlerImplTest.java
Date Wed, 18 Sep 2013 08:22:47 GMT
Author: jawi
Date: Wed Sep 18 08:22:47 2013
New Revision: 1524332

URL: http://svn.apache.org/r1524332
Log:
Added unit test for presence of default feedback channel.


Modified:
    ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/FeedbackHandlerImplTest.java

Modified: ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/FeedbackHandlerImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/FeedbackHandlerImplTest.java?rev=1524332&r1=1524331&r2=1524332&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/FeedbackHandlerImplTest.java
(original)
+++ ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/FeedbackHandlerImplTest.java
Wed Sep 18 08:22:47 2013
@@ -18,16 +18,16 @@
  */
 package org.apache.ace.agent.impl;
 
+import static org.apache.ace.agent.AgentConstants.CONFIG_FEEDBACK_CHANNELS;
 import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
+import java.io.IOException;
 import java.lang.reflect.Method;
 import java.util.Set;
 
-import org.apache.ace.agent.AgentConstants;
 import org.apache.ace.agent.ConfigurationHandler;
 import org.apache.ace.agent.EventsHandler;
 import org.apache.ace.agent.FeedbackHandler;
@@ -40,6 +40,11 @@ import org.testng.annotations.Test;
  * Testing {@link FeedbackHandlerImplTest}.
  */
 public class FeedbackHandlerImplTest extends BaseAgentTest {
+    private static final String AUDITLOG = InternalConstants.AUDITLOG_FEEDBACK_CHANNEL;
+    private static final String CUSTOMCHANNEL = "customchannel";
+    private static final String NON_EXISTING_CHANNEL = "nonExistingChannel";
+
+    private static final String AUDITLOG_AND_CUSTOMCHANNEL = AUDITLOG + "," + CUSTOMCHANNEL;
 
     private AgentContextImpl m_agentContextImpl;
 
@@ -62,80 +67,88 @@ public class FeedbackHandlerImplTest ext
         clearTestMocks();
     }
 
+    /**
+     * 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 testSingleFeedbackChannelConfig() throws Exception {
         ConfigurationHandler configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class);
 
-        configurationHandler.put(AgentConstants.CONFIG_FEEDBACK_CHANNELS, "auditlog");
+        configurationHandler.put(CONFIG_FEEDBACK_CHANNELS, AUDITLOG);
 
         FeedbackHandler feedbackHandler = m_agentContextImpl.getHandler(FeedbackHandler.class);
 
-        Set<String> names = feedbackHandler.getChannelNames();
-        assertNotNull(names);
-        assertEquals(1, names.size());
-        assertTrue(names.contains("auditlog"));
-
-        assertNotNull(feedbackHandler.getChannel("auditlog"));
-        assertNull(feedbackHandler.getChannel("nonExistingChannel"));
+        assertFeedbackChannelNames(feedbackHandler, AUDITLOG);
+        assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG);
     }
 
     @Test
     public void testUpdateConfigAddFeedbackChannel() throws Exception {
         ConfigurationHandler configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class);
 
-        configurationHandler.put(AgentConstants.CONFIG_FEEDBACK_CHANNELS, "auditlog");
+        configurationHandler.put(CONFIG_FEEDBACK_CHANNELS, AUDITLOG);
 
         FeedbackHandler feedbackHandler = m_agentContextImpl.getHandler(FeedbackHandler.class);
 
-        Set<String> names = feedbackHandler.getChannelNames();
-        assertNotNull(names);
-        assertEquals(1, names.size());
-        assertTrue(names.contains("auditlog"));
-
-        assertNotNull(feedbackHandler.getChannel("auditlog"));
-        assertNull(feedbackHandler.getChannel("nonExistingChannel"));
-
-        configurationHandler.put(AgentConstants.CONFIG_FEEDBACK_CHANNELS, "auditlog, customchannel");
-
-        names = feedbackHandler.getChannelNames();
-        assertNotNull(names);
-        assertEquals(2, names.size());
-        assertTrue(names.contains("auditlog"));
-        assertTrue(names.contains("customchannel"));
-
-        assertNotNull(feedbackHandler.getChannel("auditlog"));
-        assertNotNull(feedbackHandler.getChannel("customchannel"));
-        assertNull(feedbackHandler.getChannel("nonExistingChannel"));
+        assertFeedbackChannelNames(feedbackHandler, AUDITLOG);
+
+        assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG);
+        assertFeedbackChannelsNotPresent(feedbackHandler, CUSTOMCHANNEL);
+
+        configurationHandler.put(CONFIG_FEEDBACK_CHANNELS, AUDITLOG_AND_CUSTOMCHANNEL);
+
+        assertFeedbackChannelNames(feedbackHandler, AUDITLOG, CUSTOMCHANNEL);
+
+        assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG, CUSTOMCHANNEL);
     }
 
     @Test
     public void testUpdateConfigRemoveFeedbackChannel() throws Exception {
         ConfigurationHandler configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class);
 
-        configurationHandler.put(AgentConstants.CONFIG_FEEDBACK_CHANNELS, "auditlog, customchannel");
+        configurationHandler.put(CONFIG_FEEDBACK_CHANNELS, AUDITLOG_AND_CUSTOMCHANNEL);
 
         FeedbackHandler feedbackHandler = m_agentContextImpl.getHandler(FeedbackHandler.class);
 
-        Set<String> names = feedbackHandler.getChannelNames();
-        assertNotNull(names);
-        assertEquals(2, names.size());
-        assertTrue(names.contains("auditlog"));
-        assertTrue(names.contains("customchannel"));
-
-        assertNotNull(feedbackHandler.getChannel("auditlog"));
-        assertNotNull(feedbackHandler.getChannel("customchannel"));
-        assertNull(feedbackHandler.getChannel("nonExistingChannel"));
-
-        configurationHandler.put(AgentConstants.CONFIG_FEEDBACK_CHANNELS, "auditlog");
-
-        names = feedbackHandler.getChannelNames();
-        assertNotNull(names);
-        assertEquals(1, names.size());
-        assertTrue(names.contains("auditlog"));
-        assertFalse(names.contains("customchannel"));
-
-        assertNotNull(feedbackHandler.getChannel("auditlog"));
-        assertNull(feedbackHandler.getChannel("customchannel"));
-        assertNull(feedbackHandler.getChannel("nonExistingChannel"));
+        assertFeedbackChannelNames(feedbackHandler, AUDITLOG, CUSTOMCHANNEL);
+        assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG, CUSTOMCHANNEL);
+
+        configurationHandler.put(CONFIG_FEEDBACK_CHANNELS, AUDITLOG);
+
+        assertFeedbackChannelNames(feedbackHandler, AUDITLOG);
+        assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG);
+
+        assertFeedbackChannelsNotPresent(feedbackHandler, CUSTOMCHANNEL);
+    }
+
+    private void assertFeedbackChannelNames(FeedbackHandler handler, String... names) throws
IOException {
+        Set<String> availableNames = handler.getChannelNames();
+        assertNotNull(availableNames);
+        assertEquals(availableNames.size(), names.length);
+        for (String name : names) {
+            assertTrue(availableNames.contains(name), "Expected channel '" + name + "' to
be present!");
+        }
+    }
+
+    private void assertFeedbackChannelsPresent(FeedbackHandler handler, String... names)
throws IOException {
+        for (String name : names) {
+            assertNotNull(handler.getChannel(name), "Expected channel '" + name + "' to be
present!");
+        }
+    }
+
+    private void assertFeedbackChannelsNotPresent(FeedbackHandler handler, String... names)
throws IOException {
+        for (String name : names) {
+            assertNull(handler.getChannel(name), "Expected channel '" + name + "' NOT to
be present!");
+        }
     }
 }



Mime
View raw message