@Test public void testRemoveClassMap() throws Exception { LOG.debug("scenario: pass through with null classMapEntries collection"); assertTrue(PolicyWriterUtil.removeClassMap(null, getLocation())); LOG.debug("scenario: pass through with empty classMapEntries collection"); final ClassMap classMap = new ClassMapBuilder().setName(UNIT_CLASS_MAP_ENTRY_NAME).build(); assertTrue(PolicyWriterUtil.removeClassMap(classMap, getLocation())); LOG.debug("scenario: fail with one entry, no writeOnlyTransaction"); PowerMockito.stub(PowerMockito.method(PolicyWriterUtil.class, NETCONF_READ)).toReturn(new ClassBuilder().build()); PowerMockito.stub(PowerMockito.method(NetconfTransactionCreator.class, NETCONF_WRITE_ONLY_TRANSACTION)) .toReturn(java.util.Optional.empty()); assertFalse(PolicyWriterUtil.removeClassMap(classMap, getLocation())); LOG.debug("scenario: fail with one entry, available writeOnlyTransaction, no readOnlyTransaction"); PowerMockito.stub(PowerMockito.method(NetconfTransactionCreator.class, NETCONF_WRITE_ONLY_TRANSACTION)).toReturn(wTxOptional); when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null)); assertFalse(PolicyWriterUtil.removeClassMap(classMap, getLocation())); LOG.debug("scenario: succeed with one entry, available writeOnlyTransaction, available readOnlyTransaction"); PowerMockito.stub(PowerMockito.method(NetconfTransactionCreator.class, NETCONF_READ_ONLY_TRANSACTION)).toReturn(rTxOptional); PowerMockito.stub(PowerMockito.method(PolicyWriterUtil.class, NETCONF_READ)).toReturn(null); when(rTx.read(eq(LogicalDatastoreType.CONFIGURATION), Matchers.<InstanceIdentifier<ClassMap>>any())) .thenReturn(Futures.immediateCheckedFuture(Optional.absent())); assertTrue(PolicyWriterUtil.removeClassMap(classMap, getLocation())); LOG.debug("scenario: fail with one entry, available writeOnlyTransaction, available readOnlyTransaction, check->false"); PowerMockito.stub(PowerMockito.method(PolicyWriterUtil.class, NETCONF_READ)).toReturn(new ClassBuilder().build()); assertFalse(PolicyWriterUtil.removeClassMap(classMap, getLocation())); }
public static boolean removeClassMap(final ClassMap classMap, final PolicyManagerImpl.PolicyMapLocation location) { final DataBroker mountpoint = location.getMountpoint(); final NodeId nodeId = location.getNodeId(); boolean result = true; if (classMap == null) { return true; } final InstanceIdentifier<ClassMap> classMapIid = classMapInstanceIdentifier(classMap); netconfDeleteIfPresent(mountpoint, classMapIid); final java.util.Optional<ClassMap> checkCreated = java.util.Optional.ofNullable(netconfRead(mountpoint, classMapIid)); if (checkCreated.isPresent()) { LOG.warn("Failed to remove class-map {} on node {}", classMap.getName(), nodeId.getValue()); result = false; } else { LOG.trace("Class-map {} removed from node {}", classMap.getName(), nodeId.getValue()); } return result; }
PolicyWriterUtil { public static boolean removeClassMap(final ClassMap classMap, final PolicyManagerImpl.PolicyMapLocation location) { final DataBroker mountpoint = location.getMountpoint(); final NodeId nodeId = location.getNodeId(); boolean result = true; if (classMap == null) { return true; } final InstanceIdentifier<ClassMap> classMapIid = classMapInstanceIdentifier(classMap); netconfDeleteIfPresent(mountpoint, classMapIid); final java.util.Optional<ClassMap> checkCreated = java.util.Optional.ofNullable(netconfRead(mountpoint, classMapIid)); if (checkCreated.isPresent()) { LOG.warn("Failed to remove class-map {} on node {}", classMap.getName(), nodeId.getValue()); result = false; } else { LOG.trace("Class-map {} removed from node {}", classMap.getName(), nodeId.getValue()); } return result; } }
PolicyWriterUtil { public static boolean removeClassMap(final ClassMap classMap, final PolicyManagerImpl.PolicyMapLocation location) { final DataBroker mountpoint = location.getMountpoint(); final NodeId nodeId = location.getNodeId(); boolean result = true; if (classMap == null) { return true; } final InstanceIdentifier<ClassMap> classMapIid = classMapInstanceIdentifier(classMap); netconfDeleteIfPresent(mountpoint, classMapIid); final java.util.Optional<ClassMap> checkCreated = java.util.Optional.ofNullable(netconfRead(mountpoint, classMapIid)); if (checkCreated.isPresent()) { LOG.warn("Failed to remove class-map {} on node {}", classMap.getName(), nodeId.getValue()); result = false; } else { LOG.trace("Class-map {} removed from node {}", classMap.getName(), nodeId.getValue()); } return result; } private  PolicyWriterUtil(); }
PolicyWriterUtil { public static boolean removeClassMap(final ClassMap classMap, final PolicyManagerImpl.PolicyMapLocation location) { final DataBroker mountpoint = location.getMountpoint(); final NodeId nodeId = location.getNodeId(); boolean result = true; if (classMap == null) { return true; } final InstanceIdentifier<ClassMap> classMapIid = classMapInstanceIdentifier(classMap); netconfDeleteIfPresent(mountpoint, classMapIid); final java.util.Optional<ClassMap> checkCreated = java.util.Optional.ofNullable(netconfRead(mountpoint, classMapIid)); if (checkCreated.isPresent()) { LOG.warn("Failed to remove class-map {} on node {}", classMap.getName(), nodeId.getValue()); result = false; } else { LOG.trace("Class-map {} removed from node {}", classMap.getName(), nodeId.getValue()); } return result; } private  PolicyWriterUtil(); static boolean writeClassMap(@Nonnull final ClassMap classMap,
                                        final PolicyManagerImpl.PolicyMapLocation policyMapLocation); static boolean removeClassMap(final ClassMap classMap, final PolicyManagerImpl.PolicyMapLocation location); static boolean writePolicyMap(final PolicyMap policyMap, final PolicyManagerImpl.PolicyMapLocation location); static boolean removePolicyMap(final PolicyManagerImpl.PolicyMapLocation location); static boolean writePolicyMapEntry(final Class policyMapEntry,
                                              final PolicyManagerImpl.PolicyMapLocation location); static boolean removePolicyMapEntry(final Class policyMapEntry, final PolicyManagerImpl.PolicyMapLocation location); static boolean writeInterface(final PolicyManagerImpl.PolicyMapLocation location); static boolean removeInterface(final PolicyManagerImpl.PolicyMapLocation location); static boolean writeRemote(final ServiceFfName remoteForwarder,
                                      final PolicyManagerImpl.PolicyMapLocation location); static boolean removeRemote(final ServiceFfName remoteForwarder, final PolicyManagerImpl.PolicyMapLocation location); static boolean writeServicePath(final ServiceChain serviceChain,
                                           final PolicyManagerImpl.PolicyMapLocation location); static boolean removeServicePath(final ServiceChain serviceChain, final PolicyManagerImpl.PolicyMapLocation location); static InstanceIdentifier<PolicyMap> policyMapInstanceIdentifier(final String policyMapName); static InstanceIdentifier<ServicePolicy> interfaceInstanceIdentifier(final String ethernetName); static U netconfRead(final DataBroker mountpoint,
                                                       final InstanceIdentifier<U> readIID); }
