Merge "AAI-1523 Tweak onap-java-formatter.xml"
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / util / 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.util.genxsd;
21
22 import static org.junit.Assert.*;
23
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.Vector;
27
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.junit.runners.Parameterized;
32 import org.junit.runners.Parameterized.Parameters;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 import static org.hamcrest.CoreMatchers.is;
37
38 @RunWith(Parameterized.class)
39 public class NodeGetOperationTest {
40         private static final Logger logger = LoggerFactory.getLogger("NodeGetOperationTest.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 [][] = {
51                 {"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__"},
52                 {"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__",""},
53                 {"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"},
54                 //              {"","ctag-pool","","","",""},
55 //              {"","pserver","","","",""},
56 //              {"","oam-network","","","",""},
57 //              {"","dvs-switch","","","",""},
58 //              {"","availability-zone","","","",""}
59                 };
60                 return Arrays.asList(inputs);
61         }
62         
63         public NodeGetOperationTest(String useOpId, String xmlRootElementName, String tag, String path, String pathParams, String result) {
64                 super();
65                 this.useOpId = useOpId;
66                 this.xmlRootElementName = xmlRootElementName;
67                 this.tag = tag;
68                 this.path = path;
69                 this.pathParams=pathParams;
70                 this.result = result;
71         }
72         @BeforeClass
73         public static void setUpBeforeClass() throws Exception {
74                 String container = "p-interfaces";
75                 String queryProps[] = {
76                 "        - name: interface-name\n          in: query\n          description:\n          required: false\n          type: string",
77                 "        - name: prov-status\n          in: query\n          description:\n          required: false\n          type: string"
78                 };
79                 Vector<String> containerProps = new Vector<String>();
80                 for(String prop : queryProps) {
81                         containerProps.add(prop);
82                 }
83                 NodeGetOperation.addContainerProps(container, containerProps);
84         }
85
86         @Test
87         public void testAddContainerProps() {
88                 String container = this.xmlRootElementName;
89                 String prop = "        - name: "+container+"\n          in: query\n          description:\n          required: false\n          type: string";
90                 Vector<String> queryProps = new Vector<String>();
91                 queryProps.add(prop);
92                 String props=null;
93                 for(String p : queryProps) {
94                         props += "qProp="+p+"\n";
95 //                      logger.debug("qProp="+p);
96                 }
97 //              logger.debug("Done="+this.xmlRootElementName);
98                 NodeGetOperation.addContainerProps(container, queryProps);
99                 assertThat(props+"Done="+this.xmlRootElementName,NodeGetOperation.containers.get(container).get(0), is(prop));
100         }
101
102         @Test
103         public void testToString() {
104                 NodeGetOperation get = new NodeGetOperation(useOpId, xmlRootElementName, tag, path,  pathParams);
105                 String modResult = get.toString();
106                 assertThat(modResult, is(this.result));
107         }
108
109 }