2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2020 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.dcaegen2.platform.mod.web;
23 import org.assertj.core.api.Assertions;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
26 import org.onap.dcaegen2.platform.mod.model.restapi.PolicyModelCreateRequest;
27 import org.onap.dcaegen2.platform.mod.model.restapi.PolicyModelUpdateRequest;
28 import org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother;
30 import javax.validation.ConstraintViolation;
31 import javax.validation.Validation;
32 import javax.validation.Validator;
35 public class PolicyModelUpdateRequestValidationTest {
37 public Validator validator;
38 private PolicyModelUpdateRequest request;
42 validator = Validation.buildDefaultValidatorFactory().getValidator();
43 request = PolicyModelObjectMother.getPolicyModelUpdateRequest();
47 void test_pmNameShouldNotBeBlank(){
49 Set<ConstraintViolation<PolicyModelUpdateRequest>> violations = validator.validate(request);
50 Assertions.assertThat(violations.size()).isEqualTo(2);
54 void test_pmNameShouldFollowRegex() throws Exception{
55 request.setName("pm-1");
56 Set<ConstraintViolation<PolicyModelUpdateRequest>> violations = validator.validate(request);
57 Assertions.assertThat(violations.size()).isEqualTo(1);
61 void test_pmNameSizeValidation() throws Exception {
62 request.setName("core-name-should-not-exceed-fifty-chars-core-name-should-not-exceed-fifty-chars");
63 Set<ConstraintViolation<PolicyModelUpdateRequest>> violations = validator.validate(request);
64 Assertions.assertThat(violations.size()).isEqualTo(1);
69 void test_pmVersionShouldNotBeNull(){
70 request.setVersion("1.1.1");
71 Set<ConstraintViolation<PolicyModelUpdateRequest>> violations = validator.validate(request);
72 Assertions.assertThat(violations.size()).isEqualTo(1);
77 void test_pmVersionShouldFollowRegex() throws Exception{
78 request.setContent("1.1.1");
79 Set<ConstraintViolation<PolicyModelUpdateRequest>> violations = validator.validate(request);
80 Assertions.assertThat(violations.size()).isEqualTo(1);