PolicyWriterUtil { public static boolean removeClassMap(final ClassMap classMap, final PolicyManagerImpl.PolicyMapLocation location) { final DataBroker mountpoint = location.getMountpoint(); final NodeId nodeId = location.getNodeId(); boolean result = true; if (classMap == null) { return true; } final InstanceIdentifier<ClassMap> classMapIid = classMapInstanceIdentifier(classMap); netconfDeleteIfPresent(mountpoint, classMapIid); final java.util.Optional<ClassMap> checkCreated = java.util.Optional.ofNullable(netconfRead(mountpoint, classMapIid)); if (checkCreated.isPresent()) { LOG.warn("Failed to remove class-map {} on node {}", classMap.getName(), nodeId.getValue()); result = false; } else { LOG.trace("Class-map {} removed from node {}", classMap.getName(), nodeId.getValue()); } return result; } private  PolicyWriterUtil(); static boolean writeClassMap(@Nonnull final ClassMap classMap,
                                        final PolicyManagerImpl.PolicyMapLocation policyMapLocation); static boolean removeClassMap(final ClassMap classMap, final PolicyManagerImpl.PolicyMapLocation location); static boolean writePolicyMap(final PolicyMap policyMap, final PolicyManagerImpl.PolicyMapLocation location); static boolean removePolicyMap(final PolicyManagerImpl.PolicyMapLocation location); static boolean writePolicyMapEntry(final Class policyMapEntry,
                                              final PolicyManagerImpl.PolicyMapLocation location); static boolean removePolicyMapEntry(final Class policyMapEntry, final PolicyManagerImpl.PolicyMapLocation location); static boolean writeInterface(final PolicyManagerImpl.PolicyMapLocation location); static boolean removeInterface(final PolicyManagerImpl.PolicyMapLocation location); static boolean writeRemote(final ServiceFfName remoteForwarder,
                                      final PolicyManagerImpl.PolicyMapLocation location); static boolean removeRemote(final ServiceFfName remoteForwarder, final PolicyManagerImpl.PolicyMapLocation location); static boolean writeServicePath(final ServiceChain serviceChain,
                                           final PolicyManagerImpl.PolicyMapLocation location); static boolean removeServicePath(final ServiceChain serviceChain, final PolicyManagerImpl.PolicyMapLocation location); static InstanceIdentifier<PolicyMap> policyMapInstanceIdentifier(final String policyMapName); static InstanceIdentifier<ServicePolicy> interfaceInstanceIdentifier(final String ethernetName); static U netconfRead(final DataBroker mountpoint,
                                                       final InstanceIdentifier<U> readIID);  }