AAI-2279 coverage of schema-service/aai-schema-gen
[aai/schema-service.git] / aai-schema-gen / src / test / java / org / onap / aai / schemagen / swagger / DefinitionPropertyTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2019 Huawei Technologies (Australia) Pty Ltd. 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.aai.schemagen.swagger;
22
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.MatcherAssert.assertThat;
25
26 import java.util.Arrays;
27 import java.util.Collection;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.junit.runners.Parameterized;
33 import org.junit.runners.Parameterized.Parameters;
34
35 @RunWith(Parameterized.class)
36 public class DefinitionPropertyTest {
37     Definition.Property theProperty = null;
38     String propertyName;
39     String propertyType;
40     String propertyReference;
41     String result;
42
43     /**
44      * Parameters for the test cases all following same pattern.
45      */
46     @Parameters
47     public static Collection<String[]> testConditions() {
48         String inputs[][] = {
49             {"name1", "type1", "ref1",
50                 "Property{propertyName='name1', propertyType='type1', propertyReference='ref1'}"},
51             {"name2", "type2", "ref2",
52                 "Property{propertyName='name2', propertyType='type2', propertyReference='ref2'}"},
53             {"fake", "random", "bluff",
54                 "Property{propertyName='fake', propertyType='random', propertyReference='bluff'}"}};
55         return (Arrays.asList(inputs));
56     }
57
58     /**
59      * Constructor for the test cases all following same pattern.
60      */
61     public DefinitionPropertyTest(String propertyName, String propertyType,
62         String propertyReference, String result) {
63         super();
64         this.propertyName = propertyName;
65         this.propertyType = propertyType;
66         this.propertyReference = propertyReference;
67         this.result = result;
68     }
69
70     /**
71      * Initialise the test object.
72      */
73     @Before
74     public void setUp() throws Exception {
75         theProperty = new Definition.Property();
76     }
77
78     /**
79      * Perform the test on the test object.
80      */
81     @Test
82     public void testDefinitionProperty() {
83         theProperty.setPropertyName(this.propertyName);
84         theProperty.setPropertyType(this.propertyType);
85         theProperty.setPropertyReference(this.propertyReference);
86         assertThat(theProperty.toString(), is(this.result));
87
88         // other stuff that can be set but not necessarily
89         // included in the toString() output
90         theProperty.setHasType(true);
91         assertThat(theProperty.isHasType(), is(true));
92
93         theProperty.setRequired(true);
94         assertThat(theProperty.isRequired(), is(true));
95
96         theProperty.setHasPropertyReference(true);
97         assertThat(theProperty.isHasPropertyReference(), is(true));
98
99         theProperty.setPropertyReferenceObjectName("someName");
100         assertThat(theProperty.getPropertyReferenceObjectName(), is("someName"));
101
102         theProperty.setPropertyDescription("some description");
103         assertThat(theProperty.getPropertyDescription(), is("some description"));
104
105         theProperty.setHasPropertyDescription(true);
106         assertThat(theProperty.isHasPropertyDescription(), is(true));
107     }
108 }