Merge "[AAI] Improve test coverage for A&AI component aai-schema-service"
[aai/schema-service.git] / aai-schema-gen / src / test / java / org / onap / aai / schemagen / genxsd / HTMLfromOXMTest.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.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;
30
31 import java.io.BufferedWriter;
32 import java.io.File;
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;
39
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;
60
61 @SpringJUnitConfig(
62     classes = {SchemaConfigVersions.class, SchemaLocationsBean.class,
63         TestUtilConfigTranslatorforBusiness.class, EdgeIngestor.class, NodeIngestor.class,
64         SwaggerGenerationConfiguration.class
65
66     })
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";
74
75     @Autowired
76     HTMLfromOXM htmlFromOxm;
77
78     @Autowired
79     SchemaConfigVersions schemaConfigVersions;
80
81     @BeforeAll
82     public static void setUpContext() throws Exception {
83
84     }
85
86     @BeforeAll
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);
91     }
92
93     @BeforeEach
94     public void setUp() throws Exception {
95         setUp(0);
96     }
97
98     public void setUp(int sbopt) throws Exception {
99         XSDElementTest x = new XSDElementTest();
100         x.setUp(sbopt);
101         testXML = x.testXML;
102         logger.debug(testXML);
103         BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
104         bw.write(testXML);
105         bw.close();
106     }
107
108     @Test
109     public void testGetDocumentHeader() {
110         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
111         String header = null;
112         try {
113             htmlFromOxm.setXmlVersion(testXML, v);
114             htmlFromOxm.setSchemaConfigVersions(schemaConfigVersions);
115             header = htmlFromOxm.getDocumentHeader();
116         } catch (Exception e) {
117             e.printStackTrace();
118         }
119         logger.debug("Header:");
120         logger.debug(header);
121         assertThat(header, is(HTMLheader()));
122     }
123
124     @Test
125     public void testProcess() {
126         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
127         String fileContent = null;
128         try {
129             htmlFromOxm.setXmlVersion(testXML, v);
130             fileContent = htmlFromOxm.process();
131         } catch (Exception e) {
132             e.printStackTrace();
133         }
134         logger.debug("FileContent-I:");
135         logger.debug(fileContent);
136         assertThat(fileContent, is(HTMLresult(0)));
137     }
138
139     @Test
140     public void testProcessWithCombiningJavaTypes() {
141         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
142         String fileContent = null;
143         try {
144             setUp(1);
145             htmlFromOxm.setXmlVersion(testXML, v);
146             fileContent = htmlFromOxm.process();
147         } catch (Exception e) {
148             e.printStackTrace();
149         }
150         logger.debug("FileContent-I:");
151         logger.debug(fileContent);
152         assertThat(fileContent, is(HTMLresult(1)));
153     }
154
155     @Test
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);
164         bw.write(testXML);
165         bw.close();
166         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
167         String fileContent = null;
168         try {
169             htmlFromOxm.setXmlVersion(testXML, v);
170             fileContent = htmlFromOxm.process();
171         } catch (Exception e) {
172             e.printStackTrace();
173         }
174         XMLfile.delete();
175         logger.debug("FileContent-I:");
176         logger.debug(fileContent);
177         assertThat(fileContent, is(HTMLresult(0)));
178     }
179
180     @Test
181     public void testHTMLfromOXMStringVersion() {
182         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
183         String fileContent = null;
184         try {
185             htmlFromOxm.setXmlVersion(testXML, v);
186             fileContent = htmlFromOxm.process();
187         } catch (Exception e) {
188             e.printStackTrace();
189         }
190         logger.debug("FileContent-II:");
191         logger.debug(fileContent);
192         assertThat(fileContent, is(HTMLresult(0)));
193     }
194
195     @Test
196     public void testProcessJavaTypeElement() {
197         String target = "Element=java-type/Customer";
198         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
199         Element customer = null;
200         try {
201             htmlFromOxm.setXmlVersion(testXML, v);
202             htmlFromOxm.process();
203             customer = htmlFromOxm.getJavaTypeElementSwagger("Customer");
204         } catch (Exception e) {
205             e.printStackTrace();
206         }
207         logger.debug("Element:");
208         logger.debug("Element=" + customer.getNodeName() + "/" + customer.getAttribute("name"));
209         assertThat("Element=" + customer.getNodeName() + "/" + customer.getAttribute("name"),
210             is(target));
211     }
212
213     public String HTMLresult() {
214         return HTMLresult(0);
215     }
216
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();
222     }
223
224     public String HTMLheader() {
225         StringBuilder sb = new StringBuilder(1500);
226         sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
227             + LINE_SEPARATOR);
228         sb.append(
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\""
231                 + LINE_SEPARATOR);
232         sb.append("    jaxb:version=\"2.1\"" + LINE_SEPARATOR);
233         sb.append(
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();
238     }
239
240     public String HTMLdefs() {
241         return HTMLdefs(0);
242     }
243
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);
250         sb.append(
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>"
252                 + LINE_SEPARATOR);
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\">"
257             + LINE_SEPARATOR);
258         sb.append("          <xs:annotation>" + LINE_SEPARATOR);
259         sb.append("            <xs:appinfo>" + LINE_SEPARATOR);
260         sb.append(
261             "              <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(isKey=true,description=\"Value defined by orchestration to identify this service.\")</annox:annotate>"
262                 + LINE_SEPARATOR);
263         sb.append("            </xs:appinfo>" + LINE_SEPARATOR);
264         sb.append("          </xs:annotation>" + LINE_SEPARATOR);
265         sb.append("        </xs:element>" + LINE_SEPARATOR);
266         sb.append(
267             "        <xs:element name=\"temp-ub-sub-account-id\" type=\"xs:string\" minOccurs=\"0\">"
268                 + LINE_SEPARATOR);
269         sb.append("          <xs:annotation>" + LINE_SEPARATOR);
270         sb.append("            <xs:appinfo>" + LINE_SEPARATOR);
271         sb.append(
272             "              <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(description=\"This property will be deleted from A&amp;AI in the near future. Only stop gap solution.\")</annox:annotate>"
273                 + LINE_SEPARATOR);
274         sb.append("            </xs:appinfo>" + LINE_SEPARATOR);
275         sb.append("          </xs:annotation>" + LINE_SEPARATOR);
276         sb.append("        </xs:element>" + LINE_SEPARATOR);
277         sb.append(
278             "        <xs:element name=\"resource-version\" type=\"xs:string\" minOccurs=\"0\">"
279                 + LINE_SEPARATOR);
280         sb.append("          <xs:annotation>" + LINE_SEPARATOR);
281         sb.append("            <xs:appinfo>" + LINE_SEPARATOR);
282         sb.append(
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>"
284                 + LINE_SEPARATOR);
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);
291         sb.append(
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);
296         sb.append(
297             "          <annox:annotate target=\"class\">@org.onap.aai.annotations.Metadata(description=\"Collection of objects that group service instances.\")</annox:annotate>"
298                 + LINE_SEPARATOR);
299         sb.append("        </xs:appinfo>" + LINE_SEPARATOR);
300         sb.append("      </xs:annotation>" + LINE_SEPARATOR);
301         sb.append("      <xs:sequence>" + LINE_SEPARATOR);
302         sb.append(
303             "        <xs:element ref=\"tns:service-subscription\" minOccurs=\"0\" maxOccurs=\"5000\"/>"
304                 + LINE_SEPARATOR);
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);
312         if (sbopt == 0) {
313             sb.append(
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>"
315                     + LINE_SEPARATOR);
316         } else {
317             sb.append(
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>"
319                     + LINE_SEPARATOR);
320         }
321         sb.append("        </xs:appinfo>" + LINE_SEPARATOR);
322         sb.append("      </xs:annotation>" + LINE_SEPARATOR);
323         sb.append("      <xs:sequence>" + LINE_SEPARATOR);
324         sb.append(
325             "        <xs:element name=\"global-customer-id\" type=\"xs:string\" minOccurs=\"0\">"
326                 + LINE_SEPARATOR);
327         sb.append("          <xs:annotation>" + LINE_SEPARATOR);
328         sb.append("            <xs:appinfo>" + LINE_SEPARATOR);
329         sb.append(
330             "              <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(isKey=true,description=\"Global customer id used across to uniquely identify customer.\")</annox:annotate>"
331                 + LINE_SEPARATOR);
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\">"
336             + LINE_SEPARATOR);
337         sb.append("          <xs:annotation>" + LINE_SEPARATOR);
338         sb.append("            <xs:appinfo>" + LINE_SEPARATOR);
339         sb.append(
340             "              <annox:annotate target=\"field\">@org.onap.aai.annotations.Metadata(description=\"Subscriber name, an alternate way to retrieve a customer.\")</annox:annotate>"
341                 + LINE_SEPARATOR);
342         sb.append("            </xs:appinfo>" + LINE_SEPARATOR);
343         sb.append("          </xs:annotation>" + LINE_SEPARATOR);
344         sb.append("        </xs:element>" + LINE_SEPARATOR);
345         if (sbopt == 0) {
346             sb.append(
347                 "        <xs:element name=\"subscriber-type\" type=\"xs:string\" minOccurs=\"0\">"
348                     + LINE_SEPARATOR);
349             sb.append("          <xs:annotation>" + LINE_SEPARATOR);
350             sb.append("            <xs:appinfo>" + LINE_SEPARATOR);
351             sb.append(
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>"
353                     + LINE_SEPARATOR);
354             sb.append("            </xs:appinfo>" + LINE_SEPARATOR);
355             sb.append("          </xs:annotation>" + LINE_SEPARATOR);
356             sb.append("        </xs:element>" + LINE_SEPARATOR);
357             sb.append(
358                 "        <xs:element name=\"resource-version\" type=\"xs:string\" minOccurs=\"0\">"
359                     + LINE_SEPARATOR);
360             sb.append("          <xs:annotation>" + LINE_SEPARATOR);
361             sb.append("            <xs:appinfo>" + LINE_SEPARATOR);
362             sb.append(
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>"
364                     + LINE_SEPARATOR);
365             sb.append("            </xs:appinfo>" + LINE_SEPARATOR);
366             sb.append("          </xs:annotation>" + LINE_SEPARATOR);
367             sb.append("        </xs:element>" + LINE_SEPARATOR);
368         } else {
369             sb.append(
370                 "        <xs:element name=\"resource-version\" type=\"xs:string\" minOccurs=\"0\">"
371                     + LINE_SEPARATOR);
372             sb.append("          <xs:annotation>" + LINE_SEPARATOR);
373             sb.append("            <xs:appinfo>" + LINE_SEPARATOR);
374             sb.append(
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>"
376                     + LINE_SEPARATOR);
377             sb.append("            </xs:appinfo>" + LINE_SEPARATOR);
378             sb.append("          </xs:annotation>" + LINE_SEPARATOR);
379             sb.append("        </xs:element>" + LINE_SEPARATOR);
380             sb.append(
381                 "        <xs:element name=\"subscriber-type\" type=\"xs:string\" minOccurs=\"0\">"
382                     + LINE_SEPARATOR);
383             sb.append("          <xs:annotation>" + LINE_SEPARATOR);
384             sb.append("            <xs:appinfo>" + LINE_SEPARATOR);
385             sb.append(
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>"
387                     + LINE_SEPARATOR);
388             sb.append("            </xs:appinfo>" + LINE_SEPARATOR);
389             sb.append("          </xs:annotation>" + LINE_SEPARATOR);
390             sb.append("        </xs:element>" + LINE_SEPARATOR);
391
392         }
393         sb.append("        <xs:element ref=\"tns:service-subscriptions\" minOccurs=\"0\"/>"
394             + LINE_SEPARATOR);
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);
402         sb.append(
403             "          <annox:annotate target=\"class\">@org.onap.aai.annotations.Metadata(description=\"Collection of customer identifiers to provide linkage back to BSS information.\")</annox:annotate>"
404                 + LINE_SEPARATOR);
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\"/>"
409             + LINE_SEPARATOR);
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);
417         sb.append(
418             "          <annox:annotate target=\"class\">@org.onap.aai.annotations.Metadata(description=\"Namespace for business related constructs\")</annox:annotate>"
419                 + LINE_SEPARATOR);
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\"/>"
424             + LINE_SEPARATOR);
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\"/>"
432             + LINE_SEPARATOR);
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();
438     }
439
440     @Test
441     public void testSetOxmVersion() {
442         // Arrange
443         File oxmFile = new File(OXMFILENAME);
444         SchemaVersion version = schemaConfigVersions.getAppRootVersion();
445
446         // Act
447         try {
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);
452
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) {
456             e.printStackTrace();
457             fail("Exception occurred while setting OXM version");
458         }
459     }
460
461     @Test
462     public void testSetVersion() {
463         SchemaVersion version = schemaConfigVersions.getAppRootVersion();
464
465         try {
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);
470
471             // Assert that the version is correctly reflected in the header content
472             assertThat(header.contains(version.toString()), is(true));
473         } catch (Exception e) {
474             e.printStackTrace();
475             fail("Exception occurred while setting the version");
476         }
477     }
478
479     @Test
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));
488     }
489
490     @Test
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));
495     }
496
497     @Test
498     public void testProcessJavaTypeElement_noXmlElements() {
499         // Create a mock Element for the Java type
500         String javaTypeName = "Customer";
501         Element javaTypeElement = mock(Element.class);
502
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
507
508         // Mock the java-attributes element
509         Element javaAttributesElement = mock(Element.class);
510         when(parentNodes.item(0)).thenReturn(javaAttributesElement);
511
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
516
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
521
522         // Mock the valElement
523         Element valElement = mock(Element.class);
524         when(valNodes.item(0)).thenReturn(valElement);
525
526         // Mock getAttributes to return a NamedNodeMap
527         NamedNodeMap attributes = mock(NamedNodeMap.class);
528         when(valElement.getAttributes()).thenReturn(attributes);
529
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"
534
535         // Create a StringBuilder for inventory
536         StringBuilder sbInventory = new StringBuilder();
537
538         // Call the method that processes the Java type element
539         String result = htmlFromOxm.processJavaTypeElement(javaTypeName, javaTypeElement, sbInventory);
540
541         // Debugging: Verify the name is correctly set
542         assertNotNull("The name attribute should not be null", nameAttr);
543         assertEquals("Customer", nameAttr.getNodeValue());
544
545         // Debugging Output: Print the generated XML
546         System.out.println("Generated XML: " + result);
547
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;
554
555         assertThat(result, is(expected));
556
557         verify(javaTypeElement, times(1)).getElementsByTagName("java-attributes");
558         verify(javaAttributesElement, times(1)).getElementsByTagName("xml-element");
559
560         // Check if the generatedJavaType map is updated correctly
561         assertThat(htmlFromOxm.generatedJavaType.containsKey(javaTypeName), is(true));
562     }
563 }