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();
47 mappingService.setPool(new ClassPool());
48 mappingService.init();
50 final ModuleInfoBackedContext moduleInfo = ModuleInfoBackedContext.create();
51 moduleInfo.addModuleInfos(BindingReflections.loadModuleInfos());
52 mappingService.onGlobalContextUpdated(moduleInfo.tryToCreateSchemaContext().get());
53 this.restconfClientContext = new RestconfClientFactory().getRestconfClientContext(new URL(restconfUrl),mappingService, mappingService);
54 assertNotNull(this.restconfClientContext);
58 public void testGetAvailableEventStreams(){
59 ListenableFuture<Set<EventStreamInfo>> streamsFuture = restconfClientContext.getAvailableEventStreams();
60 while (!streamsFuture.isDone()){
63 if (streamsFuture.isDone()){
65 Set<EventStreamInfo> streams = (Set<EventStreamInfo>) streamsFuture.get();
66 assertNotNull(streams);
67 } catch (InterruptedException e) {
69 } catch (ExecutionException e) {
75 public void testGetRpcServices(){
76 ListenableFuture<Set<Class<? extends RpcService>>> servicesFuture = restconfClientContext.getRpcServices();
77 while (!servicesFuture.isDone()){
80 if (servicesFuture.isDone()){
82 Set<Class<? extends RpcService>> streams = (Set<Class<? extends RpcService>>) servicesFuture.get();
83 assertNotNull(streams);
84 } catch (InterruptedException e) {
86 } catch (ExecutionException e) {
93 public void getEventStreamContext() throws MalformedURLException, UnsupportedProtocolException, ExecutionException, InterruptedException {
94 ListenableFuture<Set<EventStreamInfo>> evtStreams = restconfClientContext.getAvailableEventStreams();
95 while (!evtStreams.isDone()){
99 Iterator<EventStreamInfo> it = evtStreams.get().iterator();
100 ListenableEventStreamContext evtStreamCtx = restconfClientContext.getEventStreamContext(it.next());
101 assertNotNull(evtStreamCtx);
104 public void testGetOperationalDatastore() throws ExecutionException, InterruptedException, MalformedURLException, UnsupportedProtocolException {
105 OperationalDatastore datastore = restconfClientContext.getOperationalDatastore();
106 assertNotNull(datastore);
110 public void testGetConfigurationDatastore() throws ExecutionException, InterruptedException, MalformedURLException, UnsupportedProtocolException {
111 ConfigurationDatastore datastore = restconfClientContext.getConfigurationDatastore();
112 assertNotNull(datastore);