Distributing Blueprint to DCAE Dashboard Issue-ID: DCAEGEN2-2385>
[dcaegen2/platform.git] / mod2 / catalog-service / src / test / java / org / onap / dcaegen2 / platform / mod / web / PolicyModelCreateRequestValidationTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  org.onap.dcae
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
10  *
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.dcaegen2.platform.mod.web;
22
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;
28
29 import javax.validation.ConstraintViolation;
30 import javax.validation.Validation;
31 import javax.validation.Validator;
32 import java.util.Set;
33
34 public class PolicyModelCreateRequestValidationTest {
35
36     public Validator validator;
37     private PolicyModelCreateRequest request;
38
39     @BeforeEach
40     public void setup(){
41         validator = Validation.buildDefaultValidatorFactory().getValidator();
42         request = PolicyModelObjectMother.getPolicyModelCreateRequest();
43     }
44
45     @Test
46     void test_pmNameShouldNotBeBlank(){
47         request.setName("");
48         Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request);
49         Assertions.assertThat(violations.size()).isEqualTo(3);
50     }
51
52     @Test
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);
57     }
58
59     @Test
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);
64     }
65
66
67     @Test
68     void test_pmVersionShouldNotBeNull(){
69         request.setVersion("");
70         Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request);
71         Assertions.assertThat(violations.size()).isEqualTo(3);
72
73     }
74
75     @Test
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);
80     }
81
82     @Test
83     void test_pmContentShouldNotBeBlank(){
84         request.setContent("");
85         Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request);
86         Assertions.assertThat(violations.size()).isEqualTo(2);
87     }
88
89     @Test
90     void test_pmOwnerShouldNotBeBlank(){
91         request.setOwner("");
92         Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request);
93         Assertions.assertThat(violations.size()).isEqualTo(2);
94     }
95 }