From 8e14a9956d2d914a82f0fa3ab0a6666556cf05a2 Mon Sep 17 00:00:00 2001 From: Ryan Goulding Date: Thu, 14 May 2015 16:40:02 -0400 Subject: [PATCH] Refactor tests for TerminationPoint options This change refactors the test procedure for TerminationPoint options. Functionality is added to perform "update" tests for the TerminationPoint options field. The existing test case for Create, Read & Delete of TerminationPoint options is consolidated with the new update test procedure resulting in one test containing 16 test cases for full CRUD coverage. Change-Id: Icf7cabf824b09e7b27e5af4ec11bb561bd10cfdf Signed-off-by: Ryan Goulding --- .../ovsdb/southbound/it/SouthboundIT.java | 340 ++++++++++++++++-- 1 file changed, 304 insertions(+), 36 deletions(-) diff --git a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java b/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java index 56c9f4d6a..587e81cf1 100644 --- a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java +++ b/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java @@ -1387,49 +1387,317 @@ public class SouthboundIT extends AbstractMdsalTestBase { Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } + /* + * Generates the test cases involved in testing TP Options. See inline comments for descriptions of + * the particular cases considered. + * + * The return value is a Map in the form (K,V)=(testCaseName,testCase). + * - testCaseName is a String + * - testCase is a Map in the form (K,V) s.t. K=(EXPECTED_VALUES_KEY|INPUT_VALUES_KEY) and V is a List of + * either corresponding INPUT TP Options, or EXPECTED TP Options + * INPUT is the List we use when calling + * TerminationPointAugmentationBuilder.setOptions() + * EXPECTED is the List we expect to receive after calling + * TerminationPointAugmentationBuilder.getOptions() + */ + private Map>> generateTerminationPointOptionsTestCases() { + Map>> testMap = + new HashMap>>(); + + final String TP_OPTIONS_KEY = "TPOptionsKey"; + final String TP_OPTIONS_VALUE = "TPOptionsValue"; + final String FORMAT_STR = "%s_%s_%d"; + final String GOOD_KEY = "GoodKey"; + final String GOOD_VALUE = "GoodValue"; + final String NO_VALUE_FOR_KEY = "NoValueForKey"; + final String NO_KEY_FOR_VALUE = "NoKeyForValue"; + + // Test Case 1: TestOneOptions + // Test Type: Positive + // Description: Create a termination point with one Options + // Expected: A termination point is created with the single Options specified below + final String testOneOptionsName = "TestOneOptions"; + int optionsCounter = 0; + List oneOptions = (List) Lists.newArrayList( + (new OptionsBuilder() + .setOption(String.format(FORMAT_STR, testOneOptionsName, + TP_OPTIONS_KEY, ++optionsCounter)) + .setValue(String.format(FORMAT_STR, testOneOptionsName, + TP_OPTIONS_VALUE, optionsCounter)) + .build())); + Map> testCase = Maps.newHashMap(); + testCase.put(EXPECTED_VALUES_KEY, oneOptions); + testCase.put(INPUT_VALUES_KEY, oneOptions); + testMap.put(testOneOptionsName, testCase); + + // Test Case 2: TestFiveOptions + // Test Type: Positive + // Description: Create a termination point with multiple (five) Options + // Expected: A termination point is created with the five options specified below + final String testFiveOptions = "TestFiveOptions"; + optionsCounter = 0; + List fiveOptions = (List) Lists.newArrayList( + (new OptionsBuilder() + .setOption(String.format(FORMAT_STR, testFiveOptions, + TP_OPTIONS_KEY, ++optionsCounter)) + .setValue(String.format(FORMAT_STR, testFiveOptions, + TP_OPTIONS_VALUE, optionsCounter)) + .build()), + (new OptionsBuilder() + .setOption(String.format(FORMAT_STR, testFiveOptions, + TP_OPTIONS_KEY, ++optionsCounter)) + .setValue(String.format(FORMAT_STR, testFiveOptions, + TP_OPTIONS_VALUE, optionsCounter)) + .build()), + (new OptionsBuilder() + .setOption(String.format(FORMAT_STR, testFiveOptions, + TP_OPTIONS_KEY, ++optionsCounter)) + .setValue(String.format(FORMAT_STR, testFiveOptions, + TP_OPTIONS_VALUE, optionsCounter)) + .build()), + (new OptionsBuilder() + .setOption(String.format(FORMAT_STR, testFiveOptions, + TP_OPTIONS_KEY, ++optionsCounter)) + .setValue(String.format(FORMAT_STR, testFiveOptions, + TP_OPTIONS_VALUE, optionsCounter)) + .build()), + (new OptionsBuilder() + .setOption(String.format(FORMAT_STR, testFiveOptions, + TP_OPTIONS_KEY, ++optionsCounter)) + .setValue(String.format(FORMAT_STR, testFiveOptions, + TP_OPTIONS_VALUE, optionsCounter)) + .build())); + testCase = Maps.newHashMap(); + testCase.put(EXPECTED_VALUES_KEY, fiveOptions); + testCase.put(INPUT_VALUES_KEY, fiveOptions); + testMap.put(testOneOptionsName, testCase); + + // Test Case 3: TestOneGoodOptionsOneMalformedOptionsValue + // Test Type: Negative + // Description: + // One perfectly fine Options + // (TestOneGoodOptionsOneMalformedOptionsValue_OptionsKey_1, + // TestOneGoodOptionsOneMalformedOptions_OptionsValue_1) + // and one malformed Options which only has key specified + // (TestOneGoodOptionsOneMalformedOptionsValue_NoValueForKey_2, + // UNSPECIFIED) + // Expected: A termination point is created without any options + final String testOneGoodOptionsOneMalformedOptionsValueName = + "TestOneGoodOptionsOneMalformedOptionsValue"; + optionsCounter = 0; + Options oneGood = new OptionsBuilder() + .setOption(String.format(FORMAT_STR, testOneGoodOptionsOneMalformedOptionsValueName, + GOOD_KEY, ++optionsCounter)) + .setValue(String.format("FORMAT_STR", + testOneGoodOptionsOneMalformedOptionsValueName, + GOOD_VALUE, optionsCounter)) + .build(); + Options oneBad = new OptionsBuilder() + .setOption(String.format(FORMAT_STR, + testOneGoodOptionsOneMalformedOptionsValueName, NO_VALUE_FOR_KEY, ++optionsCounter)) + .build(); + List oneGoodOneBadInput = (List) Lists.newArrayList( + oneGood, oneBad); + List oneGoodOneBadExpected = null; + testCase = Maps.newHashMap(); + testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); + testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); + + // Test Case 4: TestOneGoodOptionsOneMalformedOptionsKey + // Test Type: Negative + // Description: + // One perfectly fine Options + // (TestOneGoodOptionsOneMalformedOptionsValue_OptionsKey_1, + // TestOneGoodOptionsOneMalformedOptions_OptionsValue_1) + // and one malformed Options which only has key specified + // (UNSPECIFIED, + // TestOneGoodOptionsOneMalformedOptionsKey_NoKeyForValue_2) + // Expected: A termination point is created without any options + final String testOneGoodOptionsOneMalformedOptionsKeyName = + "TestOneGoodOptionsOneMalformedOptionsKey"; + optionsCounter = 0; + oneGood = new OptionsBuilder() + .setOption(String.format(FORMAT_STR, testOneGoodOptionsOneMalformedOptionsKeyName, + GOOD_KEY, ++optionsCounter)) + .setValue(String.format("FORMAT_STR", + testOneGoodOptionsOneMalformedOptionsKeyName, + GOOD_VALUE, optionsCounter)) + .build(); + oneBad = new OptionsBuilder() + .setOption(String.format(FORMAT_STR, + testOneGoodOptionsOneMalformedOptionsKeyName, NO_KEY_FOR_VALUE, ++optionsCounter)) + .build(); + oneGoodOneBadInput = (List) Lists.newArrayList( + oneGood, oneBad); + oneGoodOneBadExpected = null; + testCase = Maps.newHashMap(); + testCase.put(INPUT_VALUES_KEY, oneGoodOneBadInput); + testCase.put(EXPECTED_VALUES_KEY, oneGoodOneBadExpected); + + return testMap; + } + + /* + * @see SouthboundIT.testCRUDTerminationPointOptions() + * This is helper test method to compare a test "set" of Options against an expected "set" + */ + private void assertExpectedOptionsExist( List expected, + List test ) { + + if (expected != null) { + for (Options expectedOption : expected) { + Assert.assertTrue(test.contains(expectedOption)); + } + } else { + Assert.assertNull(test); + } + } + + /* + * @see SouthboundIT.testCRUDTPOptions() + * This is a helper test method. The method only checks if + * updateFromInputOptions != updateToInputOptions, (i.e., the updateTo "set" isn't the same + * as the updateFrom "set". Then, the method ensures each element of erase is not an element of test, as the input + * test cases are divergent. + */ + private void assertOptionsErased( List updateFromInputOptions, + List updateToInputOptions, + List updateFromExpectedOptions, + List updateToTestOptions ) { + + if (!updateFromInputOptions.containsAll(updateToInputOptions)) { + for (Options erasedOption : updateFromExpectedOptions) { + Assert.assertTrue(!updateToTestOptions.contains(erasedOption)); + } + } + } + + /* + * Tests the CRUD operations for TerminationPoint options. + * + * @see SouthboundIT.generateTerminationPointOptions() for specific test case information + */ @Test - public void testTerminationPointOptions() throws InterruptedException { + public void testCRUDTerminationPointOptions() throws InterruptedException { + final String TEST_PREFIX = "CRUDTPOptions"; + final int TERMINATION_POINT_TEST_INDEX = 0; + ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portStr); connectOvsdbNode(connectionInfo); - Assert.assertTrue(addBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)); - OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); - Assert.assertNotNull(bridge); - NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier( - connectionInfo, bridge.getBridgeName())); - OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = - createGenericOvsdbTerminationPointAugmentationBuilder(); - String portName = "testInterfaceOptions"; - ovsdbTerminationBuilder.setName(portName); - //setup - OptionsBuilder optionsBuilder1 = new OptionsBuilder(); - optionsBuilder1.setOption("option1"); - optionsBuilder1.setValue("optionValue1"); - OptionsBuilder optionsBuilder2 = new OptionsBuilder(); - optionsBuilder2.setOption("option2"); - optionsBuilder2.setValue("optionValue2"); - List options = Lists.newArrayList(optionsBuilder1.build(), - optionsBuilder2.build()); - ovsdbTerminationBuilder.setOptions(options); - Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder)); - InstanceIdentifier terminationPointIid = getTpIid(connectionInfo, bridge); - Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid); - Assert.assertNotNull(terminationPointNode); + // updateFromTestCases represent the original test case value. updateToTestCases represent the new value after + // the update has been performed. + Map>> updateFromTestCases = + generateTerminationPointOptionsTestCases(); + Map>> updateToTestCases = + generateTerminationPointOptionsTestCases(); + Map> updateFromTestCase = null; + List updateFromInputOptions = null; + List updateFromExpectedOptions = null; + List updateFromConfigurationOptions = null; + List updateFromOperationalOptions = null; + Map> updateToTestCase = null; + List updateToInputOptions = null; + List updateToExpectedOptions = null; + List updateToConfigurationOptions = null; + List updateToOperationalOptions = null; + String testBridgeName = null; + String testPortName = null; + OvsdbTerminationPointAugmentation updateFromConfigurationTerminationPointAugmentation = null; + OvsdbTerminationPointAugmentation updateFromOperationalTerminationPointAugmenation = null; + OvsdbTerminationPointAugmentation updateToConfigurationTerminationPointAugmentation = null; + OvsdbTerminationPointAugmentation updateToOperationalTerminationPointAugmentation = null; + OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = null; + OvsdbTerminationPointAugmentationBuilder tpUpdateAugmentationBuilder = null; + TerminationPointBuilder tpUpdateBuilder = null; + NodeBuilder portUpdateNodeBuilder = null; + NodeId testBridgeNodeId = null; + NodeId portUpdateNodeId = null; + InstanceIdentifier portIid = null; + boolean result = false; - List terminationPoints = terminationPointNode.getTerminationPoint(); - for (TerminationPoint terminationPoint : terminationPoints) { - OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation = - terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class); - if (ovsdbTerminationPointAugmentation.getName().equals(portName)) { - List actualOptions = ovsdbTerminationPointAugmentation. - getOptions(); - Assert.assertTrue((options.size() == actualOptions.size())); - for (Options option : options) { - Assert.assertTrue(actualOptions.contains(option)); - } + for (String updateFromTestCaseKey : updateFromTestCases.keySet()) { + updateFromTestCase = updateFromTestCases.get(updateFromTestCaseKey); + updateFromInputOptions = updateFromTestCase.get(INPUT_VALUES_KEY); + updateFromExpectedOptions = updateFromTestCase.get(EXPECTED_VALUES_KEY); + for (String testCaseKey : updateToTestCases.keySet()) { + testPortName = testBridgeName = String.format("%s_%s", TEST_PREFIX, testCaseKey); + updateToTestCase = updateToTestCases.get(testCaseKey); + updateToInputOptions = updateToTestCase.get(INPUT_VALUES_KEY); + updateToExpectedOptions = updateToTestCase.get(EXPECTED_VALUES_KEY); + + // CREATE: Create the test interface + Assert.assertTrue(addBridge(connectionInfo, null, + testBridgeName, null, true, SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), + true, null, null, null)); + testBridgeNodeId = SouthboundMapper.createManagedNodeId(SouthboundMapper.createInstanceIdentifier( + connectionInfo, new OvsdbBridgeName(testBridgeName))); + tpCreateAugmentationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); + tpCreateAugmentationBuilder.setName(testPortName); + tpCreateAugmentationBuilder.setOptions(updateFromInputOptions); + Assert.assertTrue(addTerminationPoint(testBridgeNodeId, testPortName, tpCreateAugmentationBuilder)); + + // READ: Read the test interface and ensure changes are propagated to the CONFIGURATION data store, + // then repeat for OPERATIONAL data store + updateFromConfigurationTerminationPointAugmentation = + getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, + LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); + updateFromConfigurationOptions = updateFromConfigurationTerminationPointAugmentation + .getOptions(); + assertExpectedOptionsExist(updateFromExpectedOptions, + updateFromConfigurationOptions); + updateFromOperationalTerminationPointAugmenation = + getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, + LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); + updateFromOperationalOptions = updateFromOperationalTerminationPointAugmenation + .getOptions(); + assertExpectedOptionsExist(updateFromExpectedOptions, + updateFromOperationalOptions); + + // UPDATE: update the external_ids + testBridgeNodeId = getBridgeNode(connectionInfo, testBridgeName).getNodeId(); + tpUpdateAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); + tpUpdateAugmentationBuilder.setOptions(updateToInputOptions); + portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); + portUpdateNodeBuilder = new NodeBuilder(); + portUpdateNodeId = SouthboundMapper.createManagedNodeId(portIid); + portUpdateNodeBuilder.setNodeId(portUpdateNodeId); + tpUpdateBuilder = new TerminationPointBuilder(); + tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testPortName))); + tpUpdateBuilder.addAugmentation( + OvsdbTerminationPointAugmentation.class, + tpUpdateAugmentationBuilder.build()); + portUpdateNodeBuilder.setTerminationPoint(Lists.newArrayList(tpUpdateBuilder.build())); + result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, + portIid, portUpdateNodeBuilder.build()); + Thread.sleep(OVSDB_UPDATE_TIMEOUT); + Assert.assertTrue(result); + + // READ: the test interface and ensure changes are propagated to the CONFIGURATION data store, + // then repeat for OPERATIONAL data store + updateToConfigurationTerminationPointAugmentation = + getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, + LogicalDatastoreType.CONFIGURATION, TERMINATION_POINT_TEST_INDEX); + updateToConfigurationOptions = updateToConfigurationTerminationPointAugmentation + .getOptions(); + assertExpectedOptionsExist(updateToExpectedOptions, updateToConfigurationOptions); + updateToOperationalTerminationPointAugmentation = + getOvsdbTerminationPointAugmentation(connectionInfo, testBridgeName, + LogicalDatastoreType.OPERATIONAL, TERMINATION_POINT_TEST_INDEX); + updateToOperationalOptions = updateToOperationalTerminationPointAugmentation + .getOptions(); + assertExpectedOptionsExist(updateToExpectedOptions, updateToOperationalOptions); + + // Make sure the old interface external ids aren't present in the CONFIGURATION data store + assertOptionsErased(updateFromInputOptions, updateToInputOptions, + updateFromExpectedOptions, updateToConfigurationOptions); + assertOptionsErased(updateFromInputOptions, updateToInputOptions, + updateFromExpectedOptions, updateToConfigurationOptions); + + // DELETE + Assert.assertTrue(deleteBridge(connectionInfo, testBridgeName)); } } - Assert.assertTrue(deleteBridge(connectionInfo)); Assert.assertTrue(disconnectOvsdbNode(connectionInfo)); } -- 2.36.6