blob: ab805bf71db9ebdfb46ee7e1550bdae23231ff68 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
Brian O'Connorf3d06162014-10-02 15:54:12 -070016package org.onlab.onos.net.intent;
17
Brian O'Connor520c0522014-11-23 23:50:47 -080018import org.junit.Ignore;
Thomas Vachuskac96058a2014-10-20 23:00:16 -070019import org.junit.Test;
Brian O'Connorf3d06162014-10-02 15:54:12 -070020
21import java.util.Arrays;
22import java.util.HashSet;
23import java.util.Set;
24
Thomas Vachuskac96058a2014-10-20 23:00:16 -070025import static org.junit.Assert.*;
Brian O'Connorf3d06162014-10-02 15:54:12 -070026
27/**
28 * Base facilities to test various intent tests.
29 */
Brian O'Connor520c0522014-11-23 23:50:47 -080030public abstract class IntentTest extends AbstractIntentTest {
Brian O'Connorf3d06162014-10-02 15:54:12 -070031 /**
32 * Produces a set of items from the supplied items.
33 *
34 * @param items items to be placed in set
35 * @param <T> item type
36 * @return set of items
37 */
38 protected static <T> Set<T> itemSet(T[] items) {
39 return new HashSet<>(Arrays.asList(items));
40 }
41
Brian O'Connor520c0522014-11-23 23:50:47 -080042 @Test @Ignore("Equality is based on ids, which will be different")
Brian O'Connorf3d06162014-10-02 15:54:12 -070043 public void equalsAndHashCode() {
44 Intent one = createOne();
45 Intent like = createOne();
46 Intent another = createAnother();
47
48 assertTrue("should be equal", one.equals(like));
49 assertEquals("incorrect hashCode", one.hashCode(), like.hashCode());
Brian O'Connorf3d06162014-10-02 15:54:12 -070050 assertFalse("should not be equal", one.equals(another));
Brian O'Connorf3d06162014-10-02 15:54:12 -070051 }
52
Brian O'Connor520c0522014-11-23 23:50:47 -080053 //@Test FIXME
Brian O'Connorf3d06162014-10-02 15:54:12 -070054 public void testToString() {
55 Intent one = createOne();
56 Intent like = createOne();
57 assertEquals("incorrect toString", one.toString(), like.toString());
58 }
59
60 /**
61 * Creates a new intent, but always a like intent, i.e. all instances will
62 * be equal, but should not be the same.
63 *
64 * @return intent
65 */
66 protected abstract Intent createOne();
67
68 /**
69 * Creates another intent, not equals to the one created by
70 * {@link #createOne()} and with a different hash code.
71 *
72 * @return another intent
73 */
74 protected abstract Intent createAnother();
75}