91f64185b6bb4df16e9c464ba2d80f9e9b90436c
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
23
24 import com.google.common.collect.ClassToInstanceMap;
25 import org.eclipse.jdt.annotation.NonNull;
26 import static org.junit.Assert.fail;
27 import java.util.Set;
28 import org.junit.Test;
29 import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section;
30 import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section.EnvGetter;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.UserdataHttpServlet;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataProviderImpl;
36 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.StatusChangedHandler.StatusKey;
37 import org.opendaylight.mdsal.binding.api.RpcProviderService;
38 import org.opendaylight.yangtools.concepts.ObjectRegistration;
39 import org.opendaylight.yangtools.concepts.Registration;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import org.opendaylight.yangtools.yang.binding.Rpc;
42 import org.opendaylight.yangtools.yang.binding.RpcService;
43
44 /**
45  * @author Michael Dürre
46  *
47  */
48 public class TestImplementation {
49
50     static String XY = "http://localhost:"
51             + (System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200");
52
53     @Test
54     public void test() {
55         //TestConfig.setSDNRDBURLEnv("http://localhost:"+(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200"));
56         EnvGetter env = Section.getEnvGetter();
57         Section.setEnvGetter((xy) -> {
58             System.out.println("Search " + xy);
59             return xy.equals("SDNRDBURL") ? XY : env.getenv(xy);
60         });
61         DataProviderImpl impl = new DataProviderImpl();
62         impl.setRpcProviderService(new RpcProviderService() {
63
64             @Override
65             public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type,
66                     T implementation, Set<InstanceIdentifier<?>> paths) {
67                 return null;
68             }
69
70             @Override
71             public @NonNull Registration registerRpcImplementation(Rpc<?, ?> implementation) {
72                 return null;
73             }
74
75             @Override
76             public @NonNull Registration registerRpcImplementation(Rpc<?, ?> implementation,
77                                                                    Set<InstanceIdentifier<?>> paths) {
78                 return null;
79             }
80
81             @Override
82             public @NonNull Registration registerRpcImplementations(ClassToInstanceMap<Rpc<?, ?>> implementations) {
83                 return null;
84             }
85
86             @Override
87             public @NonNull Registration registerRpcImplementations(ClassToInstanceMap<Rpc<?, ?>> implementations,
88                                                                     Set<InstanceIdentifier<?>> paths) {
89                 return null;
90             }
91
92             @Override
93             public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type,
94                     T implementation) {
95                 return null;
96             }
97         });
98         impl.setMediatorServerServlet(new MsServlet());
99         impl.setAboutServlet(new AboutHttpServlet());
100         impl.setTreeServlet(new DataTreeHttpServlet());
101         impl.setUserdataServlet(new UserdataHttpServlet());
102         try {
103             impl.init();
104         } catch (Exception e) {
105             e.printStackTrace();
106             fail("failed to init impl: " + e.getMessage());
107         }
108
109         impl.setStatus(StatusKey.CLUSTER_SIZE, "3");
110         try {
111             impl.close();
112         } catch (Exception e) {
113             e.printStackTrace();
114             fail("failed to close impl: " + e.getMessage());
115         }
116     }
117
118 }