migrate model-impl from drools-applications
[policy/models.git] / models-interactions / model-impl / vfc / src / test / java / org / onap / policy / vfc / DemoTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2017-2019 Intel Corp. All rights reserved.
4  * Modifications Copyright (C) 2019 Nordix Foundation.
5  * Modifications Copyright (C) 2018-2019 AT&T Corporation. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.vfc;
22
23 import java.util.LinkedList;
24
25 import org.junit.Test;
26 import org.onap.policy.vfc.util.Serialization;
27
28 public class DemoTest {
29
30     @Test
31     public void test() {
32         VfcRequest request = new VfcRequest();
33
34         request.setNsInstanceId("100");
35         request.setHealRequest(new VfcHealRequest());
36         request.getHealRequest().setVnfInstanceId("1");
37         request.getHealRequest().setCause("vm is down");
38
39         request.getHealRequest().setAdditionalParams(new VfcHealAdditionalParams());
40         request.getHealRequest().getAdditionalParams().setAction("restartvm");
41
42         request.getHealRequest().getAdditionalParams().setActionInfo(new VfcHealActionVmInfo());
43         request.getHealRequest().getAdditionalParams().getActionInfo().setVmid("33");
44         request.getHealRequest().getAdditionalParams().getActionInfo().setVmname("xgw-smp11");
45
46         String body = Serialization.gsonPretty.toJson(request);
47         System.out.println(body);
48
49         VfcResponse response = new VfcResponse();
50         response.setJobId("1");
51
52         body = Serialization.gsonPretty.toJson(response);
53         System.out.println(body);
54
55         response.setResponseDescriptor(new VfcResponseDescriptor());
56         response.getResponseDescriptor().setProgress("40");
57         response.getResponseDescriptor().setStatus("processing");
58         response.getResponseDescriptor().setStatusDescription("OMC VMs are decommissioned in VIM");
59         response.getResponseDescriptor().setErrorCode(null);
60         response.getResponseDescriptor().setResponseId("42");
61         body = Serialization.gsonPretty.toJson(response);
62         System.out.println(body);
63
64         VfcResponseDescriptor responseDescriptor = new VfcResponseDescriptor();
65         responseDescriptor.setProgress("20");
66         responseDescriptor.setStatus("processing");
67         responseDescriptor.setStatusDescription("OMC VMs are decommissioned in VIM");
68         responseDescriptor.setErrorCode(null);
69         responseDescriptor.setResponseId("11");
70
71         response.getResponseDescriptor().setResponseHistoryList(new LinkedList<>());
72         response.getResponseDescriptor().getResponseHistoryList().add(responseDescriptor);
73
74         body = Serialization.gsonPretty.toJson(response);
75         System.out.println(body);
76
77         response = Serialization.gsonPretty.fromJson(body, VfcResponse.class);
78         body = Serialization.gsonPretty.toJson(response);
79         System.out.println(body);
80
81     }
82 }