2 * ============LICENSE_START=======================================================
3 * SPARKY (AAI UI service)
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
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=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.openecomp.sparky.util;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertNotEquals;
32 import java.io.IOException;
34 import org.junit.Before;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.rules.TemporaryFolder;
38 import org.mockito.Mockito;
39 import org.openecomp.sparky.config.oxm.OxmModelLoader;
42 * The Class OxmModelLoaderTest.
44 public class OxmModelLoaderTest {
47 public TemporaryFolder folder = new TemporaryFolder();
49 OxmModelLoader loader;
54 * @throws IOException Signals that an I/O exception has occurred.
57 public void init() throws IOException {
63 * Test find latest oxm version expectv 9.
65 * @throws IOException Signals that an I/O exception has occurred.
68 public void test_findLatestOxmVersion_expectv9() throws IOException {
69 System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
71 folder.newFile("aai_oxm_v7.xml");
72 folder.newFile("aai_oxm_v8.xml");
73 folder.newFile("aai_oxm_v9.xml");
74 folder.newFile("randomTest.xml");
76 loader = Mockito.spy(new OxmModelLoader());
77 Mockito.when(loader.loadOxmFolder()).thenReturn(folder.getRoot());
79 String version = loader.findLatestOxmVersion();
81 assertEquals("v9", version);
85 * Test find latest oxm version expect null when folder is empty.
87 * @throws IOException Signals that an I/O exception has occurred.
90 public void test_findLatestOxmVersion_expectNullWhenFolderIsEmpty() throws IOException {
91 System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
93 loader = Mockito.spy(new OxmModelLoader());
94 Mockito.when(loader.loadOxmFolder()).thenReturn(folder.getRoot());
96 String version = loader.findLatestOxmVersion();
98 assertEquals(null, version);
102 * Test find latest oxm version expect null when files does not match expected pattern.
104 * @throws IOException Signals that an I/O exception has occurred.
107 public void test_findLatestOxmVersion_expectNullWhenFilesDoesNotMatchExpectedPattern()
109 System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
111 folder.newFile("file1.xml");
112 folder.newFile("file2.xml");
114 loader = Mockito.spy(new OxmModelLoader());
115 Mockito.when(loader.loadOxmFolder()).thenReturn(folder.getRoot());
117 String version = loader.findLatestOxmVersion();
119 assertEquals(null, version);
123 * Test load model expect success.
125 * @throws IOException Signals that an I/O exception has occurred.
128 public void test_loadModel_expectSuccess() throws IOException {
129 String version = "v9";
130 System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
132 loader = Mockito.spy(new OxmModelLoader());
133 Mockito.when(loader.loadOxmFileName(version)).thenReturn(
134 System.getProperty("AJSC_HOME") + "/bundleconfig-local/oxm/aai_oxm_" + version + ".xml");
136 loader.loadModel(version);
138 assertNotEquals(null, loader.getOxmModel());
142 * Test load model expect oxm data as empty.
144 * @throws IOException Signals that an I/O exception has occurred.
147 public void test_loadModel_expectOxmDataAsEmpty() throws IOException {
148 String version = "v8";
149 System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
151 loader = Mockito.spy(new OxmModelLoader());
152 Mockito.when(loader.loadOxmFileName(version)).thenReturn(
153 System.getProperty("AJSC_HOME") + "/bundleconfig-local/oxm/aai_oxm_" + version + ".xml");
155 loader.loadModel(version);
157 assertEquals(0, loader.getOxmModel().size());
158 assertEquals(true, loader.getSearchableEntityDescriptors().isEmpty());
159 assertEquals(0, loader.getSearchableOxmModel().size());
163 assertNotEquals(null, loader.getOxmModel());