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.TCAPolicyPreferences;
27 import org.onap.dcae.apod.analytics.common.validation.GenericValidationResponse;
28 import org.onap.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;
29 import org.onap.dcae.apod.analytics.model.domain.policy.tca.Threshold;
31 import java.util.Collections;
33 import static org.junit.Assert.assertFalse;
34 import static org.junit.Assert.assertTrue;
37 * @author Rajiv Singla . Creation Date: 12/16/2016.
39 public class TCAPolicyPreferencesValidatorTest extends BaseAnalyticsCDAPTCAUnitTest {
41 private TCAPolicyPreferencesValidator tcaPolicyPreferencesValidator;
42 private TCAPolicyPreferences tcaPolicyPreferences;
45 public void before() {
46 tcaPolicyPreferencesValidator = new TCAPolicyPreferencesValidator();
47 tcaPolicyPreferences = getSampleTCAPolicyPreferences();
51 public void testValidateAppSettingsWhenSettingsAreValid() throws Exception {
52 final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
53 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
54 assertFalse(validationResponse.hasErrors());
58 public void testValidateAppSettingsWhenDomainIsNullAndFunctionRoleIsEmpty() throws Exception {
59 tcaPolicyPreferences.setDomain(null);
60 tcaPolicyPreferences.setMetricsPerEventName(Collections.<MetricsPerEventName>emptyList());
61 final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
62 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
63 assertTrue(validationResponse.hasErrors());
64 assertTrue(validationResponse.getErrorMessages().size() == 2);
68 public void testValidateAppSettingsWhenThresholdIsEmpty() throws Exception {
69 tcaPolicyPreferences.getMetricsPerEventName().get(0).setThresholds(Collections.<Threshold>emptyList());
70 final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
71 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
72 assertTrue(validationResponse.hasErrors());
73 assertTrue(validationResponse.getErrorMessages().size() == 1);
77 public void testValidateAppSettingsWhenThresholdPathIsMissing() throws Exception {
78 tcaPolicyPreferences.getMetricsPerEventName().get(0).getThresholds().get(0).setFieldPath(null);
79 final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
80 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
81 assertTrue(validationResponse.hasErrors());
82 assertTrue(validationResponse.getErrorMessages().size() == 1);