2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.openflowjava.protocol.api.keys;
\r
11 import org.junit.Assert;
\r
12 import org.junit.Test;
\r
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
\r
20 * @author michal.polkorab
\r
23 public class MatchEntrySerializerKeyTest {
\r
26 * Test MatchEntrySerializerKey equals and hashCode
\r
29 public void test() {
\r
30 MatchEntrySerializerKey<?, ?> key1 = new MatchEntrySerializerKey<>
\r
31 (EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
\r
32 MatchEntrySerializerKey<?, ?> key2 = new MatchEntrySerializerKey<>
\r
33 (EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
\r
34 Assert.assertTrue("Wrong equals", key1.equals(key2));
\r
35 Assert.assertTrue("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
36 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
\r
37 OpenflowBasicClass.class, InPhyPort.class);
\r
38 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
39 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
40 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
\r
41 Nxm0Class.class, InPort.class);
\r
42 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
43 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
44 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF10_VERSION_ID,
\r
45 OpenflowBasicClass.class, InPhyPort.class);
\r
46 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
47 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
48 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
\r
49 OpenflowBasicClass.class, null);
\r
50 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
51 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
52 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,
\r
53 null, InPhyPort.class);
\r
54 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
55 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
56 key2.setExperimenterId(42L);
\r
57 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
61 * Test MatchEntrySerializerKey equals - additional test
\r
64 public void testEquals(){
\r
65 MatchEntrySerializerKey<?, ?> key1;
\r
66 MatchEntrySerializerKey<?, ?> key2;
\r
67 key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
\r
68 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
\r
69 Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
\r
70 Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));
\r
72 Long expId1 = 987654331L;
\r
73 Long expId2 = 123456789L;
\r
75 key1.setExperimenterId(null);
\r
76 key2.setExperimenterId(expId2);
\r
77 Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));
\r
78 key1.setExperimenterId(expId1);
\r
79 Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));
\r
80 key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, null, InPort.class);
\r
81 key1.setExperimenterId(expId2);
\r
82 Assert.assertFalse("Wrong equal by oxmClass", key1.equals(key2));
\r
83 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, null, InPort.class);
\r
84 key2.setExperimenterId(expId2);
\r
85 Assert.assertTrue("Wrong equal by oxmClass", key1.equals(key2));
\r
86 key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, null);
\r
87 key1.setExperimenterId(expId2);
\r
88 Assert.assertFalse("Wrong equal by oxmField", key1.equals(key2));
\r
89 key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, null);
\r
90 key2.setExperimenterId(expId2);
\r
91 Assert.assertTrue("Wrong equal by oxmField", key1.equals(key2));
\r
95 * Test MatchEntrySerializerKey toString()
\r
98 public void testToString(){
\r
99 MatchEntrySerializerKey<?, ?> key1;
\r
100 key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
\r
102 Assert.assertEquals("Wrong toString()", "msgVersion: 4 objectType: org.opendaylight.yang.gen.v1.urn.opendaylight"
\r
103 + ".openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries oxm_class: org.opendaylight.yang.gen.v1.urn"
\r
104 + ".opendaylight.openflow.oxm.rev130731.OpenflowBasicClass oxm_field: org.opendaylight.yang.gen.v1.urn"
\r
105 + ".opendaylight.openflow.oxm.rev130731.InPort experimenterID: null", key1.toString());
\r