TCA: Replace any openecomp reference by onap
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / test / java / org / onap / dcae / apod / analytics / cdap / tca / validator / TCAPolicyPreferencesValidatorTest.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
4  * ================================================================================
5  *    Copyright © 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.dcae.apod.analytics.cdap.tca.validator;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.onap.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
26 import org.onap.dcae.apod.analytics.cdap.tca.settings.TCAPolicyPreferences;
27 import org.onap.dcae.apod.analytics.common.validation.GenericValidationResponse;
28 import org.onap.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;
29 import org.onap.dcae.apod.analytics.model.domain.policy.tca.Threshold;
30
31 import java.util.Collections;
32
33 import static org.junit.Assert.assertFalse;
34 import static org.junit.Assert.assertTrue;
35
36 /**
37  * @author Rajiv Singla . Creation Date: 12/16/2016.
38  */
39 public class TCAPolicyPreferencesValidatorTest extends BaseAnalyticsCDAPTCAUnitTest {
40
41     private TCAPolicyPreferencesValidator tcaPolicyPreferencesValidator;
42     private TCAPolicyPreferences tcaPolicyPreferences;
43
44     @Before
45     public void before() {
46         tcaPolicyPreferencesValidator = new TCAPolicyPreferencesValidator();
47         tcaPolicyPreferences = getSampleTCAPolicyPreferences();
48     }
49
50     @Test
51     public void testValidateAppSettingsWhenSettingsAreValid() throws Exception {
52         final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
53                 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
54         assertFalse(validationResponse.hasErrors());
55     }
56
57     @Test
58     public void testValidateAppSettingsWhenDomainIsNullAndFunctionRoleIsEmpty() throws Exception {
59         tcaPolicyPreferences.setDomain(null);
60         tcaPolicyPreferences.setMetricsPerEventName(Collections.<MetricsPerEventName>emptyList());
61         final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
62                 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
63         assertTrue(validationResponse.hasErrors());
64         assertTrue(validationResponse.getErrorMessages().size() == 2);
65     }
66
67     @Test
68     public void testValidateAppSettingsWhenThresholdIsEmpty() throws Exception {
69         tcaPolicyPreferences.getMetricsPerEventName().get(0).setThresholds(Collections.<Threshold>emptyList());
70         final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
71                 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
72         assertTrue(validationResponse.hasErrors());
73         assertTrue(validationResponse.getErrorMessages().size() == 1);
74     }
75
76     @Test
77     public void testValidateAppSettingsWhenThresholdPathIsMissing() throws Exception {
78         tcaPolicyPreferences.getMetricsPerEventName().get(0).getThresholds().get(0).setFieldPath(null);
79         final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
80                 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
81         assertTrue(validationResponse.hasErrors());
82         assertTrue(validationResponse.getErrorMessages().size() == 1);
83     }
84
85 }