4e37d80c91ace60d18a20a455c4c647a6e62fbce
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / test / java / org / openecomp / dcae / apod / analytics / cdap / tca / validator / TCAPolicyPreferencesValidatorTest.java
1 /*\r
2  * ===============================LICENSE_START======================================\r
3  *  dcae-analytics\r
4  * ================================================================================\r
5  *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  *  Licensed under the Apache License, Version 2.0 (the "License");\r
8  *  you may not use this file except in compliance with the License.\r
9  *   You may obtain a copy of the License at\r
10  *\r
11  *          http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  *  Unless required by applicable law or agreed to in writing, software\r
14  *  distributed under the License is distributed on an "AS IS" BASIS,\r
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  *  See the License for the specific language governing permissions and\r
17  *  limitations under the License.\r
18  *  ============================LICENSE_END===========================================\r
19  */\r
20 \r
21 package org.openecomp.dcae.apod.analytics.cdap.tca.validator;\r
22 \r
23 import org.junit.Before;\r
24 import org.junit.Test;\r
25 import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;\r
26 import org.openecomp.dcae.apod.analytics.cdap.tca.settings.TCAPolicyPreferences;\r
27 import org.openecomp.dcae.apod.analytics.common.validation.GenericValidationResponse;\r
28 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;\r
29 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;\r
30 \r
31 import java.util.Collections;\r
32 \r
33 import static org.junit.Assert.assertFalse;\r
34 import static org.junit.Assert.assertTrue;\r
35 \r
36 /**\r
37  * @author Rajiv Singla . Creation Date: 12/16/2016.\r
38  */\r
39 public class TCAPolicyPreferencesValidatorTest extends BaseAnalyticsCDAPTCAUnitTest {\r
40 \r
41     private TCAPolicyPreferencesValidator tcaPolicyPreferencesValidator;\r
42     private TCAPolicyPreferences tcaPolicyPreferences;\r
43 \r
44     @Before\r
45     public void before() {\r
46         tcaPolicyPreferencesValidator = new TCAPolicyPreferencesValidator();\r
47         tcaPolicyPreferences = getSampleTCAPolicyPreferences();\r
48     }\r
49 \r
50     @Test\r
51     public void testValidateAppSettingsWhenSettingsAreValid() throws Exception {\r
52         final GenericValidationResponse<TCAPolicyPreferences> validationResponse =\r
53                 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);\r
54         assertFalse(validationResponse.hasErrors());\r
55     }\r
56 \r
57     @Test\r
58     public void testValidateAppSettingsWhenDomainIsNullAndFunctionRoleIsEmpty() throws Exception {\r
59         tcaPolicyPreferences.setDomain(null);\r
60         tcaPolicyPreferences.setMetricsPerEventName(Collections.<MetricsPerEventName>emptyList());\r
61         final GenericValidationResponse<TCAPolicyPreferences> validationResponse =\r
62                 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);\r
63         assertTrue(validationResponse.hasErrors());\r
64         assertTrue(validationResponse.getErrorMessages().size() == 2);\r
65     }\r
66 \r
67     @Test\r
68     public void testValidateAppSettingsWhenThresholdIsEmpty() throws Exception {\r
69         tcaPolicyPreferences.getMetricsPerEventName().get(0).setThresholds(Collections.<Threshold>emptyList());\r
70         final GenericValidationResponse<TCAPolicyPreferences> validationResponse =\r
71                 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);\r
72         assertTrue(validationResponse.hasErrors());\r
73         assertTrue(validationResponse.getErrorMessages().size() == 1);\r
74     }\r
75 \r
76     @Test\r
77     public void testValidateAppSettingsWhenThresholdPathIsMissing() throws Exception {\r
78         tcaPolicyPreferences.getMetricsPerEventName().get(0).getThresholds().get(0).setFieldPath(null);\r
79         final GenericValidationResponse<TCAPolicyPreferences> validationResponse =\r
80                 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);\r
81         assertTrue(validationResponse.hasErrors());\r
82         assertTrue(validationResponse.getErrorMessages().size() == 1);\r
83     }\r
84 \r
85 }\r