2 * ===============================LICENSE_START======================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============================LICENSE_END===========================================
\r
21 package org.openecomp.dcae.apod.analytics.cdap.tca.validator;
\r
23 import org.junit.Before;
\r
24 import org.junit.Test;
\r
25 import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
\r
26 import org.openecomp.dcae.apod.analytics.cdap.tca.settings.TCAPolicyPreferences;
\r
27 import org.openecomp.dcae.apod.analytics.common.validation.GenericValidationResponse;
\r
28 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;
\r
29 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;
\r
31 import java.util.Collections;
\r
33 import static org.junit.Assert.assertFalse;
\r
34 import static org.junit.Assert.assertTrue;
\r
37 * @author Rajiv Singla . Creation Date: 12/16/2016.
\r
39 public class TCAPolicyPreferencesValidatorTest extends BaseAnalyticsCDAPTCAUnitTest {
\r
41 private TCAPolicyPreferencesValidator tcaPolicyPreferencesValidator;
\r
42 private TCAPolicyPreferences tcaPolicyPreferences;
\r
45 public void before() {
\r
46 tcaPolicyPreferencesValidator = new TCAPolicyPreferencesValidator();
\r
47 tcaPolicyPreferences = getSampleTCAPolicyPreferences();
\r
51 public void testValidateAppSettingsWhenSettingsAreValid() throws Exception {
\r
52 final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
\r
53 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
\r
54 assertFalse(validationResponse.hasErrors());
\r
58 public void testValidateAppSettingsWhenDomainIsNullAndFunctionRoleIsEmpty() throws Exception {
\r
59 tcaPolicyPreferences.setDomain(null);
\r
60 tcaPolicyPreferences.setMetricsPerEventName(Collections.<MetricsPerEventName>emptyList());
\r
61 final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
\r
62 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
\r
63 assertTrue(validationResponse.hasErrors());
\r
64 assertTrue(validationResponse.getErrorMessages().size() == 2);
\r
68 public void testValidateAppSettingsWhenThresholdIsEmpty() throws Exception {
\r
69 tcaPolicyPreferences.getMetricsPerEventName().get(0).setThresholds(Collections.<Threshold>emptyList());
\r
70 final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
\r
71 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
\r
72 assertTrue(validationResponse.hasErrors());
\r
73 assertTrue(validationResponse.getErrorMessages().size() == 1);
\r
77 public void testValidateAppSettingsWhenThresholdPathIsMissing() throws Exception {
\r
78 tcaPolicyPreferences.getMetricsPerEventName().get(0).getThresholds().get(0).setFieldPath(null);
\r
79 final GenericValidationResponse<TCAPolicyPreferences> validationResponse =
\r
80 tcaPolicyPreferencesValidator.validateAppSettings(tcaPolicyPreferences);
\r
81 assertTrue(validationResponse.hasErrors());
\r
82 assertTrue(validationResponse.getErrorMessages().size() == 1);
\r