1.3.0 schema ingest changes
[aai/router-core.git] / src / test / java / org / onap / aai / schema / OxmModelLoaderTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.schema;
22
23
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.ArrayList;
28
29 import org.eclipse.persistence.dynamic.DynamicType;
30 import org.eclipse.persistence.internal.helper.DatabaseField;
31 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
32 import org.eclipse.persistence.mappings.DatabaseMapping;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.onap.aai.setup.SchemaLocationsBean;
36 import org.onap.aai.setup.SchemaVersions;
37 import org.onap.aai.util.EntityOxmReferenceHelper;
38 import org.onap.aai.util.ExternalOxmModelProcessor;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.test.context.ContextConfiguration;
41 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
42
43 @RunWith(SpringJUnit4ClassRunner.class)
44 @ContextConfiguration("file:src/test/resources/spring-beans/data-router-oxm.xml")
45 public class OxmModelLoaderTest {
46
47   @Autowired
48   private SchemaVersions schemaVersions;
49   @Autowired
50   private SchemaLocationsBean schemaLocationsBean;
51   
52     @Test
53     public void testLoadingMultipleOxmFiles() {
54       
55         ArrayList<ExternalOxmModelProcessor> externalOxmModelProcessors = new ArrayList<ExternalOxmModelProcessor>();
56         externalOxmModelProcessors.add(EntityOxmReferenceHelper.getInstance());
57         OxmModelLoader.registerExternalOxmModelProcessors(externalOxmModelProcessors);
58         OxmModelLoader.loadModels(schemaVersions, schemaLocationsBean);
59
60         DynamicJAXBContext jaxbContext = OxmModelLoader.getContextForVersion("v13", schemaVersions, schemaLocationsBean);
61
62         DynamicType pserver = jaxbContext.getDynamicType("Pserver");
63         DynamicType genericVnf = jaxbContext.getDynamicType("GenericVnf");
64
65         assertNotNull(pserver);
66         assertNotNull(genericVnf);
67
68         DatabaseMapping mapping = pserver.getDescriptor().getMappings().firstElement();
69         if (mapping.isAbstractDirectMapping()) {
70             DatabaseField f = mapping.getField();
71             String keyName = f.getName().substring(0, f.getName().indexOf("/"));
72             assertTrue(keyName.equals("hostname"));
73         }
74
75         mapping = genericVnf.getDescriptor().getMappings().firstElement();
76         if (mapping.isAbstractDirectMapping()) {
77             DatabaseField f = mapping.getField();
78             String keyName = f.getName().substring(0, f.getName().indexOf("/"));
79             assertTrue(keyName.equals("vnf-id"));
80         }
81       
82     }
83     
84 }