From 68a198b395368f227bb013f5259f3eb587b0e107 Mon Sep 17 00:00:00 2001 From: "matus.kubica" Date: Thu, 13 Apr 2017 18:01:34 +0200 Subject: [PATCH] Bug 8153: Enforce check-style rules for netconf - config-netconf-connector Organize Imports for Checkstyle compliance. Checkstyle compliance: line length. Checkstyle compliance: various types of small changes. Checkstyle compliant Exception handling. Checkstyle final clean up & enforcement. Add the fail on violation flag into the pom.xml . Change-Id: Idb0546157cb40658eccd2af6b73d66362fc22508 Signed-off-by: matus.kubica --- netconf/config-netconf-connector/pom.xml | 7 + .../operations/DiscardChanges.java | 7 +- .../operations/Lock.java | 14 +- .../operations/UnLock.java | 14 +- .../operations/Validate.java | 13 +- .../operations/editconfig/EditConfig.java | 6 +- .../editconfig/EditConfigXmlParser.java | 10 +- .../operations/getconfig/GetConfig.java | 3 +- .../operations/runtimerpc/RuntimeRpc.java | 6 +- .../osgi/Activator.java | 25 ++- .../osgi/NetconfOperationProvider.java | 3 +- .../NetconfOperationServiceFactoryImpl.java | 3 +- .../NetconfMappingTest.java | 164 +++++++++++------- .../operations/editconfig/EditConfigTest.java | 14 +- .../MergeEditConfigStrategyTest.java | 32 ++-- 15 files changed, 197 insertions(+), 124 deletions(-) diff --git a/netconf/config-netconf-connector/pom.xml b/netconf/config-netconf-connector/pom.xml index 8a63f3c899..85593ce6be 100644 --- a/netconf/config-netconf-connector/pom.xml +++ b/netconf/config-netconf-connector/pom.xml @@ -135,6 +135,13 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + diff --git a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/DiscardChanges.java b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/DiscardChanges.java index 52d97fb950..f3cc24494c 100644 --- a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/DiscardChanges.java +++ b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/DiscardChanges.java @@ -32,7 +32,8 @@ public class DiscardChanges extends AbstractConfigNetconfOperation { private static final Logger LOG = LoggerFactory.getLogger(DiscardChanges.class); - public DiscardChanges(final ConfigSubsystemFacade configSubsystemFacade, final String netconfSessionIdForReporting) { + public DiscardChanges(final ConfigSubsystemFacade configSubsystemFacade, + final String netconfSessionIdForReporting) { super(configSubsystemFacade, netconfSessionIdForReporting); } @@ -46,8 +47,10 @@ public class DiscardChanges extends AbstractConfigNetconfOperation { return DISCARD; } + @SuppressWarnings("checkstyle:IllegalCatch") @Override - protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement xml) throws DocumentedException { + protected Element handleWithNoSubsequentOperations(final Document document, + final XmlElement xml) throws DocumentedException { fromXml(xml); try { getConfigSubsystemFacade().abortConfiguration(); diff --git a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/Lock.java b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/Lock.java index cb5e99feeb..9cca810ec9 100644 --- a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/Lock.java +++ b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/Lock.java @@ -22,7 +22,8 @@ import org.w3c.dom.Element; /** * Simple Lock implementation that pretends to lock candidate datastore. - * Candidate datastore is allocated per session and is private so no real locking is needed (JMX is the only possible interference) + * Candidate datastore is allocated per session and is private so no real locking is needed + * (JMX is the only possible interference) */ public class Lock extends AbstractLastNetconfOperation { @@ -36,17 +37,20 @@ public class Lock extends AbstractLastNetconfOperation { } @Override - protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException { + protected Element handleWithNoSubsequentOperations(final Document document, + final XmlElement operationElement) throws DocumentedException { final Datastore targetDatastore = extractTargetParameter(operationElement); - if(targetDatastore == Datastore.candidate) { - // Since candidate datastore instances are allocated per session and not accessible anywhere else, no need to lock + if (targetDatastore == Datastore.candidate) { + // Since candidate datastore instances are allocated per session and not accessible anywhere else, + // no need to lock LOG.debug("Locking {} datastore on session: {}", targetDatastore, getNetconfSessionIdForReporting()); // TODO should this fail if we are already locked ? return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); } // Not supported running lock - throw new DocumentedException("Unable to lock " + Datastore.running + " datastore", DocumentedException.ErrorType.APPLICATION, + throw new DocumentedException("Unable to lock " + Datastore.running + " datastore", + DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, DocumentedException.ErrorSeverity.ERROR); } diff --git a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/UnLock.java b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/UnLock.java index a20426b6d4..17fff3d218 100644 --- a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/UnLock.java +++ b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/UnLock.java @@ -22,7 +22,8 @@ import org.w3c.dom.Element; /** * Simple unlock implementation that pretends to unlock candidate datastore. - * Candidate datastore is allocated per session and is private so no real locking is needed (JMX is the only possible interference) + * Candidate datastore is allocated per session and is private so no real locking is needed + * (JMX is the only possible interference) */ public class UnLock extends AbstractLastNetconfOperation { @@ -35,17 +36,20 @@ public class UnLock extends AbstractLastNetconfOperation { } @Override - protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException { + protected Element handleWithNoSubsequentOperations(final Document document, + final XmlElement operationElement) throws DocumentedException { final Datastore targetDatastore = Lock.extractTargetParameter(operationElement); - if(targetDatastore == Datastore.candidate) { - // Since candidate datastore instances are allocated per session and not accessible anywhere else, no need to lock + if (targetDatastore == Datastore.candidate) { + // Since candidate datastore instances are allocated per session and not accessible anywhere else, + // no need to lock LOG.debug("Unlocking {} datastore on session: {}", targetDatastore, getNetconfSessionIdForReporting()); // TODO this should fail if we are not locked return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); } // Not supported running lock - throw new DocumentedException("Unable to unlock " + Datastore.running + " datastore", DocumentedException.ErrorType.APPLICATION, + throw new DocumentedException("Unable to unlock " + Datastore.running + " datastore", + DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, DocumentedException.ErrorSeverity.ERROR); } diff --git a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/Validate.java b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/Validate.java index 61d05bc9f8..7c4e823e38 100644 --- a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/Validate.java +++ b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/Validate.java @@ -48,9 +48,10 @@ public class Validate extends AbstractConfigNetconfOperation { final String datastoreValue = sourceChildNode.getName(); final Datastore sourceDatastore = Datastore.valueOf(datastoreValue); - if (sourceDatastore != Datastore.candidate){ - throw new DocumentedException( "Only " + Datastore.candidate - + " is supported as source for " + VALIDATE + " but was " + datastoreValue, ErrorType.APPLICATION, ErrorTag.DATA_MISSING, ErrorSeverity.ERROR); + if (sourceDatastore != Datastore.candidate) { + throw new DocumentedException("Only " + Datastore.candidate + + " is supported as source for " + VALIDATE + " but was " + datastoreValue, ErrorType.APPLICATION, + ErrorTag.DATA_MISSING, ErrorSeverity.ERROR); } } @@ -60,7 +61,8 @@ public class Validate extends AbstractConfigNetconfOperation { } @Override - protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement xml) throws DocumentedException { + protected Element handleWithNoSubsequentOperations(final Document document, + final XmlElement xml) throws DocumentedException { checkXml(xml); try { getConfigSubsystemFacade().validateConfiguration(); @@ -72,7 +74,8 @@ public class Validate extends AbstractConfigNetconfOperation { final Map errorInfo = new HashMap<>(); errorInfo .put(ErrorTag.OPERATION_FAILED.name(), - "Datastore is not present. Use 'get-config' or 'edit-config' before triggering 'operations' operation"); + "Datastore is not present. " + + "Use 'get-config' or 'edit-config' before triggering 'operations' operation"); throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, errorInfo); diff --git a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfig.java b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfig.java index eb01a57c11..e247928033 100644 --- a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfig.java +++ b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfig.java @@ -65,8 +65,10 @@ public class EditConfig extends AbstractConfigNetconfOperation { } @Override - protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement xml) throws DocumentedException { - // FIXME config mapping getter works on dynamic yang store service and so does later executeConfigExecution method + protected Element handleWithNoSubsequentOperations(final Document document, + final XmlElement xml) throws DocumentedException { + // FIXME config mapping getter works on dynamic yang store service + // and so does later executeConfigExecution method // They might have different view of current yangs in ODL and might cause race conditions final Config cfg = getConfigSubsystemFacade().getConfigMapping(); final ConfigExecution configExecution = editConfigXmlParser.fromXml(xml, cfg); diff --git a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfigXmlParser.java b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfigXmlParser.java index c317d1dd97..ddba4ae813 100644 --- a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfigXmlParser.java +++ b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfigXmlParser.java @@ -45,8 +45,8 @@ public class EditConfigXmlParser { xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); - XmlElement targetElement = null; - XmlElement targetChildNode = null; + XmlElement targetElement; + XmlElement targetChildNode; targetElement = xml.getOnlyChildElementWithSameNamespace(EditConfigXmlParser.TARGET_KEY); targetChildNode = targetElement.getOnlyChildElementWithSameNamespace(); @@ -55,7 +55,7 @@ public class EditConfigXmlParser { LOG.debug("Setting {} to '{}'", EditConfigXmlParser.TARGET_KEY, targetDatastore); // check target - if (targetDatastore != Datastore.candidate){ + if (targetDatastore != Datastore.candidate) { throw new DocumentedException(String.format( "Only %s datastore supported for edit config but was: %s", Datastore.candidate, @@ -82,7 +82,7 @@ public class EditConfigXmlParser { .getOnlyChildElementWithSameNamespaceOptionally(EditConfigXmlParser.ERROR_OPTION_KEY); if (errorOptionElement.isPresent()) { final String errorOptionParsed = errorOptionElement.get().getTextContent(); - if (!errorOptionParsed.equals(EditConfigXmlParser.DEFAULT_ERROR_OPTION)){ + if (!errorOptionParsed.equals(EditConfigXmlParser.DEFAULT_ERROR_OPTION)) { throw new UnsupportedOperationException("Only " + EditConfigXmlParser.DEFAULT_ERROR_OPTION + " supported for " + EditConfigXmlParser.ERROR_OPTION_KEY + ", was " + errorOptionParsed); } @@ -97,7 +97,7 @@ public class EditConfigXmlParser { editStrategyType = EditStrategyType.valueOf(mergeStrategyString); } - XmlElement configElement = null; + XmlElement configElement; configElement = xml.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.CONFIG_KEY); return new ConfigExecution(cfgMapping, configElement, testOption, editStrategyType); diff --git a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/getconfig/GetConfig.java b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/getconfig/GetConfig.java index d7e3061cc3..dc1c31d198 100644 --- a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/getconfig/GetConfig.java +++ b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/getconfig/GetConfig.java @@ -28,7 +28,8 @@ public class GetConfig extends AbstractConfigNetconfOperation { private static final Logger LOG = LoggerFactory.getLogger(GetConfig.class); - public GetConfig(final ConfigSubsystemFacade configSubsystemFacade, final Optional maybeNamespace, final String netconfSessionIdForReporting) { + public GetConfig(final ConfigSubsystemFacade configSubsystemFacade, final Optional maybeNamespace, + final String netconfSessionIdForReporting) { super(configSubsystemFacade, netconfSessionIdForReporting); this.maybeNamespace = maybeNamespace; } diff --git a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java index b8d5b58a2d..bbcdf28b65 100644 --- a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java +++ b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java @@ -53,7 +53,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation { final Optional contextInstanceElement = operationElement .getOnlyChildElementOptionally(RpcFacade.CONTEXT_INSTANCE); - if (!contextInstanceElement.isPresent()){ + if (!contextInstanceElement.isPresent()) { return HandlingPriority.CANNOT_HANDLE; } @@ -97,8 +97,8 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation { execution.getAttributes()); final Object result = getConfigSubsystemFacade().getRpcFacade().executeOperation(execution); - LOG.trace("Operation {} called successfully on {} with arguments {} with result {}", execution.getOperationName(), - execution.getOn(), execution.getAttributes(), result); + LOG.trace("Operation {} called successfully on {} with arguments {} with result {}", + execution.getOperationName(), execution.getOn(), execution.getAttributes(), result); if (execution.isVoid()) { return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); diff --git a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/Activator.java b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/Activator.java index 336c03a59b..40edbec213 100644 --- a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/Activator.java +++ b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/Activator.java @@ -30,24 +30,30 @@ public class Activator implements BundleActivator { @Override public void start(final BundleContext context) throws Exception { - ServiceTrackerCustomizer schemaServiceTrackerCustomizer = new ServiceTrackerCustomizer() { + ServiceTrackerCustomizer schemaServiceTrackerCustomizer = + new ServiceTrackerCustomizer() { @Override - public ConfigSubsystemFacadeFactory addingService(ServiceReference reference) { + public ConfigSubsystemFacadeFactory addingService( + ServiceReference reference) { LOG.debug("Got addingService(SchemaContextProvider) event"); // Yang store service should not be registered multiple times - ConfigSubsystemFacadeFactory configSubsystemFacade = reference.getBundle().getBundleContext().getService(reference); + ConfigSubsystemFacadeFactory configSubsystemFacade = + reference.getBundle().getBundleContext().getService(reference); osgiRegistration = startNetconfServiceFactory(configSubsystemFacade, context); return configSubsystemFacade; } @Override - public void modifiedService(ServiceReference reference, ConfigSubsystemFacadeFactory service) { + public void modifiedService(ServiceReference reference, + ConfigSubsystemFacadeFactory service) { LOG.warn("Config manager facade was modified unexpectedly"); } @Override - public void removedService(ServiceReference reference, ConfigSubsystemFacadeFactory service) { + public void removedService(ServiceReference reference, + ConfigSubsystemFacadeFactory service) { LOG.warn("Config manager facade was removed unexpectedly"); } }; @@ -64,12 +70,15 @@ public class Activator implements BundleActivator { } } - private ServiceRegistration startNetconfServiceFactory(final ConfigSubsystemFacadeFactory configSubsystemFacade, final BundleContext context) { - final NetconfOperationServiceFactoryImpl netconfOperationServiceFactory = new NetconfOperationServiceFactoryImpl(configSubsystemFacade); + private ServiceRegistration startNetconfServiceFactory( + final ConfigSubsystemFacadeFactory configSubsystemFacade, final BundleContext context) { + final NetconfOperationServiceFactoryImpl netconfOperationServiceFactory = + new NetconfOperationServiceFactoryImpl(configSubsystemFacade); // Add properties to autowire with netconf-impl instance for cfg subsystem final Dictionary properties = new Hashtable<>(); properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.CONFIG_NETCONF_CONNECTOR); - return context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties); + return context.registerService(NetconfOperationServiceFactory.class, + netconfOperationServiceFactory, properties); } } diff --git a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/NetconfOperationProvider.java b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/NetconfOperationProvider.java index 6f0a448dd2..30064685db 100644 --- a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/NetconfOperationProvider.java +++ b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/NetconfOperationProvider.java @@ -26,7 +26,8 @@ import org.opendaylight.netconf.mapping.api.NetconfOperation; final class NetconfOperationProvider { private final Set operations; - NetconfOperationProvider(final ConfigSubsystemFacade configSubsystemFacade, final String netconfSessionIdForReporting) { + NetconfOperationProvider(final ConfigSubsystemFacade configSubsystemFacade, + final String netconfSessionIdForReporting) { operations = setUpOperations(configSubsystemFacade, netconfSessionIdForReporting); } diff --git a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java index 01405d447e..370e59e83e 100644 --- a/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java +++ b/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java @@ -24,7 +24,8 @@ public class NetconfOperationServiceFactoryImpl implements NetconfOperationServi @Override public NetconfOperationServiceImpl createService(String netconfSessionIdForReporting) { - return new NetconfOperationServiceImpl(configFacadeFactory.createFacade(netconfSessionIdForReporting), netconfSessionIdForReporting); + return new NetconfOperationServiceImpl(configFacadeFactory.createFacade(netconfSessionIdForReporting), + netconfSessionIdForReporting); } @Override diff --git a/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/NetconfMappingTest.java b/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/NetconfMappingTest.java index c935801dda..f4059a6438 100644 --- a/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/NetconfMappingTest.java +++ b/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/NetconfMappingTest.java @@ -140,7 +140,7 @@ public class NetconfMappingTest extends AbstractConfigTest { private static final String INSTANCE_NAME = "instance-from-code"; private static final String NETCONF_SESSION_ID = "foo"; - private static final String TEST_NAMESPACE= "urn:opendaylight:params:xml:ns:yang:controller:test:impl"; + private static final String TEST_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:test:impl"; private NetconfTestImplModuleFactory factory; private DepTestImplModuleFactory factory2; private IdentityTestModuleFactory factory3; @@ -176,13 +176,15 @@ public class NetconfMappingTest extends AbstractConfigTest { @Override public String fromYang(final String enumType, final String enumYangValue) { return Preconditions.checkNotNull(getEnumMapping().get(enumYangValue), - "Unable to resolve enum value %s, for enum %s with mappings %s", enumYangValue, enumType, getEnumMapping()); + "Unable to resolve enum value %s, for enum %s with mappings %s", + enumYangValue, enumType, getEnumMapping()); } @Override public String toYang(final String enumType, final String enumYangValue) { return Preconditions.checkNotNull(getEnumMapping().inverse().get(enumYangValue), - "Unable to resolve enum value %s, for enum %s with mappings %s", enumYangValue, enumType, getEnumMapping().inverse()); + "Unable to resolve enum value %s, for enum %s with mappings %s", + enumYangValue, enumType, getEnumMapping().inverse()); } }).when(this.yangStoreSnapshot).getEnumResolver(); @@ -192,27 +194,31 @@ public class NetconfMappingTest extends AbstractConfigTest { factory4 = new TestImplModuleFactory(); doNothing().when(sessionCloseable).close(); - super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, this.factory, this.factory2, - this.factory3, factory4)); + super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, this.factory, + this.factory2, this.factory3, factory4)); transactionProvider = new TransactionProvider(this.configRegistryClient, NETCONF_SESSION_ID); - configSubsystemFacade = new ConfigSubsystemFacade(configRegistryClient, configRegistryClient, yangStoreSnapshot, "mapping-test"); + configSubsystemFacade = new ConfigSubsystemFacade(configRegistryClient, configRegistryClient, yangStoreSnapshot, + "mapping-test"); } - private ObjectName createModule(final String instanceName) throws InstanceAlreadyExistsException, InstanceNotFoundException, URISyntaxException, ValidationException, ConflictingVersionException { + private ObjectName createModule(final String instanceName) throws InstanceAlreadyExistsException, + InstanceNotFoundException, URISyntaxException, ValidationException, ConflictingVersionException { final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction(); final ObjectName on = transaction.createModule(this.factory.getImplementationName(), instanceName); final NetconfTestImplModuleMXBean mxBean = transaction.newMXBeanProxy(on, NetconfTestImplModuleMXBean.class); setModule(mxBean, transaction, instanceName + "_dep"); - int i = 1; - for (final Class sInterface : factory.getImplementedServiceIntefaces()) { - final ServiceInterfaceAnnotation annotation = sInterface.getAnnotation(ServiceInterfaceAnnotation.class); + int index = 1; + for (final Class serviceInterface : + factory.getImplementedServiceIntefaces()) { + final ServiceInterfaceAnnotation annotation = + serviceInterface.getAnnotation(ServiceInterfaceAnnotation.class); transaction.saveServiceReference( - transaction.getServiceInterfaceName(annotation.namespace(), annotation.localName()), "ref_from_code_to_" + instanceName + "_" + i++, - on); + transaction.getServiceInterfaceName(annotation.namespace(), annotation.localName()), + "ref_from_code_to_" + instanceName + "_" + index++, on); } transaction.commit(); @@ -339,9 +345,9 @@ public class NetconfMappingTest extends AbstractConfigTest { @Override public void testText(final Text text) throws NodeTestException { - if(text.getData().equals("ref_dep2")) { + if (text.getData().equals("ref_dep2")) { defaultRefNameCount++; - } else if(text.getData().equals("ref_dep_user_two")) { + } else if (text.getData().equals("ref_dep_user_two")) { userRefNameCount++; } } @@ -355,7 +361,8 @@ public class NetconfMappingTest extends AbstractConfigTest { nt.performTest(tester, Node.TEXT_NODE); } - private static void assertCorrectServiceNames(final Document configCandidate, final Set refNames) throws NodeTestException { + private static void assertCorrectServiceNames(final Document configCandidate, + final Set refNames) throws NodeTestException { final Set refNames2 = new HashSet<>(refNames); final NodeList servicesNodes = configCandidate.getElementsByTagName("services"); assertEquals(1, servicesNodes.getLength()); @@ -365,10 +372,10 @@ public class NetconfMappingTest extends AbstractConfigTest { @Override public void testElement(final Element element) throws NodeTestException { - if(element.getNodeName() != null) { - if(element.getNodeName().equals("name")) { + if (element.getNodeName() != null) { + if (element.getNodeName().equals("name")) { final String elmText = element.getTextContent(); - if(refNames2.contains(elmText)) { + if (refNames2.contains(elmText)) { refNames2.remove(elmText); } else { throw new NodeTestException("Unexpected services defined: " + elmText); @@ -394,17 +401,23 @@ public class NetconfMappingTest extends AbstractConfigTest { edit("netconfMessages/editConfig.xml"); commit(); Document response = getConfigRunning(); - final Element ipElement = readXmlToElement("0:0:0:0:0:0:0:1"); - assertContainsElement(response, readXmlToElement("0:0:0:0:0:0:0:1")); + final Element ipElement = readXmlToElement( + "0:0:0:0:0:0:0:1"); + assertContainsElement(response, readXmlToElement( + "0:0:0:0:0:0:0:1")); - assertContainsElement(response, readXmlToElement("456")); + assertContainsElement(response, readXmlToElement("456")); edit("netconfMessages/editConfig_setUnions.xml"); commit(); response = getConfigRunning(); - assertContainsElement(response, readXmlToElement("127.1.2.3")); - assertContainsElement(response, readXmlToElement("randomStringForUnion")); + assertContainsElement(response, readXmlToElement( + "127.1.2.3")); + assertContainsElement(response, readXmlToElement("" + + "randomStringForUnion")); } @@ -438,7 +451,8 @@ public class NetconfMappingTest extends AbstractConfigTest { commit(); assertXMLEqual(getConfigCandidate(), getConfigRunning()); - final Document expectedResult = XmlFileLoader.xmlFileToDocument("netconfMessages/editConfig_expectedResult.xml"); + final Document expectedResult = + XmlFileLoader.xmlFileToDocument("netconfMessages/editConfig_expectedResult.xml"); XMLUnit.setIgnoreWhitespace(true); assertXMLEqual(expectedResult, getConfigRunning()); assertXMLEqual(expectedResult, getConfigCandidate()); @@ -451,9 +465,11 @@ public class NetconfMappingTest extends AbstractConfigTest { } private static void checkBigDecimal(final Document response) throws NodeTestException, SAXException, IOException { - assertContainsElement(response, readXmlToElement("2.58")); + assertContainsElement(response, readXmlToElement("2.58")); // Default - assertContainsElement(response, readXmlToElement("2.00")); + assertContainsElement(response, readXmlToElement("2.00")); } private void closeSession() throws ParserConfigurationException, SAXException, @@ -480,25 +496,29 @@ public class NetconfMappingTest extends AbstractConfigTest { executeOp(commitOp, "netconfMessages/commit.xml"); } - private static Document lockCandidate() throws ParserConfigurationException, SAXException, IOException, DocumentedException { + private static Document lockCandidate() throws ParserConfigurationException, SAXException, IOException, + DocumentedException { final Lock commitOp = new Lock(NETCONF_SESSION_ID); return executeOp(commitOp, "netconfMessages/lock.xml"); } - private static Document unlockCandidate() throws ParserConfigurationException, SAXException, IOException, DocumentedException { + private static Document unlockCandidate() throws ParserConfigurationException, SAXException, IOException, + DocumentedException { final UnLock commitOp = new UnLock(NETCONF_SESSION_ID); return executeOp(commitOp, "netconfMessages/unlock.xml"); } private Document getConfigCandidate() throws ParserConfigurationException, SAXException, IOException, DocumentedException { - final GetConfig getConfigOp = new GetConfig(configSubsystemFacade, Optional.absent(), NETCONF_SESSION_ID); + final GetConfig getConfigOp = new GetConfig(configSubsystemFacade, Optional.absent(), + NETCONF_SESSION_ID); return executeOp(getConfigOp, "netconfMessages/getConfig_candidate.xml"); } private Document getConfigRunning() throws ParserConfigurationException, SAXException, IOException, DocumentedException { - final GetConfig getConfigOp = new GetConfig(configSubsystemFacade, Optional.absent(), NETCONF_SESSION_ID); + final GetConfig getConfigOp = new GetConfig(configSubsystemFacade, Optional.absent(), + NETCONF_SESSION_ID); return executeOp(getConfigOp, "netconfMessages/getConfig.xml"); } @@ -596,9 +616,9 @@ public class NetconfMappingTest extends AbstractConfigTest { public void testUnrecognisedConfigElements() throws Exception { final String format = "netconfMessages/unrecognised/editConfig_unrecognised%d.xml"; - final int TESTS_COUNT = 8; + final int testsCount = 8; - for (int i = 0; i < TESTS_COUNT; i++) { + for (int i = 0; i < testsCount; i++) { final String file = String.format(format, i + 1); LOG.info("Reading {}", file); try { @@ -666,24 +686,33 @@ public class NetconfMappingTest extends AbstractConfigTest { return executeOp(discardOp, "netconfMessages/discardChanges.xml"); } - private static void checkBinaryLeafEdited(final Document response) throws NodeTestException, SAXException, IOException { - assertContainsElement(response, readXmlToElement("YmluYXJ5")); - assertContainsElement(response, readXmlToElement("ZGVmYXVsdEJpbg==")); + private static void checkBinaryLeafEdited(final Document response) + throws NodeTestException, SAXException, IOException { + assertContainsElement(response, readXmlToElement("YmluYXJ5")); + assertContainsElement(response, readXmlToElement("ZGVmYXVsdEJpbg==")); } private static void checkTypedefs(final Document response) throws NodeTestException, SAXException, IOException { - assertContainsElement(response, readXmlToElement("10")); + assertContainsElement(response, readXmlToElement( + "10")); // Default - assertContainsElement(response, readXmlToElement("1")); + assertContainsElement(response, readXmlToElement( + "1")); - assertContainsElement(response, readXmlToElement("20")); + assertContainsElement(response, readXmlToElement("20")); // Default - assertContainsElement(response, readXmlToElement("2")); + assertContainsElement(response, readXmlToElement("2")); - assertContainsElement(response, readXmlToElement("two")); + assertContainsElement(response, readXmlToElement("two")); // Default - assertContainsElement(response, readXmlToElement("one")); + assertContainsElement(response, readXmlToElement("one")); } private static void assertContainsString(final String string, final String substring) { @@ -705,13 +734,13 @@ public class NetconfMappingTest extends AbstractConfigTest { } private static String getXpathForNetconfImplSubnode(final String instanceName, final String subnode) { - return "/urn:ietf:params:xml:ns:netconf:base:1.0:rpc-reply" + - "/urn:ietf:params:xml:ns:netconf:base:1.0:data" + - "/urn:opendaylight:params:xml:ns:yang:controller:config:modules" + - "/urn:opendaylight:params:xml:ns:yang:controller:config:module" + - "[urn:opendaylight:params:xml:ns:yang:controller:config:name='" + instanceName + "']" + - "/urn:opendaylight:params:xml:ns:yang:controller:test:impl:impl-netconf" + - "/urn:opendaylight:params:xml:ns:yang:controller:test:impl:" + subnode; + return "/urn:ietf:params:xml:ns:netconf:base:1.0:rpc-reply" + + "/urn:ietf:params:xml:ns:netconf:base:1.0:data" + + "/urn:opendaylight:params:xml:ns:yang:controller:config:modules" + + "/urn:opendaylight:params:xml:ns:yang:controller:config:module" + + "[urn:opendaylight:params:xml:ns:yang:controller:config:name='" + instanceName + "']" + + "/urn:opendaylight:params:xml:ns:yang:controller:test:impl:impl-netconf" + + "/urn:opendaylight:params:xml:ns:yang:controller:test:impl:" + subnode; } private static void checkTypeConfigAttribute(final Document response) throws Exception { @@ -720,7 +749,7 @@ public class NetconfMappingTest extends AbstractConfigTest { "test2", "default-string"); for (final Entry nameToExpectedValue : namesToTypeValues.entrySet()) { XMLAssert.assertXpathEvaluatesTo(nameToExpectedValue.getValue(), - getXpathForNetconfImplSubnode(nameToExpectedValue.getKey(),"type"), + getXpathForNetconfImplSubnode(nameToExpectedValue.getKey(), "type"), response); } } @@ -732,7 +761,8 @@ public class NetconfMappingTest extends AbstractConfigTest { final SchemaContext schemaContext = YangParserTestUtils.parseYangStreams(yangDependencies); final YangStoreService yangStoreService = new YangStoreService(new SchemaContextProvider() { - @Override public SchemaContext getSchemaContext() { + @Override + public SchemaContext getSchemaContext() { return schemaContext; } }, mock(SchemaSourceProvider.class)); @@ -783,7 +813,8 @@ public class NetconfMappingTest extends AbstractConfigTest { assertEquals(8 * 4, getElementsSize(response, "inner-inner-running-data")); assertEquals(8 * 4, getElementsSize(response, "deep3")); assertEquals(8 * 4 * 2, getElementsSize(response, "list-of-strings")); - assertEquals(8, getElementsSize(response, "inner-running-data-additional", "urn:opendaylight:params:xml:ns:yang:controller:test:impl")); + assertEquals(8, getElementsSize(response, "inner-running-data-additional", + "urn:opendaylight:params:xml:ns:yang:controller:test:impl")); assertEquals(8, getElementsSize(response, "deep4")); // TODO assert keys @@ -818,7 +849,8 @@ public class NetconfMappingTest extends AbstractConfigTest { return response.getElementsByTagNameNS(namespace, elementName).getLength(); } - private static Document executeOp(final NetconfOperation op, final String filename) throws ParserConfigurationException, + private static Document executeOp(final NetconfOperation op, + final String filename) throws ParserConfigurationException, SAXException, IOException, DocumentedException { final Document request = XmlFileLoader.xmlFileToDocument(filename); @@ -835,8 +867,9 @@ public class NetconfMappingTest extends AbstractConfigTest { private List getYangs() { final List paths = Arrays.asList("/META-INF/yang/config.yang", "/META-INF/yang/rpc-context.yang", - "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang", "/META-INF/yang/test-types.yang", - "/META-INF/yang/test-groups.yang", "/META-INF/yang/ietf-inet-types@2013-07-15.yang"); + "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang", + "/META-INF/yang/test-types.yang", "/META-INF/yang/test-groups.yang", + "/META-INF/yang/ietf-inet-types@2013-07-15.yang"); final Collection yangDependencies = new ArrayList<>(); for (final String path : paths) { final InputStream is = Preconditions @@ -846,10 +879,11 @@ public class NetconfMappingTest extends AbstractConfigTest { return Lists.newArrayList(yangDependencies); } - private void setModule(final NetconfTestImplModuleMXBean mxBean, final ConfigTransactionJMXClient transaction, final String depName) + private void setModule(final NetconfTestImplModuleMXBean mxBean, final ConfigTransactionJMXClient transaction, + final String depName) throws InstanceAlreadyExistsException, InstanceNotFoundException { mxBean.setSimpleInt((long) 44); - mxBean.setBinaryLeaf(new byte[] { 8, 7, 9 }); + mxBean.setBinaryLeaf(new byte[]{8, 7, 9}); final DtoD dtob = getDtoD(); mxBean.setDtoD(dtob); // @@ -865,7 +899,7 @@ public class NetconfMappingTest extends AbstractConfigTest { p2.setCoreSize(44L); p2.setPort("port23"); p2.setSimpleInt3(456); - mxBean.setPeers(Lists. newArrayList(p1, p2)); + mxBean.setPeers(Lists.newArrayList(p1, p2)); // // mxBean.setSimpleLong(454545L); mxBean.setSimpleLong2(44L); @@ -874,16 +908,18 @@ public class NetconfMappingTest extends AbstractConfigTest { mxBean.setSimpleShort(new Short((short) 4)); mxBean.setSimpleTest(545); - mxBean.setComplexList(Lists. newArrayList()); - mxBean.setSimpleList(Lists. newArrayList()); + mxBean.setComplexList(Lists.newArrayList()); + mxBean.setSimpleList(Lists.newArrayList()); final ObjectName testingDepOn = transaction.createModule(this.factory2.getImplementationName(), depName); - int i = 1; - for (final Class sInterface : factory2.getImplementedServiceIntefaces()) { - final ServiceInterfaceAnnotation annotation = sInterface.getAnnotation(ServiceInterfaceAnnotation.class); + int index = 1; + for (final Class serviceInterface : + factory2.getImplementedServiceIntefaces()) { + final ServiceInterfaceAnnotation annotation = + serviceInterface.getAnnotation(ServiceInterfaceAnnotation.class); transaction.saveServiceReference( - transaction.getServiceInterfaceName(annotation.namespace(), annotation.localName()), "ref_from_code_to_" + depName + "_" + i++, - testingDepOn); + transaction.getServiceInterfaceName(annotation.namespace(), annotation.localName()), + "ref_from_code_to_" + depName + "_" + index++, testingDepOn); } mxBean.setTestingDep(testingDepOn); diff --git a/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfigTest.java b/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfigTest.java index e04f0c731f..39a3ee1e3b 100644 --- a/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfigTest.java +++ b/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/EditConfigTest.java @@ -89,7 +89,8 @@ public class EditConfigTest { EditConfig edit = new EditConfig(cfgFacade, ValidateTest.NETCONF_SESSION_ID_FOR_REPORTING); EditConfigStrategy editStrat = mock(EditConfigStrategy.class); - doNothing().when(editStrat).executeConfiguration(anyString(), anyString(), anyMapOf(String.class, AttributeConfigElement.class), + doNothing().when(editStrat).executeConfiguration(anyString(), anyString(), anyMapOf(String.class, + AttributeConfigElement.class), any(ConfigTransactionClient.class), any(ServiceRegistryWrapper.class)); ConfigExecution editConfigExecution = mockExecution(editStrat); @@ -103,7 +104,8 @@ public class EditConfigTest { verify(provider).getOrCreateTransaction(); // For every instance execute strat - verify(editStrat, times(2/* Test */+ 2/* Set */ + 2/*Handle missing instance Test*/ + 2 /*Handle missing instance Set*/)).executeConfiguration(anyString(), + verify(editStrat, times(2/* Test */ + 2/* Set */ + 2/*Handle missing instance Test*/ + + 2 /*Handle missing instance Set*/)).executeConfiguration(anyString(), anyString(), anyMapOf(String.class, AttributeConfigElement.class), any(ConfigTransactionClient.class), any(ServiceRegistryWrapper.class)); } @@ -122,7 +124,7 @@ public class EditConfigTest { } private Object getMappingDefinition(EditConfigStrategy editStrat) { - Map> result = Maps.newHashMap(); + final Map> result = Maps.newHashMap(); Multimap innerMultimap = HashMultimap.create(); Map attributes = getSimpleAttributes(); @@ -157,7 +159,7 @@ public class EditConfigTest { } private Map> getMapping(EditConfigStrategy editStrat) { - Map> result = Maps.newHashMap(); + final Map> result = Maps.newHashMap(); Multimap innerMultimap = HashMultimap.create(); Map attributes = getSimpleAttributes(); @@ -178,10 +180,10 @@ public class EditConfigTest { } static Map getSimpleAttributes() { - Map attributes = Maps.newHashMap(); + final Map attributes = Maps.newHashMap(); AttributeConfigElement ace1 = mock(AttributeConfigElement.class); doReturn("abcd").when(ace1).getResolvedDefaultValue(); - doReturn(Optional. of("abc")).when(ace1).getResolvedValue(); + doReturn(Optional.of("abc")).when(ace1).getResolvedValue(); doReturn("mockedAce1").when(ace1).toString(); doReturn("jmxNameAce1").when(ace1).getJmxName(); attributes.put("a1", ace1); diff --git a/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/MergeEditConfigStrategyTest.java b/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/MergeEditConfigStrategyTest.java index 7cc0288fe8..12b6bf4d62 100644 --- a/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/MergeEditConfigStrategyTest.java +++ b/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/operations/editconfig/MergeEditConfigStrategyTest.java @@ -32,38 +32,38 @@ import org.opendaylight.controller.config.yang.test.impl.MultipleDependenciesMod import org.opendaylight.controller.config.yang.test.impl.MultipleDependenciesModuleMXBean; public class MergeEditConfigStrategyTest extends AbstractConfigTest { - private static final MultipleDependenciesModuleFactory factory = new MultipleDependenciesModuleFactory(); + private static final MultipleDependenciesModuleFactory FACTORY = new MultipleDependenciesModuleFactory(); + private static final String FACTORY_NAME = FACTORY.getImplementationName(); public static final String PARENT = "parent"; public static final String D1 = "d1"; public static final String D2 = "d2"; public static final String D3 = "d3"; - private static final String factoryName = factory.getImplementationName(); - @Before public void setUp() throws Exception { - super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, factory)); + super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, FACTORY)); ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); - ObjectName d1 = transaction.createModule(factoryName, D1); - ObjectName d2 = transaction.createModule(factoryName, D2); - ObjectName parent = transaction.createModule(factoryName, PARENT); + ObjectName d1 = transaction.createModule(FACTORY_NAME, D1); + ObjectName d2 = transaction.createModule(FACTORY_NAME, D2); + ObjectName parent = transaction.createModule(FACTORY_NAME, PARENT); MultipleDependenciesModuleMXBean multipleDependenciesModuleMXBean = transaction.newMXBeanProxy(parent, MultipleDependenciesModuleMXBean.class); multipleDependenciesModuleMXBean.setTestingDeps(asList(d1, d2)); - transaction.createModule(factoryName, D3); + transaction.createModule(FACTORY_NAME, D3); transaction.commit(); } @Test public void testMergingOfObjectNames() throws Exception { - MergeEditConfigStrategy strategy = new MergeEditConfigStrategy(); - ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + final MergeEditConfigStrategy strategy = new MergeEditConfigStrategy(); + final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); // add D3 AttributeConfigElement attributeConfigElement = mock(AttributeConfigElement.class); - doReturn(Optional.of(new ObjectName[] {createReadOnlyModuleON(factoryName, D3)})).when(attributeConfigElement).getResolvedValue(); + doReturn(Optional.of(new ObjectName[] {createReadOnlyModuleON(FACTORY_NAME, D3)})) + .when(attributeConfigElement).getResolvedValue(); doReturn("mocked").when(attributeConfigElement).toString(); String attributeName = MultipleDependenciesModule.testingDepsJmxAttribute.getAttributeName(); doReturn(attributeName).when(attributeConfigElement).getJmxName(); @@ -71,18 +71,18 @@ public class MergeEditConfigStrategyTest extends AbstractConfigTest { attributeName, attributeConfigElement); - strategy.executeConfiguration(factoryName, PARENT, configuration, transaction, + strategy.executeConfiguration(FACTORY_NAME, PARENT, configuration, transaction, mock(ServiceRegistryWrapper.class)); transaction.commit(); // parent's attribute should contain d1,d2,d3 MultipleDependenciesModuleMXBean proxy = configRegistryClient.newMXBeanProxy( - createReadOnlyModuleON(factoryName, PARENT), + createReadOnlyModuleON(FACTORY_NAME, PARENT), MultipleDependenciesModuleMXBean.class); List testingDeps = proxy.getTestingDeps(); - List expected = asList(createReadOnlyModuleON(factoryName, D1), - createReadOnlyModuleON(factoryName, D2), - createReadOnlyModuleON(factoryName, D3)); + List expected = asList(createReadOnlyModuleON(FACTORY_NAME, D1), + createReadOnlyModuleON(FACTORY_NAME, D2), + createReadOnlyModuleON(FACTORY_NAME, D3)); assertEquals(expected, testingDeps); } } -- 2.36.6