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