2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.api.keys;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPhyPort;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
20 * @author michal.polkorab
23 public class MatchEntrySerializerKeyTest {
26 * Test MatchEntrySerializerKey equals and hashCode
30 MatchEntrySerializerKey<?, ?> key1 = new MatchEntrySerializerKey<>
31 (EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
32 MatchEntrySerializerKey<?, ?> key2 = new MatchEntrySerializerKey<>
33 (EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
34 Assert.assertTrue("Wrong equals", key1.equals(key2));
35 Assert.assertTrue("Wrong hashCode", key1.hashCode() == key2.hashCode());
36 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
37 OpenflowBasicClass.class, InPhyPort.class);
38 Assert.assertFalse("Wrong equals", key1.equals(key2));
39 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
40 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
41 Nxm0Class.class, InPort.class);
42 Assert.assertFalse("Wrong equals", key1.equals(key2));
43 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
44 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF10_VERSION_ID,
45 OpenflowBasicClass.class, InPhyPort.class);
46 Assert.assertFalse("Wrong equals", key1.equals(key2));
47 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
48 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
49 OpenflowBasicClass.class, null);
50 Assert.assertFalse("Wrong equals", key1.equals(key2));
51 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
52 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
53 null, InPhyPort.class);
54 Assert.assertFalse("Wrong equals", key1.equals(key2));
55 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
56 key2.setExperimenterId(42L);
57 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
61 * Test MatchEntrySerializerKey equals - additional test
64 public void testEquals(){
65 MatchEntrySerializerKey<?, ?> key1;
66 MatchEntrySerializerKey<?, ?> key2;
67 key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
68 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
69 Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
70 Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));
72 Long expId1 = 987654331L;
73 Long expId2 = 123456789L;
75 key1.setExperimenterId(null);
76 key2.setExperimenterId(expId2);
77 Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));
78 key1.setExperimenterId(expId1);
79 Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));
80 key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, null, InPort.class);
81 key1.setExperimenterId(expId2);
82 Assert.assertFalse("Wrong equal by oxmClass", key1.equals(key2));
83 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, null, InPort.class);
84 key2.setExperimenterId(expId2);
85 Assert.assertTrue("Wrong equal by oxmClass", key1.equals(key2));
86 key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, null);
87 key1.setExperimenterId(expId2);
88 Assert.assertFalse("Wrong equal by oxmField", key1.equals(key2));
89 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, null);
90 key2.setExperimenterId(expId2);
91 Assert.assertTrue("Wrong equal by oxmField", key1.equals(key2));
95 * Test MatchEntrySerializerKey toString()
98 public void testToString(){
99 MatchEntrySerializerKey<?, ?> key1;
100 key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
102 Assert.assertEquals("Wrong toString()", "msgVersion: 4 objectType: org.opendaylight.yang.gen.v1.urn"
103 + ".opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry"
104 + " oxm_class: org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225"
105 + ".OpenflowBasicClass oxm_field: org.opendaylight.yang.gen.v1.urn.opendaylight.openflow"
106 + ".oxm.rev150225.InPort experimenterID: null", key1.toString());