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=8b6b1aefc1971d2af9fbc7f69b4264cc79ed3327;hp=ccb793149c4d21162ac11e3495981e4de1898faa;hb=2a4c88aa665a45c5394642cb3604603bebf8c0da;hpb=237c7309b595b59641dfb4eb546412fd12f52d16 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 ccb793149c..8b6b1aefc1 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 @@ -12,6 +12,7 @@ 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 org.apache.commons.lang3.StringUtils; import org.junit.Before; import org.junit.Ignore; @@ -19,13 +20,13 @@ 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; import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; -import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot; -import org.opendaylight.controller.config.yang.store.impl.MbeParser; import org.opendaylight.controller.config.yang.test.impl.ComplexDtoBInner; import org.opendaylight.controller.config.yang.test.impl.ComplexList; import org.opendaylight.controller.config.yang.test.impl.Deep; @@ -34,6 +35,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; @@ -46,14 +48,26 @@ import org.opendaylight.controller.netconf.confignetconfconnector.operations.edi import org.opendaylight.controller.netconf.confignetconfconnector.operations.get.Get; import org.opendaylight.controller.netconf.confignetconfconnector.operations.getconfig.GetConfig; import org.opendaylight.controller.netconf.confignetconfconnector.operations.runtimerpc.RuntimeRpc; +import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreServiceImpl; +import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot; import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider; import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession; +import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshot; import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; 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.model.api.SchemaContextProvider; +import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -73,14 +87,18 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; 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.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -92,11 +110,14 @@ 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; @Mock NetconfOperationRouter netconfOperationRouter; + @Mock + NetconfOperationServiceSnapshot netconfOperationServiceSnapshot; private TransactionProvider transactionProvider; @@ -104,14 +125,19 @@ 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(); + doNothing().when(netconfOperationServiceSnapshot).close(); + 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); @@ -130,6 +156,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); @@ -140,8 +185,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"); @@ -196,6 +248,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 { @@ -226,10 +301,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") @@ -239,10 +312,10 @@ public class NetconfMappingTest extends AbstractConfigTest { assertEquals(expectedResult, responseFromCandidate); edit("netconfMessages/editConfig_none.xml"); - doNothing().when(netconfOperationRouter).close(); closeSession(); - verify(netconfOperationRouter).close(); + verify(netconfOperationServiceSnapshot).close(); verifyNoMoreInteractions(netconfOperationRouter); + verifyNoMoreInteractions(netconfOperationServiceSnapshot); } private void checkBigDecimal(Element response) { @@ -256,7 +329,7 @@ public class NetconfMappingTest extends AbstractConfigTest { private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException { - DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID); + DefaultCloseSession closeOp = new DefaultCloseSession(NETCONF_SESSION_ID, netconfOperationServiceSnapshot); executeOp(closeOp, "netconfMessages/closeSession.xml"); } @@ -497,28 +570,55 @@ public class NetconfMappingTest extends AbstractConfigTest { XmlElement modulesElement = XmlElement.fromDomElement(response).getOnlyChildElement("data") .getOnlyChildElement("modules"); - XmlElement configAttributeType = null; + List expectedValues = Lists.newArrayList("default-string", "configAttributeType"); + Set configAttributeType = Sets.newHashSet(); + for (XmlElement moduleElement : modulesElement.getChildElements("module")) { for (XmlElement type : moduleElement.getChildElements("type")) { if (type.getAttribute(XmlUtil.XMLNS_ATTRIBUTE_KEY).equals("") == false) { - configAttributeType = type; + configAttributeType.add(type.getTextContent()); } } } - // TODO verify if should be default value - assertEquals("default-string", configAttributeType.getTextContent()); + for (String expectedValue : expectedValues) { + assertTrue(configAttributeType.contains(expectedValue)); + } } private Map> getMbes() throws Exception { final List yangDependencies = getYangs(); final Map> mBeanEntries = Maps.newHashMap(); - mBeanEntries.putAll(new MbeParser().parseYangFiles(yangDependencies).getModuleMXBeanEntryMap()); + + YangParserImpl yangParser = new YangParserImpl(); + final SchemaContext schemaContext = yangParser.resolveSchemaContext(new HashSet<>(yangParser.parseYangModelsFromStreamsMapped(yangDependencies).values())); + YangStoreServiceImpl yangStoreService = new YangStoreServiceImpl(new SchemaContextProvider() { + @Override + public SchemaContext getSchemaContext() { + return schemaContext ; + } + }); + mBeanEntries.putAll(yangStoreService.getYangStoreSnapshot().getModuleMXBeanEntryMap()); 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 { @@ -581,7 +681,7 @@ public class NetconfMappingTest extends AbstractConfigTest { Preconditions.checkState(priority != HandlingPriority.CANNOT_HANDLE); - final Document response = op.handle(request, netconfOperationRouter); + final Document response = op.handle(request, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT); logger.debug("Got response\n{}", XmlUtil.toString(response)); return response.getDocumentElement(); }