2 * ===============================LICENSE_START======================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===========================================
21 package org.onap.dcae.apod.analytics.cdap.tca.validator;
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;
30 import static org.junit.Assert.assertFalse;
31 import static org.junit.Assert.assertTrue;
34 * @author Rajiv Singla . Creation Date: 12/19/2016.
36 public class TCAPreferencesValidatorTest extends BaseAnalyticsCDAPTCAUnitTest {
38 private TCAPreferencesValidator tcaPreferencesValidator;
39 private TCATestAppPreferences tcaTestAppPreferences;
42 public void before() {
43 tcaPreferencesValidator = new TCAPreferencesValidator();
44 tcaTestAppPreferences = getTCATestAppPreferences();
48 public void validateAppSettingsWithValidParameters() throws Exception {
49 final GenericValidationResponse<TCAAppPreferences> validationResponse =
50 tcaPreferencesValidator.validateAppSettings(tcaTestAppPreferences);
51 assertFalse(validationResponse.hasErrors());
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);
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);
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);