Distributing Blueprint to DCAE Dashboard Issue-ID: DCAEGEN2-2385>
[dcaegen2/platform.git] / mod2 / catalog-service / src / test / java / org / onap / dcaegen2 / platform / mod / web / PolicyModelUpdateRequestValidationTest.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.model.restapi.PolicyModelUpdateRequest;
28 import org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother;
29
30 import javax.validation.ConstraintViolation;
31 import javax.validation.Validation;
32 import javax.validation.Validator;
33 import java.util.Set;
34
35 public class PolicyModelUpdateRequestValidationTest {
36
37     public Validator validator;
38     private PolicyModelUpdateRequest request;
39
40     @BeforeEach
41     public void setup(){
42         validator = Validation.buildDefaultValidatorFactory().getValidator();
43         request = PolicyModelObjectMother.getPolicyModelUpdateRequest();
44     }
45
46     @Test
47     void test_pmNameShouldNotBeBlank(){
48         request.setName("");
49         Set<ConstraintViolation<PolicyModelUpdateRequest>> violations = validator.validate(request);
50         Assertions.assertThat(violations.size()).isEqualTo(2);
51     }
52
53     @Test
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);
58     }
59
60     @Test
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);
65     }
66
67
68     @Test
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);
73
74     }
75
76     @Test
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);
81     }
82
83 }