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