AAI-2279 coverage of schema-service/aai-schema-gen
[aai/schema-service.git] / aai-schema-gen / src / test / java / org / onap / aai / schemagen / swagger / DefinitionTest.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.ArrayList;
27 import java.util.Arrays;
28 import java.util.Collection;
29 import java.util.List;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.junit.runners.Parameterized;
35 import org.junit.runners.Parameterized.Parameters;
36
37 @RunWith(Parameterized.class)
38 public class DefinitionTest {
39     Definition theDefinition = null;
40     String definitionName;
41     String definitionDescription;
42     String result;
43
44     /**
45      * Parameters for the test cases all following same pattern.
46      */
47     @Parameters
48     public static Collection<String[]> testConditions() {
49         String inputs[][] = {
50             {"name1", "desc1", 
51                 "Definition{definitionName='name1', definitionDescription='desc1', propertyList=[]}"},
52             {"name2", "desc2", 
53                 "Definition{definitionName='name2', definitionDescription='desc2', propertyList=[]}"},
54             {"fake", "random", 
55                 "Definition{definitionName='fake', definitionDescription='random', propertyList=[]}"}};
56         return (Arrays.asList(inputs));
57     }
58
59     /**
60      * Constructor for the test cases all following same pattern.
61      */
62     public DefinitionTest(String definitionName, String definitionDescription, String result) {
63         super();
64         this.definitionName = definitionName;
65         this.definitionDescription = definitionDescription;
66         this.result = result;
67     }
68
69     /**
70      * Initialise the test object.
71      */
72     @Before
73     public void setUp() throws Exception {
74         theDefinition = new Definition();
75     }
76
77     /**
78      * Perform the test on the test object.
79      */
80     @Test
81     public void testDefinitionProperty() {
82         theDefinition.setDefinitionName(this.definitionName);
83         theDefinition.setDefinitionDescription(this.definitionDescription);
84
85         List<Definition.Property> tmpList1 = new ArrayList<Definition.Property>();
86         theDefinition.setPropertyList(tmpList1);
87         assertThat(theDefinition.toString(), is(this.result));
88
89         // other stuff that can be set but not necessarily
90         // included in the toString() output
91         theDefinition.setHasDescription(true);
92         assertThat(theDefinition.isHasDescription(), is(true));
93
94         theDefinition.setSchemaPropertyList(tmpList1);
95         assertThat(theDefinition.getSchemaPropertyList(), is(tmpList1));
96
97         theDefinition.setRegularPropertyList(tmpList1);
98         assertThat(theDefinition.getRegularPropertyList(), is(tmpList1));
99     }
100 }