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.common.utils;
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;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertTrue;
31 * @author Rajiv Singla . Creation Date: 12/12/2016.
33 public class ValidationUtilsTest extends BaseAnalyticsCDAPCommonUnitTest {
36 public void testIsEmptyWhenStringIsNull() throws Exception {
37 assertTrue(ValidationUtils.isEmpty(null));
41 public void testIsEmptyWhenStringIsEmpty() throws Exception {
42 String emptyString = "";
43 assertTrue(ValidationUtils.isEmpty(emptyString));
47 public void testIsEmptyWhenStringIsEmptyWithBlanks() throws Exception {
48 String blankString = " ";
49 assertTrue(ValidationUtils.isEmpty(blankString));
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));
65 public void testValidateSettingsWhenValidationPasses() throws Exception {
66 CDAPTestAppSettings cdapTestAppSettings = new CDAPTestAppSettings();
67 cdapTestAppSettings.setSettingsField("testValue");
68 ValidationUtils.validateSettings(cdapTestAppSettings, new CDAPTestAppSettingsValidator());
71 @Test(expected = CDAPSettingsException.class)
72 public void testValidateSettingsWhenValidationFails() throws Exception {
74 CDAPTestAppSettings cdapTestAppSettings = new CDAPTestAppSettings();
75 cdapTestAppSettings.setSettingsField("");
76 ValidationUtils.validateSettings(cdapTestAppSettings, new CDAPTestAppSettingsValidator());