Create seed code of svnfm vnfmdriver
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / test / java / com / nokia / vfcadaptor / vnfmdriver / controller / VnfmDriverAdaptorControllerTest.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
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 com.nokia.vfcadaptor.vnfmdriver.controller;
17
18 import java.io.IOException;
19 import java.net.URISyntaxException;
20
21 import org.apache.http.client.ClientProtocolException;
22 import org.junit.Before;
23 import org.junit.Test;
24
25 public class VnfmDriverAdaptorControllerTest extends BaseControllerTestCase{
26
27         private String url;
28         private String basicUrl="http://localhost:8080/NvfmDriver/api/nokiavnfm/v1";
29     private String funcPath;
30     
31     @Before
32     public void setUp()
33     {
34         isHttpsProtocol = false;
35     }
36     
37     @Test
38     public void testInstantiateVnf() throws URISyntaxException, ClientProtocolException, IOException {
39         funcPath = "/vnfmId_001/vnfs";
40         url = basicUrl + funcPath;
41         String message = "{\"vnfInstanceName\":\"vnfInstanceName_001\",\"vnfPackageId\":\"1\"}";
42         
43         String responseContent = sendPostMsg(message, url);
44         System.out.println("-------------------------------");
45         System.out.println( " Initiate Response is " + responseContent);
46     }
47     
48     @Test
49     public void testTerminateVnf() throws URISyntaxException, ClientProtocolException, IOException {
50         funcPath = "/vnfmId_001/vnfs/vnfInstanceId_001/terminate";
51         url = basicUrl + funcPath;
52         String message = "{\"terminationType\":\"graceful\"}";
53         String responseContent = sendPostMsg(message, url);
54         System.out.println("-------------------------------");
55         System.out.println("Terminate Response is " + responseContent);
56     }
57     
58    @Test
59     public void testQueryVnf() throws URISyntaxException, ClientProtocolException, IOException {
60         funcPath = "/vnfmId_001/vnfs/vnfInstanceId_001";
61         url = basicUrl + funcPath;
62         String message = "{\"vnfInfo\":\"{\"nfInstanceId\":\"1\",\"vnfInstanceName\":\"vFW\",\"vnfInstanceDescription\":\"vFW in Nanjing TIC Edge\",\"vnfdId\":\"1\"}\"}";
63         String responseContent = sendGetMsg(message, url);
64         
65         System.out.println("-------------------------------");
66         System.out.println("QueryResponse is " + responseContent);
67     }
68    
69    @Test
70    public void testOperStatusVnf() throws URISyntaxException, ClientProtocolException, IOException {
71         funcPath = "/vnfmId_001/jobs/jobId_001&responseId=responseId_001";
72         url = basicUrl + funcPath;
73         String message = "{\"jobId\":\"12345\",\"responseDescriptor\":\"{\"progress\":\"40\",\"status\":\"proccessing\"}\"}";
74         String responseContent = sendGetMsg(message, url);
75         System.out.println("-------------------------------");
76         System.out.println(" operStatus Response is " + responseContent);
77    }
78    
79    @Test
80    public void testScaleVnf() throws URISyntaxException, ClientProtocolException, IOException {
81         funcPath = "/vnfmId_001/vnfs/vnfInstanceId_001/scale";
82         url = basicUrl + funcPath;
83         String message = "{\"type\":\"12345\",\"aspectId\":\"145\"}";
84         String responseContent = sendPostMsg(message, url);
85         System.out.println("-------------------------------");
86         System.out.println(" Scale Response is " + responseContent);
87    }
88    
89    @Test
90    public void testHealVnf() throws URISyntaxException, ClientProtocolException, IOException {
91         funcPath = "/vnfmId_001/vnfs/vnfInstanceId_001/heal";
92         url = basicUrl + funcPath;
93         String message = "{\"action\":\"12345\"}";
94         String responseContent = sendPostMsg(message, url);
95         System.out.println("-------------------------------");
96         System.out.println(" Heal Response is " + responseContent);
97    }
98
99 }