d939a748e95ff2bf8cc82fbefe2a8a202195cc9e
[aai/schema-service.git] / aai-schema-gen / src / test / java / org / onap / aai / schemagen / genxsd / PatchOperationTest.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
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.junit.runners.Parameterized;
33 import org.junit.runners.Parameterized.Parameters;
34 import org.onap.aai.setup.SchemaVersion;
35
36 @RunWith(Parameterized.class)
37 public class PatchOperationTest {
38     private String useOpId;
39     private String xmlRootElementName;
40     private String tag;
41     private String path;
42     private String pathParams;
43     private String result;
44     private static SchemaVersion v = new SchemaVersion("v16");
45
46     @Parameters
47     public static Collection<String[]> testConditions() {
48         String inputs[][] = {{"NetworkGenericVnfsGenericVnf", "generic-vnf", "Network",
49             "/network/generic-vnfs/generic-vnf/{vnf-id}",
50             "        - 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             "    patch:\n      tags:\n        - Network\n      summary: update an existing generic-vnf\n      description: |\n        Update an existing generic-vnf\n        #\n        Note:  Endpoints that are not devoted to object relationships support both PUT and PATCH operations.\n        The PUT operation will entirely replace an existing object.\n        The PATCH operation sends a \"description of changes\" for an existing object.  The entire set of changes must be applied.  An error result means no change occurs.\n        #\n        Other differences between PUT and PATCH are:\n        #\n        - For PATCH, you can send any of the values shown in sample REQUEST body.  There are no required values.\n        - For PATCH, resource-id which is a required REQUEST body element for PUT, must not be sent.\n        - PATCH cannot be used to update relationship elements; there are dedicated PUT operations for this.\n      operationId: UpdateNetworkGenericVnfsGenericVnf\n      consumes:\n        - application/json\n      produces:\n        - application/json\n      responses:\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__        - name: body\n          in: body\n          description: generic-vnf object that needs to be updated.[See Examples](apidocs/aai/relations/v16/NetworkGenericVnfsGenericVnf.json)\n          required: true\n          schema:\n            $ref: \"#/definitions/generic-vnf\"\n"},
52             // if ( StringUtils.isEmpty(tag) )
53             {"GenericVnf", "generic-vnf", "", "/generic-vnf/{vnf-id}",
54                 "        - 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__",
55                 ""},
56             // Test: if ( !path.endsWith("/relationship") && !path.endsWith("}") )
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                 ""},
61             // {"","ctag-pool","","","",""},
62             // {"","pserver","","","",""},
63             // {"","oam-network","","","",""},
64             // {"","dvs-switch","","","",""},
65             // {"","availability-zone","","","",""}
66         };
67         return Arrays.asList(inputs);
68     }
69
70     public PatchOperationTest(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
84     }
85
86     @Test
87     public void testToString() {
88         PatchOperation patch =
89             new PatchOperation(useOpId, xmlRootElementName, tag, path, pathParams, v, "/aai");
90         String modResult = patch.toString();
91         assertThat(modResult, is(this.result));
92     }
93
94 }