2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2025 Deutsche Telekom.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.aai.schemagen.genxsd;
25 import com.google.common.collect.Multimap;
26 import org.junit.jupiter.api.BeforeAll;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29 import org.onap.aai.edges.EdgeIngestor;
30 import org.onap.aai.edges.EdgeRule;
31 import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
32 import org.onap.aai.nodes.NodeIngestor;
33 import org.onap.aai.schemagen.SwaggerGenerationConfiguration;
34 import org.onap.aai.schemagen.testutils.TestUtilConfigTranslatorforBusiness;
35 import org.onap.aai.setup.SchemaConfigVersions;
36 import org.onap.aai.setup.SchemaLocationsBean;
37 import org.onap.aai.setup.SchemaVersion;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
42 import org.springframework.test.context.TestPropertySource;
43 import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
44 import org.w3c.dom.Document;
45 import org.w3c.dom.Element;
46 import lombok.SneakyThrows;
48 import java.io.BufferedWriter;
50 import java.io.FileWriter;
51 import java.io.IOException;
52 import java.lang.reflect.Field;
53 import java.lang.reflect.Method;
54 import java.nio.charset.Charset;
55 import java.nio.file.Files;
56 import java.nio.file.Path;
57 import java.nio.file.Paths;
58 import java.util.SortedSet;
59 import java.util.TreeSet;
61 import static org.hamcrest.CoreMatchers.is;
62 import static org.hamcrest.MatcherAssert.assertThat;
63 import static org.junit.jupiter.api.Assertions.*;
66 classes = {SchemaConfigVersions.class, SchemaLocationsBean.class,
67 TestUtilConfigTranslatorforBusiness.class, EdgeIngestor.class, NodeIngestor.class,
68 SwaggerGenerationConfiguration.class
71 @TestPropertySource(properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000"})
72 public class YAMLfromOXMTest {
74 EdgeIngestor edgeIngestor;
77 NodeIngestor nodeIngestor;
78 private static final Logger logger = LoggerFactory.getLogger("YAMLfromOXMTest.class");
79 private static final String OXMFILENAME = "src/test/resources/oxm/business_oxm_v11.xml";
80 private static final String EDGEFILENAME =
81 "src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json";
82 public static AnnotationConfigApplicationContext ctx = null;
83 private static String testXML;
84 protected static final String SERVICE_NAME = "JUNIT";
88 YAMLfromOXM yamlFromOxm;
91 SchemaConfigVersions schemaConfigVersions;
94 public static void setUpBeforeClass() throws Exception {
95 System.setProperty("AJSC_HOME", ".");
96 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
97 System.setProperty("aai.service.name", SERVICE_NAME);
101 public void setUp() throws Exception {
102 XSDElementTest x = new XSDElementTest();
105 logger.debug(testXML);
106 BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
109 BufferedWriter bw1 = new BufferedWriter(new FileWriter(EDGEFILENAME));
110 bw1.write(EdgeDefs());
114 public void setupRelationship() throws Exception {
115 XSDElementTest x = new XSDElementTest();
117 x.setUpRelationship();
120 logger.debug(testXML);
121 BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
126 BufferedWriter bw1 = new BufferedWriter(new FileWriter(EDGEFILENAME));
127 bw1.write(EdgeDefs());
132 public void AtestIngestors() throws EdgeRuleNotFoundException {
133 Multimap<String, EdgeRule> results =
134 edgeIngestor.getAllRules(schemaConfigVersions.getDefaultVersion());
135 SortedSet<String> ss = new TreeSet<String>(results.keySet());
136 for (String key : ss) {
137 results.get(key).stream().filter((i) -> ((!i.isPrivateEdge()))).forEach((i) -> {
138 EdgeDescription ed = new EdgeDescription(i);
139 System.out.println(ed.getRuleKey());
142 Document doc = nodeIngestor.getSchema(schemaConfigVersions.getDefaultVersion());
147 public void testGetDocumentHeader() {
148 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
149 String apiVersion = v.toString();
150 String header = null;
152 yamlFromOxm.setXmlVersion(testXML, v);
153 yamlFromOxm.process();
154 header = yamlFromOxm.getDocumentHeader();
155 } catch (Exception e) {
158 assertThat("Header:\n" + header, header, is(YAMLheader()));
162 public void testProcess() {
163 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
164 String apiVersion = v.toString();
165 String fileContent = null;
167 yamlFromOxm.setXmlVersion(testXML, v);
168 fileContent = yamlFromOxm.process();
169 } catch (Exception e) {
172 assertThat("FileContent-TestProcess:\n" + fileContent, fileContent, is(YAMLresult()));
176 public void testYAMLfromOXMFileVersionFile() throws IOException {
177 String outfileName = "testXML.xml";
178 File XMLfile = new File(outfileName);
179 XMLfile.createNewFile();
180 BufferedWriter bw = null;
181 Charset charset = Charset.forName("UTF-8");
182 Path path = Paths.get(outfileName);
183 bw = Files.newBufferedWriter(path, charset);
186 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
187 String apiVersion = v.toString();
188 String fileContent = null;
190 yamlFromOxm.setXmlVersion(testXML, v);
191 fileContent = yamlFromOxm.process();
192 } catch (Exception e) {
196 assertThat("FileContent-OXMFileVersionFile:\n" + fileContent, fileContent,
201 public void testYAMLfromOXMStringVersionFile() {
202 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
203 String apiVersion = v.toString();
204 String fileContent = null;
206 yamlFromOxm.setXmlVersion(testXML, v);
207 fileContent = yamlFromOxm.process();
208 } catch (Exception e) {
211 assertThat("FileContent-OXMStringVersionFile:\n" + fileContent, fileContent,
216 public void testRelationshipListYAMLfromOXMStringVersionFile() {
219 } catch (Exception e1) {
220 // TODO Auto-generated catch block
221 e1.printStackTrace();
223 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
224 String apiVersion = v.toString();
225 String fileContent = null;
227 yamlFromOxm.setXmlVersion(testXML, v);
228 fileContent = yamlFromOxm.process();
229 } catch (Exception e) {
232 boolean matchFound = fileContent.contains((YAMLRelationshipList()));
233 assertTrue(matchFound, "RelationshipListFormat:\n");
237 public void testAppendDefinitions() {
238 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
239 String apiVersion = v.toString();
240 String definitions = null;
242 yamlFromOxm.setXmlVersion(testXML, v);
243 yamlFromOxm.process();
244 definitions = yamlFromOxm.appendDefinitions();
245 } catch (Exception e) {
248 assertThat("Definitions:\n" + definitions, definitions,
249 is(YAMLdefs() + YAMLdefsAddPatch()));
253 public void testGetXMLRootElementName() {
254 String target = "RootElement=customer";
255 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
256 String apiVersion = v.toString();
257 Element customer = null;
260 yamlFromOxm.setXmlVersion(testXML, v);
261 yamlFromOxm.process();
262 customer = yamlFromOxm.getJavaTypeElementSwagger("Customer");
263 root = yamlFromOxm.getXMLRootElementName(customer);
264 } catch (Exception e) {
267 assertThat("RootElement=" + root, is(target));
271 public void testGetXmlRootElementName() {
272 String target = "RootElement=customer";
273 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
274 String apiVersion = v.toString();
277 yamlFromOxm.setXmlVersion(testXML, v);
278 yamlFromOxm.process();
279 root = yamlFromOxm.getXmlRootElementName("Customer");
280 } catch (Exception e) {
283 assertThat("RootElement=" + root, is(target));
287 public void testGetJavaTypeElementSwagger() {
288 String target = "Element=java-type/Customer";
289 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
290 String apiVersion = v.toString();
291 Element customer = null;
293 yamlFromOxm.setXmlVersion(testXML, v);
294 yamlFromOxm.process();
295 customer = yamlFromOxm.getJavaTypeElementSwagger("Customer");
296 } catch (Exception e) {
299 assertThat("Element=" + customer.getNodeName() + "/" + customer.getAttribute("name"),
303 public String YAMLresult() {
304 StringBuilder sb = new StringBuilder(32368);
305 sb.append(YAMLheader());
306 sb.append(YAMLops());
307 sb.append(YAMLdefs());
308 sb.append(YAMLdefsAddPatch());
309 return sb.toString();
312 public String YAMLheader() {
313 StringBuilder sb = new StringBuilder(1500);
314 sb.append("#").append(OxmFileProcessor.LINE_SEPARATOR).append(
315 "# ============LICENSE_START=======================================================")
316 .append(OxmFileProcessor.LINE_SEPARATOR).append("# org.onap.aai")
317 .append(OxmFileProcessor.LINE_SEPARATOR)
319 "# ================================================================================")
320 .append(OxmFileProcessor.LINE_SEPARATOR)
321 .append("# Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.")
322 .append(OxmFileProcessor.LINE_SEPARATOR)
324 "# ================================================================================")
325 .append(OxmFileProcessor.LINE_SEPARATOR)
327 "# Licensed under the Creative Commons License, Attribution 4.0 Intl. (the \"License\");")
328 .append(OxmFileProcessor.LINE_SEPARATOR)
329 .append("# you may not use this file except in compliance with the License.")
330 .append(OxmFileProcessor.LINE_SEPARATOR)
331 .append("# You may obtain a copy of the License at")
332 .append(OxmFileProcessor.LINE_SEPARATOR).append("# <p>")
333 .append(OxmFileProcessor.LINE_SEPARATOR)
334 .append("# https://creativecommons.org/licenses/by/4.0/")
335 .append(OxmFileProcessor.LINE_SEPARATOR).append("# <p>")
336 .append(OxmFileProcessor.LINE_SEPARATOR)
337 .append("# Unless required by applicable law or agreed to in writing, software")
338 .append(OxmFileProcessor.LINE_SEPARATOR)
339 .append("# distributed under the License is distributed on an \"AS IS\" BASIS,")
340 .append(OxmFileProcessor.LINE_SEPARATOR)
341 .append("# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.")
342 .append(OxmFileProcessor.LINE_SEPARATOR)
343 .append("# See the License for the specific language governing permissions and")
344 .append(OxmFileProcessor.LINE_SEPARATOR).append("# limitations under the License.")
345 .append(OxmFileProcessor.LINE_SEPARATOR)
347 "# ============LICENSE_END=========================================================")
348 .append(OxmFileProcessor.LINE_SEPARATOR).append("#")
349 .append(OxmFileProcessor.LINE_SEPARATOR).append(OxmFileProcessor.LINE_SEPARATOR);
350 sb.append("swagger: \"2.0\"\n");
351 sb.append("info:" + OxmFileProcessor.LINE_SEPARATOR);
352 sb.append(" description: |\n");
354 " [Differences versus the previous schema version](apidocs/aai/aai_swagger_v11.diff)"
355 + OxmFileProcessor.DOUBLE_LINE_SEPARATOR);
357 " This document is best viewed with Firefox or Chrome. Nodes can be found by opening the models link below and finding the node-type. Edge definitions can be found with the node definitions."
358 + OxmFileProcessor.LINE_SEPARATOR);
359 sb.append(" version: \"v11\"" + OxmFileProcessor.LINE_SEPARATOR);
361 " title: Active and Available Inventory REST API" + OxmFileProcessor.LINE_SEPARATOR);
362 sb.append(" license:" + OxmFileProcessor.LINE_SEPARATOR);
363 sb.append(" name: Apache 2.0\n");
364 sb.append(" url: http://www.apache.org/licenses/LICENSE-2.0.html"
365 + OxmFileProcessor.LINE_SEPARATOR);
366 sb.append("host: localhost" + OxmFileProcessor.LINE_SEPARATOR);
367 sb.append("basePath: /aai/v11" + OxmFileProcessor.LINE_SEPARATOR);
368 sb.append("schemes:" + OxmFileProcessor.LINE_SEPARATOR);
369 sb.append(" - https\n");
370 sb.append("paths:" + OxmFileProcessor.LINE_SEPARATOR);
371 return sb.toString();
374 public String YAMLops() {
375 StringBuilder sb = new StringBuilder(16384);
377 " /business/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}:\n");
378 sb.append(" get:\n");
379 sb.append(" tags:\n");
380 sb.append(" - Business\n");
381 sb.append(" summary: returns service-subscription\n");
382 sb.append(" description: returns service-subscription\n");
384 " operationId: getBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
385 sb.append(" produces:\n");
386 sb.append(" - application/json\n");
387 sb.append(" - application/xml\n");
388 sb.append(" responses:\n");
389 sb.append(" \"200\":\n");
390 sb.append(" description: successful operation\n");
391 sb.append(" schema:\n");
392 sb.append(" $ref: \"#/definitions/service-subscription\"\n");
393 sb.append(" \"default\":\n");
394 sb.append(" null parameters:\n");
395 sb.append(" - name: global-customer-id\n");
396 sb.append(" in: path\n");
398 " description: Global customer id used across to uniquely identify customer.\n");
399 sb.append(" required: true\n");
400 sb.append(" type: string\n");
401 sb.append(" - name: service-type\n");
402 sb.append(" in: path\n");
404 " description: Value defined by orchestration to identify this service.\n");
405 sb.append(" required: true\n");
406 sb.append(" type: string\n");
407 sb.append(" put:\n");
408 sb.append(" tags:\n");
409 sb.append(" - Business\n");
410 sb.append(" summary: create or update an existing service-subscription\n");
411 sb.append(" description: |\n");
412 sb.append(" Create or update an existing service-subscription.\n");
415 " Note! This PUT method has a corresponding PATCH method that can be used to update just a few of the fields of an existing object, rather than a full object replacement. An example can be found in the [PATCH section] below\n");
417 " operationId: createOrUpdateBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
418 sb.append(" consumes:\n");
419 sb.append(" - application/json\n");
420 sb.append(" - application/xml\n");
421 sb.append(" produces:\n");
422 sb.append(" - application/json\n");
423 sb.append(" - application/xml\n");
424 sb.append(" responses:\n");
425 sb.append(" \"default\":\n");
426 sb.append(" null parameters:\n");
427 sb.append(" - name: global-customer-id\n");
428 sb.append(" in: path\n");
430 " description: Global customer id used across to uniquely identify customer.\n");
431 sb.append(" required: true\n");
432 sb.append(" type: string\n");
433 sb.append(" - name: service-type\n");
434 sb.append(" in: path\n");
436 " description: Value defined by orchestration to identify this service.\n");
437 sb.append(" required: true\n");
438 sb.append(" type: string\n");
439 sb.append(" - name: body\n");
440 sb.append(" in: body\n");
442 " description: service-subscription object that needs to be created or updated. [Valid relationship examples shown here](apidocs/aai/relations/v11/BusinessCustomersCustomerServiceSubscriptionsServiceSubscription.json)\n");
443 sb.append(" required: true\n");
444 sb.append(" schema:\n");
445 sb.append(" $ref: \"#/definitions/service-subscription\"\n");
446 sb.append(" patch:\n");
447 sb.append(" tags:\n");
448 sb.append(" - Business\n");
449 sb.append(" summary: update an existing service-subscription\n");
450 sb.append(" description: |\n");
451 sb.append(" Update an existing service-subscription\n");
454 " Note: Endpoints that are not devoted to object relationships support both PUT and PATCH operations.\n");
455 sb.append(" The PUT operation will entirely replace an existing object.\n");
457 " 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");
459 sb.append(" Other differences between PUT and PATCH are:\n");
462 " - For PATCH, you can send any of the values shown in sample REQUEST body. There are no required values.\n");
464 " - For PATCH, resource-id which is a required REQUEST body element for PUT, must not be sent.\n");
466 " - PATCH cannot be used to update relationship elements; there are dedicated PUT operations for this.\n");
468 " operationId: UpdateBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
469 sb.append(" consumes:\n");
470 sb.append(" - application/json\n");
471 sb.append(" produces:\n");
472 sb.append(" - application/json\n");
473 sb.append(" responses:\n");
474 sb.append(" \"default\":\n");
475 sb.append(" null parameters:\n");
476 sb.append(" - name: global-customer-id\n");
477 sb.append(" in: path\n");
479 " description: Global customer id used across to uniquely identify customer.\n");
480 sb.append(" required: true\n");
481 sb.append(" type: string\n");
482 sb.append(" - name: service-type\n");
483 sb.append(" in: path\n");
485 " description: Value defined by orchestration to identify this service.\n");
486 sb.append(" required: true\n");
487 sb.append(" type: string\n");
488 sb.append(" - name: body\n");
489 sb.append(" in: body\n");
490 sb.append(" description: service-subscription object that needs to be updated.");
492 "[See Examples](apidocs/aai/relations/v11/BusinessCustomersCustomerServiceSubscriptionsServiceSubscription.json)\n");
493 sb.append(" required: true\n");
494 sb.append(" schema:\n");
495 sb.append(" $ref: \"#/definitions/zzzz-patch-service-subscription\"\n");
496 sb.append(" delete:\n");
497 sb.append(" tags:\n");
498 sb.append(" - Business\n");
499 sb.append(" summary: delete an existing service-subscription\n");
500 sb.append(" description: delete an existing service-subscription\n");
502 " operationId: deleteBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
503 sb.append(" consumes:\n");
504 sb.append(" - application/json\n");
505 sb.append(" - application/xml\n");
506 sb.append(" produces:\n");
507 sb.append(" - application/json\n");
508 sb.append(" - application/xml\n");
509 sb.append(" responses:\n");
510 sb.append(" \"default\":\n");
511 sb.append(" null parameters:\n");
512 sb.append(" - name: global-customer-id\n");
513 sb.append(" in: path\n");
515 " description: Global customer id used across to uniquely identify customer.\n");
516 sb.append(" required: true\n");
517 sb.append(" type: string\n");
518 sb.append(" - name: service-type\n");
519 sb.append(" in: path\n");
521 " description: Value defined by orchestration to identify this service.\n");
522 sb.append(" required: true\n");
523 sb.append(" type: string\n");
524 sb.append(" - name: resource-version\n");
525 sb.append(" in: query\n");
526 sb.append(" description: resource-version for concurrency\n");
527 sb.append(" required: true\n");
528 sb.append(" type: string\n");
529 sb.append(" /business/customers/customer/{global-customer-id}/service-subscriptions:\n");
530 sb.append(" get:\n");
531 sb.append(" tags:\n");
532 sb.append(" - Business\n");
533 sb.append(" summary: returns service-subscriptions\n");
534 sb.append(" description: returns service-subscriptions\n");
535 sb.append(" operationId: getBusinessCustomersCustomerServiceSubscriptions\n");
536 sb.append(" produces:\n");
537 sb.append(" - application/json\n");
538 sb.append(" - application/xml\n");
539 sb.append(" responses:\n");
540 sb.append(" \"200\":\n");
541 sb.append(" description: successful operation\n");
542 sb.append(" schema:\n");
543 sb.append(" $ref: \"#/definitions/service-subscriptions\"\n");
544 sb.append(" \"default\":\n");
545 sb.append(" null parameters:\n");
546 sb.append(" - name: global-customer-id\n");
547 sb.append(" in: path\n");
549 " description: Global customer id used across to uniquely identify customer.\n");
550 sb.append(" required: true\n");
551 sb.append(" type: string\n");
552 sb.append(" - name: service-type\n");
553 sb.append(" in: query\n");
554 sb.append(" required: false\n");
555 sb.append(" type: string\n");
556 sb.append(" /business/customers/customer/{global-customer-id}:\n");
557 sb.append(" get:\n");
558 sb.append(" tags:\n");
559 sb.append(" - Business\n");
560 sb.append(" summary: returns customer\n");
561 sb.append(" description: returns customer\n");
562 sb.append(" operationId: getBusinessCustomersCustomer\n");
563 sb.append(" produces:\n");
564 sb.append(" - application/json\n");
565 sb.append(" - application/xml\n");
566 sb.append(" responses:\n");
567 sb.append(" \"200\":\n");
568 sb.append(" description: successful operation\n");
569 sb.append(" schema:\n");
570 sb.append(" $ref: \"#/definitions/customer\"\n");
571 sb.append(" \"default\":\n");
572 sb.append(" null parameters:\n");
573 sb.append(" - name: global-customer-id\n");
574 sb.append(" in: path\n");
576 " description: Global customer id used across to uniquely identify customer.\n");
577 sb.append(" required: true\n");
578 sb.append(" type: string\n");
579 sb.append(" put:\n");
580 sb.append(" tags:\n");
581 sb.append(" - Business\n");
582 sb.append(" summary: create or update an existing customer\n");
583 sb.append(" description: |\n");
584 sb.append(" Create or update an existing customer.\n");
587 " Note! This PUT method has a corresponding PATCH method that can be used to update just a few of the fields of an existing object, rather than a full object replacement. An example can be found in the [PATCH section] below\n");
588 sb.append(" operationId: createOrUpdateBusinessCustomersCustomer\n");
589 sb.append(" consumes:\n");
590 sb.append(" - application/json\n");
591 sb.append(" - application/xml\n");
592 sb.append(" produces:\n");
593 sb.append(" - application/json\n");
594 sb.append(" - application/xml\n");
595 sb.append(" responses:\n");
596 sb.append(" \"default\":\n");
597 sb.append(" null parameters:\n");
598 sb.append(" - name: global-customer-id\n");
599 sb.append(" in: path\n");
601 " description: Global customer id used across to uniquely identify customer.\n");
602 sb.append(" required: true\n");
603 sb.append(" type: string\n");
604 sb.append(" - name: body\n");
605 sb.append(" in: body\n");
607 " description: customer object that needs to be created or updated. [Valid relationship examples shown here](apidocs/aai/relations/v11/BusinessCustomersCustomer.json)\n");
608 sb.append(" required: true\n");
609 sb.append(" schema:\n");
610 sb.append(" $ref: \"#/definitions/customer\"\n");
611 sb.append(" patch:\n");
612 sb.append(" tags:\n");
613 sb.append(" - Business\n");
614 sb.append(" summary: update an existing customer\n");
615 sb.append(" description: |\n");
616 sb.append(" Update an existing customer\n");
619 " Note: Endpoints that are not devoted to object relationships support both PUT and PATCH operations.\n");
620 sb.append(" The PUT operation will entirely replace an existing object.\n");
622 " 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");
624 sb.append(" Other differences between PUT and PATCH are:\n");
627 " - For PATCH, you can send any of the values shown in sample REQUEST body. There are no required values.\n");
629 " - For PATCH, resource-id which is a required REQUEST body element for PUT, must not be sent.\n");
631 " - PATCH cannot be used to update relationship elements; there are dedicated PUT operations for this.\n");
632 sb.append(" operationId: UpdateBusinessCustomersCustomer\n");
633 sb.append(" consumes:\n");
634 sb.append(" - application/json\n");
635 sb.append(" produces:\n");
636 sb.append(" - application/json\n");
637 sb.append(" responses:\n");
638 sb.append(" \"default\":\n");
639 sb.append(" null parameters:\n");
640 sb.append(" - name: global-customer-id\n");
641 sb.append(" in: path\n");
643 " description: Global customer id used across to uniquely identify customer.\n");
644 sb.append(" required: true\n");
645 sb.append(" type: string\n");
646 sb.append(" - name: body\n");
647 sb.append(" in: body\n");
648 sb.append(" description: customer object that needs to be updated.");
649 sb.append("[See Examples](apidocs/aai/relations/v11/BusinessCustomersCustomer.json)\n");
650 sb.append(" required: true\n");
651 sb.append(" schema:\n");
652 sb.append(" $ref: \"#/definitions/zzzz-patch-customer\"\n");
653 sb.append(" delete:\n");
654 sb.append(" tags:\n");
655 sb.append(" - Business\n");
656 sb.append(" summary: delete an existing customer\n");
657 sb.append(" description: delete an existing customer\n");
658 sb.append(" operationId: deleteBusinessCustomersCustomer\n");
659 sb.append(" consumes:\n");
660 sb.append(" - application/json\n");
661 sb.append(" - application/xml\n");
662 sb.append(" produces:\n");
663 sb.append(" - application/json\n");
664 sb.append(" - application/xml\n");
665 sb.append(" responses:\n");
666 sb.append(" \"default\":\n");
667 sb.append(" null parameters:\n");
668 sb.append(" - name: global-customer-id\n");
669 sb.append(" in: path\n");
671 " description: Global customer id used across to uniquely identify customer.\n");
672 sb.append(" required: true\n");
673 sb.append(" type: string\n");
674 sb.append(" - name: resource-version\n");
675 sb.append(" in: query\n");
676 sb.append(" description: resource-version for concurrency\n");
677 sb.append(" required: true\n");
678 sb.append(" type: string\n");
679 sb.append(" /business/customers:\n");
680 sb.append(" get:\n");
681 sb.append(" tags:\n");
682 sb.append(" - Business\n");
683 sb.append(" summary: returns customers\n");
684 sb.append(" description: returns customers\n");
685 sb.append(" operationId: getBusinessCustomers\n");
686 sb.append(" produces:\n");
687 sb.append(" - application/json\n");
688 sb.append(" - application/xml\n");
689 sb.append(" responses:\n");
690 sb.append(" \"200\":\n");
691 sb.append(" description: successful operation\n");
692 sb.append(" schema:\n");
693 sb.append(" $ref: \"#/definitions/customers\"\n");
694 sb.append(" \"default\":\n");
695 sb.append(" null parameters:\n");
696 sb.append(" - name: global-customer-id\n");
697 sb.append(" in: query\n");
698 sb.append(" required: false\n");
699 sb.append(" type: string\n");
700 sb.append(" - name: subscriber-name\n");
701 sb.append(" in: query\n");
702 sb.append(" required: false\n");
703 sb.append(" type: string\n");
704 sb.append(" - name: subscriber-type\n");
705 sb.append(" in: query\n");
706 sb.append(" required: false\n");
707 sb.append(" type: string\n");
708 return sb.toString();
711 public String YAMLdefs() {
712 StringBuilder sb = new StringBuilder(8092);
713 sb.append("definitions:\n");
714 sb.append(" business:\n");
715 sb.append(" description: |\n");
716 sb.append(" Namespace for business related constructs\n");
717 sb.append(" properties:\n");
718 sb.append(" customers:\n");
719 sb.append(" type: object\n");
720 sb.append(" properties:\n");
721 sb.append(" customer:\n");
722 sb.append(" type: array\n");
723 sb.append(" items:\n");
724 sb.append(" $ref: \"#/definitions/customer\"\n");
725 sb.append(" customer:\n");
726 sb.append(" description: |\n");
727 sb.append(" customer identifiers to provide linkage back to BSS information.\n");
728 sb.append(" ###### Related Nodes\n");
730 " - FROM service-subscription (CHILD of customer, service-subscription BelongsTo customer, MANY2ONE)(1)\n");
732 sb.append(" -(1) IF this CUSTOMER node is deleted, this FROM node is DELETED also\n");
733 sb.append(" required:\n");
734 sb.append(" - global-customer-id\n");
735 sb.append(" - subscriber-name\n");
736 sb.append(" - subscriber-type\n");
737 sb.append(" properties:\n");
738 sb.append(" global-customer-id:\n");
739 sb.append(" type: string\n");
741 " description: Global customer id used across to uniquely identify customer.\n");
742 sb.append(" subscriber-name:\n");
743 sb.append(" type: string\n");
745 " description: Subscriber name, an alternate way to retrieve a customer.\n");
746 sb.append(" subscriber-type:\n");
747 sb.append(" type: string\n");
749 " description: Subscriber type, a way to provide VID with only the INFRA customers.\n");
750 sb.append(" resource-version:\n");
751 sb.append(" type: string\n");
753 " description: Used for optimistic concurrency. Must be empty on create, valid on update and delete.\n");
754 sb.append(" service-subscriptions:\n");
755 sb.append(" type: object\n");
756 sb.append(" properties:\n");
757 sb.append(" service-subscription:\n");
758 sb.append(" type: array\n");
759 sb.append(" items:\n");
760 sb.append(" $ref: \"#/definitions/service-subscription\"\n");
761 sb.append(" customers:\n");
762 sb.append(" description: |\n");
764 " Collection of customer identifiers to provide linkage back to BSS information.\n");
765 sb.append(" properties:\n");
766 sb.append(" customer:\n");
767 sb.append(" type: array\n");
768 sb.append(" items: \n");
769 sb.append(" $ref: \"#/definitions/customer\"\n");
770 sb.append(" inventory:\n");
771 sb.append(" properties:\n");
772 sb.append(" business:\n");
773 sb.append(" type: object\n");
774 sb.append(" $ref: \"#/definitions/business\"\n");
775 sb.append(" nodes:" + OxmFileProcessor.LINE_SEPARATOR);
776 sb.append(" properties:" + OxmFileProcessor.LINE_SEPARATOR);
777 sb.append(" inventory-item-data:" + OxmFileProcessor.LINE_SEPARATOR);
778 sb.append(" type: array" + OxmFileProcessor.LINE_SEPARATOR);
779 sb.append(" items:" + OxmFileProcessor.LINE_SEPARATOR);
780 sb.append(" $ref: \"#/definitions/inventory-item-data\""
781 + OxmFileProcessor.LINE_SEPARATOR);
782 sb.append(" service-subscription:\n");
783 sb.append(" description: |\n");
784 sb.append(" Object that group service instances.\n");
785 sb.append(" ###### Related Nodes\n");
787 " - TO customer (PARENT of service-subscription, service-subscription BelongsTo customer, MANY2ONE)(4)\n");
788 sb.append(" - TO tenant( service-subscription Uses tenant, MANY2MANY)\n");
790 " - FROM service-instance (CHILD of service-subscription, service-instance BelongsTo service-subscription, MANY2ONE)(1)\n");
793 " -(1) IF this SERVICE-SUBSCRIPTION node is deleted, this FROM node is DELETED also\n");
795 " -(4) IF this TO node is deleted, this SERVICE-SUBSCRIPTION is DELETED also\n");
796 sb.append(" required:\n");
797 sb.append(" - service-type\n");
798 sb.append(" properties:\n");
799 sb.append(" service-type:\n");
800 sb.append(" type: string\n");
802 " description: Value defined by orchestration to identify this service.\n");
803 sb.append(" temp-ub-sub-account-id:\n");
804 sb.append(" type: string\n");
806 " description: This property will be deleted from A&AI in the near future. Only stop gap solution.\n");
807 sb.append(" resource-version:\n");
808 sb.append(" type: string\n");
810 " description: Used for optimistic concurrency. Must be empty on create, valid on update and delete.\n");
811 sb.append(" service-subscriptions:\n");
812 sb.append(" description: |\n");
813 sb.append(" Collection of objects that group service instances.\n");
814 sb.append(" properties:\n");
815 sb.append(" service-subscription:\n");
816 sb.append(" type: array\n");
817 sb.append(" items: \n");
818 sb.append(" $ref: \"#/definitions/service-subscription\"\n");
819 return sb.toString();
822 public String YAMLdefsAddPatch() {
823 StringBuilder sb = new StringBuilder(8092);
824 sb.append(" zzzz-patch-customer:\n");
825 sb.append(" description: |\n");
826 sb.append(" customer identifiers to provide linkage back to BSS information.\n");
827 sb.append(" ###### Related Nodes\n");
829 " - FROM service-subscription (CHILD of customer, service-subscription BelongsTo customer, MANY2ONE)(1)\n");
831 sb.append(" -(1) IF this CUSTOMER node is deleted, this FROM node is DELETED also\n");
832 sb.append(" properties:\n");
833 sb.append(" global-customer-id:\n");
834 sb.append(" type: string\n");
836 " description: Global customer id used across to uniquely identify customer.\n");
837 sb.append(" subscriber-name:\n");
838 sb.append(" type: string\n");
840 " description: Subscriber name, an alternate way to retrieve a customer.\n");
841 sb.append(" subscriber-type:\n");
842 sb.append(" type: string\n");
844 " description: Subscriber type, a way to provide VID with only the INFRA customers.\n");
845 sb.append(" zzzz-patch-service-subscription:\n");
846 sb.append(" description: |\n");
847 sb.append(" Object that group service instances.\n");
848 sb.append(" ###### Related Nodes\n");
850 " - TO customer (PARENT of service-subscription, service-subscription BelongsTo customer, MANY2ONE)(4)\n");
851 sb.append(" - TO tenant( service-subscription Uses tenant, MANY2MANY)\n");
853 " - FROM service-instance (CHILD of service-subscription, service-instance BelongsTo service-subscription, MANY2ONE)(1)\n");
856 " -(1) IF this SERVICE-SUBSCRIPTION node is deleted, this FROM node is DELETED also\n");
858 " -(4) IF this TO node is deleted, this SERVICE-SUBSCRIPTION is DELETED also\n");
859 sb.append(" properties:\n");
860 sb.append(" service-type:\n");
861 sb.append(" type: string\n");
863 " description: Value defined by orchestration to identify this service.\n");
864 sb.append(" temp-ub-sub-account-id:\n");
865 sb.append(" type: string\n");
867 " description: This property will be deleted from A&AI in the near future. Only stop gap solution.\n");
868 return sb.toString();
871 public String YAMLRelationshipList() {
872 StringBuilder sb = new StringBuilder(8092);
873 sb.append(" relationship-list:\n");
874 sb.append(" properties:\n");
875 sb.append(" relationship:\n");
876 sb.append(" type: object\n");
877 sb.append(" $ref: \"#/definitions/relationship\"\n");
878 return sb.toString();
881 public static String EdgeDefs() {
882 StringBuilder sb = new StringBuilder(8092);
883 sb.append("{\n" + " \"rules\": [\n");
885 sb.append(" \"from\": \"service-subscription\",\n");
886 sb.append(" \"to\": \"customer\",\n"
887 + " \"label\": \"org.onap.relationships.inventory.BelongsTo\",\n"
888 + " \"direction\": \"OUT\",\n" + " \"multiplicity\": \"MANY2ONE\",\n"
889 + " \"contains-other-v\": \"!${direction}\",\n"
890 + " \"delete-other-v\": \"!${direction}\",\n"
891 + " \"prevent-delete\": \"NONE\",\n" + " \"default\": \"true\",\n"
892 + " \"description\":\"\"\n");
894 sb.append(" {\n" + " \"from\": \"service-instance\",\n"
895 + " \"to\": \"service-subscription\",\n"
896 + " \"label\": \"org.onap.relationships.inventory.BelongsTo\",\n"
897 + " \"direction\": \"OUT\",\n" + " \"multiplicity\": \"MANY2ONE\",\n"
898 + " \"contains-other-v\": \"!${direction}\",\n"
899 + " \"delete-other-v\": \"!${direction}\",\n"
900 + " \"prevent-delete\": \"NONE\",\n" + " \"default\": \"true\",\n"
901 + " \"description\":\"\"\n" + " },\n");
902 sb.append(" {\n" + " \"from\": \"service-subscription\",\n"
903 + " \"to\": \"tenant\",\n"
904 + " \"label\": \"org.onap.relationships.inventory.Uses\",\n"
905 + " \"direction\": \"OUT\",\n" + " \"multiplicity\": \"MANY2MANY\",\n"
906 + " \"contains-other-v\": \"NONE\",\n" + " \"delete-other-v\": \"NONE\",\n"
907 + " \"prevent-delete\": \"NONE\",\n" + " \"default\": \"true\",\n"
908 + " \"description\":\"\"\n" + " }");
909 sb.append(" ]\n" + "}\n");
910 return sb.toString();
914 public void testInvalidTopLevelTag_Actions_ShouldReturnFalse() {
915 String invalidTag = "Actions";
916 Boolean result = yamlFromOxm.validTag(invalidTag);
921 public void testValidTagNull() {
922 assertFalse(yamlFromOxm.validTag(null));
928 public void testSetVersion() {
929 SchemaVersion validVersion = new SchemaVersion("v1");
931 Method setVersionMethod = YAMLfromOXM.class.getDeclaredMethod("setVersion", SchemaVersion.class);
932 setVersionMethod.setAccessible(true);
933 setVersionMethod.invoke(yamlFromOxm, validVersion);
935 Field versionField = YAMLfromOXM.class.getSuperclass().getDeclaredField("v");
936 versionField.setAccessible(true);
938 Object actualVersion = versionField.get(yamlFromOxm);
939 assertEquals("v1", actualVersion.toString());
944 public void testSetOxmVersion() {
945 SchemaVersion validVersion = new SchemaVersion("v1");
946 File oxmFile = new File("path/to/oxm/file");
948 Method setOxmVersionMethod = YAMLfromOXM.class.getDeclaredMethod("setOxmVersion", File.class, SchemaVersion.class);
949 setOxmVersionMethod.setAccessible(true);
950 setOxmVersionMethod.invoke(yamlFromOxm, oxmFile, validVersion);
952 Field versionField = YAMLfromOXM.class.getSuperclass().getDeclaredField("v");
953 versionField.setAccessible(true);
954 Object actualVersion = versionField.get(yamlFromOxm);
955 assertEquals("v1", actualVersion.toString());
957 Field oxmFileField = YAMLfromOXM.class.getSuperclass().getDeclaredField("oxmFile");
958 oxmFileField.setAccessible(true);
959 Object actualFile = oxmFileField.get(yamlFromOxm);
960 assertEquals(oxmFile, actualFile);