098b33b5489cb365a77d4c39db5a7b6f8811586f
[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 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.onap.aai.setup.SchemaVersion;
28
29 import java.util.Arrays;
30 import java.util.Collection;
31
32 import static org.hamcrest.CoreMatchers.is;
33 import static org.junit.Assert.assertThat;
34
35 @RunWith(Parameterized.class)
36 public class PatchOperationTest {
37   private String useOpId;
38   private String xmlRootElementName;
39   private String tag;
40   private String path;
41   private String pathParams;
42   private String result;
43   private static SchemaVersion v = new SchemaVersion("v16");
44
45   @Parameters
46   public static Collection<String []> testConditions() {
47     String inputs [][] = {
48     {"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__","    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"},
49 //    if ( StringUtils.isEmpty(tag) )
50     {"GenericVnf","generic-vnf","","/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__",""},
51 //    Test: if ( !path.endsWith("/relationship")  &&  !path.endsWith("}") )
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__",""},
53     //    {"","ctag-pool","","","",""},
54 //    {"","pserver","","","",""},
55 //    {"","oam-network","","","",""},
56 //    {"","dvs-switch","","","",""},
57 //    {"","availability-zone","","","",""}
58     };
59     return Arrays.asList(inputs);
60   }
61
62   public PatchOperationTest(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
74   }
75
76   @Test
77   public void testToString() {
78     PatchOperation patch = new PatchOperation(useOpId, xmlRootElementName, tag, path,  pathParams, v, "/aai" );
79     String modResult = patch.toString();
80     assertThat(modResult, is(this.result));
81   }
82
83 }