Use ByteBuf.readRetainedSlice()
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / ofpspecific / MessageIntelligenceAgencyImplTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.impl.statistics.ofpspecific;
9
10 import static org.junit.Assert.assertTrue;
11
12 import java.util.List;
13 import org.junit.Test;
14 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
15
16 public class MessageIntelligenceAgencyImplTest {
17
18     @Test
19     public void testMessageIntelligenceAgency() {
20         final MessageIntelligenceAgencyImpl messageIntelligenceAgency = new MessageIntelligenceAgencyImpl();
21         messageIntelligenceAgency.spyMessage(String.class, MessageSpy.StatisticsGroup.FROM_SWITCH);
22         messageIntelligenceAgency.spyMessage(Integer.class, MessageSpy.StatisticsGroup.TO_SWITCH_ENTERED);
23         final List<String> intelligence = messageIntelligenceAgency.provideIntelligence();
24         findExpectedStatistics(intelligence,
25                 "FROM_SWITCH: MSG[String] -> +1 | 1", "TO_SWITCH_ENTERED: MSG[Integer] -> +1 | 1");
26     }
27
28     private static void findExpectedStatistics(final List<String> statisticsInfo, String ... expectedValues) {
29         for (String expectedValue : expectedValues) {
30             assertTrue("Expected value " + expectedValue + "wasn't found.",
31                     findValueInStatistics(statisticsInfo, expectedValue));
32         }
33     }
34
35     private static  boolean findValueInStatistics(List<String> statisticsInfo, String expectedValue) {
36         for (String pieceOfInfo : statisticsInfo) {
37             if (pieceOfInfo.equals(expectedValue)) {
38                 return true;
39             }
40         }
41         return false;
42     }
43 }