From: Ed Warnicke Date: Wed, 15 Jan 2014 03:05:03 +0000 (+0000) Subject: Merge "Switch initial config files format to xml and add autodetect adapter for confi... X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~93 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=306f95ccf8d699e2eed111f193b2fc388fa03e70;hp=dea24d658123f9059a3fbb3a650c2dbfdb480fcf Merge "Switch initial config files format to xml and add autodetect adapter for config persister." --- diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java index 10f19e8399..7075865573 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java @@ -12,6 +12,16 @@ 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 java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.io.FileUtils; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; @@ -22,6 +32,7 @@ import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper; import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang2sources.spi.CodeGenerator; @@ -29,17 +40,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.impl.StaticLoggerBinder; -import java.io.File; -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - /** * This class interfaces with yang-maven-plugin. Gets parsed yang modules in * {@link SchemaContext}, and parameters form the plugin configuration, and @@ -70,7 +70,7 @@ public class JMXGenerator implements CodeGenerator { @Override public Collection generateSources(SchemaContext context, - File outputBaseDir, Set yangModulesInCurrentMavenModule) { + File outputBaseDir, Set yangModulesInCurrentMavenModule) { Preconditions.checkArgument(context != null, "Null context received"); Preconditions.checkArgument(outputBaseDir != null, @@ -86,24 +86,25 @@ public class JMXGenerator implements CodeGenerator { outputBaseDir.mkdirs(); GeneratedFilesTracker generatedFiles = new GeneratedFilesTracker(); + // create SIE structure qNamesToSIEs Map qNamesToSIEs = new HashMap<>(); - // create SIE structure qNamesToSIEs + + Map knownSEITracker = new HashMap<>(); for (Module module : context.getModules()) { String packageName = packageTranslator.getPackageName(module); Map namesToSIEntries = ServiceInterfaceEntry - .create(module, packageName); + .create(module, packageName, knownSEITracker); for (Entry sieEntry : namesToSIEntries .entrySet()) { - // merge value into qNamesToSIEs if (qNamesToSIEs.containsKey(sieEntry.getKey()) == false) { qNamesToSIEs.put(sieEntry.getKey(), sieEntry.getValue()); } else { throw new IllegalStateException( - "Cannot add two SIE with same qname " - + sieEntry.getValue()); + "Cannot add two SIE with same qname " + + sieEntry.getValue()); } } if (yangModulesInCurrentMavenModule.contains(module)) { diff --git a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntry.java b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntry.java index 869488e777..5bcc5402af 100644 --- a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntry.java +++ b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntry.java @@ -7,11 +7,9 @@ */ package org.opendaylight.controller.config.yangjmxgenerator; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static java.lang.String.format; -import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName; - +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Optional; +import com.google.common.collect.Sets; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -21,7 +19,6 @@ import java.util.Map.Entry; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.opendaylight.controller.config.yangjmxgenerator.attribute.AbstractDependencyAttribute; import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc; import org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute; @@ -52,10 +49,10 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.UsesNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; -import com.google.common.collect.Sets; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static java.lang.String.format; +import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName; /** * Represents part of yang model that describes a module. diff --git a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntry.java b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntry.java index aa2d6a5d7f..ef40d9515b 100644 --- a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntry.java +++ b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntry.java @@ -7,10 +7,7 @@ */ package org.opendaylight.controller.config.yangjmxgenerator; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; -import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.SERVICE_TYPE_Q_NAME; - +import com.google.common.base.Optional; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -18,15 +15,15 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; - import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import com.google.common.base.Optional; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.lang.String.format; +import static org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.SERVICE_TYPE_Q_NAME; /** * Represents identity derived from {@link ConfigConstants#SERVICE_TYPE_Q_NAME}. @@ -123,7 +120,7 @@ public class ServiceInterfaceEntry extends AbstractEntry { * values */ public static Map create(Module currentModule, - String packageName) { + String packageName,Map definedSEItracker) { logger.debug("Generating ServiceInterfaces from {} to package {}", currentModule.getNamespace(), packageName); @@ -152,7 +149,7 @@ public class ServiceInterfaceEntry extends AbstractEntry { // this is a base type created = new ServiceInterfaceEntry(identity, packageName, ModuleUtil.getQName(currentModule)); } else { - ServiceInterfaceEntry foundBase = identitiesToSIs + ServiceInterfaceEntry foundBase = definedSEItracker .get(identity.getBaseIdentity()); // derived type, did we convert the parent? if (foundBase != null) { @@ -160,12 +157,15 @@ public class ServiceInterfaceEntry extends AbstractEntry { Optional.of(foundBase), identity, packageName, ModuleUtil.getQName(currentModule)); } } + + if (created != null) { created.setYangModuleName(currentModule.getName()); // TODO how to get local name created.setYangModuleLocalname(identity.getQName() .getLocalName()); identitiesToSIs.put(identity, created); + definedSEItracker.put(identity, created); iterator.remove(); } } diff --git a/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryTest.java b/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryTest.java index e86c876169..9ea34ca2b8 100644 --- a/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryTest.java +++ b/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryTest.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.config.yangjmxgenerator; import com.google.common.collect.Sets; +import java.util.HashMap; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc; @@ -22,6 +23,7 @@ import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath; import javax.management.openmbean.ArrayType; @@ -94,16 +96,18 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest { @Before public void setUp() { + Map identitiesToSIs = new HashMap<>(); modulesToSIEs = ServiceInterfaceEntry.create(threadsModule, - "packages.sis"); + "packages.sis",identitiesToSIs); } @Test public void test_jmxImplModule() { + Map identitiesToSIs = new HashMap<>(); Map modulesToSIEs = ServiceInterfaceEntry - .create(threadsModule, PACKAGE_NAME); + .create(threadsModule, PACKAGE_NAME,identitiesToSIs); modulesToSIEs.putAll(ServiceInterfaceEntry.create(jmxModule, - PACKAGE_NAME)); + PACKAGE_NAME,identitiesToSIs)); Map namesToMBEs = ModuleMXBeanEntry .create(jmxImplModule, modulesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl(context)) , PACKAGE_NAME); diff --git a/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/RuntimeBeanEntryTest.java b/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/RuntimeBeanEntryTest.java index 97258fb697..b570302563 100644 --- a/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/RuntimeBeanEntryTest.java +++ b/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/RuntimeBeanEntryTest.java @@ -7,12 +7,14 @@ */ package org.opendaylight.controller.config.yangjmxgenerator; +import java.util.HashMap; import org.junit.Test; import org.mockito.Mockito; import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute; import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; +import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; @@ -41,6 +43,7 @@ public class RuntimeBeanEntryTest extends AbstractYangTest { public static final String SLEEP_RPC_OUTPUT = "ThreadState"; public static final String SLEEP_RPC_INPUT_NAME = "millis"; public static final String SLEEP_RPC_INPUT_TYPE = "Long"; + private static final Map identitiesToSIs = new HashMap<>(); @Test public void createRuntimeBean() { @@ -61,7 +64,7 @@ public class RuntimeBeanEntryTest extends AbstractYangTest { public void runtimeBeanRPCTest() { // create service interfaces Map modulesToSIEs = ServiceInterfaceEntry - .create(threadsModule, "packages.sis"); + .create(threadsModule, "packages.sis",identitiesToSIs); assertNotNull(modulesToSIEs); // create MXBeans map diff --git a/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntryTest.java b/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntryTest.java index 0da61b46c3..eed8695103 100644 --- a/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntryTest.java +++ b/opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntryTest.java @@ -7,27 +7,26 @@ */ package org.opendaylight.controller.config.yangjmxgenerator; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; - +import com.google.common.collect.Sets; import java.net.URI; import java.net.URISyntaxException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; - import org.hamcrest.CoreMatchers; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; - -import com.google.common.collect.Sets; +import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; public class ServiceInterfaceEntryTest extends AbstractYangTest { public static final String PACKAGE_NAME = "packages.sis"; @@ -38,6 +37,7 @@ public class ServiceInterfaceEntryTest extends AbstractYangTest { private static final URI THREADS_NAMESPACE; private static final Date THREADS_REVISION_DATE; + static { try { THREADS_NAMESPACE = new URI(ConfigConstants.CONFIG_NAMESPACE @@ -77,8 +77,9 @@ public class ServiceInterfaceEntryTest extends AbstractYangTest { @Test public void testCreateFromIdentities() { // each identity has to have a base that leads to service-type + Map definedIdentities = new HashMap<>(); Map namesToSIEntries = ServiceInterfaceEntry - .create(threadsModule, PACKAGE_NAME); + .create(threadsModule, PACKAGE_NAME,definedIdentities); // expected eventbus, threadfactory, threadpool, // scheduled-threadpool,thread-rpc-context assertThat(namesToSIEntries.size(), is(expectedSIEFileNames.size())); diff --git a/opendaylight/config/yang-store-impl/src/main/java/org/opendaylight/controller/config/yang/store/impl/MbeParser.java b/opendaylight/config/yang-store-impl/src/main/java/org/opendaylight/controller/config/yang/store/impl/MbeParser.java index 2be6c81ee7..d54996dbb7 100644 --- a/opendaylight/config/yang-store-impl/src/main/java/org/opendaylight/controller/config/yang/store/impl/MbeParser.java +++ b/opendaylight/config/yang-store-impl/src/main/java/org/opendaylight/controller/config/yang/store/impl/MbeParser.java @@ -17,6 +17,7 @@ import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper; import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; @@ -47,11 +48,12 @@ public class MbeParser { Map qNamesToSIEs = new HashMap<>(); + Map knownSEITracker = new HashMap<>(); // create SIE structure qNamesToSIEs for (Module module : resolveSchemaContext.getModules()) { String packageName = packageTranslator.getPackageName(module); Map namesToSIEntries = ServiceInterfaceEntry - .create(module, packageName); + .create(module, packageName,knownSEITracker); for (Entry sieEntry : namesToSIEntries .entrySet()) { diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonIncorrectTopLevelTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonIncorrectTopLevelTest.java index a589f9fca3..47222571b8 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonIncorrectTopLevelTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonIncorrectTopLevelTest.java @@ -119,12 +119,6 @@ public class CnSnToJsonIncorrectTopLevelTest extends YangAndXmlAndDataSchemaLoad return null; } - public YangNode getParent() { - // TODO Auto-generated method stub - return null; - } - - @Override public boolean isAddedByUses() { // TODO Auto-generated method stub return false; diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonNotExistingLeafTypeTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonNotExistingLeafTypeTest.java index e2d7f0ce13..7fdd6cac47 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonNotExistingLeafTypeTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonNotExistingLeafTypeTest.java @@ -69,9 +69,7 @@ public class CnSnToJsonNotExistingLeafTypeTest extends YangAndXmlAndDataSchemaLo leafBuild.setConfiguration(true); contBuild.addChildNode(leafBuild); - // FIXME: build method does not accept any arguments - //return contBuild.build(null); - return null; + return contBuild.build(); } } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlNotExistingLeafTypeTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlNotExistingLeafTypeTest.java index 4da354c2c0..555f2b3e3c 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlNotExistingLeafTypeTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlNotExistingLeafTypeTest.java @@ -63,10 +63,7 @@ public class CnSnToXmlNotExistingLeafTypeTest { leafBuild.setConfiguration(true); contBuild.addChildNode(leafBuild); - // FIXME: build method does not accept any arguments - //return contBuild.build(null); - return null; - + return contBuild.build(); } } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyMountInstanceImpl.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyMountInstanceImpl.java new file mode 100644 index 0000000000..181aa04811 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyMountInstanceImpl.java @@ -0,0 +1,78 @@ +package org.opendaylight.controller.sal.restconf.impl.test; + +import java.util.concurrent.Future; + +import org.opendaylight.controller.sal.core.api.data.DataChangeListener; +import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction; +import org.opendaylight.controller.sal.core.api.mount.MountInstance; +import org.opendaylight.controller.sal.core.api.notify.NotificationListener; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.concepts.Registration; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; + +class DummyMountInstanceImpl implements MountInstance { + + SchemaContext schemaContext; + + public static class Builder { + SchemaContext schemaContext; + + public Builder setSchemaContext(SchemaContext schemaContext) { + this.schemaContext = schemaContext; + return this; + } + + public MountInstance build() { + DummyMountInstanceImpl instance = new DummyMountInstanceImpl(); + instance.schemaContext = schemaContext; + return instance; + } + } + + @Override + public Registration addNotificationListener(QName notification, NotificationListener listener) { + // TODO Auto-generated method stub + return null; + } + + @Override + public CompositeNode readConfigurationData(InstanceIdentifier path) { + // TODO Auto-generated method stub + return null; + } + + @Override + public CompositeNode readOperationalData(InstanceIdentifier path) { + // TODO Auto-generated method stub + return null; + } + + @Override + public DataModificationTransaction beginTransaction() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ListenerRegistration registerDataChangeListener(InstanceIdentifier path, + DataChangeListener listener) { + // TODO Auto-generated method stub + return null; + } + + @Override + public SchemaContext getSchemaContext() { + return schemaContext; + } + + @Override + public Future> rpc(QName type, CompositeNode input) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ReadConfAndOperDataTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ReadConfAndOperDataTest.java deleted file mode 100644 index f2eea9dbd2..0000000000 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/ReadConfAndOperDataTest.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.opendaylight.controller.sal.restconf.impl.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.FileNotFoundException; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URLEncoder; -import java.util.List; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.LogRecord; - -import javax.ws.rs.core.Application; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.test.JerseyTest; -import org.glassfish.jersey.test.TestProperties; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider; -import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; -import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; -import org.opendaylight.controller.sal.restconf.impl.ControllerContext; -import org.opendaylight.controller.sal.restconf.impl.RestconfImpl; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -import com.google.common.base.Charsets; - -public class ReadConfAndOperDataTest extends JerseyTest { - - private static ControllerContext controllerContext; - private static BrokerFacade brokerFacade; - private static RestconfImpl restconfImpl; - private static final MediaType MEDIA_TYPE_DRAFT02 = new MediaType("application", "yang.data+xml"); - - @BeforeClass - public static void init() throws FileNotFoundException { - Set allModules = TestUtils.loadModulesFrom("/full-versions/yangs"); - assertNotNull(allModules); - SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules); - controllerContext = ControllerContext.getInstance(); - controllerContext.setSchemas(schemaContext); - brokerFacade = mock(BrokerFacade.class); - restconfImpl = RestconfImpl.getInstance(); - restconfImpl.setBroker(brokerFacade); - restconfImpl.setControllerContext(controllerContext); - } - - @Before - public void logs() { - List loggedRecords = getLoggedRecords(); - for (LogRecord l : loggedRecords) { - System.out.println(l.getMessage()); - } - } - - @Test - public void testReadConfigurationData() throws UnsupportedEncodingException, FileNotFoundException { - - String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/eth0"); - - CompositeNode loadedCompositeNode = TestUtils.readInputToCnSn("/parts/ietf-interfaces_interfaces.xml", true, - XmlToCompositeNodeProvider.INSTANCE); - when(brokerFacade.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(loadedCompositeNode); - - Response response = target(uri).request(MEDIA_TYPE_DRAFT02).get(); - assertEquals(200, response.getStatus()); - - uri = createUri("/config/", "ietf-interfaces:interfaces/interface/example"); - when(brokerFacade.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(null); - - response = target(uri).request(MEDIA_TYPE_DRAFT02).get(); - assertEquals(404, response.getStatus()); - } - - @Test - public void testReadOperationalData() throws UnsupportedEncodingException, FileNotFoundException { - String uri = createUri("/operational/", "ietf-interfaces:interfaces/interface/eth0"); - - CompositeNode loadedCompositeNode = TestUtils.readInputToCnSn("/parts/ietf-interfaces_interfaces.xml", true, - XmlToCompositeNodeProvider.INSTANCE); - - when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(loadedCompositeNode); - - Response response = target(uri).request(MEDIA_TYPE_DRAFT02).get(); - assertEquals(200, response.getStatus()); - - uri = createUri("/config/", "ietf-interfaces:interfaces/interface/example"); - when(brokerFacade.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(null); - - response = target(uri).request(MEDIA_TYPE_DRAFT02).get(); - assertEquals(404, response.getStatus()); - } - - private String createUri(String prefix, String encodedPart) throws UnsupportedEncodingException { - return URI.create(prefix + URLEncoder.encode(encodedPart, Charsets.US_ASCII.name()).toString()).toASCIIString(); - } - - @Override - protected Application configure() { - enable(TestProperties.LOG_TRAFFIC); - enable(TestProperties.DUMP_ENTITY); - enable(TestProperties.RECORD_LOG_LEVEL); - set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue()); - - ResourceConfig resourceConfig = new ResourceConfig(); - resourceConfig = resourceConfig.registerInstances(restconfImpl, StructuredDataToXmlProvider.INSTANCE, - XmlToCompositeNodeProvider.INSTANCE); - return resourceConfig; - } -} diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DeleteRestCallTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java similarity index 85% rename from opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DeleteRestCallTest.java rename to opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java index 7b164d4615..814c8a3c64 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DeleteRestCallTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java @@ -4,19 +4,15 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.createUri; import java.io.FileNotFoundException; -import java.io.InputStream; import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URLEncoder; import java.util.Set; import java.util.concurrent.Future; import java.util.logging.Level; -import javax.ws.rs.client.Entity; import javax.ws.rs.core.Application; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -28,20 +24,16 @@ import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider; -import org.opendaylight.controller.sal.rest.impl.XmlMapper; import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; import org.opendaylight.controller.sal.restconf.impl.ControllerContext; import org.opendaylight.controller.sal.restconf.impl.RestconfImpl; import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import com.google.common.base.Charsets; - -public class DeleteRestCallTest extends JerseyTest { +public class RestDeleteOperationTest extends JerseyTest { private static ControllerContext controllerContext; private static BrokerFacade brokerFacade; @@ -61,6 +53,22 @@ public class DeleteRestCallTest extends JerseyTest { restconfImpl.setControllerContext(controllerContext); } + @Override + protected Application configure() { + /* enable/disable Jersey logs to console */ + /* + * enable(TestProperties.LOG_TRAFFIC); + */ + enable(TestProperties.DUMP_ENTITY); + enable(TestProperties.RECORD_LOG_LEVEL); + set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue()); + + ResourceConfig resourceConfig = new ResourceConfig(); + resourceConfig = resourceConfig.registerInstances(restconfImpl, StructuredDataToXmlProvider.INSTANCE, + XmlToCompositeNodeProvider.INSTANCE); + return resourceConfig; + } + @Test public void testDeleteConfigurationData() throws UnsupportedEncodingException, FileNotFoundException { String uri2 = createUri("/config/", "test-interface:interfaces"); @@ -82,20 +90,4 @@ public class DeleteRestCallTest extends JerseyTest { assertEquals(500, response.getStatus()); } - private String createUri(String prefix, String encodedPart) throws UnsupportedEncodingException { - return URI.create(prefix + URLEncoder.encode(encodedPart, Charsets.US_ASCII.name()).toString()).toASCIIString(); - } - - @Override - protected Application configure() { - enable(TestProperties.LOG_TRAFFIC); - enable(TestProperties.DUMP_ENTITY); - enable(TestProperties.RECORD_LOG_LEVEL); - set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue()); - - ResourceConfig resourceConfig = new ResourceConfig(); - resourceConfig = resourceConfig.registerInstances(restconfImpl, StructuredDataToXmlProvider.INSTANCE, - XmlToCompositeNodeProvider.INSTANCE); - return resourceConfig; - } } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java new file mode 100644 index 0000000000..d997a8afb1 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java @@ -0,0 +1,307 @@ +package org.opendaylight.controller.sal.restconf.impl.test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.JSON; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.XML; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.createUri; + +import java.io.FileNotFoundException; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +import javax.ws.rs.core.Application; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.glassfish.jersey.test.TestProperties; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.controller.sal.core.api.mount.MountService; +import org.opendaylight.controller.sal.rest.api.Draft01; +import org.opendaylight.controller.sal.rest.api.Draft02; +import org.opendaylight.controller.sal.rest.api.RestconfService; +import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider; +import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider; +import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider; +import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; +import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; +import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper; +import org.opendaylight.controller.sal.restconf.impl.ControllerContext; +import org.opendaylight.controller.sal.restconf.impl.RestconfImpl; +import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.Node; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; + +public class RestGetOperationTest extends JerseyTest { + + private static BrokerFacade brokerFacade; + private static RestconfImpl restconfImpl; + private static SchemaContext schemaContextYangsIetf; + private static SchemaContext schemaContextTestModule; + + @BeforeClass + public static void init() throws FileNotFoundException { + schemaContextYangsIetf = TestUtils.loadSchemaContext("/full-versions/yangs"); + schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module"); + ControllerContext controllerContext = ControllerContext.getInstance(); + controllerContext.setSchemas(schemaContextYangsIetf); + brokerFacade = mock(BrokerFacade.class); + restconfImpl = RestconfImpl.getInstance(); + restconfImpl.setBroker(brokerFacade); + restconfImpl.setControllerContext(controllerContext); + } + + @Before + public void logs() { + /* enable/disable Jersey logs to console */ + /* + * List loggedRecords = getLoggedRecords(); for (LogRecord l + * : loggedRecords) { System.out.println(l.getMessage()); } + */ + } + + @Override + protected Application configure() { + /* enable/disable Jersey logs to console */ + /* + * enable(TestProperties.LOG_TRAFFIC); + */ + enable(TestProperties.DUMP_ENTITY); + enable(TestProperties.RECORD_LOG_LEVEL); + set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue()); + + ResourceConfig resourceConfig = new ResourceConfig(); + resourceConfig = resourceConfig.registerInstances(restconfImpl, StructuredDataToXmlProvider.INSTANCE, + StructuredDataToJsonProvider.INSTANCE, XmlToCompositeNodeProvider.INSTANCE, + JsonToCompositeNodeProvider.INSTANCE); + return resourceConfig; + } + + /** + * Tests {@link RestconfImpl#readData() readAllData()} method of + * RestconfImpl with url {@code "/datastore/ identifier}"}. Status codes 200 + * is tested. + */ + @Test + public void getDatastoreDataViaUrlTest200() throws FileNotFoundException, UnsupportedEncodingException { + mockReadOperationalDataMethod(); + getDataWithUrl("/datastore/", Draft01.MediaTypes.DATA + JSON, 200); + getDataWithUrl("/datastore/", Draft01.MediaTypes.DATA + XML, 200); + getDataWithUrl("/datastore/", MediaType.APPLICATION_JSON, 200); + getDataWithUrl("/datastore/", MediaType.APPLICATION_XML, 200); + getDataWithUrl("/datastore/", MediaType.TEXT_XML, 200); + } + + /** + * Tests {@link RestconfImpl#readData() readAllData()} method of + * RestconfImpl with url {@code "/datastore/ identifier}"}. Status codes 400 + * is tested. + */ + @Test + public void getDatastoreDataViaUrlTest400() throws FileNotFoundException, UnsupportedEncodingException { + mockReadOperationalDataMethod(); + getDataWithUrl("/datastore/", Draft01.MediaTypes.DATA + JSON, 400); + getDataWithUrl("/datastore/", Draft01.MediaTypes.DATA + XML, 400); + getDataWithUrl("/datastore/", MediaType.APPLICATION_JSON, 400); + getDataWithUrl("/datastore/", MediaType.APPLICATION_XML, 400); + getDataWithUrl("/datastore/", MediaType.TEXT_XML, 400); + } + + /** + * Tests {@link RestconfImpl#readOperationalData(String) + * readOperationalData(String)} method of RestconfImpl with url + * {@code "/operational/...identifier..."}. Status codes 200 is tested. + */ + @Test + public void getOperationalDataViaUrl200() throws UnsupportedEncodingException { + mockReadOperationalDataMethod(); + getDataWithUrl("/operational/", Draft02.MediaTypes.DATA + JSON, 200); + getDataWithUrl("/operational/", Draft02.MediaTypes.DATA + XML, 200); + getDataWithUrl("/operational/", MediaType.APPLICATION_JSON, 200); + getDataWithUrl("/operational/", MediaType.APPLICATION_XML, 200); + getDataWithUrl("/operational/", MediaType.TEXT_XML, 200); + } + + /** + * Tests {@link RestconfImpl#readOperationalData(String) + * readOperationalData(String)} method of RestconfImpl with url + * {@code "/operational/...identifier..."}. Status codes 400 is tested. + */ + @Test + public void getOperationalDataViaUrl400() throws UnsupportedEncodingException { + mockReadOperationalDataMethod(); + getDataWithUrl("/operational/", Draft02.MediaTypes.DATA + JSON, 400); + getDataWithUrl("/operational/", Draft02.MediaTypes.DATA + XML, 400); + getDataWithUrl("/operational/", MediaType.APPLICATION_JSON, 400); + getDataWithUrl("/operational/", MediaType.APPLICATION_XML, 400); + getDataWithUrl("/operational/", MediaType.TEXT_XML, 400); + } + + /** + * Tests {@link RestconfImpl#readOperationalData + * #readConfigurationData(String) readConfigurationData(String)} method of + * RestconfImpl with url {@code "/config/...identifier..."}. Status codes + * 200 is tested. + */ + @Test + public void getConfigDataViaUrl200() throws UnsupportedEncodingException { + mockReadConfigurationDataMethod(); + getDataWithUrl("/config/", Draft02.MediaTypes.DATA + JSON, 200); + getDataWithUrl("/config/", Draft02.MediaTypes.DATA + XML, 200); + getDataWithUrl("/config/", MediaType.APPLICATION_JSON, 200); + getDataWithUrl("/config/", MediaType.APPLICATION_XML, 200); + getDataWithUrl("/config/", MediaType.TEXT_XML, 200); + } + + /** + * Tests {@link RestconfImpl#readOperationalData + * #readConfigurationData(String) readConfigurationData(String)} method of + * RestconfImpl with url {@code "/config/...identifier..."}. Status codes + * 400 is tested. + */ + @Test + public void getConfigDataViaUrl400() throws UnsupportedEncodingException { + mockReadConfigurationDataMethod(); + getDataWithUrl("/config/", Draft02.MediaTypes.DATA + JSON, 400); + getDataWithUrl("/config/", Draft02.MediaTypes.DATA + XML, 400); + getDataWithUrl("/config/", MediaType.APPLICATION_JSON, 400); + getDataWithUrl("/config/", MediaType.APPLICATION_XML, 400); + getDataWithUrl("/config/", MediaType.TEXT_XML, 400); + } + + /** + * Tests {@link RestconfImpl#readAllData() readAllData()} method of + * RestconfImpl with url {@code "/datastore"}. Currently the method isn't + * supported so it returns 500 + */ + @Test + public void getDatastoreDataAllTest500() throws UnsupportedEncodingException { + getDatastoreAllDataTest(Draft01.MediaTypes.DATASTORE + XML); + getDatastoreAllDataTest(Draft01.MediaTypes.DATASTORE + JSON); + } + + /** + * + * Tests {@link RestconfImpl#getModules getModules} method of RestconfImpl + * with uri {@code "/modules"}. Currently the method isn't supported so it + * returns 500 + */ + @Test + public void getModulesDataTest500() throws UnsupportedEncodingException { + getModulesDataTest(Draft01.MediaTypes.API + JSON); + getModulesDataTest(Draft01.MediaTypes.API + XML); + getModulesDataTest(Draft02.MediaTypes.API + JSON); + getModulesDataTest(Draft02.MediaTypes.API + XML); + } + + /** + * Test of request for not existing data. Returning status code 404 + */ + @Test + public void getDataWithUrlNoExistingDataTest404() throws UnsupportedEncodingException, URISyntaxException { + String uri = createUri("/datastore/", "ietf-interfaces:interfaces/interface/eth0"); + + when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(null); + + Response response = target(uri).request(Draft01.MediaTypes.DATA + RestconfService.XML).get(); + assertEquals(404, response.getStatus()); + } + + /** + * MountPoint test. URI represents mount point. + */ + @Test + public void getDataWithUrlMountPoint() throws UnsupportedEncodingException, FileNotFoundException, + URISyntaxException { + when(brokerFacade.readConfigurationData(any(InstanceIdentifier.class))).thenReturn( + prepareCnDataForMountPointTest()); + + MountService mockMountService = mock(MountService.class); + + when(mockMountService.getMountPoint(any(InstanceIdentifier.class))).thenReturn( + new DummyMountInstanceImpl.Builder().setSchemaContext(schemaContextTestModule).build()); + + ControllerContext.getInstance().setMountService(mockMountService); + + String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/0/test-module:cont/cont1"); + Response response = target(uri).request(Draft02.MediaTypes.DATA + XML).get(); + assertEquals(200, response.getStatus()); + } + + private void getDataWithUrl(String mediaTypePrefix, String mediaType, int statusCode) + throws UnsupportedEncodingException { + String uri = null; + switch (statusCode) { + case 400: + uri = createUri(mediaTypePrefix, "wrong-module:interfaces/interface/eth0"); + break; + case 200: + uri = createUri(mediaTypePrefix, "ietf-interfaces:interfaces/interface/eth0"); + break; + } + Response response = target(uri).request(mediaType).get(); + assertEquals("Status is incorrect for media type " + mediaType + ".", statusCode, response.getStatus()); + + } + + private void getModulesDataTest(String mediaType) throws UnsupportedEncodingException { + String uri = createUri("/modules", ""); + Response response = target(uri).request(mediaType).get(); + + assertEquals("Status is incorrect for media type " + mediaType + ".", 500, response.getStatus()); + } + + private void getDatastoreAllDataTest(String mediaType) throws UnsupportedEncodingException { + String uri = createUri("/datastore", ""); + Response response = target(uri).request(mediaType).get(); + + assertEquals(500, response.getStatus()); + } + + private CompositeNode prepareCnDataForMountPointTest() throws URISyntaxException { + CompositeNodeWrapper cont1 = new CompositeNodeWrapper(new URI("test:module"), "cont1"); + SimpleNodeWrapper lf11 = new SimpleNodeWrapper(new URI("test:module"), "lf11", "lf11 value"); + cont1.addValue(lf11); + return cont1.unwrap(); + } + + private CompositeNode prepareCompositeNodeWithIetfInterfacesInterfacesData() { + CompositeNode intface; + try { + intface = new CompositeNodeWrapper(new URI("interface"), "interface"); + List> childs = new ArrayList<>(); + + childs.add(new SimpleNodeWrapper(new URI("name"), "name", "eth0")); + childs.add(new SimpleNodeWrapper(new URI("type"), "type", "ethernetCsmacd")); + childs.add(new SimpleNodeWrapper(new URI("enabled"), "enabled", Boolean.FALSE)); + childs.add(new SimpleNodeWrapper(new URI("description"), "description", "some interface")); + intface.setValue(childs); + return intface; + } catch (URISyntaxException e) { + } + + return null; + } + + private void mockReadOperationalDataMethod() { + CompositeNode loadedCompositeNode = prepareCompositeNodeWithIetfInterfacesInterfacesData(); + when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(loadedCompositeNode); + } + + private void mockReadConfigurationDataMethod() { + CompositeNode loadedCompositeNode = prepareCompositeNodeWithIetfInterfacesInterfacesData(); + when(brokerFacade.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(loadedCompositeNode); + } +} diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestOperationUtils.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestOperationUtils.java new file mode 100644 index 0000000000..1f0daace70 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestOperationUtils.java @@ -0,0 +1,31 @@ +package org.opendaylight.controller.sal.restconf.impl.test; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLEncoder; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; + +import com.google.common.base.Charsets; + +public class RestOperationUtils { + + static final String JSON = "+json"; + static final String XML = "+xml"; + + private RestOperationUtils() { + } + + static Entity entity(String data, MediaType mediaType) { + return Entity.entity(data, mediaType); + } + + static Entity entity(String data, String mediaType) { + return Entity.entity(data, mediaType); + } + + static String createUri(String prefix, String encodedPart) throws UnsupportedEncodingException { + return URI.create(prefix + URLEncoder.encode(encodedPart, Charsets.US_ASCII.name()).toString()).toASCIIString(); + } +} diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java new file mode 100644 index 0000000000..9bf6a0f03c --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java @@ -0,0 +1,384 @@ +package org.opendaylight.controller.sal.restconf.impl.test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.JSON; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.XML; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.createUri; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.entity; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.concurrent.Future; +import java.util.logging.Level; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.glassfish.jersey.test.TestProperties; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.controller.md.sal.common.api.TransactionStatus; +import org.opendaylight.controller.sal.core.api.mount.MountService; +import org.opendaylight.controller.sal.rest.api.Draft01; +import org.opendaylight.controller.sal.rest.api.Draft02; +import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider; +import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider; +import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider; +import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; +import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; +import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper; +import org.opendaylight.controller.sal.restconf.impl.ControllerContext; +import org.opendaylight.controller.sal.restconf.impl.RestconfImpl; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; + +public class RestPostOperationTest extends JerseyTest { + + private static String xmlData; + private static String xmlDataAbsolutePath; + private static String jsonData; + private static String jsonDataAbsolutePath; + private static String xmlDataRpcInput; + private static CompositeNodeWrapper cnSnDataOutput; + private static String jsonDataRpcInput; + private static String xmlData2; + + private static ControllerContext controllerContext; + private static BrokerFacade brokerFacade; + private static RestconfImpl restconfImpl; + private static SchemaContext schemaContextYangsIetf; + private static SchemaContext schemaContextTestModule; + + @BeforeClass + public static void init() throws URISyntaxException, IOException { + schemaContextYangsIetf = TestUtils.loadSchemaContext("/full-versions/yangs"); + schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module"); + controllerContext = ControllerContext.getInstance(); + brokerFacade = mock(BrokerFacade.class); + restconfImpl = RestconfImpl.getInstance(); + restconfImpl.setBroker(brokerFacade); + restconfImpl.setControllerContext(controllerContext); + loadData(); + } + + @Before + public void logs() throws IOException, URISyntaxException { + /* enable/disable Jersey logs to console */ + /* + * List loggedRecords = getLoggedRecords(); for (LogRecord l + * : loggedRecords) { System.out.println(l.getMessage()); } + */ + } + + @Override + protected Application configure() { + /* enable/disable Jersey logs to console */ + + /* + * enable(TestProperties.LOG_TRAFFIC); + */ + enable(TestProperties.DUMP_ENTITY); + enable(TestProperties.RECORD_LOG_LEVEL); + set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue()); + + ResourceConfig resourceConfig = new ResourceConfig(); + resourceConfig = resourceConfig.registerInstances(restconfImpl, StructuredDataToXmlProvider.INSTANCE, + StructuredDataToJsonProvider.INSTANCE, XmlToCompositeNodeProvider.INSTANCE, + JsonToCompositeNodeProvider.INSTANCE); + return resourceConfig; + } + + @Test + public void postOperationsDataViaUrl200() throws URISyntaxException, IOException { + controllerContext.setSchemas(schemaContextTestModule); + postOperationsDataViaUrl(Draft02.MediaTypes.DATA + JSON, cnSnDataOutput, jsonDataRpcInput, 200); + postOperationsDataViaUrl(Draft01.MediaTypes.DATA + JSON, cnSnDataOutput, jsonDataRpcInput, 200); + postOperationsDataViaUrl(MediaType.APPLICATION_JSON, cnSnDataOutput, jsonDataRpcInput, 200); + + postOperationsDataViaUrl(Draft01.MediaTypes.DATA + XML, cnSnDataOutput, xmlDataRpcInput, 200); + postOperationsDataViaUrl(Draft02.MediaTypes.DATA + XML, cnSnDataOutput, xmlDataRpcInput, 200); + postOperationsDataViaUrl(MediaType.APPLICATION_XML, cnSnDataOutput, xmlDataRpcInput, 200); + postOperationsDataViaUrl(MediaType.TEXT_XML, cnSnDataOutput, xmlDataRpcInput, 200); + } + + @Test + public void postOperationsDataViaUrl204() throws URISyntaxException, IOException { + controllerContext.setSchemas(schemaContextTestModule); + postOperationsDataViaUrl(Draft02.MediaTypes.DATA + JSON, cnSnDataOutput, jsonDataRpcInput, 204); + postOperationsDataViaUrl(Draft01.MediaTypes.DATA + JSON, cnSnDataOutput, jsonDataRpcInput, 204); + postOperationsDataViaUrl(MediaType.APPLICATION_JSON, cnSnDataOutput, jsonDataRpcInput, 204); + + postOperationsDataViaUrl(Draft01.MediaTypes.DATA + XML, cnSnDataOutput, xmlDataRpcInput, 204); + postOperationsDataViaUrl(Draft02.MediaTypes.DATA + XML, cnSnDataOutput, xmlDataRpcInput, 204); + postOperationsDataViaUrl(MediaType.APPLICATION_XML, cnSnDataOutput, xmlDataRpcInput, 204); + postOperationsDataViaUrl(MediaType.TEXT_XML, cnSnDataOutput, xmlDataRpcInput, 204); + } + + @Test + public void postOperationsDataViaUrl500() throws URISyntaxException, IOException { + controllerContext.setSchemas(schemaContextTestModule); + postOperationsDataViaUrl(Draft02.MediaTypes.DATA + JSON, cnSnDataOutput, jsonDataRpcInput, 500); + postOperationsDataViaUrl(Draft01.MediaTypes.DATA + JSON, cnSnDataOutput, jsonDataRpcInput, 500); + postOperationsDataViaUrl(MediaType.APPLICATION_JSON, cnSnDataOutput, jsonDataRpcInput, 500); + + postOperationsDataViaUrl(Draft01.MediaTypes.DATA + XML, cnSnDataOutput, xmlDataRpcInput, 500); + postOperationsDataViaUrl(Draft02.MediaTypes.DATA + XML, cnSnDataOutput, xmlDataRpcInput, 500); + postOperationsDataViaUrl(MediaType.APPLICATION_XML, cnSnDataOutput, xmlDataRpcInput, 500); + postOperationsDataViaUrl(MediaType.TEXT_XML, cnSnDataOutput, xmlDataRpcInput, 500); + } + + @Test + public void postOperationsDataViaUrl400() throws URISyntaxException, IOException { + controllerContext.setSchemas(schemaContextTestModule); + postOperationsDataViaUrl(Draft02.MediaTypes.DATA + JSON, cnSnDataOutput, jsonDataRpcInput, 400); + postOperationsDataViaUrl(Draft01.MediaTypes.DATA + JSON, cnSnDataOutput, jsonDataRpcInput, 400); + postOperationsDataViaUrl(MediaType.APPLICATION_JSON, cnSnDataOutput, jsonDataRpcInput, 400); + + postOperationsDataViaUrl(Draft01.MediaTypes.DATA + XML, cnSnDataOutput, xmlDataRpcInput, 400); + postOperationsDataViaUrl(Draft02.MediaTypes.DATA + XML, cnSnDataOutput, xmlDataRpcInput, 400); + postOperationsDataViaUrl(MediaType.APPLICATION_XML, cnSnDataOutput, xmlDataRpcInput, 400); + postOperationsDataViaUrl(MediaType.TEXT_XML, cnSnDataOutput, xmlDataRpcInput, 400); + } + + @Test + public void postOperationsDataViaUrl404() throws URISyntaxException, IOException { + controllerContext.setSchemas(schemaContextTestModule); + postOperationsDataViaUrl(Draft02.MediaTypes.DATA + JSON, cnSnDataOutput, jsonDataRpcInput, 404); + postOperationsDataViaUrl(Draft01.MediaTypes.DATA + JSON, cnSnDataOutput, jsonDataRpcInput, 404); + postOperationsDataViaUrl(MediaType.APPLICATION_JSON, cnSnDataOutput, jsonDataRpcInput, 404); + + postOperationsDataViaUrl(Draft01.MediaTypes.DATA + XML, cnSnDataOutput, xmlDataRpcInput, 404); + postOperationsDataViaUrl(Draft02.MediaTypes.DATA + XML, cnSnDataOutput, xmlDataRpcInput, 404); + postOperationsDataViaUrl(MediaType.APPLICATION_XML, cnSnDataOutput, xmlDataRpcInput, 404); + postOperationsDataViaUrl(MediaType.TEXT_XML, cnSnDataOutput, xmlDataRpcInput, 404); + } + + @Test + public void postConfigDataViaUrlConfigOnlyTest204() throws UnsupportedEncodingException, FileNotFoundException { + controllerContext.setSchemas(schemaContextYangsIetf); + mockCommitConfigurationDataPostMethod(TransactionStatus.COMMITED); + postDataViaUrlTest("/config", "", Draft02.MediaTypes.DATA + JSON, jsonDataAbsolutePath, 204); + postDataViaUrlTest("/config", "", Draft02.MediaTypes.DATA + XML, xmlDataAbsolutePath, 204); + postDataViaUrlTest("/config", "", MediaType.APPLICATION_JSON, jsonDataAbsolutePath, 204); + postDataViaUrlTest("/config", "", MediaType.APPLICATION_XML, xmlDataAbsolutePath, 204); + postDataViaUrlTest("/config", "", MediaType.TEXT_XML, xmlDataAbsolutePath, 204); + } + + @Test + public void postConfigDataViaUrlConfigOnlyTest202() throws UnsupportedEncodingException, FileNotFoundException { + controllerContext.setSchemas(schemaContextYangsIetf); + mockCommitConfigurationDataPostMethod(null); + postDataViaUrlTest("/config", "", Draft02.MediaTypes.DATA + JSON, jsonDataAbsolutePath, 202); + postDataViaUrlTest("/config", "", Draft02.MediaTypes.DATA + XML, xmlDataAbsolutePath, 202); + postDataViaUrlTest("/config", "", MediaType.APPLICATION_JSON, jsonDataAbsolutePath, 202); + postDataViaUrlTest("/config", "", MediaType.APPLICATION_XML, xmlDataAbsolutePath, 202); + postDataViaUrlTest("/config", "", MediaType.TEXT_XML, xmlDataAbsolutePath, 202); + } + + @Test + public void postConfigDataViaUrlConfigOnlyTest500() throws UnsupportedEncodingException, FileNotFoundException { + controllerContext.setSchemas(schemaContextYangsIetf); + mockCommitConfigurationDataPostMethod(TransactionStatus.FAILED); + postDataViaUrlTest("/config", "", Draft02.MediaTypes.DATA + JSON, jsonDataAbsolutePath, 500); + postDataViaUrlTest("/config", "", Draft02.MediaTypes.DATA + XML, xmlDataAbsolutePath, 500); + postDataViaUrlTest("/config", "", MediaType.APPLICATION_JSON, jsonDataAbsolutePath, 500); + postDataViaUrlTest("/config", "", MediaType.APPLICATION_XML, xmlDataAbsolutePath, 500); + postDataViaUrlTest("/config", "", MediaType.TEXT_XML, xmlDataAbsolutePath, 500); + } + + @Test + public void postConfigDataViaUrlTest204() throws UnsupportedEncodingException { + controllerContext.setSchemas(schemaContextYangsIetf); + mockCommitConfigurationDataPostMethod(TransactionStatus.COMMITED); + String urlPath = "ietf-interfaces:interfaces"; + postDataViaUrlTest("/config/", urlPath, Draft02.MediaTypes.DATA + JSON, jsonData, 204); + postDataViaUrlTest("/config/", urlPath, Draft02.MediaTypes.DATA + XML, xmlData, 204); + postDataViaUrlTest("/config/", urlPath, MediaType.APPLICATION_JSON, jsonData, 204); + postDataViaUrlTest("/config/", urlPath, MediaType.APPLICATION_XML, xmlData, 204); + postDataViaUrlTest("/config/", urlPath, MediaType.TEXT_XML, xmlData, 204); + } + + @Test + public void postConfigDataViaUrlTest202() throws UnsupportedEncodingException { + controllerContext.setSchemas(schemaContextYangsIetf); + mockCommitConfigurationDataPostMethod(null); + String urlPath = "ietf-interfaces:interfaces"; + postDataViaUrlTest("/config/", urlPath, Draft02.MediaTypes.DATA + JSON, jsonData, 202); + postDataViaUrlTest("/config/", urlPath, Draft02.MediaTypes.DATA + XML, xmlData, 202); + postDataViaUrlTest("/config/", urlPath, MediaType.APPLICATION_JSON, jsonData, 202); + postDataViaUrlTest("/config/", urlPath, MediaType.APPLICATION_XML, xmlData, 202); + postDataViaUrlTest("/config/", urlPath, MediaType.TEXT_XML, xmlData, 202); + } + + @Test + public void postConfigDataViaUrlTest500() throws UnsupportedEncodingException { + controllerContext.setSchemas(schemaContextYangsIetf); + mockCommitConfigurationDataPostMethod(TransactionStatus.FAILED); + String urlPath = "ietf-interfaces:interfaces"; + postDataViaUrlTest("/config/", urlPath, Draft02.MediaTypes.DATA + JSON, jsonData, 500); + postDataViaUrlTest("/config/", urlPath, Draft02.MediaTypes.DATA + XML, xmlData, 500); + postDataViaUrlTest("/config/", urlPath, MediaType.APPLICATION_JSON, jsonData, 500); + postDataViaUrlTest("/config/", urlPath, MediaType.APPLICATION_XML, xmlData, 500); + postDataViaUrlTest("/config/", urlPath, MediaType.TEXT_XML, xmlData, 500); + } + + @Test + public void postDatastoreDataViaUrlTest204() throws UnsupportedEncodingException { + controllerContext.setSchemas(schemaContextYangsIetf); + mockCommitConfigurationDataPostMethod(TransactionStatus.COMMITED); + String urlPath = "ietf-interfaces:interfaces"; + postDataViaUrlTest("/datastore/", urlPath, Draft01.MediaTypes.DATA + JSON, jsonData, 204); + postDataViaUrlTest("/datastore/", urlPath, Draft01.MediaTypes.DATA + XML, xmlData, 204); + postDataViaUrlTest("/datastore/", urlPath, MediaType.APPLICATION_JSON, jsonData, 204); + postDataViaUrlTest("/datastore/", urlPath, MediaType.APPLICATION_XML, xmlData, 204); + postDataViaUrlTest("/datastore/", urlPath, MediaType.TEXT_XML, xmlData, 204); + } + + @Test + public void postDatastoreDataViaUrlTest202() throws UnsupportedEncodingException { + controllerContext.setSchemas(schemaContextYangsIetf); + mockCommitConfigurationDataPostMethod(null); + String urlPath = "ietf-interfaces:interfaces"; + postDataViaUrlTest("/datastore/", urlPath, Draft01.MediaTypes.DATA + JSON, jsonData, 202); + postDataViaUrlTest("/datastore/", urlPath, Draft01.MediaTypes.DATA + XML, xmlData, 202); + postDataViaUrlTest("/datastore/", urlPath, MediaType.APPLICATION_JSON, jsonData, 202); + postDataViaUrlTest("/datastore/", urlPath, MediaType.APPLICATION_XML, xmlData, 202); + postDataViaUrlTest("/datastore/", urlPath, MediaType.TEXT_XML, xmlData, 202); + } + + @Test + public void postDatastoreDataViaUrlTest500() throws UnsupportedEncodingException { + controllerContext.setSchemas(schemaContextYangsIetf); + mockCommitConfigurationDataPostMethod(TransactionStatus.FAILED); + String urlPath = "ietf-interfaces:interfaces"; + postDataViaUrlTest("/datastore/", urlPath, Draft01.MediaTypes.DATA + JSON, jsonData, 500); + postDataViaUrlTest("/datastore/", urlPath, Draft01.MediaTypes.DATA + XML, xmlData, 500); + postDataViaUrlTest("/datastore/", urlPath, MediaType.APPLICATION_JSON, jsonData, 500); + postDataViaUrlTest("/datastore/", urlPath, MediaType.APPLICATION_XML, xmlData, 500); + postDataViaUrlTest("/datastore/", urlPath, MediaType.TEXT_XML, xmlData, 500); + } + + @Test + public void postDataViaUrlMountPoint() throws UnsupportedEncodingException { + controllerContext.setSchemas(schemaContextYangsIetf); + mockCommitConfigurationDataPostMethod(TransactionStatus.COMMITED); + + MountService mockMountService = mock(MountService.class); + SchemaContext otherSchemaContext = schemaContextTestModule; + when(mockMountService.getMountPoint(any(InstanceIdentifier.class))).thenReturn( + new DummyMountInstanceImpl.Builder().setSchemaContext(otherSchemaContext).build()); + + ControllerContext.getInstance().setMountService(mockMountService); + + String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/0/test-module:cont/cont1"); + Response response = target(uri).request(Draft02.MediaTypes.DATA + XML).post( + entity(xmlData2, Draft02.MediaTypes.DATA + XML)); + // 204 code is returned when COMMITED transaction status is put as input + // to mock method + assertEquals(204, response.getStatus()); + } + + private void postDataViaUrlTest(String urlPrefix, String urlPath, String mediaType, String data, int responseStatus) + throws UnsupportedEncodingException { + String url = createUri(urlPrefix, urlPath); + Response response = target(url).request(mediaType).post(entity(data, mediaType)); + assertEquals(responseStatus, response.getStatus()); + } + + private void mockCommitConfigurationDataPostMethod(TransactionStatus statusName) { + RpcResult rpcResult = new DummyRpcResult.Builder().result(statusName) + .build(); + Future> dummyFuture = null; + if (statusName != null) { + dummyFuture = DummyFuture.builder().rpcResult(rpcResult).build(); + } else { + dummyFuture = DummyFuture.builder().build(); + } + + when(brokerFacade.commitConfigurationDataPost(any(InstanceIdentifier.class), any(CompositeNode.class))) + .thenReturn(dummyFuture); + } + + private static CompositeNodeWrapper prepareCnSnRpcOutput() throws URISyntaxException { + CompositeNodeWrapper cnSnDataOutput = new CompositeNodeWrapper(new URI("test:module"), "output"); + CompositeNodeWrapper cont = new CompositeNodeWrapper(new URI("test:module"), "cont-output"); + cnSnDataOutput.addValue(cont); + cnSnDataOutput.unwrap(); + return cnSnDataOutput; + } + + private void mockInvokeRpc(CompositeNode compositeNode, boolean sucessful) { + RpcResult rpcResult = new DummyRpcResult.Builder().result(compositeNode) + .isSuccessful(sucessful).build(); + when(brokerFacade.invokeRpc(any(QName.class), any(CompositeNode.class))).thenReturn(rpcResult); + } + + private void postOperationsDataViaUrl(String mediaType, CompositeNode cnSnDataOut, String dataIn, int statusCode) + throws FileNotFoundException, UnsupportedEncodingException { + String url = createUri("/operations/", "test-module:rpc-test"); + Response response = null; + switch (statusCode) { + case 200: + mockInvokeRpc(cnSnDataOut, true); + break; + case 204: + mockInvokeRpc(null, true); + break; + case 500: + mockInvokeRpc(null, false); + break; + case 400: + response = target(url).request(mediaType).post(Entity.entity("{}", mediaType)); + break; + case 404: + url = createUri("/operations/", "test-module:rpc-wrongtest"); + break; + } + response = response == null ? target(url).request(mediaType).post(Entity.entity(dataIn, mediaType)) : response; + assertEquals(statusCode, response.getStatus()); + } + + private static void loadData() throws IOException, URISyntaxException { + + InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml"); + xmlData = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream)); + + xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces_absolute_path.xml"); + xmlDataAbsolutePath = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream)); + + String jsonPath = RestconfImplTest.class.getResource("/parts/ietf-interfaces_interfaces.json").getPath(); + jsonData = TestUtils.loadTextFile(jsonPath); + + String jsonFullPath = RestconfImplTest.class + .getResource("/parts/ietf-interfaces_interfaces_absolute_path.json").getPath(); + jsonDataAbsolutePath = TestUtils.loadTextFile(jsonFullPath); + + String xmlPathRpcInput = RestconfImplTest.class.getResource("/full-versions/test-data2/data-rpc-input.xml") + .getPath(); + xmlDataRpcInput = TestUtils.loadTextFile(xmlPathRpcInput); + cnSnDataOutput = prepareCnSnRpcOutput(); + + String jsonPathToRpcInput = RestconfImplTest.class.getResource("/full-versions/test-data2/data-rpc-input.json") + .getPath(); + jsonDataRpcInput = TestUtils.loadTextFile(jsonPathToRpcInput); + + String data2Input = RestconfImplTest.class.getResource("/full-versions/test-data2/data2.xml").getPath(); + xmlData2 = TestUtils.loadTextFile(data2Input); + + } +} diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java new file mode 100644 index 0000000000..2bef9ba4ef --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java @@ -0,0 +1,210 @@ +package org.opendaylight.controller.sal.restconf.impl.test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.JSON; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.XML; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.createUri; +import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.entity; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.util.concurrent.Future; +import java.util.logging.Level; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.glassfish.jersey.test.TestProperties; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.controller.md.sal.common.api.TransactionStatus; +import org.opendaylight.controller.sal.core.api.mount.MountService; +import org.opendaylight.controller.sal.rest.api.Draft01; +import org.opendaylight.controller.sal.rest.api.Draft02; +import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider; +import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider; +import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider; +import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; +import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; +import org.opendaylight.controller.sal.restconf.impl.ControllerContext; +import org.opendaylight.controller.sal.restconf.impl.RestconfImpl; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; + +public class RestPutOperationTest extends JerseyTest { + + private static String xmlData; + private static String jsonData; + + private static BrokerFacade brokerFacade; + private static RestconfImpl restconfImpl; + private static SchemaContext schemaContextYangsIetf; + private static SchemaContext schemaContextTestModule; + + @BeforeClass + public static void init() throws IOException { + schemaContextYangsIetf = TestUtils.loadSchemaContext("/full-versions/yangs"); + schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module"); + ControllerContext controllerContext = ControllerContext.getInstance(); + controllerContext.setSchemas(schemaContextYangsIetf); + brokerFacade = mock(BrokerFacade.class); + restconfImpl = RestconfImpl.getInstance(); + restconfImpl.setBroker(brokerFacade); + restconfImpl.setControllerContext(controllerContext); + loadData(); + } + + @Before + public void logs() throws IOException { + /* enable/disable Jersey logs to console */ + /* + * List loggedRecords = getLoggedRecords(); for (LogRecord l + * : loggedRecords) { System.out.println(l.getMessage()); } + */ + } + + @Override + protected Application configure() { + /* enable/disable Jersey logs to console */ + /* + * enable(TestProperties.LOG_TRAFFIC); + */ + enable(TestProperties.DUMP_ENTITY); + enable(TestProperties.RECORD_LOG_LEVEL); + set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue()); + + ResourceConfig resourceConfig = new ResourceConfig(); + resourceConfig = resourceConfig.registerInstances(restconfImpl, StructuredDataToXmlProvider.INSTANCE, + StructuredDataToJsonProvider.INSTANCE, XmlToCompositeNodeProvider.INSTANCE, + JsonToCompositeNodeProvider.INSTANCE); + return resourceConfig; + } + + /** + * Test method + * {@link RestconfImpl#updateConfigurationData(String, CompositeNode)} of + * RestconfImpl for "/config/...identifier..." URL. Return status code is + * 200. + * + */ + @Test + public void putConfigDataViaUrlTest200() throws UnsupportedEncodingException { + mockCommitConfigurationDataPutMethod(TransactionStatus.COMMITED); + putDataViaUrlTest("/config/", Draft02.MediaTypes.DATA + JSON, jsonData, 200); + putDataViaUrlTest("/config/", Draft02.MediaTypes.DATA + XML, xmlData, 200); + putDataViaUrlTest("/config/", MediaType.APPLICATION_JSON, jsonData, 200); + putDataViaUrlTest("/config/", MediaType.APPLICATION_XML, xmlData, 200); + putDataViaUrlTest("/config/", MediaType.TEXT_XML, xmlData, 200); + + } + + /** + * Test method + * {@link RestconfImpl#updateConfigurationData(String, CompositeNode)} of + * RestconfImpl for "/config/...identifier..." URL. Return status code is + * 500. + * + */ + @Test + public void putConfigDataViaUrlTest500() throws UnsupportedEncodingException { + mockCommitConfigurationDataPutMethod(TransactionStatus.FAILED); + putDataViaUrlTest("/config/", Draft02.MediaTypes.DATA + JSON, jsonData, 500); + putDataViaUrlTest("/config/", Draft02.MediaTypes.DATA + XML, xmlData, 500); + putDataViaUrlTest("/config/", MediaType.APPLICATION_JSON, jsonData, 500); + putDataViaUrlTest("/config/", MediaType.APPLICATION_XML, xmlData, 500); + putDataViaUrlTest("/config/", MediaType.TEXT_XML, xmlData, 500); + + } + + /** + * Test method + * {@link RestconfImpl#updateConfigurationData(String, CompositeNode)} of + * RestconfImpl for "/datastore/...identifier..." URL. Return status code is + * 200. + * + */ + @Test + public void putDatastoreDataViaUrlTest200() throws UnsupportedEncodingException { + mockCommitConfigurationDataPutMethod(TransactionStatus.COMMITED); + putDataViaUrlTest("/datastore/", Draft01.MediaTypes.DATA + JSON, jsonData, 200); + putDataViaUrlTest("/datastore/", Draft01.MediaTypes.DATA + XML, xmlData, 200); + putDataViaUrlTest("/datastore/", MediaType.APPLICATION_JSON, jsonData, 200); + putDataViaUrlTest("/datastore/", MediaType.APPLICATION_XML, xmlData, 200); + putDataViaUrlTest("/datastore/", MediaType.TEXT_XML, xmlData, 200); + } + + /** + * Test method + * {@link RestconfImpl#updateConfigurationData(String, CompositeNode)} of + * RestconfImpl for "/datastore/...identifier..." URL. Return status code is + * 500. + * + */ + @Test + public void putDatastoreDataViaUrlTest500() throws UnsupportedEncodingException { + mockCommitConfigurationDataPutMethod(TransactionStatus.FAILED); + putDataViaUrlTest("/datastore/", Draft01.MediaTypes.DATA + JSON, jsonData, 500); + putDataViaUrlTest("/datastore/", Draft01.MediaTypes.DATA + XML, xmlData, 500); + putDataViaUrlTest("/datastore/", MediaType.APPLICATION_JSON, jsonData, 500); + putDataViaUrlTest("/datastore/", MediaType.APPLICATION_XML, xmlData, 500); + putDataViaUrlTest("/datastore/", MediaType.TEXT_XML, xmlData, 500); + } + + @Test + public void testRpcResultCommitedToStatusCodesWithMountPoint() throws UnsupportedEncodingException, + FileNotFoundException, URISyntaxException { + + mockCommitConfigurationDataPutMethod(TransactionStatus.COMMITED); + + InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/full-versions/test-data2/data2.xml"); + String xml = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream)); + Entity entity = Entity.entity(xml, Draft02.MediaTypes.DATA + XML); + + MountService mockMountService = mock(MountService.class); + when(mockMountService.getMountPoint(any(InstanceIdentifier.class))).thenReturn( + new DummyMountInstanceImpl.Builder().setSchemaContext(schemaContextTestModule).build()); + + ControllerContext.getInstance().setMountService(mockMountService); + + String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/0/test-module:cont"); + Response response = target(uri).request(Draft02.MediaTypes.DATA + XML).put(entity); + assertEquals(200, response.getStatus()); + } + + private void putDataViaUrlTest(String uriPrefix, String mediaType, String data, int responseStatus) + throws UnsupportedEncodingException { + String uri = createUri(uriPrefix, "ietf-interfaces:interfaces/interface/eth0"); + Response response = target(uri).request(mediaType).put(entity(data, mediaType)); + assertEquals(responseStatus, response.getStatus()); + } + + private static void loadData() throws IOException { + InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml"); + xmlData = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream)); + + String jsonPath = RestconfImplTest.class.getResource("/parts/ietf-interfaces_interfaces.json").getPath(); + jsonData = TestUtils.loadTextFile(jsonPath); + } + + private void mockCommitConfigurationDataPutMethod(TransactionStatus statusName) { + RpcResult rpcResult = new DummyRpcResult.Builder().result(statusName) + .build(); + Future> dummyFuture = DummyFuture.builder().rpcResult(rpcResult).build(); + when(brokerFacade.commitConfigurationDataPut(any(InstanceIdentifier.class), any(CompositeNode.class))) + .thenReturn(dummyFuture); + } + +} diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java index 3427fbde38..5ef66c3b25 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java @@ -6,9 +6,11 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; @@ -276,4 +278,18 @@ public final class TestUtils { return byteArrayOS.toString(); } + + public static String loadTextFile(String filePath) throws IOException { + FileReader fileReader = new FileReader(filePath); + BufferedReader bufReader = new BufferedReader(fileReader); + + String line = null; + StringBuilder result = new StringBuilder(); + while ((line = bufReader.readLine()) != null) { + result.append(line); + } + bufReader.close(); + return result.toString(); + + } } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlProvidersTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlProvidersTest.java deleted file mode 100644 index 7cce34ffb6..0000000000 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlProvidersTest.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.opendaylight.controller.sal.restconf.impl.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Future; -import java.util.logging.Level; -import java.util.logging.LogRecord; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.Application; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.test.JerseyTest; -import org.glassfish.jersey.test.TestProperties; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.controller.md.sal.common.api.TransactionStatus; -import org.opendaylight.controller.sal.rest.api.Draft01; -import org.opendaylight.controller.sal.rest.api.RestconfService; -import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider; -import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; -import org.opendaylight.controller.sal.restconf.impl.BrokerFacade; -import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper; -import org.opendaylight.controller.sal.restconf.impl.ControllerContext; -import org.opendaylight.controller.sal.restconf.impl.RestconfImpl; -import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -import com.google.common.base.Charsets; - -public class XmlProvidersTest extends JerseyTest { - - private static ControllerContext controllerContext; - private static BrokerFacade brokerFacade; - private static RestconfImpl restconfImpl; - private static final MediaType MEDIA_TYPE = new MediaType("application", "vnd.yang.data+xml"); - private static final MediaType MEDIA_TYPE_DRAFT02 = new MediaType("application", "yang.data+xml"); - - @BeforeClass - public static void init() throws FileNotFoundException { - Set allModules = TestUtils.loadModulesFrom("/full-versions/yangs"); - assertNotNull(allModules); - SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules); - controllerContext = ControllerContext.getInstance(); - controllerContext.setSchemas(schemaContext); - brokerFacade = mock(BrokerFacade.class); - restconfImpl = RestconfImpl.getInstance(); - restconfImpl.setBroker(brokerFacade); - restconfImpl.setControllerContext(controllerContext); - } - - @Before - public void logs() { - List loggedRecords = getLoggedRecords(); - for (LogRecord l : loggedRecords) { - System.out.println(l.getMessage()); - } - } - - @Test - public void testStructuredDataToXmlProvider() throws FileNotFoundException, UnsupportedEncodingException { - String uri = createUri("/datastore/", "ietf-interfaces:interfaces/interface/eth0"); - - CompositeNode loadedCompositeNode = prepareCompositeNodeWithIetfInterfacesInterfacesData(); - when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(loadedCompositeNode); - - Response response = target(uri).request(MEDIA_TYPE).get(); - assertEquals(200, response.getStatus()); - } - - private CompositeNode prepareCompositeNodeWithIetfInterfacesInterfacesData() { - CompositeNode intface; - try { - intface = new CompositeNodeWrapper(new URI("interface"), "interface"); - List> childs = new ArrayList<>(); - - childs.add(new SimpleNodeWrapper(new URI("name"), "name", "eth0")); - childs.add(new SimpleNodeWrapper(new URI("type"), "type", "ethernetCsmacd")); - childs.add(new SimpleNodeWrapper(new URI("enabled"), "enabled", Boolean.FALSE)); - childs.add(new SimpleNodeWrapper(new URI("description"), "description", "some interface")); - intface.setValue(childs); - return intface; - } catch (URISyntaxException e) { - } - - return null; - } - - @Test - public void testBadFormatXmlToCompositeNodeProvider() throws UnsupportedEncodingException, URISyntaxException { - String uri = createUri("/operations/", "ietf-interfaces:interfaces/interface/eth0"); - - Response response = target(uri).request(Draft01.MediaTypes.DATA + RestconfService.XML).post( - Entity.entity("", MEDIA_TYPE)); - assertEquals(400, response.getStatus()); - - response = target(uri).request(Draft01.MediaTypes.DATA + RestconfService.XML).post( - Entity.entity("", MEDIA_TYPE)); - assertEquals(400, response.getStatus()); - } - - @Test - public void testXmlToCompositeNode404NotFound() throws UnsupportedEncodingException, URISyntaxException { - String uri = createUri("/datastore/", "ietf-interfaces:interfaces/interface/eth0"); - - when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(null); - - Response response = target(uri).request(Draft01.MediaTypes.DATA + RestconfService.XML).get(); - assertEquals(404, response.getStatus()); - } - - @Test - public void testXmlToCompositeNode400() throws UnsupportedEncodingException, URISyntaxException { - String uri = createUri("/datastore/", "simple-nodes:user/name"); - - when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(null); - - Response response = target(uri).request(Draft01.MediaTypes.DATA + RestconfService.XML).get(); - assertEquals(400, response.getStatus()); - } - - @Test - public void testRpcResultCommitedToStatusCodes() throws UnsupportedEncodingException { - InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml"); - String xml = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream)); - Entity entity = Entity.entity(xml, MEDIA_TYPE_DRAFT02); - RpcResult rpcResult = new DummyRpcResult.Builder().result( - TransactionStatus.COMMITED).build(); - Future> dummyFuture = DummyFuture.builder().rpcResult(rpcResult).build(); - when(brokerFacade.commitConfigurationDataPut(any(InstanceIdentifier.class), any(CompositeNode.class))) - .thenReturn(dummyFuture); - when(brokerFacade.commitConfigurationDataPost(any(InstanceIdentifier.class), any(CompositeNode.class))) - .thenReturn(dummyFuture); - - String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/eth0"); - Response response = target(uri).request(MEDIA_TYPE_DRAFT02).put(entity); - assertEquals(200, response.getStatus()); - - uri = createUri("/config/", "ietf-interfaces:interfaces"); - response = target(uri).request(MEDIA_TYPE_DRAFT02).post(entity); - assertEquals(204, response.getStatus()); - - uri = createUri("/config/", "ietf-interfaces:interfaces/interface/eth0"); - response = target(uri).request(MEDIA_TYPE_DRAFT02).put(entity); - assertEquals(200, response.getStatus()); - - uri = createUri("/config/", "ietf-interfaces:interfaces"); - response = target(uri).request(MEDIA_TYPE_DRAFT02).post(entity); - assertEquals(204, response.getStatus()); - - uri = createUri("/datastore/", "ietf-interfaces:interfaces/interface/eth0"); - entity = Entity.entity(xml, MEDIA_TYPE); - response = target(uri).request(MEDIA_TYPE).put(entity); - assertEquals(200, response.getStatus()); - - uri = createUri("/datastore/", "ietf-interfaces:interfaces"); - entity = Entity.entity(xml, MEDIA_TYPE); - response = target(uri).request(MEDIA_TYPE).post(entity); - assertEquals(204, response.getStatus()); - } - - @Test - public void testRpcResultOtherToStatusCodes() throws UnsupportedEncodingException { - InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml"); - String xml = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream)); - Entity entity = Entity.entity(xml, MEDIA_TYPE_DRAFT02); - RpcResult rpcResult = new DummyRpcResult.Builder().result( - TransactionStatus.FAILED).build(); - Future> dummyFuture = DummyFuture.builder().rpcResult(rpcResult).build(); - when(brokerFacade.commitConfigurationDataPut(any(InstanceIdentifier.class), any(CompositeNode.class))) - .thenReturn(dummyFuture); - - String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/eth0"); - Response response = target(uri).request(MEDIA_TYPE_DRAFT02).put(entity); - assertEquals(500, response.getStatus()); - response = target(uri).request(MEDIA_TYPE_DRAFT02).post(entity); - assertEquals(500, response.getStatus()); - - uri = createUri("/config/", "ietf-interfaces:interfaces/interface/eth0"); - response = target(uri).request(MEDIA_TYPE_DRAFT02).put(entity); - assertEquals(500, response.getStatus()); - response = target(uri).request(MEDIA_TYPE_DRAFT02).post(entity); - assertEquals(500, response.getStatus()); - - uri = createUri("/datastore/", "ietf-interfaces:interfaces/interface/eth0"); - entity = Entity.entity(xml, MEDIA_TYPE); - response = target(uri).request().put(entity); - assertEquals(500, response.getStatus()); - response = target(uri).request().accept(MEDIA_TYPE).post(entity); - assertEquals(500, response.getStatus()); - } - - private String createUri(String prefix, String encodedPart) throws UnsupportedEncodingException { - return URI.create(prefix + URLEncoder.encode(encodedPart, Charsets.US_ASCII.name()).toString()).toASCIIString(); - } - - @Override - protected Application configure() { - enable(TestProperties.LOG_TRAFFIC); - enable(TestProperties.DUMP_ENTITY); - enable(TestProperties.RECORD_LOG_LEVEL); - set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue()); - - ResourceConfig resourceConfig = new ResourceConfig(); - resourceConfig = resourceConfig.registerInstances(restconfImpl, StructuredDataToXmlProvider.INSTANCE, - XmlToCompositeNodeProvider.INSTANCE); - return resourceConfig; - } - -} diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-data2/data-rpc-input.json b/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-data2/data-rpc-input.json new file mode 100644 index 0000000000..0eae37ac21 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-data2/data-rpc-input.json @@ -0,0 +1,10 @@ +{ + "test-module:input":{ + "cont":{ + "cont1":{ + "lf11":"lf1 data", + "lf12":"lf2 data" + } + } + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-data2/data-rpc-input.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-data2/data-rpc-input.xml new file mode 100644 index 0000000000..5954c091e3 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-data2/data-rpc-input.xml @@ -0,0 +1,8 @@ + + + + lf1 data + lf2 data + + + \ No newline at end of file diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-data2/data2.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-data2/data2.xml new file mode 100644 index 0000000000..8fbc0a99c4 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-data2/data2.xml @@ -0,0 +1,6 @@ + + + lf1 data + lf2 data + + diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-module/test-module b/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-module/test-module new file mode 100644 index 0000000000..ad0716bc11 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-module/test-module @@ -0,0 +1,43 @@ +module test-module { + namespace "test:module"; + prefix tstmod; + + revision 2014-01-09 { + } + + container cont { + container cont1 { + leaf lf11 { + type string; + } + leaf lf12 { + type string; + } + } + } + + + rpc rpc-test { + input { + container cont { + container cont1 { + leaf lf11 { + type string; + } + leaf lf12 { + type string; + } + } + } + } + output { + container cont-output { + } + } + + } + + + + +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/parts/ietf-interfaces_interfaces.json b/opendaylight/md-sal/sal-rest-connector/src/test/resources/parts/ietf-interfaces_interfaces.json new file mode 100644 index 0000000000..0b39dc7241 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/parts/ietf-interfaces_interfaces.json @@ -0,0 +1,10 @@ +{ + "interface":[ + { + "name":"eth0", + "type":"ethernetCsmacd", + "enabled":false, + "description": "some interface" + } + ] +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/parts/ietf-interfaces_interfaces_absolute_path.json b/opendaylight/md-sal/sal-rest-connector/src/test/resources/parts/ietf-interfaces_interfaces_absolute_path.json new file mode 100644 index 0000000000..7de7fac444 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/parts/ietf-interfaces_interfaces_absolute_path.json @@ -0,0 +1,12 @@ +{ + "ietf-interfaces:interfaces":{ + "interface":[ + { + "name":"eth0", + "type":"ethernetCsmacd", + "enabled":false, + "description": "some interface" + } + ] + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/parts/ietf-interfaces_interfaces_absolute_path.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/parts/ietf-interfaces_interfaces_absolute_path.xml new file mode 100644 index 0000000000..7e3aa97987 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/parts/ietf-interfaces_interfaces_absolute_path.xml @@ -0,0 +1,8 @@ + + + eth0 + ethernetCsmacd + false + some interface + + \ No newline at end of file diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java index 446c500896..1bce3143d5 100644 --- a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java +++ b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java @@ -44,7 +44,7 @@ public class NetconfSSHActivator implements BundleActivator{ ServiceTrackerCustomizer customizer = new ServiceTrackerCustomizer(){ @Override public IUserManager addingService(ServiceReference reference) { - logger.info("Service IUserManager added, let there be SSH bridge."); + logger.info("Service {} added, let there be SSH bridge.", reference); iUserManager = context.getService(reference); try { onUserManagerFound(iUserManager); @@ -55,13 +55,13 @@ public class NetconfSSHActivator implements BundleActivator{ } @Override public void modifiedService(ServiceReference reference, IUserManager service) { - logger.info("Replacing modified service IUserManager in netconf SSH."); + logger.info("Replacing modified service {} in netconf SSH.", reference); server.addUserManagerService(service); } @Override public void removedService(ServiceReference reference, IUserManager service) { - logger.info("Removing service IUserManager from netconf SSH. " + - "SSH won't authenticate users until IUserManeger service will be started."); + logger.info("Removing service {} from netconf SSH. " + + "SSH won't authenticate users until IUserManeger service will be started.", reference); removeUserManagerService(); } }; diff --git a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java index d3c262f222..642b3bb197 100644 --- a/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java +++ b/opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronPortsNorthbound.java @@ -30,7 +30,6 @@ import org.codehaus.enunciate.jaxrs.StatusCodes; import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD; import org.opendaylight.controller.networkconfig.neutron.INeutronPortAware; import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD; -import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetAware; import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD; import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces; import org.opendaylight.controller.networkconfig.neutron.NeutronPort; @@ -268,7 +267,7 @@ public class NeutronPortsNorthbound { List bulk = input.getBulk(); Iterator i = bulk.iterator(); HashMap testMap = new HashMap(); - Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null); + Object[] instances = ServiceHelper.getGlobalInstances(INeutronPortAware.class, this, null); while (i.hasNext()) { NeutronPort test = i.next();