blob: a95314942a167898bfcaacc33145130ea38aacb9 [file] [log] [blame]
Ray Milkey8010bb42015-02-12 11:53:40 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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.net.intent;
17
Ray Milkey8010bb42015-02-12 11:53:40 -080018import org.junit.After;
19import org.junit.Before;
20import org.junit.Test;
21import org.onosproject.core.IdGenerator;
Ray Milkey8010bb42015-02-12 11:53:40 -080022import org.onosproject.store.Timestamp;
23
24import com.google.common.testing.EqualsTester;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
Ray Milkey43a28222015-02-23 13:57:58 -080028import static org.onosproject.net.intent.IntentTestsMocks.MockIntent;
29import static org.onosproject.net.intent.IntentTestsMocks.MockTimestamp;
Ray Milkey8010bb42015-02-12 11:53:40 -080030
31/**
32 * Unit tests for intent data objects.
33 */
34public class IntentDataTest {
Ray Milkey8010bb42015-02-12 11:53:40 -080035
36 private Timestamp timestamp1;
37 private Timestamp timestamp2;
38 private Timestamp timestamp3;
39
40 private Intent intent1;
41 private Intent intent2;
42 private Intent intent3;
43
44 private IntentData data1;
45 private IntentData data1Copy;
46 private IntentData data2;
47 private IntentData data2Copy;
48 private IntentData data3;
49 private IntentData data3Copy;
50
51 IdGenerator idGenerator;
52
53 @Before
54 public void setUpTest() {
55 idGenerator = new MockIdGenerator();
56 Intent.bindIdGenerator(idGenerator);
57
58 timestamp1 = new MockTimestamp(1);
59 timestamp2 = new MockTimestamp(2);
60 timestamp3 = new MockTimestamp(3);
61
62 intent1 = new MockIntent(1L);
63 intent2 = new MockIntent(2L);
64 intent3 = new MockIntent(3L);
65
66 data1 = new IntentData(intent1, IntentState.INSTALLED, timestamp1);
67 data1Copy = new IntentData(intent1, IntentState.INSTALLED, timestamp1);
68 data2 = new IntentData(intent2, IntentState.INSTALLED, timestamp2);
69 data2Copy = new IntentData(intent2, IntentState.INSTALLED, timestamp2);
70 data3 = new IntentData(intent3, IntentState.INSTALLED, timestamp3);
71 data3Copy = new IntentData(intent3, IntentState.INSTALLED, timestamp3);
72 }
73
74 @After
75 public void tearDownTest() {
76 Intent.unbindIdGenerator(idGenerator);
77 }
78
79 /**
80 * Checks that intent data objects are properly constructed.
81 */
82 @Test
83 public void checkConstruction() {
84 assertThat(data1.state(), is(IntentState.INSTALLED));
85 assertThat(data1.version(), is(timestamp1));
86 assertThat(data1.intent(), is(intent1));
87 }
88
89 /**
90 * Checks equals() for intent data objects.
91 */
92 @Test
93 public void checkEquals() {
94 new EqualsTester()
95 .addEqualityGroup(data1, data1Copy)
96 .addEqualityGroup(data2, data2Copy)
97 .addEqualityGroup(data3, data3Copy)
98 .testEquals();
99 }
100}