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