9bc79b675b12857b790a14c7f0f64742d1d4297d
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-plugins / src / test / java / org / openecomp / dcae / apod / analytics / cdap / plugins / validator / DMaaPMRSourcePluginConfigValidatorTest.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.openecomp.dcae.apod.analytics.cdap.plugins.validator;
22
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;
29
30 import static org.junit.Assert.assertFalse;
31 import static org.junit.Assert.assertTrue;
32
33 /**
34  * @author Rajiv Singla . Creation Date: 1/30/2017.
35  */
36 public class DMaaPMRSourcePluginConfigValidatorTest extends BaseAnalyticsCDAPPluginsUnitTest {
37
38     private TestDMaaPMRSourcePluginConfig sourcePluginConfig;
39     private DMaaPMRSourcePluginConfigValidator sourcePluginConfigValidator;
40
41     @Before
42     public void before() {
43         sourcePluginConfigValidator = new DMaaPMRSourcePluginConfigValidator();
44         sourcePluginConfig = getTestDMaaPMRSourcePluginConfig();
45     }
46
47     @Test
48     public void validateAppSettingsWithValidDMaaPSourceConfig() throws Exception {
49         final GenericValidationResponse<DMaaPMRSourcePluginConfig> validationResponse =
50                 sourcePluginConfigValidator.validateAppSettings(sourcePluginConfig);
51         assertFalse(validationResponse.hasErrors());
52     }
53
54
55     @Test
56     public void validateAppSettingsWithValidDMaaPSourceConfigWhenHostNameIsNotPresent() throws Exception {
57         sourcePluginConfig.setHostName(null);
58         assertResponseHasErrors(sourcePluginConfig, sourcePluginConfigValidator);
59     }
60
61     @Test
62     public void validateAppSettingsWithValidDMaaPSourceConfigWhenHostPortIsNotPresent() throws Exception {
63         sourcePluginConfig.setPortNumber(null);
64         assertResponseHasErrors(sourcePluginConfig, sourcePluginConfigValidator);
65     }
66
67     @Test
68     public void validateAppSettingsWithValidDMaaPSourceConfigWhenTopicNameIsNotPresent() throws Exception {
69         sourcePluginConfig.setTopicName(null);
70         assertResponseHasErrors(sourcePluginConfig, sourcePluginConfigValidator);
71     }
72
73     @Test
74     public void validateAppSettingsWithValidDMaaPSourcePollingIntervalIsNotPresent() throws Exception {
75         sourcePluginConfig.setPollingInterval(null);
76         assertResponseHasErrors(sourcePluginConfig, sourcePluginConfigValidator);
77     }
78
79     private static void assertResponseHasErrors(final TestDMaaPMRSourcePluginConfig sourcePluginConfig,
80                                                 final DMaaPMRSourcePluginConfigValidator validator) {
81         final GenericValidationResponse validationResponse = validator.validateAppSettings(sourcePluginConfig);
82         assertTrue(validationResponse.hasErrors());
83     }
84
85 }