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