2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property.
\r
6 * Copyright © 2017 Amdocs
\r
7 * All rights reserved.
\r
8 * ================================================================================
\r
9 * Licensed under the Apache License, Version 2.0 (the "License");
\r
10 * you may not use this file except in compliance with the License.
\r
11 * You may obtain a copy of the License at
\r
13 * http://www.apache.org/licenses/LICENSE-2.0
\r
15 * Unless required by applicable law or agreed to in writing, software
\r
16 * distributed under the License is distributed on an "AS IS" BASIS,
\r
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
18 * See the License for the specific language governing permissions and
\r
19 * limitations under the License.
\r
20 * ============LICENSE_END=========================================================
\r
22 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
24 package org.onap.aai.modelloader.service;
\r
26 import org.junit.Assert;
\r
27 import org.junit.Before;
\r
28 import org.junit.Test;
\r
29 import org.mockito.Mockito;
\r
31 import javax.servlet.http.HttpServletRequest;
\r
32 import javax.ws.rs.core.Response;
\r
33 import java.io.File;
\r
34 import java.io.IOException;
\r
35 import java.lang.reflect.Field;
\r
36 import java.lang.reflect.Modifier;
\r
38 public class ModelLoaderServiceTest {
\r
40 ModelLoaderService service;
\r
42 public void init() throws IOException, NoSuchFieldException, IllegalAccessException {
\r
43 System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
\r
44 setFinalStatic(System.getProperty("AJSC_HOME")+"/src/test/resources/model-loader.properties");
\r
45 service = new ModelLoaderService();
\r
49 public void testLoadModel(){
\r
50 Response response = service.loadModel("model-1");
\r
51 Assert.assertNotNull(response);
\r
55 public void testSaveModel(){
\r
56 Response response = service.saveModel("model-1", "name-1");
\r
57 Assert.assertNotNull(response);
\r
61 public void testIngestModel() throws IOException {
\r
62 HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
\r
63 Response response = service.ingestModel("model-id-1", req, "payload");
\r
64 Assert.assertNotNull(response);
\r
67 static void setFinalStatic(String fieldValue) throws NoSuchFieldException, SecurityException,
\r
68 IllegalArgumentException, IllegalAccessException {
\r
69 Field configField = ModelLoaderService.class.getDeclaredField("CONFIG_FILE");
\r
70 configField.setAccessible(true);
\r
72 Field modifiersField = Field.class.getDeclaredField( "modifiers" );
\r
73 modifiersField.setAccessible( true );
\r
74 modifiersField.setInt( configField, configField.getModifiers() & ~Modifier.FINAL );
\r
76 configField.set(null, fieldValue);
\r
78 Field authField = ModelLoaderService.class.getDeclaredField("CONFIG_AUTH_LOCATION");
\r
79 authField.setAccessible(true);
\r
81 Field modifiersField1 = Field.class.getDeclaredField( "modifiers" );
\r
82 modifiersField1.setAccessible( true );
\r
83 modifiersField1.setInt( authField, authField.getModifiers() & ~Modifier.FINAL );
\r
85 authField.set(null, System.getProperty("AJSC_HOME"));
\r