Code Improvements-Vnfsdk-refrepo sonar issue fixes
[vnfsdk/refrepo.git] / vnfmarket-be / vnf-sdk-marketplace / src / test / java / org / onap / vnfsdk / marketplace / onboarding / hooks / validatelifecycle / LifecycleTestExceutorTest.java
1 /**
2  * Copyright 2018 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.vnfsdk.marketplace.onboarding.hooks.validatelifecycle;
17
18 import mockit.Mock;
19 import mockit.MockUp;
20 import org.apache.http.HttpEntity;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.onap.vnfsdk.marketplace.common.FileUtil;
24 import org.onap.vnfsdk.marketplace.msb.MsbDetails;
25 import org.onap.vnfsdk.marketplace.msb.MsbDetailsHolder;
26 import org.onap.vnfsdk.marketplace.msb.MsbServer;
27 import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest;
28 import org.onap.vnfsdk.marketplace.rest.RestResponse;
29 import org.onap.vnfsdk.marketplace.rest.RestfulClient;
30
31 import static org.mockito.Mockito.mock;
32 import static org.junit.Assert.assertNotNull;
33
34 public class LifecycleTestExceutorTest {
35    private LifecycleTestExceutor lifecycleTestExceutor;
36     private OnBoradingRequest onBoradingRequest;
37     LifeCycleTestReq lifeCycleTestReq;
38     @Before
39     public void setUp()
40     {
41        // lifecycleTestExceutor = new LifecycleTestExceutor();
42         lifeCycleTestReq = mock(LifeCycleTestReq.class);
43     }
44
45     @Test
46     public void testupLoadPackageToCatalougeForGson()
47     {
48         new MockUp<FileUtil>(){
49             @Mock
50             public boolean validatePath(String path) {
51                 return true;
52             }
53         };
54         new MockUp<LifecycleTestExceutor>(){
55             @Mock
56             private boolean checkValidResponse(RestResponse rsp) {
57                 return true;
58             }
59         };
60         new MockUp<RestResponse>(){
61             @Mock
62             public String getResult() {
63                 return "{\"csarId\":\"huawei\"}";
64             }
65         };
66         new MockUp<MsbDetails>(){
67             @Mock
68             public MsbServer getDefaultServer() {
69                 MsbServer msbServer = new MsbServer();
70                 msbServer.setHost("0.0.0.0");
71                 msbServer.setPort("5005");
72                 return msbServer;
73             }
74         };
75         new MockUp<RestfulClient>(){
76             @Mock
77             public RestResponse post(String ip, int port, String url, HttpEntity requestBody) {
78                 RestResponse rsp = new RestResponse();
79                 rsp.setStatusCode(200);
80                 rsp.setResult("OK");
81                 return rsp;
82             }
83         };
84         new MockUp<MsbServer>(){
85             @Mock
86             public String getHost() {
87                 return "0.0.0.0";
88             }
89             @Mock
90             public String getPort() {
91                 return "5005";
92             }
93         };
94         new MockUp<MsbDetailsHolder>(){
95             @Mock
96             public synchronized MsbDetails getMsbDetails(){
97                 MsbDetails msbDetails = new MsbDetails();
98                 return msbDetails;
99             }
100         };
101         onBoradingRequest = new OnBoradingRequest();
102         onBoradingRequest.setCsarId("huawei");
103         onBoradingRequest.setPackagePath("");
104         onBoradingRequest.setPackageName("huawei");
105         onBoradingRequest.setCsarIdCatalouge("catalog");
106         assertNotNull(LifecycleTestExceutor.uploadPackageToCatalouge(onBoradingRequest));
107     }
108     public void testExeclifecycleTest()
109     {
110         LifecycleTestExceutor.execlifecycleTest(onBoradingRequest,lifeCycleTestReq);
111
112     }
113
114
115 }