blob: f2ee159cffd3a1af5fa37ae996c552c3f0865a05 [file] [log] [blame]
Jian Lic565ebf2017-02-04 14:49:52 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Lic565ebf2017-02-04 14:49:52 +09003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.mapping;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20import org.onosproject.net.DeviceId;
21
22import static org.hamcrest.MatcherAssert.assertThat;
23import static org.hamcrest.Matchers.is;
24
25/**
26 * Unit tests for the default mapping entry class.
27 */
28public class DefaultMappingEntryTest {
29
Jian Li44155b02017-02-15 17:03:38 +090030 private static final MappingKey MAPPING_KEY =
31 new MappingTestMocks.MockMappingKey();
32 private static final MappingValue MAPPING_VALUE =
33 new MappingTestMocks.MockMappingValue();
Jian Lic565ebf2017-02-04 14:49:52 +090034
Jian Li98763102017-02-19 23:48:46 +090035 private final MappingEntry entry1 = makeMappingEntry(1);
36 private final MappingEntry sameAsEntry1 = makeMappingEntry(1);
37 private final MappingEntry entry2 = makeMappingEntry(2);
38
Jian Lic565ebf2017-02-04 14:49:52 +090039 /**
40 * Creates a new mapping entry from an unique value.
41 *
42 * @param value unique value
43 * @return a new mapping entry
44 */
45 private static DefaultMappingEntry makeMappingEntry(int value) {
46 Mapping mapping = new DefaultMapping.Builder()
47 .forDevice(DeviceId.deviceId("lisp:10.1.1." +
48 Integer.toString(value)))
49 .withKey(MAPPING_KEY)
50 .withValue(MAPPING_VALUE)
51 .withId(value)
52 .build();
53
54 return new DefaultMappingEntry(mapping, MappingEntry.MappingEntryState.ADDED);
55 }
56
Jian Lic565ebf2017-02-04 14:49:52 +090057 /**
58 * Tests the equals, hashCode and toString methods using Guava EqualsTester.
59 */
60 @Test
61 public void testEquals() {
62 new EqualsTester()
63 .addEqualityGroup(entry1, sameAsEntry1)
64 .addEqualityGroup(entry2)
65 .testEquals();
66 }
67
68 /**
69 * Tests creation of a DefaultMappingEntry using a mapping builder.
70 */
71 @Test
72 public void testConstruction() {
73 DefaultMappingEntry entry = (DefaultMappingEntry) entry1;
74
75 assertThat(entry.deviceId(), is(DeviceId.deviceId("lisp:10.1.1.1")));
76 assertThat(entry.id(), is(MappingId.valueOf(1)));
77 assertThat(entry.key(), is(MAPPING_KEY));
78 assertThat(entry.value(), is(MAPPING_VALUE));
79 }
80}