+ @Test
+ public void testIdentityRefs() throws Exception {
+ edit("netconfMessages/editConfig_identities.xml");
+
+ commit();
+ getConfigRunning();
+ }
+
+ @Override
+ protected CodecRegistry getCodecRegistry() {
+ IdentityCodec<?> idCodec = mock(IdentityCodec.class);
+ doReturn(TestIdentity1.class).when(idCodec).deserialize(TestIdentity1.QNAME);
+ doReturn(TestIdentity2.class).when(idCodec).deserialize(TestIdentity2.QNAME);
+
+ CodecRegistry codecReg = super.getCodecRegistry();
+ doReturn(idCodec).when(codecReg).getIdentityCodec();
+ return codecReg;
+ }
+
+ @Test
+ public void testServicePersistance() throws Exception {
+ createModule(INSTANCE_NAME);
+
+ edit("netconfMessages/editConfig.xml");
+ Document config = getConfigCandidate();
+ assertCorrectServiceNames(config, Sets.newHashSet("user_to_instance_from_code", "ref_dep_user",
+ "ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
+ "ref_from_code_to_instance-from-code_1"));
+
+
+ edit("netconfMessages/editConfig_addServiceName.xml");
+ config = getConfigCandidate();
+ assertCorrectServiceNames(config, Sets.newHashSet("user_to_instance_from_code", "ref_dep_user",
+ "ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
+ "ref_from_code_to_instance-from-code_1", "ref_dep_user_another"));
+
+ edit("netconfMessages/editConfig_addServiceNameOnTest.xml");
+ config = getConfigCandidate();
+ assertCorrectServiceNames(config, Sets.newHashSet("user_to_instance_from_code", "ref_dep_user",
+ "ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
+ "ref_from_code_to_instance-from-code_1", "ref_dep_user_another"));
+
+ commit();
+ config = getConfigRunning();
+ assertCorrectRefNamesForDependencies(config);
+ assertCorrectServiceNames(config, Sets.newHashSet("user_to_instance_from_code", "ref_dep_user",
+ "ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
+ "ref_from_code_to_instance-from-code_1", "ref_dep_user_another"));
+
+ edit("netconfMessages/editConfig_replace_default.xml");
+ config = getConfigCandidate();
+ assertCorrectServiceNames(config, Collections.<String>emptySet());
+
+ edit("netconfMessages/editConfig_remove.xml");
+ config = getConfigCandidate();
+ assertCorrectServiceNames(config, Collections.<String>emptySet());
+
+ commit();
+ config = getConfigCandidate();
+ assertCorrectServiceNames(config, Collections.<String>emptySet());
+
+ }
+
+ private void assertCorrectRefNamesForDependencies(Document config) throws NodeTestException {
+ NodeList modulesList = config.getElementsByTagName("modules");
+ assertEquals(1, modulesList.getLength());
+
+ NodeTest nt = new NodeTest((DocumentTraversal) config, modulesList.item(0));
+ NodeTester tester = new AbstractNodeTester() {
+ private int defaultRefNameCount = 0;
+ private int userRefNameCount = 0;
+
+ @Override
+ public void testText(Text text) throws NodeTestException {
+ if(text.getData().equals("ref_dep2")) {
+ defaultRefNameCount++;
+ } else if(text.getData().equals("ref_dep_user_two")) {
+ userRefNameCount++;
+ }
+ }
+
+ @Override
+ public void noMoreNodes(NodeTest forTest) throws NodeTestException {
+ assertEquals(0, defaultRefNameCount);
+ assertEquals(2, userRefNameCount);
+ }
+ };
+ nt.performTest(tester, Node.TEXT_NODE);
+ }
+
+ private void assertCorrectServiceNames(Document configCandidate, Set<String> refNames) throws NodeTestException {
+ final Set<String> refNames2 = new HashSet<>(refNames);
+ NodeList servicesNodes = configCandidate.getElementsByTagName("services");
+ assertEquals(1, servicesNodes.getLength());
+
+ NodeTest nt = new NodeTest((DocumentTraversal) configCandidate, servicesNodes.item(0));
+ NodeTester tester = new AbstractNodeTester() {
+
+ @Override
+ public void testElement(Element element) throws NodeTestException {
+ if(element.getNodeName() != null) {
+ if(element.getNodeName().equals("name")) {
+ String elmText = element.getTextContent();
+ if(refNames2.contains(elmText)) {
+ refNames2.remove(elmText);
+ } else {
+ throw new NodeTestException("Unexpected services defined: " + elmText);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void noMoreNodes(NodeTest forTest) throws NodeTestException {
+ assertEquals(Collections.<String>emptySet(), refNames2);
+ assertTrue(refNames2.toString(), refNames2.isEmpty());
+ }
+ };
+ nt.performTest(tester, Node.ELEMENT_NODE);
+ }
+
+ @Test
+ public void testConfigNetconfUnionTypes() throws Exception {
+
+ createModule(INSTANCE_NAME);
+
+ 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>"));
+
+ 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>"));
+
+ }
+