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