3c983e7a79b2c8c760b6afeb3d9d26322fce607e
[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 static org.junit.Assert.fail;
25 import java.util.Set;
26 import org.junit.Test;
27 import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section;
28 import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section.EnvGetter;
29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet;
30 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.UserdataHttpServlet;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataProviderImpl;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.StatusChangedHandler.StatusKey;
35 import org.opendaylight.mdsal.binding.api.RpcProviderService;
36 import org.opendaylight.yangtools.concepts.ObjectRegistration;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.opendaylight.yangtools.yang.binding.RpcService;
39
40 /**
41  * @author Michael Dürre
42  *
43  */
44 public class TestImplementation {
45
46     static String XY = "http://localhost:"
47             + (System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200");
48
49     @Test
50     public void test() {
51         //TestConfig.setSDNRDBURLEnv("http://localhost:"+(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200"));
52         EnvGetter env = Section.getEnvGetter();
53         Section.setEnvGetter((xy) -> {
54             System.out.println("Search " + xy);
55             return xy.equals("SDNRDBURL") ? XY : env.getenv(xy);
56         });
57         DataProviderImpl impl = new DataProviderImpl();
58         impl.setRpcProviderService(new RpcProviderService() {
59
60             @Override
61             public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type,
62                     T implementation, Set<InstanceIdentifier<?>> paths) {
63                 return null;
64             }
65
66             @Override
67             public <S extends RpcService, T extends S> ObjectRegistration<T> registerRpcImplementation(Class<S> type,
68                     T implementation) {
69                 return null;
70             }
71         });
72         impl.setMediatorServerServlet(new MsServlet());
73         impl.setAboutServlet(new AboutHttpServlet());
74         impl.setTreeServlet(new DataTreeHttpServlet());
75         impl.setUserdataServlet(new UserdataHttpServlet());
76         try {
77             impl.init();
78         } catch (Exception e) {
79             e.printStackTrace();
80             fail("failed to init impl: " + e.getMessage());
81         }
82
83         impl.setStatus(StatusKey.CLUSTER_SIZE, "3");
84         try {
85             impl.close();
86         } catch (Exception e) {
87             e.printStackTrace();
88             fail("failed to close impl: " + e.getMessage());
89         }
90     }
91
92 }