Adjust to yangtools-2.0.0/odlparent-3.0.0 changes
[netconf.git] / netconf / config-netconf-connector / src / test / java / org / opendaylight / netconf / confignetconfconnector / NetconfMappingTest.java
index fe191300f8effcd471591268107ce18741726404..923141f8a617665c73b89dcefdea86eb3f8b6851 100644 (file)
@@ -33,19 +33,14 @@ import com.google.common.collect.BiMap;
 import com.google.common.collect.HashBiMap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import io.netty.channel.Channel;
 import java.io.IOException;
-import java.io.InputStream;
 import java.math.BigInteger;
 import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -94,6 +89,7 @@ import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMX
 import org.opendaylight.controller.config.yang.test.impl.Peers;
 import org.opendaylight.controller.config.yang.test.impl.TestImplModuleFactory;
 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
+import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
 import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
 import org.opendaylight.netconf.confignetconfconnector.operations.Commit;
 import org.opendaylight.netconf.confignetconfconnector.operations.DiscardChanges;
@@ -115,13 +111,9 @@ import org.opendaylight.netconf.util.messages.NetconfMessageUtil;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity2;
-import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.osgi.framework.Filter;
 import org.osgi.framework.ServiceListener;
 import org.osgi.framework.ServiceReference;
@@ -141,7 +133,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;
@@ -177,13 +169,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();
 
