X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2FNetconfMappingTest.java;h=72d62efe84c21cfcf47e1c0d7ac8eb60bdbc97a7;hp=b248342a0a9c308a23714a3f82966f11456faa02;hb=c05e8241fcef668a8d2fe00776839df56187a401;hpb=23ec2c1ab1e9266029437be0818101efbc74450e diff --git a/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java b/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java index b248342a0a..72d62efe84 100644 --- a/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java +++ b/opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java @@ -8,11 +8,33 @@ package org.opendaylight.controller.netconf.confignetconfconnector; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import java.io.FileNotFoundException; +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.List; +import java.util.Map; +import java.util.Set; + +import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; +import javax.management.ObjectName; +import javax.xml.parsers.ParserConfigurationException; + import org.apache.commons.lang3.StringUtils; import org.junit.Before; import org.junit.Ignore; @@ -35,6 +57,7 @@ import org.opendaylight.controller.config.yang.test.impl.DtoAInner; import org.opendaylight.controller.config.yang.test.impl.DtoAInnerInner; import org.opendaylight.controller.config.yang.test.impl.DtoC; import org.opendaylight.controller.config.yang.test.impl.DtoD; +import org.opendaylight.controller.config.yang.test.impl.IdentityTestModuleFactory; import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleFactory; import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMXBean; import org.opendaylight.controller.config.yang.test.impl.Peers; @@ -55,6 +78,13 @@ import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.controller.netconf.util.xml.XmlElement; import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.util.xml.XmlUtil; +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.yang.data.impl.codec.CodecRegistry; +import org.opendaylight.yangtools.yang.data.impl.codec.IdentityCodec; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -62,30 +92,11 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import javax.management.InstanceAlreadyExistsException; -import javax.management.InstanceNotFoundException; -import javax.management.ObjectName; -import javax.xml.parsers.ParserConfigurationException; -import java.io.FileNotFoundException; -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.List; -import java.util.Map; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; public class NetconfMappingTest extends AbstractConfigTest { @@ -95,6 +106,7 @@ public class NetconfMappingTest extends AbstractConfigTest { private static final String NETCONF_SESSION_ID = "foo"; private NetconfTestImplModuleFactory factory; private DepTestImplModuleFactory factory2; + private IdentityTestModuleFactory factory3; @Mock YangStoreSnapshot yangStoreSnapshot; @@ -107,9 +119,13 @@ public class NetconfMappingTest extends AbstractConfigTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); doReturn(getMbes()).when(this.yangStoreSnapshot).getModuleMXBeanEntryMap(); + doReturn(getModules()).when(this.yangStoreSnapshot).getModules(); + this.factory = new NetconfTestImplModuleFactory(); this.factory2 = new DepTestImplModuleFactory(); - super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.factory, this.factory2)); + this.factory3 = new IdentityTestModuleFactory(); + super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.factory, this.factory2, + this.factory3)); transactionProvider = new TransactionProvider(this.configRegistryClient, NETCONF_SESSION_ID); } @@ -133,6 +149,25 @@ public class NetconfMappingTest extends AbstractConfigTest { return on; } + @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); @@ -143,8 +178,15 @@ public class NetconfMappingTest extends AbstractConfigTest { "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(); + 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"); @@ -199,6 +241,29 @@ public class NetconfMappingTest extends AbstractConfigTest { } } + @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, "0:0:0:0:0:0:0:1"); + assertContainsString(trimmedResponse, "456"); + + + edit("netconfMessages/editConfig_setUnions.xml"); + commit(); + response = getConfigRunning(); + + trimmedResponse = XmlUtil.toString(response).replaceAll("\\s", ""); + assertContainsString(trimmedResponse, "127.1.2.3"); + assertContainsString(trimmedResponse, "randomStringForUnion"); + + } + @Test public void testConfigNetconf() throws Exception { @@ -229,10 +294,8 @@ public class NetconfMappingTest extends AbstractConfigTest { commit(); response = getConfigCandidate(); final String responseFromCandidate = XmlUtil.toString(response).replaceAll("\\s+", ""); - // System.out.println(responseFromCandidate); response = getConfigRunning(); final String responseFromRunning = XmlUtil.toString(response).replaceAll("\\s+", ""); - // System.out.println(responseFromRunning); assertEquals(responseFromCandidate, responseFromRunning); final String expectedResult = XmlFileLoader.fileToString("netconfMessages/editConfig_expectedResult.xml") @@ -525,6 +588,21 @@ public class NetconfMappingTest extends AbstractConfigTest { return mBeanEntries; } + private Set getModules() throws Exception { + SchemaContext resolveSchemaContext = getSchemaContext(); + return resolveSchemaContext.getModules(); + } + + private SchemaContext getSchemaContext() throws Exception { + final List yangDependencies = getYangs(); + YangParserImpl parser = new YangParserImpl(); + + Set allYangModules = parser.parseYangModelsFromStreams(yangDependencies); + + return parser.resolveSchemaContext(Sets + .newHashSet(allYangModules)); + } + @Test public void testConfigNetconfRuntime() throws Exception {