c52300182849441e264fbabb350a5512c0efc7f2
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / SerializerRegistryImplTest.java
1
2 /*
3  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9 package org.opendaylight.openflowjava.protocol.impl.serialization;
10
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.protocol.impl.util.OF13MatchSerializer;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
17
18 /**
19  * 
20  * @author madamjak
21  *
22  */
23 public class SerializerRegistryImplTest {
24     
25     private static final short OF13 = EncodeConstants.OF13_VERSION_ID;
26     private static final short OF10 = EncodeConstants.OF10_VERSION_ID;
27
28     /**
29      * Test - register serializer without arguments
30      */
31     @Test(expected = IllegalArgumentException.class)
32     public void testRegisterSerializerNoArgs(){
33
34         SerializerRegistryImpl serReg = new SerializerRegistryImpl();
35         serReg.registerSerializer(null, null);
36     }
37
38     /**
39      * Test - unregister serializer without MessageTypeKye
40      */
41     @Test(expected = IllegalArgumentException.class)
42     public void testUnRegisterSerializerNoMessageTypeKey(){
43         SerializerRegistryImpl serReg = new SerializerRegistryImpl();
44         serReg.init();
45         serReg.registerSerializer(new MessageTypeKey<>(OF13, Match.class), new OF13MatchSerializer());
46         serReg.unregisterSerializer(null);
47     }
48
49     /**
50      * Test - unregister serializer 
51      */
52     @Test
53     public void testUnRegisterSerialize(){
54         SerializerRegistryImpl serReg = new SerializerRegistryImpl();
55         serReg.init();
56         serReg.registerSerializer(new MessageTypeKey<>(OF13, Match.class), new OF13MatchSerializer());
57         Assert.assertTrue("Wrong - unregister serializer",serReg.unregisterSerializer(new MessageTypeKey<>(OF13, Match.class)));
58
59         serReg.registerSerializer(new MessageTypeKey<>(OF13, Match.class), new OF13MatchSerializer());
60         Assert.assertFalse("Wrong - unregister serializer",serReg.unregisterSerializer(new MessageTypeKey<>(OF10, Match.class)));
61     }
62 }