Add instructions to invoke the linter and code formatter plugins to the README and...
[aai/schema-service.git] / aai-schema-gen / src / test / java / org / onap / aai / schemagen / genxsd / GetOperationTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 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.aai.schemagen.genxsd;
22
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.junit.Assert.assertThat;
25
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.Vector;
29
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.junit.runners.Parameterized;
34 import org.junit.runners.Parameterized.Parameters;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 @RunWith(Parameterized.class)
39 public class GetOperationTest {
40     private static final Logger logger = LoggerFactory.getLogger("GetOperationTest.class");
41     private String useOpId;
42     private String xmlRootElementName;
43     private String tag;
44     private String path;
45     private String pathParams;
46     private String result;
47
48     @Parameters
49     public static Collection<String[]> testConditions() {
50         String inputs[][] = {{"NetworkGenericVnfsGenericVnf", "generic-vnf", "Network",
51             "/network/generic-vnfs/generic-vnf/{vnf-id}",
52             "        - name: vnf-id\n          in: path\n          description: Unique id of VNF.  This is unique across the graph.\n          required: true\n          type: string\n          example: __VNF-ID__",
53             "  /network/generic-vnfs/generic-vnf/{vnf-id}:\n    get:\n      tags:\n        - Network\n      summary: returns generic-vnf\n      description: returns generic-vnf\n      operationId: getNetworkGenericVnfsGenericVnf\n      produces:\n        - application/json\n        - application/xml\n      responses:\n        \"200\":\n          description: successful operation\n          schema:\n              $ref: \"#/definitions/generic-vnf\"\n        \"default\":\n          null      parameters:\n        - name: vnf-id\n          in: path\n          description: Unique id of VNF.  This is unique across the graph.\n          required: true\n          type: string\n          example: __VNF-ID__"},
54             {"GenericVnf", "generic-vnf", "", "/generic-vnf/{vnf-id}",
55                 "        - name: vnf-id\n          in: path\n          description: Unique id of VNF.  This is unique across the graph.\n          required: true\n          type: string\n          example: __VNF-ID__",
56                 ""},
57             {"CloudInfrastructurePserversPserverPInterfaces", "p-interfaces", "CloudInfrastructure",
58                 "/cloud-infrastructure/pservers/pserver/{hostname}/p-interfaces",
59                 "        - name: hostname\n          in: path\n          description: Value from executing hostname on the compute node.\n          required: true\n          type: string\n          example: __HOSTNAME__",
60                 "  /cloud-infrastructure/pservers/pserver/{hostname}/p-interfaces:\n    get:\n      tags:\n        - CloudInfrastructure\n      summary: returns p-interfaces\n      description: returns p-interfaces\n      operationId: getCloudInfrastructurePserversPserverPInterfaces\n      produces:\n        - application/json\n        - application/xml\n      responses:\n        \"200\":\n          description: successful operation\n          schema:\n              $ref: \"#/definitions/p-interfaces\"\n        \"default\":\n          null      parameters:\n        - name: hostname\n          in: path\n          description: Value from executing hostname on the compute node.\n          required: true\n          type: string\n          example: __HOSTNAME__        - name: interface-name\n          in: query\n          description:\n          required: false\n          type: string        - name: prov-status\n          in: query\n          description:\n          required: false\n          type: string"},
61             // {"","ctag-pool","","","",""},
62             // {"","pserver","","","",""},
63             // {"","oam-network","","","",""},
64             // {"","dvs-switch","","","",""},
65             // {"","availability-zone","","","",""}
66         };
67         return Arrays.asList(inputs);
68     }
69
70     public GetOperationTest(String useOpId, String xmlRootElementName, String tag, String path,
71         String pathParams, String result) {
72         super();
73         this.useOpId = useOpId;
74         this.xmlRootElementName = xmlRootElementName;
75         this.tag = tag;
76         this.path = path;
77         this.pathParams = pathParams;
78         this.result = result;
79     }
80
81     @BeforeClass
82     public static void setUpBeforeClass() throws Exception {
83         String container = "p-interfaces";
84         String queryProps[] = {
85             "        - name: interface-name\n          in: query\n          description:\n          required: false\n          type: string",
86             "        - name: prov-status\n          in: query\n          description:\n          required: false\n          type: string"};
87         Vector<String> containerProps = new Vector<String>();
88         for (String prop : queryProps) {
89             containerProps.add(prop);
90         }
91         GetOperation.addContainerProps(container, containerProps);
92     }
93
94     @Test
95     public void testAddContainerProps() {
96         String container = this.xmlRootElementName;
97         String prop = "        - name: " + container
98             + "\n          in: query\n          description:\n          required: false\n          type: string";
99         Vector<String> queryProps = new Vector<String>();
100         queryProps.add(prop);
101         for (String p : queryProps) {
102             logger.debug("qProp=" + p);
103         }
104         logger.debug("Done=" + this.xmlRootElementName);
105         GetOperation.addContainerProps(container, queryProps);
106         assertThat(GetOperation.containers.get(container).get(0), is(prop));
107     }
108
109     @Test
110     public void testToString() {
111         GetOperation get = new GetOperation(useOpId, xmlRootElementName, tag, path, pathParams);
112         String modResult = get.toString();
113         assertThat(modResult, is(this.result));
114     }
115
116 }