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