aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCoreBPMN
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/MSOCoreBPMN')
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java9
1 files changed, 0 insertions, 9 deletions
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java
index 0e03989e64..419f545cdf 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java
@@ -54,7 +54,6 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable {
private String serviceRole;
private ServiceInstance serviceInstance;
private Request request;
- private Customer customer;
private String callbackURN;
private String sdncVersion;
@JsonProperty("project")
@@ -217,14 +216,6 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable {
this.request = request;
}
- public Customer getCustomer() {
- return customer;
- }
-
- public void setCustomer(Customer customer) {
- this.customer = customer;
- }
-
public String getCallbackURN() {
return callbackURN;
}
154' href='#n154'>154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
/*
Copyright 2018 Intel Corporation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package api

import (
	"bytes"
	"encoding/json"
	"k8s.io/client-go/kubernetes"
	"net/http"
	"net/http/httptest"
	"reflect"
	"testing"

	"k8splugin/csar"
	"k8splugin/db"
)

type mockDB struct {
	db.DatabaseConnection
}

func (c *mockDB) InitializeDatabase() error {
	return nil
}

func (c *mockDB) CheckDatabase() error {
	return nil
}

func (c *mockDB) CreateEntry(key string, value string) error {
	return nil
}

func (c *mockDB) ReadEntry(key string) (string, bool, error) {
	str := "{\"deployment\":[\"cloud1-default-uuid-sisedeploy\"],\"service\":[\"cloud1-default-uuid-sisesvc\"]}"
	return str, true, nil
}

func (c *mockDB) DeleteEntry(key string) error {
	return nil
}

func (c *mockDB) ReadAll(key string) ([]string, error) {
	returnVal := []string{"cloud1-default-uuid1", "cloud1-default-uuid2"}
	return returnVal, nil
}

func executeRequest(req *http.Request) *httptest.ResponseRecorder {
	router := NewRouter("")
	recorder := httptest.NewRecorder()
	router.ServeHTTP(recorder, req)

	return recorder
}

func checkResponseCode(t *testing.T, expected, actual int) {
	if expected != actual {
		t.Errorf("Expected response code %d. Got %d\n", expected, actual)
	}
}

func TestVNFInstanceCreation(t *testing.T) {
	t.Run("Succesful create a VNF", func(t *testing.T) {
		payload := []byte(`{
			"cloud_region_id": "region1",
			"namespace": "test",
			"csar_id": "UUID-1",
			"oof_parameters": [{
				"key1": "value1",
				"key2": "value2",
				"key3": {}
			}],
			"network_parameters": {
				"oam_ip_address": {
					"connection_point": "string",
					"ip_address": "string",
					"workload_name": "string"
				}
			}
		}`)

		data := map[string][]string{
			"deployment": []string{"cloud1-default-uuid-sisedeploy"},
			"service":    []string{"cloud1-default-uuid-sisesvc"},
		}

		expected := &CreateVnfResponse{
			VNFID:         "test_UUID",
			CloudRegionID: "region1",
			Namespace:     "test",
			VNFComponents: data,
		}

		var result CreateVnfResponse

		req, _ := http.NewRequest("POST", "/v1/vnf_instances/", bytes.NewBuffer(payload))

		GetVNFClient = func(configPath string) (kubernetes.Clientset, error) {
			return kubernetes.Clientset{}, nil
		}

		csar.CreateVNF = func(id string, r string, n string, kubeclient *kubernetes.Clientset) (string, map[string][]string, error) {
			return "externaluuid", data, nil
		}

		db.DBconn = &mockDB{}

		response := executeRequest(req)
		checkResponseCode(t, http.StatusCreated, response.Code)

		err := json.NewDecoder(response.Body).Decode(&result)
		if err != nil {
			t.Fatalf("TestVNFInstanceCreation returned:\n result=%v\n expected=%v", err, expected.VNFComponents)
		}
	})
	t.Run("Missing body failure", func(t *testing.T) {
		req, _ := http.NewRequest("POST", "/v1/vnf_instances/", nil)
		response := executeRequest(req)

		checkResponseCode(t, http.StatusBadRequest, response.Code)
	})
	t.Run("Invalid JSON request format", func(t *testing.T) {
		payload := []byte("invalid")
		req, _ := http.NewRequest("POST", "/v1/vnf_instances/", bytes.NewBuffer(payload))
		response := executeRequest(req)
		checkResponseCode(t, http.StatusUnprocessableEntity, response.Code)
	})
	t.Run("Missing parameter failure", func(t *testing.T) {
		payload := []byte(`{
			"csar_id": "testID",
			"oof_parameters": {
				"key_values": {
					"key1": "value1",
					"key2": "value2"
				}
			},
			"vnf_instance_name": "test",
			"vnf_instance_description": "vRouter_test_description"
		}`)
		req, _ := http.NewRequest("POST", "/v1/vnf_instances/", bytes.NewBuffer(payload))
		response := executeRequest(req)
		checkResponseCode(t, http.StatusUnprocessableEntity, response.Code)
	})
}

func TestVNFInstancesRetrieval(t *testing.T) {
	t.Run("Succesful get a list of VNF", func(t *testing.T) {
		expected := &ListVnfsResponse{
			VNFs: []string{"uuid1", "uuid2"},
		}
		var result ListVnfsResponse

		req, _ := http.NewRequest("GET", "/v1/vnf_instances/cloud1/default", nil)

		db.DBconn = &mockDB{}

		response := executeRequest(req)
		checkResponseCode(t, http.StatusOK, response.Code)

		err := json.NewDecoder(response.Body).Decode(&result)
		if err != nil {
			t.Fatalf("TestVNFInstancesRetrieval returned:\n result=%v\n expected=list", err)
		}
		if !reflect.DeepEqual(*expected, result) {
			t.Fatalf("TestVNFInstancesRetrieval returned:\n result=%v\n expected=%v", result, *expected)
		}
	})
	t.Run("Get empty list", func(t *testing.T) {
		req, _ := http.NewRequest("GET", "/v1/vnf_instances/cloudregion1/testnamespace", nil)
		db.DBconn = &mockDB{}
		response := executeRequest(req)
		checkResponseCode(t, http.StatusOK, response.Code)
	})
}

func TestVNFInstanceDeletion(t *testing.T) {
	t.Run("Succesful delete a VNF", func(t *testing.T) {
		req, _ := http.NewRequest("DELETE", "/v1/vnf_instances/cloudregion1/testnamespace/1", nil)

		GetVNFClient = func(configPath string) (kubernetes.Clientset, error) {
			return kubernetes.Clientset{}, nil
		}

		csar.DestroyVNF = func(d map[string][]string, n string, kubeclient *kubernetes.Clientset) error {
			return nil
		}

		db.DBconn = &mockDB{}

		response := executeRequest(req)
		checkResponseCode(t, http.StatusAccepted, response.Code)

		if result := response.Body.String(); result != "" {
			t.Fatalf("TestVNFInstanceDeletion returned:\n result=%v\n expected=%v", result, "")
		}
	})
	// t.Run("Malformed delete request", func(t *testing.T) {
	// 	req, _ := http.NewRequest("DELETE", "/v1/vnf_instances/foo", nil)
	// 	response := executeRqequest(req)
	// 	checkResponseCode(t, http.StatusBadRequest, response.Code)
	// })
}

// TODO: Update this test when the UpdateVNF endpoint is fixed.
/*
func TestVNFInstanceUpdate(t *testing.T) {
	t.Run("Succesful update a VNF", func(t *testing.T) {
		payload := []byte(`{
			"cloud_region_id": "region1",
			"csar_id": "UUID-1",
			"oof_parameters": [{
				"key1": "value1",
				"key2": "value2",
				"key3": {}
			}],
			"network_parameters": {
				"oam_ip_address": {
					"connection_point": "string",
					"ip_address": "string",
					"workload_name": "string"
				}
			}
		}`)
		expected := &UpdateVnfResponse{
			DeploymentID: "1",
		}

		var result UpdateVnfResponse

		req, _ := http.NewRequest("PUT", "/v1/vnf_instances/1", bytes.NewBuffer(payload))

		GetVNFClient = func(configPath string) (krd.VNFInstanceClientInterface, error) {
			return &mockClient{
				update: func() error {
					return nil
				},
			}, nil
		}
		utils.ReadCSARFromFileSystem = func(csarID string) (*krd.KubernetesData, error) {
			kubeData := &krd.KubernetesData{
				Deployment: &appsV1.Deployment{},
				Service:    &coreV1.Service{},
			}
			return kubeData, nil
		}

		response := executeRequest(req)
		checkResponseCode(t, http.StatusCreated, response.Code)

		err := json.NewDecoder(response.Body).Decode(&result)
		if err != nil {
			t.Fatalf("TestVNFInstanceUpdate returned:\n result=%v\n expected=%v", err, expected.DeploymentID)
		}

		if result.DeploymentID != expected.DeploymentID {
			t.Fatalf("TestVNFInstanceUpdate returned:\n result=%v\n expected=%v", result.DeploymentID, expected.DeploymentID)
		}
	})
}
*/

func TestVNFInstanceRetrieval(t *testing.T) {
	t.Run("Succesful get a VNF", func(t *testing.T) {

		data := map[string][]string{
			"deployment": []string{"cloud1-default-uuid-sisedeploy"},
			"service":    []string{"cloud1-default-uuid-sisesvc"},
		}

		expected := GetVnfResponse{
			VNFID:         "1",
			CloudRegionID: "cloud1",
			Namespace:     "default",
			VNFComponents: data,
		}

		req, _ := http.NewRequest("GET", "/v1/vnf_instances/cloud1/default/1", nil)

		GetVNFClient = func(configPath string) (kubernetes.Clientset, error) {
			return kubernetes.Clientset{}, nil
		}

		db.DBconn = &mockDB{}

		response := executeRequest(req)
		checkResponseCode(t, http.StatusOK, response.Code)

		var result GetVnfResponse

		err := json.NewDecoder(response.Body).Decode(&result)
		if err != nil {
			t.Fatalf("TestVNFInstanceRetrieval returned:\n result=%v\n expected=%v", err, expected)
		}

		if !reflect.DeepEqual(expected, result) {
			t.Fatalf("TestVNFInstanceRetrieval returned:\n result=%v\n expected=%v", result, expected)
		}
	})
	t.Run("VNF not found", func(t *testing.T) {
		req, _ := http.NewRequest("GET", "/v1/vnf_instances/cloudregion1/testnamespace/1", nil)
		response := executeRequest(req)

		checkResponseCode(t, http.StatusOK, response.Code)
	})
}