aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
blob: 36f4bdd43dba8f65b392e37118ec27d8eb8916ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package org.onap.vid.mso;

import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.vid.mso.rest.RequestDetails;
import org.onap.vid.properties.Features;
import org.onap.portalsdk.core.util.SystemProperties;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.togglz.core.manager.FeatureManager;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.onap.vid.controllers.MsoController.SVC_INSTANCE_ID;
import static org.onap.vid.controllers.MsoController.VNF_INSTANCE_ID;
import static org.onap.vid.mso.MsoBusinessLogicImpl.validateEndpointPath;

@ContextConfiguration(classes = {SystemProperties.class})
@WebAppConfiguration
public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {

    @InjectMocks
    private MsoBusinessLogicImpl msoBusinessLogic;

    @Mock
    private FeatureManager featureManagerMock;

    @Mock
    private MsoInterface msoInterfaceMock;


    @BeforeTest
    public void initMocks(){
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void validateEndpointPath_endPointIsNotEmptyAndVaild_returnProperty(){
        System.setProperty("TestEnv","123");
        String foundEndPoint = validateEndpointPath("TestEnv");
        Assert.assertEquals("123",foundEndPoint);
    }

    @Test(expectedExceptions = RuntimeException.class)
    public void validateEndpointPath_endPointIsNull_throwRuntimeException(){
        validateEndpointPath("NotExists");
    }

    @Test(expectedExceptions = RuntimeException.class)
    public void validateEndpointPath_endPointIsNotEmptyButDoesntExists_throwRuntimeException(){
        System.setProperty("EmptyEndPoint","");
        validateEndpointPath("EmptyEndPoint");
    }


    //@Test(dataProvider = "unAssignOrDeleteParams")
    public void deleteSvcInstance_verifyEndPointPathConstructing_unAssignFeatureOffOrUnAssignFlagIsFalse(boolean isAssignFlag,String status) {
        Mockito.reset(msoInterfaceMock);
        String endpoint = validateEndpointPath(isAssignFlag ? MsoProperties.MSO_DELETE_OR_UNASSIGN_REST_API_SVC_INSTANCE : MsoProperties.MSO_REST_API_SVC_INSTANCE);
        RequestDetails requestDetails = new RequestDetails();

        when(featureManagerMock.isActive(Features.FLAG_UNASSIGN_SERVICE)).thenReturn(isAssignFlag);

        msoBusinessLogic.deleteSvcInstance(requestDetails, "tempId", status);

        verify(msoInterfaceMock).deleteSvcInstance(requestDetails, endpoint + "/tempId");
    }

    @DataProvider
    public Object[][] unAssignOrDeleteParams() {
        return new Object[][]{
                {Boolean.FALSE, "active"},
                {Boolean.FALSE, "created"},
                {Boolean.TRUE, "Active"},
                {Boolean.TRUE, "unexpected-status"},
        };
    }

    //@Test(dataProvider = "unAssignStatus")
    public void deleteSvcInstance_verifyEndPointPathConstructing_unAssignFeatureOnAndUnAssignFlagIsTrue(String status) {
        Mockito.reset(msoInterfaceMock);
        // in the test Features.FLAG_UNASSIGN_SERVICE is active so the endpoint should be MsoProperties.MSO_DELETE_OR_UNASSIGN_REST_API_SVC_INSTANCE
        String endpoint = validateEndpointPath(MsoProperties.MSO_DELETE_OR_UNASSIGN_REST_API_SVC_INSTANCE);
        RequestDetails requestDetails = new RequestDetails();

        when(featureManagerMock.isActive(Features.FLAG_UNASSIGN_SERVICE)).thenReturn(true);

        msoBusinessLogic.deleteSvcInstance(requestDetails, "tempId", status);

        verify(msoInterfaceMock).unassignSvcInstance(requestDetails, endpoint + "/tempId/unassign");
    }

    @DataProvider
    public Object[][] unAssignStatus() {
        return new Object[][]{
                {"Created"},
                {"Pendingdelete"},
                {"pending-Delete"},
                {"Assigned"}
        };
    }

    @Test
    public void deleteVnf_verifyEndPointPathConstructing() {
        String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
        RequestDetails requestDetails = new RequestDetails();

        String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, "serviceInstanceTempId");

        msoBusinessLogic.deleteVnf(requestDetails, "serviceInstanceTempId","vnfInstanceTempId");
        verify(msoInterfaceMock).deleteVnf(requestDetails, vnf_endpoint + "/vnfInstanceTempId");
    }

    @Test
    public void deleteVfModule_verifyEndPointPathConstructing() {
        String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
        RequestDetails requestDetails = new RequestDetails();

        String vf__modules_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, "serviceInstanceTempId").replaceFirst(VNF_INSTANCE_ID, "vnfInstanceTempId");

        msoBusinessLogic.deleteVfModule(requestDetails, "serviceInstanceTempId","vnfInstanceTempId", "vfModuleTempId");
        verify(msoInterfaceMock).deleteVfModule(requestDetails, vf__modules_endpoint + "/vfModuleTempId" );
    }

    @Test
    public void insertServiceInstantiationToDB_StartJob() {

//        broker = new JobsBrokerServiceInDatabaseImpl(dataAccessServiceMock, sessionFactory);
//        ((JobsBrokerServiceInDatabaseImpl)broker).deleteAll();
//
////        msoBusinessLogic.setDataAccessService(dataAccessServiceMock);
////        msoBusinessLogic.setJobsBrokerService(broker);
////        msoBusinessLogic.setJobAdapter(jobAdapter);
//
//        ServiceInstantiation serviceInstantiation = new ServiceInstantiation();
//        serviceInstantiation.setCount(2);
//        serviceInstantiation.setInstanceName("TestName");
//
//        msoBusinessLogic.pushBulkJob(serviceInstantiation, "testUserId");
//
//        List<ServiceInfo> serviceInfoList = dataAccessServiceMock.getList(ServiceInfo.class, null);
//        int k = 9;
//        Assert.assertEquals(serviceInstantiation, containsInAnyOrder(serviceInfoList.toArray()));
    }
}