Toshio Koide | b609b3b | 2014-02-14 18:25:52 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent; |
| 2 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 3 | import static org.junit.Assert.assertEquals; |
Toshio Koide | b609b3b | 2014-02-14 18:25:52 -0800 | [diff] [blame] | 4 | import net.onrc.onos.intent.Intent.IntentState; |
| 5 | |
| 6 | import org.junit.After; |
| 7 | import org.junit.Before; |
| 8 | import org.junit.Test; |
| 9 | |
| 10 | public 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 Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 23 | IntentOperationList operations = new IntentOperationList(); |
Toshio Koide | b609b3b | 2014-02-14 18:25:52 -0800 | [diff] [blame] | 24 | |
| 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 | } |