Ray Milkey | 8010bb4 | 2015-02-12 11:53:40 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.net.intent; |
| 17 | |
Ray Milkey | 8010bb4 | 2015-02-12 11:53:40 -0800 | [diff] [blame] | 18 | import org.junit.After; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.core.IdGenerator; |
Ray Milkey | 8010bb4 | 2015-02-12 11:53:40 -0800 | [diff] [blame] | 22 | import org.onosproject.store.Timestamp; |
| 23 | |
| 24 | import com.google.common.testing.EqualsTester; |
| 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.is; |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 28 | import static org.onosproject.net.intent.IntentTestsMocks.MockIntent; |
| 29 | import static org.onosproject.net.intent.IntentTestsMocks.MockTimestamp; |
Ray Milkey | 8010bb4 | 2015-02-12 11:53:40 -0800 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Unit tests for intent data objects. |
| 33 | */ |
| 34 | public class IntentDataTest { |
Ray Milkey | 8010bb4 | 2015-02-12 11:53:40 -0800 | [diff] [blame] | 35 | |
| 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 | } |