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=0a4f82f057b72bb24dfc51b7d2c18df950b47483;hp=9511673ea40781446c4134f02d3b1defbe47353a;hb=4eb724db3877173d502ba38c6d83bec780b38bb2;hpb=662465381994f266eb32aa3dceba426e747df678 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 9511673ea4..0a4f82f057 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 @@ -20,6 +20,8 @@ import org.junit.Test; import org.junit.matchers.JUnitMatchers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.config.api.ConflictingVersionException; +import org.opendaylight.controller.config.api.ValidationException; import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface; import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation; import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; @@ -35,6 +37,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 +58,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; @@ -84,6 +94,7 @@ 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; @@ -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,14 +119,18 @@ 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); } - private ObjectName createModule(final String instanceName) throws InstanceAlreadyExistsException, InstanceNotFoundException, URISyntaxException { + 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); @@ -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); @@ -236,7 +271,6 @@ public class NetconfMappingTest extends AbstractConfigTest { edit("netconfMessages/editConfig.xml"); Element configCandidate = getConfigCandidate(); - System.err.println(XmlUtil.toString(configCandidate)); checkBinaryLeafEdited(configCandidate); @@ -260,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") @@ -556,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 {