OPNFLWPLUG-1070
[openflowplugin.git] / extension / openflowjava-extension-eric / src / test / java / org / opendaylight / openflowjava / eric / EricExtensionsRegistratorTest.java
1 /*
2  * Copyright (c) 2019 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.openflowjava.eric;
10
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.mockito.Matchers;
15 import org.mockito.Mock;
16 import org.mockito.Mockito;
17 import org.mockito.runners.MockitoJUnitRunner;
18 import org.opendaylight.openflowjava.eric.api.EricConstants;
19 import org.opendaylight.openflowjava.eric.api.EricExtensionCodecRegistrator;
20 import org.opendaylight.openflowjava.eric.codec.match.Icmpv6NDOptionsTypeCodec;
21 import org.opendaylight.openflowjava.eric.codec.match.Icmpv6NDReservedCodec;
22 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
23 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
24 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EricExpClass;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.Icmpv6NdOptionsType;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.Icmpv6NdReserved;
28
29 @RunWith(MockitoJUnitRunner.class)
30 public class EricExtensionsRegistratorTest {
31
32     private EricExtensionsRegistrator ericExtensionsRegistrator;
33
34     @Mock
35     EricExtensionCodecRegistrator registrator;
36
37     @Before
38     public void setUp() {
39         ericExtensionsRegistrator = new EricExtensionsRegistrator(registrator);
40     }
41
42     @Test
43     public void registerEricExtensionsTest() {
44         Mockito.verify(registrator).registerMatchEntrySerializer(Matchers
45                 .eq(new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, EricExpClass.class,
46                         Icmpv6NdReserved.class)), Matchers.any(Icmpv6NDReservedCodec.class));
47         Mockito.verify(registrator).registerMatchEntryDeserializer(Matchers
48                 .eq(new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
49                         EricConstants.ERICOXM_OF_EXPERIMENTER_ID, EricConstants.ERICOXM_OF_ICMPV6_ND_RESERVED)),
50                 Matchers.any(Icmpv6NDReservedCodec.class));
51
52         Mockito.verify(registrator).registerMatchEntrySerializer(Matchers
53                         .eq(new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, EricExpClass.class,
54                                 Icmpv6NdOptionsType.class)), Matchers.any(Icmpv6NDOptionsTypeCodec.class));
55         Mockito.verify(registrator).registerMatchEntryDeserializer(Matchers
56                         .eq(new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
57                                 EricConstants.ERICOXM_OF_EXPERIMENTER_ID,
58                                 EricConstants.ERICOXM_OF_ICMPV6_ND_OPTIONS_TYPE)),
59                 Matchers.any(Icmpv6NDOptionsTypeCodec.class));
60     }
61
62     @Test
63     public void unregisterExtensionsTest() {
64         ericExtensionsRegistrator.close();
65
66         Mockito.verify(registrator).unregisterMatchEntrySerializer(
67                 new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, EricExpClass.class,
68                         Icmpv6NdReserved.class));
69         Mockito.verify(registrator).unregisterMatchEntryDeserializer(
70                 new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID, EricConstants.ERICOXM_OF_EXPERIMENTER_ID,
71                         EricConstants.ERICOXM_OF_ICMPV6_ND_RESERVED));
72
73         Mockito.verify(registrator).unregisterMatchEntrySerializer(
74                 new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, EricExpClass.class,
75                         Icmpv6NdOptionsType.class));
76         Mockito.verify(registrator).unregisterMatchEntryDeserializer(
77                 new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID, EricConstants.ERICOXM_OF_EXPERIMENTER_ID,
78                          EricConstants.ERICOXM_OF_ICMPV6_ND_OPTIONS_TYPE));
79     }
80
81 }