548157cb10b51f34a44a81066d90978a2234c095
[usecase-ui/server.git] /
1 /**
2  * Copyright 2016-2017 ZTE 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 org.onap.usecaseui.server.service.lcm.impl;
17
18 import jakarta.annotation.Resource;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.InjectMocks;
23 import org.mockito.Mock;
24 import org.mockito.junit.MockitoJUnitRunner;
25 import org.onap.usecaseui.server.service.lcm.CustomerService;
26 import org.onap.usecaseui.server.service.lcm.ServiceInstanceService;
27 import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
28 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
29 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstanceRsp;
30 import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException;
31 import org.onap.usecaseui.server.util.CallStub;
32
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.List;
36
37 import static org.mockito.Mockito.doNothing;
38 import static org.mockito.Mockito.mock;
39 import static org.mockito.Mockito.when;
40 import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall;
41 import static org.onap.usecaseui.server.util.CallStub.failedCall;
42 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
43
44 public class DefaultServiceInstanceServiceTest {
45
46     @Test
47     public void itCanRetrieveServiceInstanceFromAAI() {
48         AAIService aaiService = mock(AAIService.class);
49         String customerId = "1";
50         String serviceType = "service";
51         List<String> instances = Collections.singletonList("{\"service-instance-id\":\"35e88f8e-473f-4d88-92f8-6739a42baa23\",\"service-instance-name\":\"SDWANVPNInfra1\",\"service-type\":\"E2E Service\",\"service-role\":\"E2E Service\",\"model-invariant-id\":\"88dcb2f0-085b-4548-8b93-0882e37d25d8\",\"model-version-id\":\"462f84e5-f0e5-44c5-ab95-38fb4bf77064\",\"resource-version\":\"1535687551051\",\"input-parameters\":\"{\\n    \\\"service\\\":{\\n        \\\"name\\\":\\\"SDWANVPNInfra\\\",\\n        \\\"description\\\":\\\"SDWANVPNInfra\\\",\\n        \\\"serviceInvariantUuid\\\":\\\"88dcb2f0-085b-4548-8b93-0882e37d25d8\\\",\\n        \\\"serviceUuid\\\":\\\"462f84e5-f0e5-44c5-ab95-38fb4bf77064\\\",\\n        \\\"globalSubscriberId\\\":\\\"Demonstration\\\",\\n        \\\"serviceType\\\":\\\"CCVPN\\\",\\n        \\\"parameters\\\":{\\n            \\\"locationConstraints\\\":[\\n\\n            ],\\n            \\\"resources\\\":[\\n                {\\n                    \\\"resourceName\\\":\\\"SDWANConnectivity 0\\\",\\n                    \\\"resourceInvariantUuid\\\":\\\"f99a9a23-c88e-44ff-a4dc-22b88675d278\\\",\\n                    \\\"resourceUuid\\\":\\\"7baa7742-3a13-4288-8330-868015adc340\\\",\\n                    \\\"resourceCustomizationUuid\\\":\\\"94ec574b-2306-4cbd-8214-09662b040f73\\\",\\n                    \\\"parameters\\\":{\\n                        \\\"locationConstraints\\\":[\\n\\n                        ],\\n                        \\\"resources\\\":[\\n\\n                        ],\\n                        \\\"requestInputs\\\":{\\n\\n                        }\\n                    }\\n                },\\n                {\\n                    \\\"resourceName\\\":\\\"SPPartnerVF 0\\\",\\n                    \\\"resourceInvariantUuid\\\":\\\"072f9238-15b0-4bc5-a5f5-f18548739470\\\",\\n                    \\\"resourceUuid\\\":\\\"81b9430b-8abe-45d6-8bf9-f41a8f5c735f\\\",\\n                    \\\"resourceCustomizationUuid\\\":\\\"a7baba5d-6ac3-42b5-b47d-070841303ab1\\\",\\n                    \\\"parameters\\\":{\\n                        \\\"locationConstraints\\\":[\\n\\n                        ],\\n                        \\\"resources\\\":[\\n\\n                        ],\\n                        \\\"requestInputs\\\":{\\n\\n                        }\\n                    }\\n                }\\n            ],\\n            \\\"requestInputs\\\":{\\n                \\\"sdwanconnectivity0_name\\\":\\\"CMCCVPN\\\",\\n                \\\"sdwanconnectivity0_topology\\\":\\\"hub-spoke\\\"\\n            }\\n        }\\n    }\\n}\",\"relationship-list\":{\"relationship\":[{\"related-to\":\"sdwan-vpn\",\"relationship-label\":\"org.onap.relationships.inventory.PartOf\",\"related-link\":\"/aai/v13/network/sdwan-vpns/sdwan-vpn/4efe6dff-acfc-4d13-a3fd-1177d3c08e89\",\"relationship-data\":[{\"relationship-key\":\"sdwan-vpn.sdwan-vpn-id\",\"relationship-value\":\"4efe6dff-acfc-4d13-a3fd-1177d3c08e89\"}],\"related-to-property\":[{\"property-key\":\"sdwan-vpn.sdwan-vpn-name\",\"property-value\":\"vdfvpn\"}]},{\"related-to\":\"sp-partner\",\"relationship-label\":\"org.onap.relationships.inventory.PartOf\",\"related-link\":\"/aai/v13/business/sp-partners/sp-partner/1b9c677d-fddf-4b70-938b-925a7fa57d00\",\"relationship-data\":[{\"relationship-key\":\"sp-partner.sp-partner-id\",\"relationship-value\":\"1b9c677d-fddf-4b70-938b-925a7fa57d00\"}],\"related-to-property\":[{\"property-key\":\"sp-partner.sp-partner-id\",\"property-value\":\"1b9c677d-fddf-4b70-938b-925a7fa57d00\"}]},{\"related-to\":\"allotted-resource\",\"relationship-label\":\"org.onap.relationships.inventory.Uses\",\"related-link\":\"/aai/v13/business/customers/customer/Democcy/service-subscriptions/service-subscription/CCVPN/service-instances/service-instance/189b87a5-72fe-4197-a307-6929c3831f81/allotted-resources/allotted-resource/2214feec-1aef-4890-abba-f8f3a906935f\",\"relationship-data\":[{\"relationship-key\":\"customer.global-customer-id\",\"relationship-value\":\"Democcy\"},{\"relationship-key\":\"service-subscription.service-type\",\"relationship-value\":\"CCVPN\"},{\"relationship-key\":\"service-instance.service-instance-id\",\"relationship-value\":\"189b87a5-72fe-4197-a307-6929c3831f81\"},{\"relationship-key\":\"allotted-resource.id\",\"relationship-value\":\"2214feec-1aef-4890-abba-f8f3a906935f\"}],\"related-to-property\":[{\"property-key\":\"allotted-resource.description\",\"property-value\":\"2214feec-1aef-4890-abba-f8f3a906935f\"},{\"property-key\":\"allotted-resource.allotted-resource-name\",\"property-value\":\"sdwan ar\"}]},{\"related-to\":\"allotted-resource\",\"relationship-label\":\"org.onap.relationships.inventory.Uses\",\"related-link\":\"/aai/v13/business/customers/customer/Democcy/service-subscriptions/service-subscription/CCVPN/service-instances/service-instance/089b87a5-72fe-4197-a307-6929c3831f80/allotted-resources/allotted-resource/1114feec-1aef-4890-abba-f8f3a906935f\",\"relationship-data\":[{\"relationship-key\":\"customer.global-customer-id\",\"relationship-value\":\"Democcy\"},{\"relationship-key\":\"service-subscription.service-type\",\"relationship-value\":\"CCVPN\"},{\"relationship-key\":\"service-instance.service-instance-id\",\"relationship-value\":\"089b87a5-72fe-4197-a307-6929c3831f80\"},{\"relationship-key\":\"allotted-resource.id\",\"relationship-value\":\"1114feec-1aef-4890-abba-f8f3a906935f\"}],\"related-to-property\":[{\"property-key\":\"allotted-resource.description\",\"property-value\":\"1114feec-1aef-4890-abba-f8f3a906935f\"},{\"property-key\":\"allotted-resource.allotted-resource-name\",\"property-value\":\"sdwan ar\"}]}]}}");
52         ServiceInstanceRsp rsp = new ServiceInstanceRsp();
53         rsp.setServiceInstances(instances);
54         when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(emptyBodyCall());
55
56         ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
57
58         Assert.assertTrue(service.listServiceInstances(customerId, serviceType).isEmpty());
59     }
60
61     @Test
62     public void retrieveServiceInstancesWillThrowExceptionWhenAAIIsNotAvailable() {
63         AAIService aaiService = mock(AAIService.class);
64         String customerId = "1";
65         String serviceType = "service";
66         when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(failedCall("AAI is not available!"));
67
68         ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
69         service.listServiceInstances(customerId, serviceType);
70     }
71
72     @Test
73     public void retrieveServiceInstancesWillThrowExceptionWhenNoServiceInstancesInAAI() {
74         AAIService aaiService = mock(AAIService.class);
75         String customerId = "1";
76         String serviceType = "service";
77         when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(emptyBodyCall());
78
79         ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
80         List<String> serviceInstances = service.listServiceInstances(customerId, serviceType);
81
82         Assert.assertTrue("service instances should be empty.", serviceInstances.isEmpty());
83     }
84
85     @Test
86     public void getRelationShipDataWillThrowExceptionWhenAAIIsNotAvailable() {
87         AAIService aaiService = mock(AAIService.class);
88         String customerId = "1";
89         String serviceType = "service";
90         String result="result";
91         when(aaiService.getAAIServiceInstance(customerId, serviceType,result)).thenReturn(failedCall("AAI is not available!"));
92
93         ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
94         service.getRelationShipData(customerId, serviceType,result);
95     }
96
97     @Test
98     public void getRelationShipDataWillThrowExceptionWhenNoServiceInstancesInAAI() {
99         AAIService aaiService = mock(AAIService.class);
100         String customerId = "1";
101         String serviceType = "service";
102         String result="result";
103         when(aaiService.getAAIServiceInstance(customerId, serviceType,result)).thenReturn(emptyBodyCall());
104
105         ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
106         String aa = service.getRelationShipData(customerId, serviceType,result);
107
108         Assert.assertTrue("service instances should be empty.", aa.isEmpty());
109     }
110 }