2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.schemagen.swagger;
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.MatcherAssert.assertThat;
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;
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;
39 @RunWith(Parameterized.class)
40 public class ApiHttpVerbTest {
41 Api.HttpVerb theVerb = null;
46 List<String> consumes;
47 List<String> produces;
51 * Parameters for the test cases all following same pattern.
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));
65 * Constructor for the test cases all following same pattern.
67 public ApiHttpVerbTest(String tags, String type, String summary, String operationId,
68 String consumes, String produces, String result) {
70 this.tags = Arrays.asList(tags.split(","));
72 this.summary = summary;
73 this.operationId = operationId;
74 this.consumes = Arrays.asList(consumes.split(","));
75 this.produces = Arrays.asList(produces.split(","));
81 * Initialise the test object.
84 public void setUp() throws Exception {
85 theVerb = new Api.HttpVerb();
89 * Perform the test on the test object.
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);
100 // other stuff that can be set but not necessarily
101 // included in the toString() output
102 theVerb.setConsumerEnabled(true);
104 List<Api.HttpVerb.Response> tmpList1 = new ArrayList<Api.HttpVerb.Response>();
105 theVerb.setResponses(tmpList1);
107 List<Map<String, Object>> tmpList2 = new ArrayList<Map<String, Object>>();
108 theVerb.setParameters(tmpList2);
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("");
120 assertThat(theVerb.toString(), is(this.result));