Initial TCA commit into DCAEGEN2
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-common / src / test / java / org / openecomp / dcae / apod / analytics / cdap / common / utils / ValidationUtilsTest.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.common.utils;
22
23 import org.junit.Test;
24 import org.openecomp.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest;
25 import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;
26
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertTrue;
29
30 /**
31  * @author Rajiv Singla . Creation Date: 12/12/2016.
32  */
33 public class ValidationUtilsTest extends BaseAnalyticsCDAPCommonUnitTest {
34
35     @Test
36     public void testIsEmptyWhenStringIsNull() throws Exception {
37         assertTrue(ValidationUtils.isEmpty(null));
38     }
39
40     @Test
41     public void testIsEmptyWhenStringIsEmpty() throws Exception {
42         String emptyString = "";
43         assertTrue(ValidationUtils.isEmpty(emptyString));
44     }
45
46     @Test
47     public void testIsEmptyWhenStringIsEmptyWithBlanks() throws Exception {
48         String blankString = "   ";
49         assertTrue(ValidationUtils.isEmpty(blankString));
50     }
51
52
53     @Test
54     public void testIsNotPresent() throws Exception {
55         assertFalse(ValidationUtils.isPresent(null));
56         String emptyString = "";
57         assertFalse(ValidationUtils.isPresent(emptyString));
58         String blankString = "   ";
59         assertFalse(ValidationUtils.isPresent(blankString));
60         String validString = "SomeValue";
61         assertTrue(ValidationUtils.isPresent(validString));
62     }
63
64     @Test
65     public void testValidateSettingsWhenValidationPasses() throws Exception {
66         CDAPTestAppSettings cdapTestAppSettings = new CDAPTestAppSettings();
67         cdapTestAppSettings.setSettingsField("testValue");
68         ValidationUtils.validateSettings(cdapTestAppSettings, new CDAPTestAppSettingsValidator());
69     }
70
71     @Test(expected = CDAPSettingsException.class)
72     public void testValidateSettingsWhenValidationFails() throws Exception {
73
74         CDAPTestAppSettings cdapTestAppSettings = new CDAPTestAppSettings();
75         cdapTestAppSettings.setSettingsField("");
76         ValidationUtils.validateSettings(cdapTestAppSettings, new CDAPTestAppSettingsValidator());
77     }
78
79 }
80