2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.schema;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
27 import java.util.ArrayList;
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;
43 @RunWith(SpringJUnit4ClassRunner.class)
44 @ContextConfiguration("file:src/test/resources/spring-beans/data-router-oxm.xml")
45 public class OxmModelLoaderTest {
48 private SchemaVersions schemaVersions;
50 private SchemaLocationsBean schemaLocationsBean;
53 public void testLoadingMultipleOxmFiles() {
55 ArrayList<ExternalOxmModelProcessor> externalOxmModelProcessors = new ArrayList<ExternalOxmModelProcessor>();
56 externalOxmModelProcessors.add(EntityOxmReferenceHelper.getInstance());
57 OxmModelLoader.registerExternalOxmModelProcessors(externalOxmModelProcessors);
58 OxmModelLoader.loadModels(schemaVersions, schemaLocationsBean);
60 DynamicJAXBContext jaxbContext = OxmModelLoader.getContextForVersion("v13", schemaVersions, schemaLocationsBean);
62 DynamicType pserver = jaxbContext.getDynamicType("Pserver");
63 DynamicType genericVnf = jaxbContext.getDynamicType("GenericVnf");
65 assertNotNull(pserver);
66 assertNotNull(genericVnf);
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"));
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"));