+ @Test
+ public void testServicePersistance() throws Exception {
+ createModule(INSTANCE_NAME);
+
+ edit("netconfMessages/editConfig.xml");
+ Element config = getConfigCandidate();
+ assertCorrectServiceNames(config, 6, "ref_test2", "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, 7, "ref_test2", "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, 7, "ref_test2", "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, 7, "ref_test2", "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, 2, "ref_dep", "ref_dep2");
+
+ edit("netconfMessages/editConfig_remove.xml");
+ config = getConfigCandidate();
+ assertCorrectServiceNames(config, 0);
+
+ commit();
+ config = getConfigCandidate();
+ assertCorrectServiceNames(config, 0);
+
+ }
+
+ private void assertCorrectRefNamesForDependencies(Element config) {
+ NodeList modulesList = config.getElementsByTagName("modules");
+ assertEquals(1, modulesList.getLength());
+
+ Element modules = (Element) modulesList.item(0);
+
+ String trimmedModules = XmlUtil.toString(modules).replaceAll("\\s", "");
+ int defaultRefNameCount = StringUtils.countMatches(trimmedModules, "ref_dep2");
+ int userRefNameCount = StringUtils.countMatches(trimmedModules, "ref_dep_user_two");
+
+ assertEquals(0, defaultRefNameCount);
+ assertEquals(2, userRefNameCount);
+ }
+
+ private void assertCorrectServiceNames(Element configCandidate, int servicesSize, String... refNames) {
+ NodeList elements = configCandidate.getElementsByTagName("provider");
+ assertEquals(servicesSize, elements.getLength());
+
+ NodeList servicesList = configCandidate.getElementsByTagName("services");
+ assertEquals(1, servicesList.getLength());
+
+ Element services = (Element) servicesList.item(0);
+ String trimmedServices = XmlUtil.toString(services).replaceAll("\\s", "");
+
+ for (String s : refNames) {
+ assertThat(trimmedServices, JUnitMatchers.containsString(s));
+ }
+ }
+
+ @Test
+ public void testConfigNetconfUnionTypes() throws Exception {
+
+ createModule(INSTANCE_NAME);
+
+ edit("netconfMessages/editConfig.xml");
+ commit();
+ Element response = getConfigRunning();
+ String trimmedResponse = XmlUtil.toString(response).replaceAll("\\s", "");
+ assertContainsString(trimmedResponse, "<ipxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">0:0:0:0:0:0:0:1</ip>");
+ assertContainsString(trimmedResponse, "<union-test-attrxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">456</union-test-attr>");
+
+
+ edit("netconfMessages/editConfig_setUnions.xml");
+ commit();
+ response = getConfigRunning();
+
+ trimmedResponse = XmlUtil.toString(response).replaceAll("\\s", "");
+ assertContainsString(trimmedResponse, "<ipxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">127.1.2.3</ip>");
+ assertContainsString(trimmedResponse, "<union-test-attrxmlns=\"urn:opendaylight:params:xml:ns:yang:controller:test:impl\">randomStringForUnion</union-test-attr>");
+
+ }
+