- fix of getConfigurationDatastore returning null 04/5304/3
authorMartin Bobak <mbobak@cisco.com>
Wed, 12 Feb 2014 11:54:42 +0000 (12:54 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Fri, 14 Feb 2014 08:35:21 +0000 (09:35 +0100)
- basic tests added

Change-Id: Id4b3c97fa3c438b1daf822d223066fa4e427a299
Signed-off-by: Martin Bobak <mbobak@cisco.com>
restconf/pom.xml
restconf/restconf-client-impl/pom.xml
restconf/restconf-client-impl/src/main/java/org/opendaylight/yangtools/restconf/client/RestconfClientImpl.java
restconf/restconf-client-impl/src/test/java/org/opendaylight/yangtools/restconf/client/RestconfClientImplTest.java
restconf/restconf-util/src/main/java/org/opendaylight/yangtools/restconf/utils/RestconfUtils.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaServiceListener.java

index 0d67f1dac9098666c10d7773b6fe7eebc05a25dc..1cc80e70f4694e0e673b2d08eab40ff5e23df98f 100644 (file)
                 <artifactId>yang-data-api</artifactId>
                 <version>${project.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>yang-data-util</artifactId>
+                <version>${project.version}</version>
+            </dependency>
             <dependency>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-data-impl</artifactId>
index 692bbe76cfa3189a311effd115a45c81f3ea6c22..a4615fde9816f32d0d038dddcf70f530114c69d3 100644 (file)
@@ -33,7 +33,7 @@
       </dependency>
       <dependency>
           <groupId>org.opendaylight.yangtools</groupId>
-          <artifactId>yang-data-api</artifactId>
+          <artifactId>yang-binding</artifactId>
       </dependency>
       <dependency>
           <groupId>org.opendaylight.yangtools</groupId>
       <dependency>
           <groupId>org.opendaylight.yangtools</groupId>
           <artifactId>yang-model-util</artifactId>
+      </dependency>
+      <dependency>
+          <groupId>org.opendaylight.yangtools</groupId>
+          <artifactId>yang-data-util</artifactId>
       </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
index 7730762fbab7eeeb1efcbf78a4cac8186c3fe022..d1c45a8c953311155dc570f9a39212d345663026 100644 (file)
@@ -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() {
index 2e1ae64f4cc7989c98285bf496a8e9e5ddf53054..ce3c61eaf0acd8d8d46494a729492e6edbc40788 100644 (file)
  */
 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<Set<EventStreamInfo>> streamsFuture = restconfClientContext.getAvailableEventStreams();
+        while (!streamsFuture.isDone()){
+            //noop
+        }
+        if (streamsFuture.isDone()){
+            try {
+                Set<EventStreamInfo> streams = (Set<EventStreamInfo>) streamsFuture.get();
+                assertNotNull(streams);
+            } catch (InterruptedException e) {
+                fail(e.getMessage());
+            } catch (ExecutionException e) {
+                fail(e.getMessage());
+            }
+        }
+    }
+//    @Test
+    public void testGetRpcServices(){
+        ListenableFuture<Set<Class<? extends RpcService>>> servicesFuture = restconfClientContext.getRpcServices();
+        while (!servicesFuture.isDone()){
+            //noop
+        }
+        if (servicesFuture.isDone()){
+            try {
+                Set<Class<? extends RpcService>> streams = (Set<Class<? extends RpcService>>) servicesFuture.get();
+                assertNotNull(streams);
+            } catch (InterruptedException e) {
+                fail(e.getMessage());
+            } catch (ExecutionException e) {
+                fail(e.getMessage());
+            }
+        }
+    }
 
-          // Example use of client
-//        ListenableFuture<Optional<Nodes>> result = datastore.readData(InstanceIdentifier.builder(Nodes.class).toInstance());
-//        Optional<Nodes> optionalNodes = result.get();
-//        Nodes node = optionalNodes.get();
-//        assertNotNull(node);
+//    @Test
+    public void getEventStreamContext() throws MalformedURLException, UnsupportedProtocolException, ExecutionException, InterruptedException {
+        ListenableFuture<Set<EventStreamInfo>>  evtStreams = restconfClientContext.getAvailableEventStreams();
+        while (!evtStreams.isDone()){
+            //noop
+        }
 
+        Iterator<EventStreamInfo> 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);
+    }
+
 
 }
index aa1542bc406b4fa9bb82dbce9603c1546d832745..238228ce822df913b992d1b087cbc96f76ff88f6 100644 (file)
@@ -227,7 +227,7 @@ public class RestconfUtils {
         return moduleName;
     }
 
-    public static Set<Class<? extends RpcService>> rpcServicesFromInputStream(InputStream inputStream, BindingIndependentMappingService mappingService){
+    public static Set<Class<? extends RpcService>> 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<Node<?>> domNodes = XmlDocumentUtils.toDomNodes(rootElement, Optional.<Set<DataSchemaNode>>absent());
+            XmlDocumentUtils.fromElement(rootElement).getNodeType();
 
+            List<Node<?>> domNodes = XmlDocumentUtils.toDomNodes(rootElement, Optional.of(schemaContext.getChildNodes()));
             Set<Class<? extends RpcService>> rpcServices = new HashSet<Class<? extends RpcService>>();
             for (Node<?> node:domNodes){
                 rpcServices.add(mappingService.getRpcServiceClassFor(node.getNodeType().getNamespace().toString(),node.getNodeType().getRevision().toString()).get());
index c629333a978a65774f4d11d9a2c935380b977544..c9e11facc5593fe94831384a301c01bfd2033b2a 100644 (file)
@@ -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);
-
 }