2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.schemagen.genxsd;
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.fail;
27 import static org.mockito.Mockito.*;
28 import static org.onap.aai.schemagen.genxsd.OxmFileProcessor.LINE_SEPARATOR;
29 import static org.springframework.test.util.AssertionErrors.assertNotNull;
31 import java.io.BufferedWriter;
33 import java.io.FileWriter;
34 import java.io.IOException;
35 import java.nio.charset.Charset;
36 import java.nio.file.Files;
37 import java.nio.file.Path;
38 import java.nio.file.Paths;
40 import org.junit.jupiter.api.BeforeAll;
41 import org.junit.jupiter.api.BeforeEach;
42 import org.junit.jupiter.api.Test;
43 import org.onap.aai.edges.EdgeIngestor;
44 import org.onap.aai.nodes.NodeIngestor;
45 import org.onap.aai.schemagen.SwaggerGenerationConfiguration;
46 import org.onap.aai.schemagen.testutils.TestUtilConfigTranslatorforBusiness;
47 import org.onap.aai.setup.SchemaConfigVersions;
48 import org.onap.aai.setup.SchemaLocationsBean;
49 import org.onap.aai.setup.SchemaVersion;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52 import org.springframework.beans.factory.annotation.Autowired;
53 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
54 import org.springframework.test.context.TestPropertySource;
55 import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
56 import org.w3c.dom.Attr;
57 import org.w3c.dom.Element;
58 import org.w3c.dom.NamedNodeMap;
59 import org.w3c.dom.NodeList;
62 classes = {SchemaConfigVersions.class, SchemaLocationsBean.class,
63 TestUtilConfigTranslatorforBusiness.class, EdgeIngestor.class, NodeIngestor.class,
64 SwaggerGenerationConfiguration.class
67 @TestPropertySource(properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000"})
68 public class HTMLfromOXMTest {
69 private static final Logger logger = LoggerFactory.getLogger("HTMLfromOXMTest.class");
70 private static final String OXMFILENAME = "src/test/resources/oxm/business_oxm_v11.xml";
71 public static AnnotationConfigApplicationContext ctx = null;
72 private static String testXML;
73 protected static final String SERVICE_NAME = "JUNIT";
76 HTMLfromOXM htmlFromOxm;
79 SchemaConfigVersions schemaConfigVersions;
82 public static void setUpContext() throws Exception {
87 public static void setupBundleconfig() throws Exception {
88 System.setProperty("AJSC_HOME", ".");
89 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
90 System.setProperty("aai.service.name", SERVICE_NAME);
94 public void setUp() throws Exception {
98 public void setUp(int sbopt) throws Exception {
99 XSDElementTest x = new XSDElementTest();
102 logger.debug(testXML);
103 BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
109 public void testGetDocumentHeader() {
110 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
111 String header = null;
113 htmlFromOxm.setXmlVersion(testXML, v);
114 htmlFromOxm.setSchemaConfigVersions(schemaConfigVersions);
115 header = htmlFromOxm.getDocumentHeader();
116 } catch (Exception e) {
119 logger.debug("Header:");
120 logger.debug(header);
121 assertThat(header, is(HTMLheader()));
125 public void testProcess() {
126 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
127 String fileContent = null;
129 htmlFromOxm.setXmlVersion(testXML, v);
130 fileContent = htmlFromOxm.process();
131 } catch (Exception e) {
134 logger.debug("FileContent-I:");
135 logger.debug(fileContent);
136 assertThat(fileContent, is(HTMLresult(0)));
140 public void testProcessWithCombiningJavaTypes() {
141 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
142 String fileContent = null;
145 htmlFromOxm.setXmlVersion(testXML, v);
146 fileContent = htmlFromOxm.process();
147 } catch (Exception e) {
150 logger.debug("FileContent-I:");
151 logger.debug(fileContent);
152 assertThat(fileContent, is(HTMLresult(1)));
156 public void testHTMLfromOXMFileVersion() throws IOException {
157 String outfileName = "testXML.xml";
158 File XMLfile = new File(outfileName);
159 XMLfile.createNewFile();
160 BufferedWriter bw = null;
161 Charset charset = Charset.forName("UTF-8");
162 Path path = Paths.get(outfileName);
163 bw = Files.newBufferedWriter(path, charset);
166 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
167 String fileContent = null;
169 htmlFromOxm.setXmlVersion(testXML, v);
170 fileContent = htmlFromOxm.process();
171 } catch (Exception e) {
175 logger.debug("FileContent-I:");
176 logger.debug(fileContent);
177 assertThat(fileContent, is(HTMLresult(0)));
181 public void testHTMLfromOXMStringVersion() {
182 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
183 String fileContent = null;
185 htmlFromOxm.setXmlVersion(testXML, v);
186 fileContent = htmlFromOxm.process();
187 } catch (Exception e) {
190 logger.debug("FileContent-II:");
191 logger.debug(fileContent);
192 assertThat(fileContent, is(HTMLresult(0)));
196 public void testProcessJavaTypeElement() {
197 String target = "Element=java-type/Customer";
198 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
199 Element customer = null;
201 htmlFromOxm.setXmlVersion(testXML, v);
202 htmlFromOxm.process();
203 customer = htmlFromOxm.getJavaTypeElementSwagger("Customer");
204 } catch (Exception e) {
207 logger.debug("Element:");
208 logger.debug("Element=" + customer.getNodeName() + "/" + customer.getAttribute("name"));
209 assertThat("Element=" + customer.getNodeName() + "/" + customer.getAttribute("name"),
213 public String HTMLresult() {
214 return HTMLresult(0);
217 public String HTMLresult(int sbopt) {
218 StringBuilder sb = new StringBuilder(32368);
219 sb.append(HTMLheader());
220 sb.append(HTMLdefs(sbopt));
221 return sb.toString();
224 public String HTMLheader() {
225 StringBuilder sb = new StringBuilder(1500);
226 sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
229 "<xs:schema elementFormDefault=\"qualified\" version=\"1.0\" targetNamespace=\"http://org.onap.aai.inventory/v11\" xmlns:tns=\"http://org.onap.aai.inventory/v11\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
230 + LINE_SEPARATOR + "xmlns:jaxb=\"http://java.sun.com/xml/ns/jaxb\""
232 sb.append(" jaxb:version=\"2.1\"" + LINE_SEPARATOR);
234 " xmlns:annox=\"http://annox.dev.java.net\"" + LINE_SEPARATOR);
235 sb.append(" jaxb:extensionBindingPrefixes=\"annox\">"
236 + OxmFileProcessor.DOUBLE_LINE_SEPARATOR);
237 return sb.toString();
240 public String HTMLdefs() {
244 public String HTMLdefs(int sbopt) {
245 StringBuilder sb = new StringBuilder(1500);
246 sb.append(" <xs:element name=\"service-subscription\">" + LINE_SEPARATOR);
247 sb.append(" <xs:complexType>" + LINE_SEPARATOR);
248 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
249 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
251 " <annox:annotate target=\"class\">@org.onap.aai.annotations.Metadata(description=\"Object that group service instances.\",indexedProps=\"service-type\",dependentOn=\"customer\",container=\"service-subscriptions\",crossEntityReference=\"service-instance,service-type\")</annox:annotate>"
253 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
254 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
255 sb.append(" <xs:sequence>" + LINE_SEPARATOR);
256 sb.append(" <xs:element name=\"service-type\" type=\"xs:string\" minOccurs=\"0\">"
258 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
259 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
261 " <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(isKey=true,description=\"Value defined by orchestration to identify this service.\")</annox:annotate>"
263 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
264 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
265 sb.append(" </xs:element>" + LINE_SEPARATOR);
267 " <xs:element name=\"temp-ub-sub-account-id\" type=\"xs:string\" minOccurs=\"0\">"
269 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
270 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
272 " <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(description=\"This property will be deleted from A&AI in the near future. Only stop gap solution.\")</annox:annotate>"
274 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
275 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
276 sb.append(" </xs:element>" + LINE_SEPARATOR);
278 " <xs:element name=\"resource-version\" type=\"xs:string\" minOccurs=\"0\">"
280 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
281 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
283 " <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(description=\"Used for optimistic concurrency. Must be empty on create, valid on update and delete.\")</annox:annotate>"
285 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
286 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
287 sb.append(" </xs:element>" + LINE_SEPARATOR);
288 sb.append(" </xs:sequence>" + LINE_SEPARATOR);
289 sb.append(" </xs:complexType>" + LINE_SEPARATOR);
290 sb.append(" </xs:element>" + LINE_SEPARATOR);
292 " <xs:element name=\"service-subscriptions\">" + LINE_SEPARATOR);
293 sb.append(" <xs:complexType>" + LINE_SEPARATOR);
294 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
295 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
297 " <annox:annotate target=\"class\">@org.onap.aai.annotations.Metadata(description=\"Collection of objects that group service instances.\")</annox:annotate>"
299 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
300 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
301 sb.append(" <xs:sequence>" + LINE_SEPARATOR);
303 " <xs:element ref=\"tns:service-subscription\" minOccurs=\"0\" maxOccurs=\"5000\"/>"
305 sb.append(" </xs:sequence>" + LINE_SEPARATOR);
306 sb.append(" </xs:complexType>" + LINE_SEPARATOR);
307 sb.append(" </xs:element>" + LINE_SEPARATOR);
308 sb.append(" <xs:element name=\"customer\">" + LINE_SEPARATOR);
309 sb.append(" <xs:complexType>" + LINE_SEPARATOR);
310 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
311 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
314 " <annox:annotate target=\"class\">@org.onap.aai.annotations.Metadata(description=\"customer identifiers to provide linkage back to BSS information.\",nameProps=\"subscriber-name\",indexedProps=\"subscriber-name,global-customer-id,subscriber-type\",searchable=\"global-customer-id,subscriber-name\",uniqueProps=\"global-customer-id\",container=\"customers\",namespace=\"business\")</annox:annotate>"
318 " <annox:annotate target=\"class\">@org.onap.aai.annotations.Metadata(description=\"customer identifiers to provide linkage back to BSS information.\",nameProps=\"subscriber-name\",indexedProps=\"subscriber-type,subscriber-name,global-customer-id\",searchable=\"global-customer-id,subscriber-name\",uniqueProps=\"global-customer-id\",container=\"customers\",namespace=\"business\")</annox:annotate>"
321 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
322 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
323 sb.append(" <xs:sequence>" + LINE_SEPARATOR);
325 " <xs:element name=\"global-customer-id\" type=\"xs:string\" minOccurs=\"0\">"
327 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
328 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
330 " <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(isKey=true,description=\"Global customer id used across to uniquely identify customer.\")</annox:annotate>"
332 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
333 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
334 sb.append(" </xs:element>" + LINE_SEPARATOR);
335 sb.append(" <xs:element name=\"subscriber-name\" type=\"xs:string\" minOccurs=\"0\">"
337 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
338 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
340 " <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(description=\"Subscriber name, an alternate way to retrieve a customer.\")</annox:annotate>"
342 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
343 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
344 sb.append(" </xs:element>" + LINE_SEPARATOR);
347 " <xs:element name=\"subscriber-type\" type=\"xs:string\" minOccurs=\"0\">"
349 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
350 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
352 " <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(description=\"Subscriber type, a way to provide VID with only the INFRA customers.\",defaultValue=\"CUST\")</annox:annotate>"
354 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
355 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
356 sb.append(" </xs:element>" + LINE_SEPARATOR);
358 " <xs:element name=\"resource-version\" type=\"xs:string\" minOccurs=\"0\">"
360 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
361 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
363 " <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(description=\"Used for optimistic concurrency. Must be empty on create, valid on update and delete.\")</annox:annotate>"
365 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
366 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
367 sb.append(" </xs:element>" + LINE_SEPARATOR);
370 " <xs:element name=\"resource-version\" type=\"xs:string\" minOccurs=\"0\">"
372 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
373 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
375 " <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(description=\"Used for optimistic concurrency. Must be empty on create, valid on update and delete.\")</annox:annotate>"
377 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
378 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
379 sb.append(" </xs:element>" + LINE_SEPARATOR);
381 " <xs:element name=\"subscriber-type\" type=\"xs:string\" minOccurs=\"0\">"
383 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
384 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
386 " <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(description=\"Subscriber type, a way to provide VID with only the INFRA customers.\",defaultValue=\"CUST\")</annox:annotate>"
388 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
389 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
390 sb.append(" </xs:element>" + LINE_SEPARATOR);
393 sb.append(" <xs:element ref=\"tns:service-subscriptions\" minOccurs=\"0\"/>"
395 sb.append(" </xs:sequence>" + LINE_SEPARATOR);
396 sb.append(" </xs:complexType>" + LINE_SEPARATOR);
397 sb.append(" </xs:element>" + LINE_SEPARATOR);
398 sb.append(" <xs:element name=\"customers\">" + LINE_SEPARATOR);
399 sb.append(" <xs:complexType>" + LINE_SEPARATOR);
400 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
401 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
403 " <annox:annotate target=\"class\">@org.onap.aai.annotations.Metadata(description=\"Collection of customer identifiers to provide linkage back to BSS information.\")</annox:annotate>"
405 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
406 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
407 sb.append(" <xs:sequence>" + LINE_SEPARATOR);
408 sb.append(" <xs:element ref=\"tns:customer\" minOccurs=\"0\" maxOccurs=\"5000\"/>"
410 sb.append(" </xs:sequence>" + LINE_SEPARATOR);
411 sb.append(" </xs:complexType>" + LINE_SEPARATOR);
412 sb.append(" </xs:element>" + LINE_SEPARATOR);
413 sb.append(" <xs:element name=\"business\">" + LINE_SEPARATOR);
414 sb.append(" <xs:complexType>" + LINE_SEPARATOR);
415 sb.append(" <xs:annotation>" + LINE_SEPARATOR);
416 sb.append(" <xs:appinfo>" + LINE_SEPARATOR);
418 " <annox:annotate target=\"class\">@org.onap.aai.annotations.Metadata(description=\"Namespace for business related constructs\")</annox:annotate>"
420 sb.append(" </xs:appinfo>" + LINE_SEPARATOR);
421 sb.append(" </xs:annotation>" + LINE_SEPARATOR);
422 sb.append(" <xs:sequence>" + LINE_SEPARATOR);
423 sb.append(" <xs:element ref=\"tns:customers\" minOccurs=\"0\"/>"
425 sb.append(" </xs:sequence>" + LINE_SEPARATOR);
426 sb.append(" </xs:complexType>" + LINE_SEPARATOR);
427 sb.append(" </xs:element>" + LINE_SEPARATOR);
428 sb.append(" <xs:element name=\"inventory\">" + LINE_SEPARATOR);
429 sb.append(" <xs:complexType>" + LINE_SEPARATOR);
430 sb.append(" <xs:sequence>" + LINE_SEPARATOR);
431 sb.append(" <xs:element ref=\"tns:business\" minOccurs=\"0\"/>"
433 sb.append(" </xs:sequence>" + LINE_SEPARATOR);
434 sb.append(" </xs:complexType>" + LINE_SEPARATOR);
435 sb.append(" </xs:element>" + LINE_SEPARATOR);
436 sb.append("</xs:schema>" + LINE_SEPARATOR);
437 return sb.toString();
441 public void testSetOxmVersion() {
443 File oxmFile = new File(OXMFILENAME);
444 SchemaVersion version = schemaConfigVersions.getAppRootVersion();
448 htmlFromOxm.setOxmVersion(oxmFile, version); // Setting the version
449 // Check the document header which should reflect the version set
450 String header = htmlFromOxm.getDocumentHeader();
451 logger.debug("Header: " + header);
453 // Verify that the version is properly included in the header
454 assertThat(header.contains(version.toString()), is(true)); // Check if version is part of the header
455 } catch (Exception e) {
457 fail("Exception occurred while setting OXM version");
462 public void testSetVersion() {
463 SchemaVersion version = schemaConfigVersions.getAppRootVersion();
466 htmlFromOxm.setVersion(version);
467 // Check if the version is correctly reflected in the document header
468 String header = htmlFromOxm.getDocumentHeader();
469 logger.debug("Header: " + header);
471 // Assert that the version is correctly reflected in the header content
472 assertThat(header.contains(version.toString()), is(true));
473 } catch (Exception e) {
475 fail("Exception occurred while setting the version");
480 public void testIsValidName() {
481 assertThat(htmlFromOxm.isValidName("valid-name"), is(true));
482 assertThat(htmlFromOxm.isValidName("valid123-name"), is(true));
483 assertThat(htmlFromOxm.isValidName("InvalidName"), is(false));
484 assertThat(htmlFromOxm.isValidName("invalid_name"), is(false));
485 assertThat(htmlFromOxm.isValidName("12345"), is(true));
486 assertThat(htmlFromOxm.isValidName(""), is(false));
487 assertThat(htmlFromOxm.isValidName(null), is(false));
491 public void testSkipCheck() {
492 assertThat(htmlFromOxm.skipCheck("model"), is(true));
493 assertThat(htmlFromOxm.skipCheck("eventHeader"), is(true));
494 assertThat(htmlFromOxm.skipCheck("otherAttribute"), is(false));
498 public void testProcessJavaTypeElement_noXmlElements() {
499 // Create a mock Element for the Java type
500 String javaTypeName = "Customer";
501 Element javaTypeElement = mock(Element.class);
503 // Mock parentNodes to simulate presence of a `java-attributes` node
504 NodeList parentNodes = mock(NodeList.class);
505 when(javaTypeElement.getElementsByTagName("java-attributes")).thenReturn(parentNodes);
506 when(parentNodes.getLength()).thenReturn(1); // Simulating one java-attributes element
508 // Mock the java-attributes element
509 Element javaAttributesElement = mock(Element.class);
510 when(parentNodes.item(0)).thenReturn(javaAttributesElement);
512 // Mock "xml-element" inside java-attributes to be an empty NodeList
513 NodeList xmlElementNodes = mock(NodeList.class);
514 when(javaAttributesElement.getElementsByTagName("xml-element")).thenReturn(xmlElementNodes);
515 when(xmlElementNodes.getLength()).thenReturn(0); // No xml-element nodes inside
517 // Mock the xml-root-element element to return the correct root element name
518 NodeList valNodes = mock(NodeList.class);
519 when(javaTypeElement.getElementsByTagName("xml-root-element")).thenReturn(valNodes);
520 when(valNodes.getLength()).thenReturn(1); // Simulating one xml-root-element node
522 // Mock the valElement
523 Element valElement = mock(Element.class);
524 when(valNodes.item(0)).thenReturn(valElement);
526 // Mock getAttributes to return a NamedNodeMap
527 NamedNodeMap attributes = mock(NamedNodeMap.class);
528 when(valElement.getAttributes()).thenReturn(attributes);
530 // Mock getNamedItem("name") to return the correct attribute value "Customer"
531 Attr nameAttr = mock(Attr.class);
532 when(attributes.getNamedItem("name")).thenReturn(nameAttr);
533 when(nameAttr.getNodeValue()).thenReturn("Customer"); // Ensure the value is set to "Customer"
535 // Create a StringBuilder for inventory
536 StringBuilder sbInventory = new StringBuilder();
538 // Call the method that processes the Java type element
539 String result = htmlFromOxm.processJavaTypeElement(javaTypeName, javaTypeElement, sbInventory);
541 // Debugging: Verify the name is correctly set
542 assertNotNull("The name attribute should not be null", nameAttr);
543 assertEquals("Customer", nameAttr.getNodeValue());
545 // Debugging Output: Print the generated XML
546 System.out.println("Generated XML: " + result);
548 // Expected result format (adjusted to match generated XML structure for no xml-element nodes)
549 String expected = " <xs:element name=\"" + null + "\">" + LINE_SEPARATOR
550 + " <xs:complexType>" + LINE_SEPARATOR
551 + " <xs:sequence/>" + LINE_SEPARATOR
552 + " </xs:complexType>" + LINE_SEPARATOR
553 + " </xs:element>" + LINE_SEPARATOR;
555 assertThat(result, is(expected));
557 verify(javaTypeElement, times(1)).getElementsByTagName("java-attributes");
558 verify(javaAttributesElement, times(1)).getElementsByTagName("xml-element");
560 // Check if the generatedJavaType map is updated correctly
561 assertThat(htmlFromOxm.generatedJavaType.containsKey(javaTypeName), is(true));