Merge "OPNFLWPLUG-929 : Remove deprecated guava library"
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / DeserializerRegistryImplTest.java
1 /*
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. 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.openflowjava.protocol.impl.deserialization;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10;
17
18 /**
19  * Unit tests for DeserializerRegistryImpl.
20  *
21  * @author madamjak
22  */
23 public class DeserializerRegistryImplTest {
24
25     private static final short OF13 = EncodeConstants.OF13_VERSION_ID;
26     private static final short OF10 = EncodeConstants.OF10_VERSION_ID;
27     private static final int EMPTY_VALUE = EncodeConstants.EMPTY_VALUE;
28
29     /**
30      * Test - register deserializer without arguments.
31      */
32     @Test(expected = IllegalArgumentException.class)
33     public void testRegisterDeserializerNoArgs() {
34         DeserializerRegistryImpl serReg = new DeserializerRegistryImpl();
35         serReg.registerDeserializer(null, null);
36     }
37
38     /**
39      * Test - register deserializer with no key.
40      */
41     @Test(expected = IllegalArgumentException.class)
42     public void testRegisterDeserializerNoKey() {
43         DeserializerRegistryImpl serReg = new DeserializerRegistryImpl();
44         serReg.registerDeserializer(null, new MatchDeserializer());
45     }
46
47     /**
48      * Test - register deserializer with no deserializer.
49      */
50     @Test(expected = IllegalArgumentException.class)
51     public void testRegisterDeserializerNoDeserializer() {
52         DeserializerRegistryImpl serReg = new DeserializerRegistryImpl();
53         serReg.registerDeserializer(new MessageCodeKey(OF13, EMPTY_VALUE, Match.class), null);
54     }
55
56     /**
57      * Test - unregister deserializer without MessageTypeKey.
58      */
59     @Test(expected = IllegalArgumentException.class)
60     public void testUnRegisterDeserializerNoMessageTypeKey() {
61         DeserializerRegistryImpl derserReg = new DeserializerRegistryImpl();
62         derserReg.init();
63         derserReg.unregisterDeserializer(null);
64     }
65
66     /**
67      * Test - unregister deserializer.
68      */
69     @Test
70     public void testUnRegisterDeserializer() {
71         DeserializerRegistryImpl derserReg = new DeserializerRegistryImpl();
72         derserReg.init();
73         Assert.assertTrue("Wrong - unregister serializer",derserReg.unregisterDeserializer(
74                 new MessageCodeKey(OF13,EMPTY_VALUE, Match.class)));
75         Assert.assertFalse("Wrong - unregister serializer",derserReg.unregisterDeserializer(
76                 new MessageCodeKey(OF10,EMPTY_VALUE, Match.class)));
77     }
78
79     /**
80      * Test - get deserializer.
81      */
82     @Test(expected = IllegalStateException.class)
83     public void testGetDeserializer() {
84         DeserializerRegistryImpl registry = new DeserializerRegistryImpl();
85         registry.init();
86         registry.getDeserializer(new MessageCodeKey((short) 5000, EncodeConstants.EMPTY_VALUE, MatchV10.class));
87         Assert.fail();
88     }
89 }