Coverage - MessageIntelligenceAgencyImpl.
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / ofpspecific / MessageIntelligenceAgencyImplTest.java
1 package org.opendaylight.openflowplugin.impl.statistics.ofpspecific;
2
3 import junit.framework.TestCase;
4 import org.junit.Test;
5 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
6
7 import java.util.List;
8
9 import static org.junit.Assert.assertTrue;
10
11
12 public class MessageIntelligenceAgencyImplTest {
13
14     @Test
15     public void testMessageIntelligenceAgency() {
16         final MessageIntelligenceAgencyImpl messageIntelligenceAgency = new MessageIntelligenceAgencyImpl();
17         messageIntelligenceAgency.spyMessage(String.class, MessageSpy.STATISTIC_GROUP.FROM_SWITCH);
18         messageIntelligenceAgency.spyMessage(Integer.class, MessageSpy.STATISTIC_GROUP.TO_SWITCH_ENTERED);
19         final List<String> intelligence = messageIntelligenceAgency.provideIntelligence();
20         findExpectedStatistics(intelligence, "FROM_SWITCH: MSG[String] -> +1 | 1", "TO_SWITCH_ENTERED: MSG[Integer] -> +1 | 1");
21     }
22
23     private void findExpectedStatistics(final List<String> statisticsInfo, String ... expectedValues) {
24         for (String expectedValue : expectedValues) {
25             assertTrue("Expected value " + expectedValue + "wasn't found.", findValueInStatistics(statisticsInfo, expectedValue));
26         }
27     }
28
29     private boolean findValueInStatistics(List<String> statisticsInfo, String expectedValue) {
30         for (String pieceOfInfo : statisticsInfo) {
31             if (pieceOfInfo.equals(expectedValue)) {
32                 return true;
33             }
34         }
35         return false;
36     }
37
38
39 }