From bbdf78b5da678e78c4b07bb7220da430d3a597b0 Mon Sep 17 00:00:00 2001 From: Martin Bobak Date: Wed, 12 Feb 2014 12:54:42 +0100 Subject: [PATCH] - fix of getConfigurationDatastore returning null - basic tests added Change-Id: Id4b3c97fa3c438b1daf822d223066fa4e427a299 Signed-off-by: Martin Bobak --- restconf/pom.xml | 5 + restconf/restconf-client-impl/pom.xml | 6 +- .../restconf/client/RestconfClientImpl.java | 9 +- .../client/RestconfClientImplTest.java | 98 ++++++++++++++----- .../restconf/utils/RestconfUtils.java | 5 +- .../yang/model/api/SchemaServiceListener.java | 3 - 6 files changed, 93 insertions(+), 33 deletions(-) diff --git a/restconf/pom.xml b/restconf/pom.xml index 0d67f1dac9..1cc80e70f4 100644 --- a/restconf/pom.xml +++ b/restconf/pom.xml @@ -79,6 +79,11 @@ yang-data-api ${project.version} + + org.opendaylight.yangtools + yang-data-util + ${project.version} + org.opendaylight.yangtools yang-data-impl diff --git a/restconf/restconf-client-impl/pom.xml b/restconf/restconf-client-impl/pom.xml index 692bbe76cf..a4615fde98 100644 --- a/restconf/restconf-client-impl/pom.xml +++ b/restconf/restconf-client-impl/pom.xml @@ -33,7 +33,7 @@ org.opendaylight.yangtools - yang-data-api + yang-binding org.opendaylight.yangtools @@ -76,6 +76,10 @@ org.opendaylight.yangtools yang-model-util + + + org.opendaylight.yangtools + yang-data-util org.opendaylight.yangtools diff --git a/restconf/restconf-client-impl/src/main/java/org/opendaylight/yangtools/restconf/client/RestconfClientImpl.java b/restconf/restconf-client-impl/src/main/java/org/opendaylight/yangtools/restconf/client/RestconfClientImpl.java index 7730762fba..d1c45a8c95 100644 --- a/restconf/restconf-client-impl/src/main/java/org/opendaylight/yangtools/restconf/client/RestconfClientImpl.java +++ b/restconf/restconf-client-impl/src/main/java/org/opendaylight/yangtools/restconf/client/RestconfClientImpl.java @@ -62,6 +62,7 @@ public class RestconfClientImpl implements RestconfClientContext, SchemaContextL private final BindingIndependentMappingService mappingService; private OperationalDataStoreImpl operationalDatastoreAccessor; + private ConfigurationDataStoreImpl configurationDatastoreAccessor; public RestconfClientImpl(URL url,BindingIndependentMappingService mappingService, SchemaContextHolder schemaContextHolder){ @@ -110,7 +111,7 @@ public class RestconfClientImpl implements RestconfClientContext, SchemaContextL + response.getStatus()); } - return RestconfUtils.rpcServicesFromInputStream(response.getEntityInputStream(),mappingService); + return RestconfUtils.rpcServicesFromInputStream(response.getEntityInputStream(),mappingService,schemaContextHolder.getSchemaContext()); } }); return future; @@ -160,7 +161,9 @@ public class RestconfClientImpl implements RestconfClientContext, SchemaContextL @Override public ConfigurationDatastore getConfigurationDatastore() { - return null;//new ConfigurationDataStoreImplOld(this); + if (configurationDatastoreAccessor == null) + configurationDatastoreAccessor = new ConfigurationDataStoreImpl(this); + return configurationDatastoreAccessor; } @Override @@ -178,7 +181,7 @@ public class RestconfClientImpl implements RestconfClientContext, SchemaContextL @Override public void onGlobalContextUpdated(SchemaContext context) { - //this.schemaContext = context; + } protected Client getRestClient() { diff --git a/restconf/restconf-client-impl/src/test/java/org/opendaylight/yangtools/restconf/client/RestconfClientImplTest.java b/restconf/restconf-client-impl/src/test/java/org/opendaylight/yangtools/restconf/client/RestconfClientImplTest.java index 2e1ae64f4c..ce3c61eaf0 100644 --- a/restconf/restconf-client-impl/src/test/java/org/opendaylight/yangtools/restconf/client/RestconfClientImplTest.java +++ b/restconf/restconf-client-impl/src/test/java/org/opendaylight/yangtools/restconf/client/RestconfClientImplTest.java @@ -7,60 +7,110 @@ */ package org.opendaylight.yangtools.restconf.client; -import static org.junit.Assert.assertNotNull; - +import com.google.common.util.concurrent.ListenableFuture; import java.net.MalformedURLException; -import java.net.URI; +import java.net.URL; +import java.util.Iterator; +import java.util.Set; import java.util.concurrent.ExecutionException; - import javassist.ClassPool; - -import org.junit.Test; +import org.junit.Before; import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext; import org.opendaylight.yangtools.restconf.client.api.UnsupportedProtocolException; +import org.opendaylight.yangtools.restconf.client.api.data.ConfigurationDatastore; import org.opendaylight.yangtools.restconf.client.api.data.OperationalDatastore; +import org.opendaylight.yangtools.restconf.client.api.event.EventStreamInfo; +import org.opendaylight.yangtools.restconf.client.api.event.ListenableEventStreamContext; import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl; +import org.opendaylight.yangtools.yang.binding.RpcService; import org.opendaylight.yangtools.yang.binding.util.BindingReflections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; public class RestconfClientImplTest { private static final Logger logger = LoggerFactory.getLogger(RestconfClientImplTest.class); private static final String restconfUrl = "http://localhost:8080"; + //private static final String restconfUrl = "http://pce-guest35.cisco.com:9080"; public static final String JSON = "+json"; public static final String XML = "+xml"; private RestconfClientContext restconfClientContext; + private RuntimeGeneratedMappingServiceImpl mappingService; - - - @Test - public void testGetRpcServiceContext() throws ExecutionException, InterruptedException, MalformedURLException, UnsupportedProtocolException { - URI uri = URI.create(restconfUrl); - RestconfClientFactory factory = new RestconfClientFactory(); - RuntimeGeneratedMappingServiceImpl mappingService = new RuntimeGeneratedMappingServiceImpl(); + @Before + public void setupRestconfClientContext() throws MalformedURLException, UnsupportedProtocolException { + mappingService = new RuntimeGeneratedMappingServiceImpl(); mappingService.setPool(new ClassPool()); mappingService.init(); - ModuleInfoBackedContext moduleInfo = ModuleInfoBackedContext.create(); + final ModuleInfoBackedContext moduleInfo = ModuleInfoBackedContext.create(); moduleInfo.addModuleInfos(BindingReflections.loadModuleInfos()); - mappingService.onGlobalContextUpdated(moduleInfo.tryToCreateSchemaContext().get()); + this.restconfClientContext = new RestconfClientFactory().getRestconfClientContext(new URL(restconfUrl),mappingService, mappingService); + assertNotNull(this.restconfClientContext); + } - restconfClientContext = factory.getRestconfClientContext(uri.toURL(), mappingService, mappingService); - assertNotNull(restconfClientContext); - - OperationalDatastore datastore = restconfClientContext.getOperationalDatastore(); +// @Test + public void testGetAvailableEventStreams(){ + ListenableFuture> streamsFuture = restconfClientContext.getAvailableEventStreams(); + while (!streamsFuture.isDone()){ + //noop + } + if (streamsFuture.isDone()){ + try { + Set streams = (Set) streamsFuture.get(); + assertNotNull(streams); + } catch (InterruptedException e) { + fail(e.getMessage()); + } catch (ExecutionException e) { + fail(e.getMessage()); + } + } + } +// @Test + public void testGetRpcServices(){ + ListenableFuture>> servicesFuture = restconfClientContext.getRpcServices(); + while (!servicesFuture.isDone()){ + //noop + } + if (servicesFuture.isDone()){ + try { + Set> streams = (Set>) servicesFuture.get(); + assertNotNull(streams); + } catch (InterruptedException e) { + fail(e.getMessage()); + } catch (ExecutionException e) { + fail(e.getMessage()); + } + } + } - // Example use of client -// ListenableFuture> result = datastore.readData(InstanceIdentifier.builder(Nodes.class).toInstance()); -// Optional optionalNodes = result.get(); -// Nodes node = optionalNodes.get(); -// assertNotNull(node); +// @Test + public void getEventStreamContext() throws MalformedURLException, UnsupportedProtocolException, ExecutionException, InterruptedException { + ListenableFuture> evtStreams = restconfClientContext.getAvailableEventStreams(); + while (!evtStreams.isDone()){ + //noop + } + Iterator it = evtStreams.get().iterator(); + ListenableEventStreamContext evtStreamCtx = restconfClientContext.getEventStreamContext(it.next()); + assertNotNull(evtStreamCtx); + } +// @Test + public void testGetOperationalDatastore() throws ExecutionException, InterruptedException, MalformedURLException, UnsupportedProtocolException { + OperationalDatastore datastore = restconfClientContext.getOperationalDatastore(); + assertNotNull(datastore); } +// @Test + public void testGetConfigurationDatastore() throws ExecutionException, InterruptedException, MalformedURLException, UnsupportedProtocolException { + ConfigurationDatastore datastore = restconfClientContext.getConfigurationDatastore(); + assertNotNull(datastore); + } + } diff --git a/restconf/restconf-util/src/main/java/org/opendaylight/yangtools/restconf/utils/RestconfUtils.java b/restconf/restconf-util/src/main/java/org/opendaylight/yangtools/restconf/utils/RestconfUtils.java index aa1542bc40..238228ce82 100644 --- a/restconf/restconf-util/src/main/java/org/opendaylight/yangtools/restconf/utils/RestconfUtils.java +++ b/restconf/restconf-util/src/main/java/org/opendaylight/yangtools/restconf/utils/RestconfUtils.java @@ -227,7 +227,7 @@ public class RestconfUtils { return moduleName; } - public static Set> rpcServicesFromInputStream(InputStream inputStream, BindingIndependentMappingService mappingService){ + public static Set> rpcServicesFromInputStream(InputStream inputStream, BindingIndependentMappingService mappingService,SchemaContext schemaContext){ try { DocumentBuilderFactory documentBuilder = DocumentBuilderFactory.newInstance(); documentBuilder.setNamespaceAware(true); @@ -235,8 +235,9 @@ public class RestconfUtils { Document doc = builder.parse(inputStream); Element rootElement = doc.getDocumentElement(); - List> domNodes = XmlDocumentUtils.toDomNodes(rootElement, Optional.>absent()); + XmlDocumentUtils.fromElement(rootElement).getNodeType(); + List> domNodes = XmlDocumentUtils.toDomNodes(rootElement, Optional.of(schemaContext.getChildNodes())); Set> rpcServices = new HashSet>(); for (Node node:domNodes){ rpcServices.add(mappingService.getRpcServiceClassFor(node.getNodeType().getNamespace().toString(),node.getNodeType().getRevision().toString()).get()); diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaServiceListener.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaServiceListener.java index c629333a97..c9e11facc5 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaServiceListener.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaServiceListener.java @@ -9,8 +9,6 @@ package org.opendaylight.yangtools.yang.model.api; import java.util.EventListener; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - /** * @deprecated Please use {@link SchemaContextListener} instead. */ @@ -18,5 +16,4 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; public interface SchemaServiceListener extends EventListener { // FIXME: move declaration to SchemaContextListener void onGlobalContextUpdated(SchemaContext context); - } -- 2.36.6