@@ -193,27 +187,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 (Class<? extends AbstractServiceInterface> sInterface : factory.getImplementedServiceIntefaces()) {
-            ServiceInterfaceAnnotation annotation = sInterface.getAnnotation(ServiceInterfaceAnnotation.class);
+        int index = 1;
+        for (final Class<? extends AbstractServiceInterface> 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();
@@ -255,7 +253,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
         final BindingRuntimeContext ret = super.getBindingRuntimeContext();
         doReturn(TestIdentity1.class).when(ret).getIdentityClass(TestIdentity1.QNAME);
         doReturn(TestIdentity2.class).when(ret).getIdentityClass(TestIdentity2.QNAME);
-        doReturn(parseYangStreams(getYangs())).when(ret).getSchemaContext();
+        doReturn(getSchemaContext()).when(ret).getSchemaContext();
         return ret;
     }
 
@@ -298,10 +296,10 @@ public class NetconfMappingTest extends AbstractConfigTest {
         try {
             edit("netconfMessages/editConfig_removeServiceNameOnTest.xml");
             fail("Should've failed, non-existing service instance");
-        } catch (DocumentedException e) {
-            assertEquals(e.getErrorSeverity(), DocumentedException.ErrorSeverity.error);
-            assertEquals(e.getErrorTag(), DocumentedException.ErrorTag.operation_failed);
-            assertEquals(e.getErrorType(), DocumentedException.ErrorType.application);
+        } catch (final DocumentedException e) {
+            assertEquals(e.getErrorSeverity(), DocumentedException.ErrorSeverity.ERROR);
+            assertEquals(e.getErrorTag(), DocumentedException.ErrorTag.OPERATION_FAILED);
+            assertEquals(e.getErrorType(), DocumentedException.ErrorType.APPLICATION);
         }
 
         edit("netconfMessages/editConfig_replace_default.xml");
@@ -325,19 +323,19 @@ public class NetconfMappingTest extends AbstractConfigTest {
     }
 
     private static void assertCorrectRefNamesForDependencies(final Document config) throws NodeTestException {
-        NodeList modulesList = config.getElementsByTagName("modules");
+        final NodeList modulesList = config.getElementsByTagName("modules");
         assertEquals(1, modulesList.getLength());
 
-        NodeTest nt = new NodeTest((DocumentTraversal) config, modulesList.item(0));
-        NodeTester tester = new AbstractNodeTester() {
+        final NodeTest nt = new NodeTest((DocumentTraversal) config, modulesList.item(0));
+        final NodeTester tester = new AbstractNodeTester() {
             private int defaultRefNameCount = 0;
             private int userRefNameCount = 0;
 
             @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++;
                 }
             }
@@ -351,20 +349,21 @@ public class NetconfMappingTest extends AbstractConfigTest {
         nt.performTest(tester, Node.TEXT_NODE);
     }
 
-    private static void assertCorrectServiceNames(final Document configCandidate, final Set<String> refNames) throws NodeTestException {
+    private static void assertCorrectServiceNames(final Document configCandidate,
+                                                  final Set<String> refNames) throws NodeTestException {
         final Set<String> refNames2 = new HashSet<>(refNames);
-        NodeList servicesNodes = configCandidate.getElementsByTagName("services");
+        final NodeList servicesNodes = configCandidate.getElementsByTagName("services");
         assertEquals(1, servicesNodes.getLength());
 
-        NodeTest nt = new NodeTest((DocumentTraversal) configCandidate, servicesNodes.item(0));
-        NodeTester tester = new AbstractNodeTester() {
+        final NodeTest nt = new NodeTest((DocumentTraversal) configCandidate, servicesNodes.item(0));
+        final NodeTester tester = new AbstractNodeTester() {
 
             @Override
             public void testElement(final Element element) throws NodeTestException {
-                if(element.getNodeName() != null) {
-                    if(element.getNodeName().equals("name")) {
-                        String elmText = element.getTextContent();
-                        if(refNames2.contains(elmText)) {
+                if (element.getNodeName() != null) {
+                    if (element.getNodeName().equals("name")) {
+                        final String elmText = element.getTextContent();
+                        if (refNames2.contains(elmText)) {
                             refNames2.remove(elmText);
                         } else {
                             throw new NodeTestException("Unexpected services defined: " + elmText);
@@ -390,17 +389,23 @@ public class NetconfMappingTest extends AbstractConfigTest {
         edit("netconfMessages/editConfig.xml");
         commit();
         Document response = getConfigRunning();
-        Element ipElement = readXmlToElement("<ip xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">0:0:0:0:0:0:0:1</ip>");
-        assertContainsElement(response, readXmlToElement("<ip xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">0:0:0:0:0:0:0:1</ip>"));
+        final Element ipElement = readXmlToElement(
+                "<ip xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">0:0:0:0:0:0:0:1</ip>");
+        assertContainsElement(response, readXmlToElement(
+                "<ip xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">0:0:0:0:0:0:0:1</ip>"));
 
-        assertContainsElement(response, readXmlToElement("<union-test-attr xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">456</union-test-attr>"));
+        assertContainsElement(response, readXmlToElement("<union-test-attr xmlns="
+                + "\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">456</union-test-attr>"));
 
 
         edit("netconfMessages/editConfig_setUnions.xml");
         commit();
         response = getConfigRunning();
-        assertContainsElement(response, readXmlToElement("<ip xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">127.1.2.3</ip>"));
-        assertContainsElement(response, readXmlToElement("<union-test-attr xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">randomStringForUnion</union-test-attr>"));
+        assertContainsElement(response, readXmlToElement(
+                "<ip xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">127.1.2.3</ip>"));
+        assertContainsElement(response, readXmlToElement("<union-test-attr xmlns="
+                + "\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">"
+                + "randomStringForUnion</union-test-attr>"));
 
     }
 
@@ -410,7 +415,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
         createModule(INSTANCE_NAME);
 
         edit("netconfMessages/editConfig.xml");
-        Document configCandidate = getConfigCandidate();
+        final Document configCandidate = getConfigCandidate();
         checkBinaryLeafEdited(configCandidate);
 
 
@@ -420,7 +425,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
 
         // check after edit
         commit();
-        Document response = getConfigRunning();
+        final Document response = getConfigRunning();
 
         checkBinaryLeafEdited(response);
         checkTypeConfigAttribute(response);
@@ -434,7 +439,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());
@@ -447,9 +453,11 @@ public class NetconfMappingTest extends AbstractConfigTest {
     }
 
     private static void checkBigDecimal(final Document response) throws NodeTestException, SAXException, IOException {
-        assertContainsElement(response, readXmlToElement("<sleep-factor xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2.58</sleep-factor>"));
+        assertContainsElement(response, readXmlToElement("<sleep-factor xmlns="
+                + "\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2.58</sleep-factor>"));
         // Default
-        assertContainsElement(response, readXmlToElement("<sleep-factor xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2.00</sleep-factor>"));
+        assertContainsElement(response, readXmlToElement("<sleep-factor xmlns="
+                + "\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2.00</sleep-factor>"));
     }
 
     private void closeSession() throws ParserConfigurationException, SAXException,
@@ -460,41 +468,45 @@ public class NetconfMappingTest extends AbstractConfigTest {
         final NetconfServerSession session =
                 new NetconfServerSession(listener, channel, 1L,
                         NetconfHelloMessageAdditionalHeader.fromString("[netconf;10.12.0.102:48528;ssh;;;;;;]"));
-        DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID, sessionCloseable);
+        final DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID, sessionCloseable);
         closeOp.setNetconfSession(session);
         executeOp(closeOp, "netconfMessages/closeSession.xml");
     }
 
     private void edit(final String resource) throws ParserConfigurationException, SAXException, IOException,
             DocumentedException {
-        EditConfig editOp = new EditConfig(configSubsystemFacade, NETCONF_SESSION_ID);
+        final EditConfig editOp = new EditConfig(configSubsystemFacade, NETCONF_SESSION_ID);
         executeOp(editOp, resource);
     }
 
     private void commit() throws ParserConfigurationException, SAXException, IOException, DocumentedException {
-        Commit commitOp = new Commit(configSubsystemFacade, NETCONF_SESSION_ID);
+        final Commit commitOp = new Commit(configSubsystemFacade, NETCONF_SESSION_ID);
         executeOp(commitOp, "netconfMessages/commit.xml");
     }
 
-    private static Document lockCandidate() throws ParserConfigurationException, SAXException, IOException, DocumentedException {
-        Lock commitOp = new Lock(NETCONF_SESSION_ID);
+    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 {
-        UnLock commitOp = new UnLock(NETCONF_SESSION_ID);
+    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 {
-        GetConfig getConfigOp = new GetConfig(configSubsystemFacade, Optional.<String> absent(), NETCONF_SESSION_ID);
+        final GetConfig getConfigOp = new GetConfig(configSubsystemFacade, Optional.<String>absent(),
+                NETCONF_SESSION_ID);
         return executeOp(getConfigOp, "netconfMessages/getConfig_candidate.xml");
     }
 
     private Document getConfigRunning() throws ParserConfigurationException, SAXException, IOException,
             DocumentedException {
-        GetConfig getConfigOp = new GetConfig(configSubsystemFacade, Optional.<String> absent(), NETCONF_SESSION_ID);
+        final GetConfig getConfigOp = new GetConfig(configSubsystemFacade, Optional.<String>absent(),
+                NETCONF_SESSION_ID);
         return executeOp(getConfigOp, "netconfMessages/getConfig.xml");
     }
 
@@ -533,8 +545,8 @@ public class NetconfMappingTest extends AbstractConfigTest {
         try {
             edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespaces.xml");
             fail();
-        } catch (DocumentedException e) {
-            String message = e.getMessage();
+        } catch (final DocumentedException e) {
+            final String message = e.getMessage();
             assertContainsString(message, "Element simpleInt present multiple times with different namespaces");
             assertContainsString(message, TEST_NAMESPACE);
             assertContainsString(message, XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
@@ -546,8 +558,8 @@ public class NetconfMappingTest extends AbstractConfigTest {
         try {
             edit("netconfMessages/namespaces/editConfig_differentNamespaceTO.xml");
             fail();
-        } catch (DocumentedException e) {
-            String message = e.getMessage();
+        } catch (final DocumentedException e) {
+            final String message = e.getMessage();
             assertContainsString(message, "Unrecognised elements");
             assertContainsString(message, "simple-int2");
             assertContainsString(message, "dto_d");
@@ -559,8 +571,8 @@ public class NetconfMappingTest extends AbstractConfigTest {
         try {
             edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespacesList.xml");
             fail();
-        } catch (DocumentedException e) {
-            String message = e.getMessage();
+        } catch (final DocumentedException e) {
+            final String message = e.getMessage();
             assertContainsString(message, "Element allow-user present multiple times with different namespaces");
             assertContainsString(message, TEST_NAMESPACE);
             assertContainsString(message, XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
@@ -574,7 +586,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
         edit("netconfMessages/namespaces/editConfig_typeNameConfigAttributeMatching.xml");
         commit();
 
-        Document response = getConfigRunning();
+        final Document response = getConfigRunning();
         checkTypeConfigAttribute(response);
     }
 
@@ -591,15 +603,15 @@ public class NetconfMappingTest extends AbstractConfigTest {
     @Test
     public void testUnrecognisedConfigElements() throws Exception {
 
-        String format = "netconfMessages/unrecognised/editConfig_unrecognised%d.xml";
-        final int TESTS_COUNT = 8;
+        final String format = "netconfMessages/unrecognised/editConfig_unrecognised%d.xml";
+        final int testsCount = 8;
 
-        for (int i = 0; i < TESTS_COUNT; i++) {
-            String file = String.format(format, i + 1);
+        for (int i = 0; i < testsCount; i++) {
+            final String file = String.format(format, i + 1);
             LOG.info("Reading {}", file);
             try {
                 edit(file);
-            } catch (DocumentedException e) {
+            } catch (final DocumentedException e) {
                 assertContainsString(e.getMessage(), "Unrecognised elements");
                 assertContainsString(e.getMessage(), "unknownAttribute");
                 continue;
@@ -645,41 +657,50 @@ public class NetconfMappingTest extends AbstractConfigTest {
         final ConfigSubsystemFacade facade = mock(ConfigSubsystemFacade.class);
         doThrow(new RuntimeException("Mocked runtime exception, Abort has to fail")).when(facade).abortConfiguration();
 
-        DiscardChanges discardOp = new DiscardChanges(facade, NETCONF_SESSION_ID);
+        final DiscardChanges discardOp = new DiscardChanges(facade, NETCONF_SESSION_ID);
 
         try {
             executeOp(discardOp, "netconfMessages/discardChanges.xml");
             fail("Should've failed, abort on mocked is supposed to throw RuntimeException");
-        } catch (DocumentedException e) {
-            assertTrue(e.getErrorTag() == DocumentedException.ErrorTag.operation_failed);
-            assertTrue(e.getErrorSeverity() == DocumentedException.ErrorSeverity.error);
-            assertTrue(e.getErrorType() == DocumentedException.ErrorType.application);
+        } catch (final DocumentedException e) {
+            assertTrue(e.getErrorTag() == DocumentedException.ErrorTag.OPERATION_FAILED);
+            assertTrue(e.getErrorSeverity() == DocumentedException.ErrorSeverity.ERROR);
+            assertTrue(e.getErrorType() == DocumentedException.ErrorType.APPLICATION);
         }
     }
 
     private Document discard() throws ParserConfigurationException, SAXException, IOException, DocumentedException {
-        DiscardChanges discardOp = new DiscardChanges(configSubsystemFacade, NETCONF_SESSION_ID);
+        final DiscardChanges discardOp = new DiscardChanges(configSubsystemFacade, NETCONF_SESSION_ID);
         return executeOp(discardOp, "netconfMessages/discardChanges.xml");
     }
 
-    private static void checkBinaryLeafEdited(final Document response) throws NodeTestException, SAXException, IOException {
-        assertContainsElement(response, readXmlToElement("<binaryLeaf xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">YmluYXJ5</binaryLeaf>"));
-        assertContainsElement(response, readXmlToElement("<binaryLeaf xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">ZGVmYXVsdEJpbg==</binaryLeaf>"));
+    private static void checkBinaryLeafEdited(final Document response)
+            throws NodeTestException, SAXException, IOException {
+        assertContainsElement(response, readXmlToElement("<binaryLeaf xmlns="
+                + "\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">YmluYXJ5</binaryLeaf>"));
+        assertContainsElement(response, readXmlToElement("<binaryLeaf xmlns="
+                + "\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">ZGVmYXVsdEJpbg==</binaryLeaf>"));
     }
 
     private static void checkTypedefs(final Document response) throws NodeTestException, SAXException, IOException {
 
-        assertContainsElement(response, readXmlToElement("<extended xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">10</extended>"));
+        assertContainsElement(response, readXmlToElement(
+                "<extended xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">10</extended>"));
         // Default
-        assertContainsElement(response, readXmlToElement("<extended xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">1</extended>"));
+        assertContainsElement(response, readXmlToElement(
+                "<extended xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">1</extended>"));
 
-        assertContainsElement(response, readXmlToElement("<extended-twice xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">20</extended-twice>"));
+        assertContainsElement(response, readXmlToElement("<extended-twice xmlns="
+                + "\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">20</extended-twice>"));
         // Default
-        assertContainsElement(response, readXmlToElement("<extended-twice xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2</extended-twice>"));
+        assertContainsElement(response, readXmlToElement("<extended-twice xmlns="
+                + "\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">2</extended-twice>"));
 
-        assertContainsElement(response, readXmlToElement("<extended-enum xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">two</extended-enum>"));
+        assertContainsElement(response, readXmlToElement("<extended-enum xmlns="
+                + "\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">two</extended-enum>"));
         // Default
-        assertContainsElement(response, readXmlToElement("<extended-enum xmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">one</extended-enum>"));
+        assertContainsElement(response, readXmlToElement("<extended-enum xmlns="
+                + "\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">one</extended-enum>"));
     }
 
     private static void assertContainsString(final String string, final String substring) {
@@ -688,7 +709,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
 
     private static void checkEnum(final Document response) throws Exception {
 
-        String expectedEnumContent = "two";
+        final String expectedEnumContent = "two";
 
         XMLAssert.assertXpathEvaluatesTo(expectedEnumContent,
                 getXpathForNetconfImplSubnode(INSTANCE_NAME, "extended-enum"),
@@ -696,46 +717,41 @@ public class NetconfMappingTest extends AbstractConfigTest {
     }
 
     private static void checkTestingDeps(final Document response) {
-        int testingDepsSize = response.getElementsByTagName("testing-deps").getLength();
+        final int testingDepsSize = response.getElementsByTagName("testing-deps").getLength();
         assertEquals(2, testingDepsSize);
     }
 
     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 {
 
-        Map<String,String> namesToTypeValues = ImmutableMap.of("instance-from-code", "configAttributeType",
+        final Map<String, String> namesToTypeValues = ImmutableMap.of("instance-from-code", "configAttributeType",
                 "test2", "default-string");
-        for (Entry<String, String> nameToExpectedValue : namesToTypeValues.entrySet()) {
+        for (final Entry<String, String> nameToExpectedValue : namesToTypeValues.entrySet()) {
             XMLAssert.assertXpathEvaluatesTo(nameToExpectedValue.getValue(),
-                    getXpathForNetconfImplSubnode(nameToExpectedValue.getKey(),"type"),
+                    getXpathForNetconfImplSubnode(nameToExpectedValue.getKey(), "type"),
                     response);
         }
     }
 
-    private Map<String, Map<String, ModuleMXBeanEntry>> getMbes() throws Exception {
-        final List<InputStream> yangDependencies = getYangs();
-
-        final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries = Maps.newHashMap();
+    private static Map<String, Map<String, ModuleMXBeanEntry>> getMbes() {
 
-        final SchemaContext schemaContext = parseYangStreams(yangDependencies);
-        YangStoreService yangStoreService = new YangStoreService(new SchemaContextProvider() {
-            @Override public SchemaContext getSchemaContext() {
-                return schemaContext;
-            }
-        }, mock(SchemaSourceProvider.class));
+        final SchemaContext schemaContext = getSchemaContext();
+        final YangStoreService yangStoreService = new YangStoreService(() -> schemaContext,
+            mock(SchemaSourceProvider.class));
         final BindingRuntimeContext bindingRuntimeContext = mock(BindingRuntimeContext.class);
         doReturn(schemaContext).when(bindingRuntimeContext).getSchemaContext();
         doReturn(getEnumMapping()).when(bindingRuntimeContext).getEnumMapping(any(Class.class));
         yangStoreService.refresh(bindingRuntimeContext);
+        final Map<String, Map<String, ModuleMXBeanEntry>> mBeanEntries = new HashMap<>();
         mBeanEntries.putAll(yangStoreService.getModuleMXBeanEntryMap());
 
         return mBeanEntries;
@@ -751,22 +767,8 @@ public class NetconfMappingTest extends AbstractConfigTest {
         return enumBiMap;
     }
 
-    private Set<org.opendaylight.yangtools.yang.model.api.Module> getModules() throws Exception {
-        SchemaContext resolveSchemaContext = parseYangStreams(getYangs());
-        return resolveSchemaContext.getModules();
-    }
-
-    private static SchemaContext parseYangStreams(final List<InputStream> streams) {
-
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
-                .newBuild();
-        final SchemaContext schemaContext;
-        try {
-            schemaContext = reactor.buildEffective(streams);
-        } catch (ReactorException e) {
-            throw new RuntimeException("Unable to build schema context from " + streams, e);
-        }
-        return schemaContext;
+    private static Set<org.opendaylight.yangtools.yang.model.api.Module> getModules() {
+        return getSchemaContext().getModules();
     }
 
     @Test
@@ -792,17 +794,18 @@ 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
 
-        RuntimeRpc netconf = new RuntimeRpc(configSubsystemFacade, NETCONF_SESSION_ID);
+        final RuntimeRpc netconf = new RuntimeRpc(configSubsystemFacade, NETCONF_SESSION_ID);
 
         response = executeOp(netconf, "netconfMessages/rpc.xml");
         assertContainsElementWithText(response, "testarg1");
 
         response = executeOp(netconf, "netconfMessages/rpcInner.xml");
-        Document expectedReplyOk = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc-reply_ok.xml");
+        final Document expectedReplyOk = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc-reply_ok.xml");
         XMLUnit.setIgnoreWhitespace(true);
         XMLAssert.assertXMLEqual(expectedReplyOk, response);
 
@@ -815,7 +818,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
     }
 
     private Document get() throws ParserConfigurationException, SAXException, IOException, DocumentedException {
-        Get getOp = new Get(configSubsystemFacade, NETCONF_SESSION_ID);
+        final Get getOp = new Get(configSubsystemFacade, NETCONF_SESSION_ID);
         return executeOp(getOp, "netconfMessages/get.xml");
     }
 
@@ -827,13 +830,14 @@ 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);
 
         LOG.debug("Executing netconf operation\n{}", XmlUtil.toString(request));
-        HandlingPriority priority = op.canHandle(request);
+        final HandlingPriority priority = op.canHandle(request);
 
         Preconditions.checkState(priority != HandlingPriority.CANNOT_HANDLE);
 
@@ -842,23 +846,19 @@ public class NetconfMappingTest extends AbstractConfigTest {
         return response;
     }
 
-    private List<InputStream> getYangs() {
-        List<String> 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.yang");
-        final Collection<InputStream> yangDependencies = new ArrayList<>();
-        for (String path : paths) {
-            final InputStream is = Preconditions
-                    .checkNotNull(getClass().getResourceAsStream(path), path + " not found");
-            yangDependencies.add(is);
-        }
-        return Lists.newArrayList(yangDependencies);
+    private static SchemaContext getSchemaContext() {
+        return YangParserTestUtils.parseYangResources(NetconfMappingTest.class,
+            "/META-INF/yang/config@2013-04-05.yang", "/META-INF/yang/rpc-context@2013-06-17.yang",
+            "/META-INF/yang/config-test@2013-06-13.yang", "/META-INF/yang/config-test-impl@2013-04-03.yang",
+            "/META-INF/yang/test-types@2013-11-27.yang", "/META-INF/yang/test-groups@2014-12-08.yang",
+            "/META-INF/yang/ietf-inet-types@2013-07-15.yang");
     }
 
-    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);
         //
@@ -874,7 +874,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
         p2.setCoreSize(44L);
         p2.setPort("port23");
         p2.setSimpleInt3(456);
-        mxBean.setPeers(Lists.<Peers> newArrayList(p1, p2));
+        mxBean.setPeers(Lists.<Peers>newArrayList(p1, p2));
         // //
         mxBean.setSimpleLong(454545L);
         mxBean.setSimpleLong2(44L);
@@ -883,16 +883,18 @@ public class NetconfMappingTest extends AbstractConfigTest {
         mxBean.setSimpleShort(new Short((short) 4));
         mxBean.setSimpleTest(545);
 
-        mxBean.setComplexList(Lists.<ComplexList> newArrayList());
-        mxBean.setSimpleList(Lists.<Integer> newArrayList());
+        mxBean.setComplexList(Lists.<ComplexList>newArrayList());
+        mxBean.setSimpleList(Lists.<Integer>newArrayList());
 
         final ObjectName testingDepOn = transaction.createModule(this.factory2.getImplementationName(), depName);
-        int i = 1;
-        for (Class<? extends AbstractServiceInterface> sInterface : factory2.getImplementedServiceIntefaces()) {
-            ServiceInterfaceAnnotation annotation = sInterface.getAnnotation(ServiceInterfaceAnnotation.class);
+        int index = 1;
+        for (final Class<? extends AbstractServiceInterface> 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);