Merge "OPNFLWPLUG-929 : Remove deprecated guava library"
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / SerializerRegistryImplTest.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.serialization;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowjava.protocol.impl.util.OF13MatchSerializer;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match;
16
17 /**
18  * Unit tests for SerializerRegistryImpl.
19  *
20  * @author madamjak
21  */
22 public class SerializerRegistryImplTest {
23
24     private static final short OF13 = EncodeConstants.OF13_VERSION_ID;
25     private static final short OF10 = EncodeConstants.OF10_VERSION_ID;
26
27     /**
28      * Test - register serializer without arguments.
29      */
30     @Test(expected = IllegalArgumentException.class)
31     public void testRegisterSerializerNoArgs() {
32
33         SerializerRegistryImpl serReg = new SerializerRegistryImpl();
34         serReg.registerSerializer(null, null);
35     }
36
37     /**
38      * Test - unregister serializer without MessageTypeKey.
39      */
40     @Test(expected = IllegalArgumentException.class)
41     public void testUnRegisterSerializerNoMessageTypeKey() {
42         SerializerRegistryImpl serReg = new SerializerRegistryImpl();
43         serReg.init();
44         serReg.registerSerializer(new MessageTypeKey<>(OF13, Match.class), new OF13MatchSerializer());
45         serReg.unregisterSerializer(null);
46     }
47
48     /**
49      * Test - unregister serializer.
50      */
51     @Test
52     public void testUnRegisterSerializer() {
53         SerializerRegistryImpl serReg = new SerializerRegistryImpl();
54         serReg.init();
55         serReg.registerSerializer(new MessageTypeKey<>(OF13, Match.class), new OF13MatchSerializer());
56         Assert.assertTrue("Wrong - unregister serializer",
57                 serReg.unregisterSerializer(new MessageTypeKey<>(OF13, Match.class)));
58
59         serReg.registerSerializer(new MessageTypeKey<>(OF13, Match.class), new OF13MatchSerializer());
60         Assert.assertFalse("Wrong - unregister serializer",
61                 serReg.unregisterSerializer(new MessageTypeKey<>(OF10, Match.class)));
62     }
63 }