2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.restconf.client;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.net.MalformedURLException;
13 import java.util.Iterator;
15 import java.util.concurrent.ExecutionException;
16 import javassist.ClassPool;
17 import org.junit.Before;
18 import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext;
19 import org.opendaylight.yangtools.restconf.client.api.UnsupportedProtocolException;
20 import org.opendaylight.yangtools.restconf.client.api.data.ConfigurationDatastore;
21 import org.opendaylight.yangtools.restconf.client.api.data.OperationalDatastore;
22 import org.opendaylight.yangtools.restconf.client.api.event.EventStreamInfo;
23 import org.opendaylight.yangtools.restconf.client.api.event.ListenableEventStreamContext;
24 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
25 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
26 import org.opendaylight.yangtools.yang.binding.RpcService;
27 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.fail;
33 public class RestconfClientImplTest {
35 private static final Logger logger = LoggerFactory.getLogger(RestconfClientImplTest.class);
36 private static final String restconfUrl = "http://localhost:8080";
37 //private static final String restconfUrl = "http://pce-guest35.cisco.com:9080";
38 public static final String JSON = "+json";
39 public static final String XML = "+xml";
40 private RestconfClientContext restconfClientContext;
41 private RuntimeGeneratedMappingServiceImpl mappingService;
45 public void setupRestconfClientContext() throws MalformedURLException, UnsupportedProtocolException {
46 mappingService = new RuntimeGeneratedMappingServiceImpl(new ClassPool());
48 final ModuleInfoBackedContext moduleInfo = ModuleInfoBackedContext.create();
49 moduleInfo.addModuleInfos(BindingReflections.loadModuleInfos());
50 mappingService.onGlobalContextUpdated(moduleInfo.tryToCreateSchemaContext().get());
51 this.restconfClientContext = new RestconfClientFactory().getRestconfClientContext(new URL(restconfUrl),mappingService, mappingService);
52 assertNotNull(this.restconfClientContext);
56 public void testGetAvailableEventStreams(){
57 ListenableFuture<Set<EventStreamInfo>> streamsFuture = restconfClientContext.getAvailableEventStreams();
58 while (!streamsFuture.isDone()){
61 if (streamsFuture.isDone()){
63 Set<EventStreamInfo> streams = (Set<EventStreamInfo>) streamsFuture.get();
64 assertNotNull(streams);
65 } catch (InterruptedException e) {
67 } catch (ExecutionException e) {
73 public void testGetRpcServices(){
74 ListenableFuture<Set<Class<? extends RpcService>>> servicesFuture = restconfClientContext.getRpcServices();
75 while (!servicesFuture.isDone()){
78 if (servicesFuture.isDone()){
80 Set<Class<? extends RpcService>> streams = (Set<Class<? extends RpcService>>) servicesFuture.get();
81 assertNotNull(streams);
82 } catch (InterruptedException e) {
84 } catch (ExecutionException e) {
91 public void getEventStreamContext() throws MalformedURLException, UnsupportedProtocolException, ExecutionException, InterruptedException {
92 ListenableFuture<Set<EventStreamInfo>> evtStreams = restconfClientContext.getAvailableEventStreams();
93 while (!evtStreams.isDone()){
97 Iterator<EventStreamInfo> it = evtStreams.get().iterator();
98 ListenableEventStreamContext evtStreamCtx = restconfClientContext.getEventStreamContext(it.next());
99 assertNotNull(evtStreamCtx);
102 public void testGetOperationalDatastore() throws ExecutionException, InterruptedException, MalformedURLException, UnsupportedProtocolException {
103 OperationalDatastore datastore = restconfClientContext.getOperationalDatastore();
104 assertNotNull(datastore);
108 public void testGetConfigurationDatastore() throws ExecutionException, InterruptedException, MalformedURLException, UnsupportedProtocolException {
109 ConfigurationDatastore datastore = restconfClientContext.getConfigurationDatastore();
110 assertNotNull(datastore);