02691726d8c04892d8eb87837e14b928345e3f87
[so.git] / adapters / mso-vnf-adapter / src / test / java / org / openecomp / mso / adapters / vnf / test / VnfCreateTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. 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.openecomp.mso.adapters.vnf.test;
22
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import javax.xml.ws.Holder;
28
29 import org.openecomp.mso.adapters.vnf.MsoVnfAdapter;
30 import org.openecomp.mso.adapters.vnf.MsoVnfAdapterImpl;
31 import org.openecomp.mso.openstack.beans.VnfRollback;
32 import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
33
34 public class VnfCreateTest {
35         public final static void main (String args[])
36         {
37                 MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl();
38                 log ("Got a VnfAdapter");
39                 
40                 // Web Service Inputs
41                 String cloudId = "MT";
42                 String tenantName = "John_Test";
43                 String vnfType = "ApacheDemo";
44                 String vnfName = "AdapterTest";
45                 Map<String,String> inputs = new HashMap<String,String>();
46                 inputs.put("vnf_id", "abc");
47                 inputs.put("extra", "whocares");
48                 inputs.put("private_subnet_gateway", "10.4.1.1");
49                 inputs.put("private_subnet_cidr", "10.4.1.0/29");
50                 
51                 // Web Service Outputs
52                 Holder<String> vnfId = new Holder<String>();
53                 Holder<Map<String,String>> outputs = new Holder<Map<String,String>>();
54                 Holder<VnfRollback> vnfRollback = new Holder<VnfRollback>();
55
56                 try {
57                         vnfAdapter.createVnf(cloudId, tenantName, vnfType,null, vnfName, null, null, inputs, false, true, null,
58                                         vnfId, outputs, vnfRollback);
59                 } catch (VnfException e) {
60                         log ("Got a Create Exception: " + e);
61                         System.exit(1);
62                 }
63                 
64                 log ("Created VNF, ID = " + vnfId.value);
65                 for (String key : outputs.value.keySet()) {
66                         log ("   " + key + " = " + outputs.value.get(key));
67                 }
68                 if (vnfRollback.value != null)
69                         log (vnfRollback.value.toString());
70                 
71                 try {
72                         Thread.sleep(5000);
73                 } catch (InterruptedException e) {}
74                 
75                 log ("Rolling Back VNF");
76                 try {
77                         vnfAdapter.rollbackVnf(vnfRollback.value);
78                 } catch (VnfException e) {
79                         log ("Got a Rollback Exception: " + e);
80                 }
81                 log ("VNF Rolled Back");
82         }
83         
84         private static void log (String msg) {
85                 System.out.println (msg);
86         }
87 }