0d15f6fc41b044b9136b31dc5bd6bad0ad57ada4
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / test / java / org / openecomp / dcae / apod / analytics / cdap / tca / validator / TCAPreferencesValidatorTest.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.TCAAppPreferences;\r
27 import org.openecomp.dcae.apod.analytics.cdap.tca.settings.TCATestAppPreferences;\r
28 import org.openecomp.dcae.apod.analytics.common.validation.GenericValidationResponse;\r
29 \r
30 import static org.junit.Assert.assertFalse;\r
31 import static org.junit.Assert.assertTrue;\r
32 \r
33 /**\r
34  * @author Rajiv Singla . Creation Date: 12/19/2016.\r
35  */\r
36 public class TCAPreferencesValidatorTest extends BaseAnalyticsCDAPTCAUnitTest {\r
37 \r
38     private TCAPreferencesValidator tcaPreferencesValidator;\r
39     private TCATestAppPreferences tcaTestAppPreferences;\r
40 \r
41     @Before\r
42     public void before() {\r
43         tcaPreferencesValidator = new TCAPreferencesValidator();\r
44         tcaTestAppPreferences = getTCATestAppPreferences();\r
45     }\r
46 \r
47     @Test\r
48     public void validateAppSettingsWithValidParameters() throws Exception {\r
49         final GenericValidationResponse<TCAAppPreferences> validationResponse =\r
50                 tcaPreferencesValidator.validateAppSettings(tcaTestAppPreferences);\r
51         assertFalse(validationResponse.hasErrors());\r
52     }\r
53 \r
54     @Test\r
55     public void validateAppSettingsWhenSubscriberHostOrTopicNameIsNotPresent() throws Exception {\r
56         tcaTestAppPreferences.setSubscriberHostName(null);\r
57         tcaTestAppPreferences.setSubscriberTopicName(null);\r
58         final GenericValidationResponse<TCAAppPreferences> validationResponse =\r
59                 tcaPreferencesValidator.validateAppSettings(tcaTestAppPreferences);\r
60         assertTrue(validationResponse.hasErrors());\r
61         assertTrue(validationResponse.getErrorMessages().size() == 2);\r
62     }\r
63 \r
64     @Test\r
65     public void validateAppSettingsWhenPublisherHostOrTopicNameIsNotPresent() throws Exception {\r
66         tcaTestAppPreferences.setPublisherHostName(null);\r
67         tcaTestAppPreferences.setPublisherTopicName(null);\r
68         final GenericValidationResponse<TCAAppPreferences> validationResponse =\r
69                 tcaPreferencesValidator.validateAppSettings(tcaTestAppPreferences);\r
70         assertTrue(validationResponse.hasErrors());\r
71         assertTrue(validationResponse.getErrorMessages().size() == 2);\r
72     }\r
73 \r
74     @Test\r
75     public void validateAppSettingsWhenAAIEnrichmentIsEnabledAndAAIRequiredFieldsAreNotPresent() throws Exception {\r
76         tcaTestAppPreferences.setEnableAAIEnrichment(true);\r
77         tcaTestAppPreferences.setAaiEnrichmentHost(null);\r
78         tcaTestAppPreferences.setAaiVMEnrichmentAPIPath(null);\r
79         tcaTestAppPreferences.setAaiVNFEnrichmentAPIPath(null);\r
80         final GenericValidationResponse<TCAAppPreferences> validationResponse =\r
81                 tcaPreferencesValidator.validateAppSettings(tcaTestAppPreferences);\r
82         assertTrue(validationResponse.hasErrors());\r
83         assertTrue(validationResponse.getErrorMessages().size() == 3);\r
84     }\r
85 \r
86 }\r