BUG-981: remove deprecated elements
[yangtools.git] / restconf / restconf-client-impl / src / test / java / org / opendaylight / yangtools / restconf / client / RestconfClientImplTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.restconf.client;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.net.MalformedURLException;
12 import java.net.URL;
13 import java.util.Iterator;
14 import java.util.Set;
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;
32
33 public class RestconfClientImplTest {
34
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;
42
43
44     @Before
45     public void setupRestconfClientContext() throws MalformedURLException, UnsupportedProtocolException {
46         mappingService = new RuntimeGeneratedMappingServiceImpl(new ClassPool());
47
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);
53     }
54
55 //    @Test
56     public void testGetAvailableEventStreams(){
57         ListenableFuture<Set<EventStreamInfo>> streamsFuture = restconfClientContext.getAvailableEventStreams();
58         while (!streamsFuture.isDone()){
59             //noop
60         }
61         if (streamsFuture.isDone()){
62             try {
63                 Set<EventStreamInfo> streams = (Set<EventStreamInfo>) streamsFuture.get();
64                 assertNotNull(streams);
65             } catch (InterruptedException e) {
66                 fail(e.getMessage());
67             } catch (ExecutionException e) {
68                 fail(e.getMessage());
69             }
70         }
71     }
72 //    @Test
73     public void testGetRpcServices(){
74         ListenableFuture<Set<Class<? extends RpcService>>> servicesFuture = restconfClientContext.getRpcServices();
75         while (!servicesFuture.isDone()){
76             //noop
77         }
78         if (servicesFuture.isDone()){
79             try {
80                 Set<Class<? extends RpcService>> streams = (Set<Class<? extends RpcService>>) servicesFuture.get();
81                 assertNotNull(streams);
82             } catch (InterruptedException e) {
83                 fail(e.getMessage());
84             } catch (ExecutionException e) {
85                 fail(e.getMessage());
86             }
87         }
88     }
89
90 //    @Test
91     public void getEventStreamContext() throws MalformedURLException, UnsupportedProtocolException, ExecutionException, InterruptedException {
92         ListenableFuture<Set<EventStreamInfo>>  evtStreams = restconfClientContext.getAvailableEventStreams();
93         while (!evtStreams.isDone()){
94             //noop
95         }
96
97         Iterator<EventStreamInfo> it = evtStreams.get().iterator();
98         ListenableEventStreamContext evtStreamCtx = restconfClientContext.getEventStreamContext(it.next());
99         assertNotNull(evtStreamCtx);
100     }
101 //    @Test
102     public void testGetOperationalDatastore() throws ExecutionException, InterruptedException, MalformedURLException, UnsupportedProtocolException {
103         OperationalDatastore datastore = restconfClientContext.getOperationalDatastore();
104         assertNotNull(datastore);
105
106     }
107 //    @Test
108     public void testGetConfigurationDatastore() throws ExecutionException, InterruptedException, MalformedURLException, UnsupportedProtocolException {
109         ConfigurationDatastore datastore = restconfClientContext.getConfigurationDatastore();
110         assertNotNull(datastore);
111     }
112
113
114 }