Replace all tab characters in java files with two spaces to remove linter warning
[aai/schema-service.git] / aai-schema-gen / src / test / java / org / onap / aai / schemagen / genxsd / NodeGetOperationTest.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 package org.onap.aai.schemagen.genxsd;
21
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.junit.runners.Parameterized;
26 import org.junit.runners.Parameterized.Parameters;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import java.util.Arrays;
31 import java.util.Collection;
32 import java.util.Vector;
33
34 import static org.hamcrest.CoreMatchers.is;
35 import static org.junit.Assert.assertThat;
36
37 @RunWith(Parameterized.class)
38 public class NodeGetOperationTest {
39   private static final Logger logger = LoggerFactory.getLogger("NodeGetOperationTest.class");
40   private String useOpId;
41   private String xmlRootElementName;
42   private String tag;
43   private String path;
44   private String pathParams;
45   private String result;
46
47   @Parameters
48   public static Collection<String []> testConditions() {
49     String inputs [][] = {
50     {"NetworkGenericVnfsGenericVnf","generic-vnf","Network","/network/generic-vnfs/generic-vnf/{vnf-id}","        - 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__","  /nodes/generic-vnfs/generic-vnf/{vnf-id}:\n    get:\n      tags:\n        - Operations\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\n      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__"},
51     {"GenericVnf","generic-vnf","","/Network/generic-vnf/{vnf-id}","        - 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__",""},
52     {"CloudInfrastructurePserversPserverPInterfaces","p-interfaces","CloudInfrastructure","/cloud-infrastructure/pservers/pserver/{hostname}/p-interfaces","        - name: hostname\n          in: path\n          description: Value from executing hostname on the compute node.\n          required: true\n          type: string\n          example: __HOSTNAME__","  /nodes/p-interfaces?parameter=value[&parameter2=value2]:\n    get:\n      tags:\n        - Operations\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\n      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__\n        - 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"},
53     //    {"","ctag-pool","","","",""},
54 //    {"","pserver","","","",""},
55 //    {"","oam-network","","","",""},
56 //    {"","dvs-switch","","","",""},
57 //    {"","availability-zone","","","",""}
58     };
59     return Arrays.asList(inputs);
60   }
61
62   public NodeGetOperationTest(String useOpId, String xmlRootElementName, String tag, String path, String pathParams, String result) {
63     super();
64     this.useOpId = useOpId;
65     this.xmlRootElementName = xmlRootElementName;
66     this.tag = tag;
67     this.path = path;
68     this.pathParams=pathParams;
69     this.result = result;
70   }
71   @BeforeClass
72   public static void setUpBeforeClass() throws Exception {
73     String container = "p-interfaces";
74     String queryProps[] = {
75     "        - name: interface-name\n          in: query\n          description:\n          required: false\n          type: string",
76     "        - name: prov-status\n          in: query\n          description:\n          required: false\n          type: string"
77     };
78     Vector<String> containerProps = new Vector<String>();
79     for(String prop : queryProps) {
80       containerProps.add(prop);
81     }
82     NodeGetOperation.addContainerProps(container, containerProps);
83   }
84
85   @Test
86   public void testAddContainerProps() {
87     String container = this.xmlRootElementName;
88     String prop = "        - name: "+container+"\n          in: query\n          description:\n          required: false\n          type: string";
89     Vector<String> queryProps = new Vector<String>();
90     queryProps.add(prop);
91     String props=null;
92     for(String p : queryProps) {
93       props += "qProp="+p+"\n";
94 //      logger.debug("qProp="+p);
95     }
96 //    logger.debug("Done="+this.xmlRootElementName);
97     NodeGetOperation.addContainerProps(container, queryProps);
98     assertThat(props+"Done="+this.xmlRootElementName,NodeGetOperation.containers.get(container).get(0), is(prop));
99   }
100
101   @Test
102   public void testToString() {
103     NodeGetOperation get = new NodeGetOperation(useOpId, xmlRootElementName, tag, path,  pathParams);
104     String modResult = get.toString();
105     assertThat(modResult, is(this.result));
106   }
107
108 }