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.objectmothers.PolicyModelObjectMother;
29 import javax.validation.ConstraintViolation;
30 import javax.validation.Validation;
31 import javax.validation.Validator;
34 public class PolicyModelCreateRequestValidationTest {
36 public Validator validator;
37 private PolicyModelCreateRequest request;
41 validator = Validation.buildDefaultValidatorFactory().getValidator();
42 request = PolicyModelObjectMother.getPolicyModelCreateRequest();
46 void test_pmNameShouldNotBeBlank(){
48 Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request);
49 Assertions.assertThat(violations.size()).isEqualTo(3);
53 void test_pmNameShouldFollowRegex() throws Exception{
54 request.setName("pm-1");
55 Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request);
56 Assertions.assertThat(violations.size()).isEqualTo(1);
60 void test_pmNameSizeValidation() throws Exception {
61 request.setName("core-name-should-not-exceed-fifty-chars-core-name-should-not-exceed-fifty-chars");
62 Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request);
63 Assertions.assertThat(violations.size()).isEqualTo(1);
68 void test_pmVersionShouldNotBeNull(){
69 request.setVersion("");
70 Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request);
71 Assertions.assertThat(violations.size()).isEqualTo(3);
76 void test_pmVersionShouldFollowRegex() throws Exception{
77 request.setContent("1.1.1");
78 Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request);
79 Assertions.assertThat(violations.size()).isEqualTo(1);
83 void test_pmContentShouldNotBeBlank(){
84 request.setContent("");
85 Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request);
86 Assertions.assertThat(violations.size()).isEqualTo(2);
90 void test_pmOwnerShouldNotBeBlank(){
92 Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request);
93 Assertions.assertThat(violations.size()).isEqualTo(2);