blob: bad546de47fdbce52589c2b75b4dc181b7d287bf [file] [log] [blame]
Toshio Koideb609b3b2014-02-14 18:25:52 -08001package net.onrc.onos.intent;
2
Toshio Koide27ffd412014-02-18 19:15:27 -08003import static org.junit.Assert.assertEquals;
Toshio Koideb609b3b2014-02-14 18:25:52 -08004import net.onrc.onos.intent.Intent.IntentState;
5
6import org.junit.After;
7import org.junit.Before;
8import org.junit.Test;
9
10public class IntentMapTest {
11
12 @Before
13 public void setUp() throws Exception {
14 }
15
16 @After
17 public void tearDown() throws Exception {
18 }
19
20 @Test
21 public void test() {
22 IntentMap intents = new IntentMap();
Toshio Koide4f308732014-02-18 15:19:48 -080023 IntentOperationList operations = new IntentOperationList();
Toshio Koideb609b3b2014-02-14 18:25:52 -080024
25 // add three intents
26
27 ShortestPathIntent intent1 =
28 new ShortestPathIntent("1", 11L, 12L, 13L, 14L, 15L, 16L);
29 ShortestPathIntent intent2 =
30 new ShortestPathIntent("2", 21L, 22L, 23L, 24L, 25L, 26L);
31 ConstrainedShortestPathIntent intent3 =
32 new ConstrainedShortestPathIntent("3", 31L, 32L, 33L, 34L, 35L, 36L, 1000.0);
33
34 operations.add(new IntentOperation(IntentOperation.Operator.ADD, intent1));
35 operations.add(new IntentOperation(IntentOperation.Operator.ADD, intent2));
36 operations.add(new IntentOperation(IntentOperation.Operator.ADD, intent3));
37 intents.executeOperations(operations);
38
39 // check
40
41 assertEquals(3, intents.getAllIntents().size());
42 assertEquals(intent1, intents.getIntent("1"));
43 assertEquals(intent2, intents.getIntent("2"));
44 assertEquals(intent3, intents.getIntent("3"));
45
46 // request removal of an intent
47
48 Intent intent4 = new Intent("1");
49 operations.clear();
50 operations.add(new IntentOperation(IntentOperation.Operator.REMOVE, intent4));
51 intents.executeOperations(operations);
52
53 // check
54
55 assertEquals(3, intents.getAllIntents().size());
56 assertEquals(IntentState.DEL_REQ, intent1.getState());
57
58 // change intents' state which will be purged
59
60 intent2.setState(IntentState.INST_NACK);
61 intent3.setState(IntentState.DEL_ACK);
62
63 // purge
64
65 intents.purge();
66
67 // check
68
69 assertEquals(1, intents.getAllIntents().size());
70 assertEquals("1", intents.getAllIntents().iterator().next().getId());
71 }
72}