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.openecomp.dcae.apod.analytics.cdap.plugins.validator;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
26 import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.dmaap.DMaaPMRSourcePluginConfig;
27 import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.dmaap.TestDMaaPMRSourcePluginConfig;
28 import org.openecomp.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: 1/30/2017.
36 public class DMaaPMRSourcePluginConfigValidatorTest extends BaseAnalyticsCDAPPluginsUnitTest {
38 private TestDMaaPMRSourcePluginConfig sourcePluginConfig;
39 private DMaaPMRSourcePluginConfigValidator sourcePluginConfigValidator;
42 public void before() {
43 sourcePluginConfigValidator = new DMaaPMRSourcePluginConfigValidator();
44 sourcePluginConfig = getTestDMaaPMRSourcePluginConfig();
48 public void validateAppSettingsWithValidDMaaPSourceConfig() throws Exception {
49 final GenericValidationResponse<DMaaPMRSourcePluginConfig> validationResponse =
50 sourcePluginConfigValidator.validateAppSettings(sourcePluginConfig);
51 assertFalse(validationResponse.hasErrors());
56 public void validateAppSettingsWithValidDMaaPSourceConfigWhenHostNameIsNotPresent() throws Exception {
57 sourcePluginConfig.setHostName(null);
58 assertResponseHasErrors(sourcePluginConfig, sourcePluginConfigValidator);
62 public void validateAppSettingsWithValidDMaaPSourceConfigWhenHostPortIsNotPresent() throws Exception {
63 sourcePluginConfig.setPortNumber(null);
64 assertResponseHasErrors(sourcePluginConfig, sourcePluginConfigValidator);
68 public void validateAppSettingsWithValidDMaaPSourceConfigWhenTopicNameIsNotPresent() throws Exception {
69 sourcePluginConfig.setTopicName(null);
70 assertResponseHasErrors(sourcePluginConfig, sourcePluginConfigValidator);
74 public void validateAppSettingsWithValidDMaaPSourcePollingIntervalIsNotPresent() throws Exception {
75 sourcePluginConfig.setPollingInterval(null);
76 assertResponseHasErrors(sourcePluginConfig, sourcePluginConfigValidator);
79 private static void assertResponseHasErrors(final TestDMaaPMRSourcePluginConfig sourcePluginConfig,
80 final DMaaPMRSourcePluginConfigValidator validator) {
81 final GenericValidationResponse validationResponse = validator.validateAppSettings(sourcePluginConfig);
82 assertTrue(validationResponse.hasErrors());