AAI-2279 coverage of schema-service/aai-schema-gen
[aai/schema-service.git] / aai-schema-gen / src / test / java / org / onap / aai / schemagen / swagger / ApiHttpVerbTest.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.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.junit.runners.Parameterized;
37 import org.junit.runners.Parameterized.Parameters;
38
39 @RunWith(Parameterized.class)
40 public class ApiHttpVerbTest {
41     Api.HttpVerb theVerb = null;
42     List<String> tags;
43     String type;
44     String summary;
45     String operationId;
46     List<String> consumes;
47     List<String> produces;
48     String result;
49
50     /**
51      * Parameters for the test cases all following same pattern.
52      */
53     @Parameters
54     public static Collection<String[]> testConditions() {
55         String inputs[][] = {{"tag1,tag2", "typeA", "summaryB", "operationC", "consumesD,consumesE",
56             "producesF,producesG",
57             "HttpVerb{tags=[tag1, tag2], type='typeA', summary='summaryB', operationId='operationC', consumes=[consumesD, consumesE], produces=[producesF, producesG], responses=[], parameters=[]}"},
58             {"tag11,tag22", "typeAA", "summaryBB", "operationCC", "consumesDD,consumesEE",
59                 "producesFF,producesGG",
60                 "HttpVerb{tags=[tag11, tag22], type='typeAA', summary='summaryBB', operationId='operationCC', consumes=[consumesDD, consumesEE], produces=[producesFF, producesGG], responses=[], parameters=[]}"}};
61         return (Arrays.asList(inputs));
62     }
63
64     /**
65      * Constructor for the test cases all following same pattern.
66      */
67     public ApiHttpVerbTest(String tags, String type, String summary, String operationId,
68         String consumes, String produces, String result) {
69         super();
70         this.tags = Arrays.asList(tags.split(","));
71         this.type = type;
72         this.summary = summary;
73         this.operationId = operationId;
74         this.consumes = Arrays.asList(consumes.split(","));
75         this.produces = Arrays.asList(produces.split(","));
76         this.result = result;
77
78     }
79
80     /**
81      * Initialise the test object.
82      */
83     @Before
84     public void setUp() throws Exception {
85         theVerb = new Api.HttpVerb();
86     }
87
88     /**
89      * Perform the test on the test object.
90      */
91     @Test
92     public void testApiHttpVerb() {
93         theVerb.setTags(this.tags);
94         theVerb.setType(this.type);
95         theVerb.setSummary(this.summary);
96         theVerb.setOperationId(this.operationId);
97         theVerb.setConsumes(this.consumes);
98         theVerb.setProduces(this.produces);
99
100         // other stuff that can be set but not necessarily
101         // included in the toString() output
102         theVerb.setConsumerEnabled(true);
103
104         List<Api.HttpVerb.Response> tmpList1 = new ArrayList<Api.HttpVerb.Response>();
105         theVerb.setResponses(tmpList1);
106
107         List<Map<String, Object>> tmpList2 = new ArrayList<Map<String, Object>>();
108         theVerb.setParameters(tmpList2);
109
110         Map<String, Object> tmpMap1 = new HashMap<String, Object>();
111         theVerb.setBodyParameters(tmpMap1);
112         theVerb.setBodyParametersEnabled(true);
113         theVerb.setParametersEnabled(true);
114         theVerb.setSchemaLink("");
115         theVerb.setSchemaType("");
116         theVerb.setHasReturnSchema(true);
117         theVerb.setReturnSchemaLink("");
118         theVerb.setReturnSchemaObject("");
119
120         assertThat(theVerb.toString(), is(this.result));
121     }
122
123 }