SfcOvsDataStoreAPI implements Callable { @Override public Object call() throws Exception { Object result = null; switch (methodToCall) { case READ_OVSDB_BRIDGE: try { InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIID = (InstanceIdentifier<OvsdbBridgeAugmentation>) methodParameters[0]; result = readOvsdbBridge(bridgeIID); } catch (ClassCastException e) { LOG.error( "Cannot call readOvsdbBridge, passed method argument " + "is not instance of InstanceIdentifier<OvsdbBridgeAugmentation>: {}", methodParameters[0].toString()); } break; case PUT_OVSDB_BRIDGE: try { OvsdbBridgeAugmentation ovsdbBridge = (OvsdbBridgeAugmentation) methodParameters[0]; result = putOvsdbBridge(ovsdbBridge); } catch (ClassCastException e) { LOG.error("Cannot call putOvsdbBridge, passed method argument " + "is not instance of OvsdbBridgeAugmentation: {}", methodParameters[0].toString()); } break; case DELETE_OVSDB_NODE: try { InstanceIdentifier<Node> nodeIID = (InstanceIdentifier<Node>) methodParameters[0]; result = deleteOvsdbNode(nodeIID); } catch (ClassCastException e) { LOG.error( "Cannot call deleteOvsdbNode, passed method argument " + "is not instance of InstanceIdentifier<Node>: {}", methodParameters[0].toString()); } break; case PUT_OVSDB_TERMINATION_POINT: try { OvsdbBridgeAugmentation ovsdbBridge = (OvsdbBridgeAugmentation) methodParameters[0]; OvsdbTerminationPointAugmentation ovsdbTerminationPoint = (OvsdbTerminationPointAugmentation) methodParameters[1]; result = putOvsdbTerminationPoint(ovsdbBridge, ovsdbTerminationPoint); } catch (ClassCastException e) { LOG.error( "Cannot call putOvsdbTerminationPoint, passed method arguments " + "are not instances of OvsdbBridgeAugmentation{} and OvsdbTerminationPointAugmentation: {}", methodParameters[0].toString(), methodParameters[1].toString()); } break; case DELETE_OVSDB_TERMINATION_POINT: try { InstanceIdentifier<TerminationPoint> ovsdbTerminationPointIID = (InstanceIdentifier<TerminationPoint>) methodParameters[0]; result = deleteOvsdbTerminationPoint(ovsdbTerminationPointIID); } catch (ClassCastException e) { LOG.error( "Cannot call deleteOvsdbTerminationPoint, passed method argument " + "is not instance of InstanceIdentifier<TerminationPoint>: {}", methodParameters[0].toString()); } break; case READ_OVSDB_NODE_BY_IP: try { result = readOvsdbNodeByIp((String) methodParameters[0]); } catch (ClassCastException e) { LOG.error( "Cannot call readOvsdbNodeByIp, passed method argument " + "is not instance of String: {}", methodParameters[0].toString()); } break; case READ_OVSDB_NODE_BY_REF: try { result = readOvsdbNodeByRef((OvsdbNodeRef) methodParameters[0]); } catch (ClassCastException e) { LOG.error("Cannot call readOvsdbNodeByIp, passed method argument " + "is not instance of OvsdbNodeRef: {}", methodParameters[0]); } } return result; } SfcOvsDataStoreAPI(Method methodToCall, Object[] newMethodParameters); @Override Object call();  }
@Test public void testPutAndDeleteOvsdbTerminationPoint() throws Exception { SffDataPlaneLocatorBuilder sffDataPlaneLocatorBuilder = new SffDataPlaneLocatorBuilder(); sffDataPlaneLocatorBuilder.setName(dplName); SffDataPlaneLocator sffDataPlaneLocator = sffDataPlaneLocatorBuilder.build(); methodToCall = SfcOvsDataStoreAPI.Method.PUT_OVSDB_TERMINATION_POINT; methodParams[0] = createOvsdbBridgeAugmentation(); methodParams[1] = createOvsdbTerminationPointAugmentation(); sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); testResult = sfcOvsDataStoreAPIObject.call(); assertNotNull("Must not be null", testResult); methodToCall = SfcOvsDataStoreAPI.Method.DELETE_OVSDB_TERMINATION_POINT; methodParams[0] = createOvsdbTerminationPointIID(new SffName(testIpv4), sffDataPlaneLocator.getName()); sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); testResult = sfcOvsDataStoreAPIObject.call(); assertNotNull("Must not be null", testResult); }
@Test public void testReadOvsdbNodeByIpFailed() throws Exception { methodToCall = SfcOvsDataStoreAPI.Method.READ_OVSDB_NODE_BY_IP; methodParams[0] = testIpv4; sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); PowerMockito.stub(PowerMockito.method(SfcDataStoreAPI.class, "readTransactionAPI")) .toReturn(createFaultyTopology()); testResult = sfcOvsDataStoreAPIObject.call(); assertNull("Must be null", testResult); }
@Test public void testReadOvsdbNodeByIpFailedAgain() throws Exception { methodToCall = SfcOvsDataStoreAPI.Method.READ_OVSDB_NODE_BY_IP; methodParams[0] = testIpv4; sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); PowerMockito.stub(PowerMockito.method(SfcDataStoreAPI.class, "readTransactionAPI")) .toReturn(createFaultyTopologyAgain()); testResult = sfcOvsDataStoreAPIObject.call(); assertNull("Must be null", testResult); }
@Test public void testReadOvsdbNodeByIpv4() throws Exception { methodToCall = SfcOvsDataStoreAPI.Method.READ_OVSDB_NODE_BY_IP; methodParams[0] = testIpv4; sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); PowerMockito.stub(PowerMockito.method(SfcDataStoreAPI.class, "readTransactionAPI")) .toReturn(createIpv4Topology()); testResult = sfcOvsDataStoreAPIObject.call(); assertNotNull("Must not be null", testResult); }
@Test public void testReadOvsdbNodeByIpv6() throws Exception { methodToCall = SfcOvsDataStoreAPI.Method.READ_OVSDB_NODE_BY_IP; methodParams[0] = testIpv6; sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); PowerMockito.stub(PowerMockito.method(SfcDataStoreAPI.class, "readTransactionAPI")) .toReturn(createIpv6Topology()); testResult = sfcOvsDataStoreAPIObject.call(); assertNotNull("Must not be null", testResult); }
@Test public void testAllCallsWithIncorrectParameters() throws Exception { methodToCall = SfcOvsDataStoreAPI.Method.READ_OVSDB_BRIDGE; methodParams[0] = createOvsdbTerminationPointAugmentation(); sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); testResult = sfcOvsDataStoreAPIObject.call(); assertNull("Must be null", testResult); methodToCall = SfcOvsDataStoreAPI.Method.PUT_OVSDB_BRIDGE; methodParams[0] = createOvsdbTerminationPointAugmentation(); sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); testResult = sfcOvsDataStoreAPIObject.call(); assertNull("Must be null", testResult); methodToCall = SfcOvsDataStoreAPI.Method.DELETE_OVSDB_NODE; methodParams[0] = createOvsdbTerminationPointAugmentation(); sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); testResult = sfcOvsDataStoreAPIObject.call(); assertNull("Must be null", testResult); methodToCall = SfcOvsDataStoreAPI.Method.PUT_OVSDB_TERMINATION_POINT; methodParams[0] = createOvsdbTerminationPointAugmentation(); methodParams[1] = createOvsdbTerminationPointAugmentation(); sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); testResult = sfcOvsDataStoreAPIObject.call(); assertNull("Must be null", testResult); methodToCall = SfcOvsDataStoreAPI.Method.DELETE_OVSDB_TERMINATION_POINT; methodParams[0] = createOvsdbTerminationPointAugmentation(); sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); testResult = sfcOvsDataStoreAPIObject.call(); assertNull("Must be null", testResult); methodToCall = SfcOvsDataStoreAPI.Method.READ_OVSDB_NODE_BY_IP; methodParams[0] = createOvsdbTerminationPointAugmentation(); sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); testResult = sfcOvsDataStoreAPIObject.call(); assertNull("Must be null", testResult); methodToCall = SfcOvsDataStoreAPI.Method.READ_OVSDB_NODE_BY_REF; methodParams[0] = createOvsdbTerminationPointAugmentation(); sfcOvsDataStoreAPIObject = new SfcOvsDataStoreAPI(methodToCall, methodParams); testResult = sfcOvsDataStoreAPIObject.call(); assertNull("Must be null", testResult); }