Saved vnfOperationalEnvironmentId to be used later
[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 vnfOperationalEnvironmentId = "VNF_operationalEnvironmentId";
45         String requestId = "TEST_requestId";
46         String origRequestId = "TEST_requestId";
47
48         String workloadContext1 = "TEST_workloadContext1";
49         String serviceModelVersionId1 = "TEST_serviceModelVersionId1";  
50         String distributionId1 = "TEST_distributionId1";
51         String errorReason = "ABORTED";
52         int retryCountThree = 3;
53         int retryCountZero = 0;
54         String recoveryActionRetry  = "RETRY";
55         String statusOk = DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString();
56         String statusError = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString();
57         String statusSent = "SENT";
58
59         OperationalEnvDistributionStatus expectedDistStatus;
60         OperationalEnvServiceModelStatus expectedServiceModelStatus;    
61         
62         @Autowired
63         private ActivateVnfDBHelper dbHelper;
64         
65         @Before
66         public void testSetUp() {
67                 // prepare expected OperationalEnvDistributionStatus object 
68                 expectedDistStatus = new OperationalEnvDistributionStatus(); 
69                 expectedDistStatus.setDistributionId(distributionId1);
70                 expectedDistStatus.setOperationalEnvId(operationalEnvironmentId);
71                 expectedDistStatus.setServiceModelVersionId(serviceModelVersionId1);
72                 expectedDistStatus.setDistributionIdStatus(statusOk);
73                 expectedDistStatus.setRequestId(requestId);
74                 expectedDistStatus.setDistributionIdErrorReason("");
75
76                 // prepare expected OperationalEnvServiceModelStatus object             
77                 expectedServiceModelStatus = new OperationalEnvServiceModelStatus();
78                 expectedServiceModelStatus.setRequestId(requestId);
79                 expectedServiceModelStatus.setOperationalEnvId(operationalEnvironmentId);
80                 expectedServiceModelStatus.setServiceModelVersionId(serviceModelVersionId1);
81                 expectedServiceModelStatus.setServiceModelVersionDistrStatus(statusOk);
82                 expectedServiceModelStatus.setRecoveryAction(recoveryActionRetry);
83                 expectedServiceModelStatus.setRetryCount(new Integer(retryCountThree));
84                 expectedServiceModelStatus.setWorkloadContext(workloadContext1);
85                 expectedServiceModelStatus.setVnfOperationalEnvId(vnfOperationalEnvironmentId);
86         }       
87         
88         @Test
89         public void testOperationalEnvDistributionStatusDbMethods() throws Exception {
90
91                 // test insert method 
92                 OperationalEnvDistributionStatus distStatus1 = 
93                                 dbHelper.insertRecordToOperationalEnvDistributionStatus(distributionId1, 
94                                                                                                                                                 operationalEnvironmentId, 
95                                                                                                                                                 serviceModelVersionId1,
96                                                                                                                                                 requestId,                                                                                                                                              
97                                                                                                                                                 statusOk, 
98                                                                                                                                                 "");
99                 assertThat(distStatus1, sameBeanAs(expectedDistStatus));                
100                 
101                 // prepare updated expected object
102                 OperationalEnvDistributionStatus expectedUpdatedDistStatus = expectedDistStatus;
103                 expectedUpdatedDistStatus.setDistributionIdStatus(statusError);
104                 expectedUpdatedDistStatus.setDistributionIdErrorReason(errorReason);            
105                 
106                 // test update method - statusOk to statusError
107                 OperationalEnvDistributionStatus distStatus2 = 
108                                 dbHelper.updateStatusInOperationalEnvDistributionStatus(distStatus1, 
109                                                                                                                                                 statusError,
110                                                                                                                                                 errorReason
111                                                                                                                                                 );
112                 assertThat(distStatus2, sameBeanAs(expectedUpdatedDistStatus));
113         
114         }
115
116         @Test
117         public void testOperationalEnvServiceModelStatusDbMethods() throws Exception {
118
119                 // test insert method  
120                 OperationalEnvServiceModelStatus serviceModelStatus1 = 
121                                 dbHelper.insertRecordToOperationalEnvServiceModelStatus(requestId, 
122                                                                                                                                                 operationalEnvironmentId, 
123                                                                                                                                                 serviceModelVersionId1, 
124                                                                                                                                                 statusOk, 
125                                                                                                                                                 recoveryActionRetry, 
126                                                                                                                                                 retryCountThree, 
127                                                                                                                                                 workloadContext1,
128                                                                                                                                                 vnfOperationalEnvironmentId);
129                 assertThat(serviceModelStatus1, sameBeanAs(expectedServiceModelStatus));
130                 
131                 // prepare updated expected object              
132                 OperationalEnvServiceModelStatus expectedUpdatedServiceModelStatus = serviceModelStatus1;
133                 expectedUpdatedServiceModelStatus.setServiceModelVersionDistrStatus(statusError);
134                 expectedUpdatedServiceModelStatus.setRetryCount(new Integer(retryCountZero));
135                 
136                 // test update method - update statusOk to statusError & retryCountThree to retryCountZero   
137                 OperationalEnvServiceModelStatus serviceModelStatus2 = 
138                                 dbHelper.updateRetryCountAndStatusInOperationalEnvServiceModelStatus(serviceModelStatus1, 
139                                                                                                                                                                          statusError, 
140                                                                                                                                                                          retryCountZero);
141                 assertThat(serviceModelStatus2, sameBeanAs(expectedUpdatedServiceModelStatus)); 
142         
143         }       
144         
145 }