Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.batchoperation; |
| 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 4 | import static org.junit.Assert.assertTrue; |
| 5 | |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 6 | import java.util.List; |
| 7 | |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 8 | import net.onrc.onos.api.batchoperation.TestBatchOperation.IntegerTarget; |
| 9 | import net.onrc.onos.api.batchoperation.TestBatchOperation.Operator; |
| 10 | import net.onrc.onos.api.batchoperation.TestBatchOperation.StringTarget; |
| 11 | |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 12 | import org.junit.Test; |
| 13 | |
| 14 | /** |
| 15 | * Unit tests for BatchOperation class. |
| 16 | */ |
| 17 | public class BatchOperationTest { |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 18 | /** |
| 19 | * Tests constructor of the BatchOperation. It checks the size of the |
| 20 | * operations equals to 0. |
| 21 | */ |
| 22 | @Test |
| 23 | public void testConstructor() { |
| 24 | // Initialization |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 25 | TestBatchOperation ops = new TestBatchOperation(); |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 26 | |
| 27 | // Checks if there is no operation in the object |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 28 | assertEquals(0, ops.size()); |
| 29 | assertEquals(0, ops.getOperations().size()); |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | /** |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 33 | * Tests adding the operations to the BatchOperation. |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 34 | */ |
| 35 | @Test |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 36 | public void testAddOp() { |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 37 | // Initialization |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 38 | TestBatchOperation ops = new TestBatchOperation(); |
| 39 | assertEquals(0, ops.size()); |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 40 | |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 41 | // Adds one string-operation |
| 42 | ops.addStringOperation("target1"); |
| 43 | assertEquals(1, ops.size()); |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 44 | |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 45 | // Adds one integer-operation |
| 46 | ops.addIntegerOperation(123); |
| 47 | assertEquals(2, ops.size()); |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 48 | |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 49 | // Checks entries with the list |
| 50 | List<BatchOperationEntry<Operator, ?>> list = ops.getOperations(); |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 51 | assertEquals(2, list.size()); |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 52 | |
| 53 | BatchOperationEntry<Operator, ?> entry = list.get(0); |
| 54 | assertEquals(Operator.STRING, entry.getOperator()); |
| 55 | IBatchOperationTarget target = entry.getTarget(); |
| 56 | assertTrue(target instanceof StringTarget); |
| 57 | assertEquals("target1", ((StringTarget) target).getString()); |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 58 | |
| 59 | entry = list.get(1); |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 60 | assertEquals(Operator.INTEGER, entry.getOperator()); |
| 61 | target = entry.getTarget(); |
| 62 | assertTrue(target instanceof IntegerTarget); |
| 63 | assertEquals(Integer.valueOf(123), ((IntegerTarget) target).getInteger()); |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 64 | } |
| 65 | } |