Containerization feature of SO
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / onap / so / apihandlerinfra / tenantisolation / helpers / ActivateVnfDBHelperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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.onap.so.apihandlerinfra.tenantisolation.helpers;
22
23 import static org.junit.Assert.assertThat;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.onap.so.apihandlerinfra.ApiHandlerApplication;
29 import org.onap.so.apihandlerinfra.BaseTest;
30 import org.onap.so.apihandlerinfra.tenantisolationbeans.DistributionStatus;
31 import org.onap.so.db.request.beans.OperationalEnvDistributionStatus;
32 import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.boot.test.context.SpringBootTest;
35 import org.springframework.test.context.ActiveProfiles;
36 import org.springframework.test.context.junit4.SpringRunner;
37
38 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
39
40
41 public class ActivateVnfDBHelperTest extends BaseTest{
42
43         String operationalEnvironmentId = "TEST_operationalEnvironmentId";
44         String requestId = "TEST_requestId";
45         String origRequestId = "TEST_requestId";
46
47         String workloadContext1 = "TEST_workloadContext1";
48         String serviceModelVersionId1 = "TEST_serviceModelVersionId1";  
49         String distributionId1 = "TEST_distributionId1";
50         String errorReason = "ABORTED";
51         int retryCountThree = 3;
52         int retryCountZero = 0;
53         String recoveryActionRetry  = "RETRY";
54         String statusOk = DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString();
55         String statusError = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString();
56         String statusSent = "SENT";
57
58         OperationalEnvDistributionStatus expectedDistStatus;
59         OperationalEnvServiceModelStatus expectedServiceModelStatus;    
60         
61         @Autowired
62         private ActivateVnfDBHelper dbHelper;
63         
64         @Before
65         public void testSetUp() {
66                 // prepare expected OperationalEnvDistributionStatus object 
67                 expectedDistStatus = new OperationalEnvDistributionStatus(); 
68                 expectedDistStatus.setDistributionId(distributionId1);
69                 expectedDistStatus.setOperationalEnvId(operationalEnvironmentId);
70                 expectedDistStatus.setServiceModelVersionId(serviceModelVersionId1);
71                 expectedDistStatus.setDistributionIdStatus(statusOk);
72                 expectedDistStatus.setRequestId(requestId);
73                 expectedDistStatus.setDistributionIdErrorReason("");
74
75                 // prepare expected OperationalEnvServiceModelStatus object             
76                 expectedServiceModelStatus = new OperationalEnvServiceModelStatus();
77                 expectedServiceModelStatus.setRequestId(requestId);
78                 expectedServiceModelStatus.setOperationalEnvId(operationalEnvironmentId);
79                 expectedServiceModelStatus.setServiceModelVersionId(serviceModelVersionId1);
80                 expectedServiceModelStatus.setServiceModelVersionDistrStatus(statusOk);
81                 expectedServiceModelStatus.setRecoveryAction(recoveryActionRetry);
82                 expectedServiceModelStatus.setRetryCount(new Integer(retryCountThree));
83                 expectedServiceModelStatus.setWorkloadContext(workloadContext1);
84         }       
85         
86         @Test
87         public void testOperationalEnvDistributionStatusDbMethods() throws Exception {
88
89                 // test insert method 
90                 OperationalEnvDistributionStatus distStatus1 = 
91                                 dbHelper.insertRecordToOperationalEnvDistributionStatus(distributionId1, 
92                                                                                                                                                 operationalEnvironmentId, 
93                                                                                                                                                 serviceModelVersionId1,
94                                                                                                                                                 requestId,                                                                                                                                              
95                                                                                                                                                 statusOk, 
96                                                                                                                                                 "");
97                 assertThat(distStatus1, sameBeanAs(expectedDistStatus));                
98                 
99                 // prepare updated expected object
100                 OperationalEnvDistributionStatus expectedUpdatedDistStatus = expectedDistStatus;
101                 expectedUpdatedDistStatus.setDistributionIdStatus(statusError);
102                 expectedUpdatedDistStatus.setDistributionIdErrorReason(errorReason);            
103                 
104                 // test update method - statusOk to statusError
105                 OperationalEnvDistributionStatus distStatus2 = 
106                                 dbHelper.updateStatusInOperationalEnvDistributionStatus(distStatus1, 
107                                                                                                                                                 statusError,
108                                                                                                                                                 errorReason
109                                                                                                                                                 );
110                 assertThat(distStatus2, sameBeanAs(expectedUpdatedDistStatus));
111         
112         }
113
114         @Test
115         public void testOperationalEnvServiceModelStatusDbMethods() throws Exception {
116
117                 // test insert method  
118                 OperationalEnvServiceModelStatus serviceModelStatus1 = 
119                                 dbHelper.insertRecordToOperationalEnvServiceModelStatus(requestId, 
120                                                                                                                                                 operationalEnvironmentId, 
121                                                                                                                                                 serviceModelVersionId1, 
122                                                                                                                                                 statusOk, 
123                                                                                                                                                 recoveryActionRetry, 
124                                                                                                                                                 retryCountThree, 
125                                                                                                                                                 workloadContext1);
126                 assertThat(serviceModelStatus1, sameBeanAs(expectedServiceModelStatus));
127                 
128                 // prepare updated expected object              
129                 OperationalEnvServiceModelStatus expectedUpdatedServiceModelStatus = serviceModelStatus1;
130                 expectedUpdatedServiceModelStatus.setServiceModelVersionDistrStatus(statusError);
131                 expectedUpdatedServiceModelStatus.setRetryCount(new Integer(retryCountZero));
132                 
133                 // test update method - update statusOk to statusError & retryCountThree to retryCountZero   
134                 OperationalEnvServiceModelStatus serviceModelStatus2 = 
135                                 dbHelper.updateRetryCountAndStatusInOperationalEnvServiceModelStatus(serviceModelStatus1, 
136                                                                                                                                                                          statusError, 
137                                                                                                                                                                          retryCountZero);
138                 assertThat(serviceModelStatus2, sameBeanAs(expectedUpdatedServiceModelStatus)); 
139         
140         }       
141         
142 }