Merge "Reformat ONAP-PDP-REST test cases"
[policy/engine.git] / ONAP-SDK-APP / src / test / java / org / onap / portalapp / conf / ExternalAppConfigTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (C) 2019 Samsung
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22
23 package org.onap.portalapp.conf;
24
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import java.net.MalformedURLException;
28 import java.util.Collections;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import org.onap.portalapp.scheduler.RegistryAdapter;
32 import org.onap.portalsdk.core.scheduler.Registerable;
33 import org.onap.portalsdk.workflow.services.WorkflowScheduleService;
34 import org.quartz.Trigger;
35 import org.springframework.context.ApplicationContext;
36 import org.springframework.core.io.UrlResource;
37 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
38 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
39
40 public class ExternalAppConfigTest {
41     @Test
42     public void testConfig() throws MalformedURLException {
43         // Setup test data
44         ApplicationContext ctx = Mockito.mock(ApplicationContext.class);
45         UrlResource value = new UrlResource("http://localhost");
46         Mockito.when(ctx.getResource(Mockito.any())).thenReturn(value);
47         ResourceHandlerRegistry registry = new ResourceHandlerRegistry(ctx, null);
48         InterceptorRegistry interceptor = new InterceptorRegistry();
49         RegistryAdapter schedulerRegistryAdapter = new RegistryAdapter();
50         Registerable reg = Mockito.mock(Registerable.class);
51         Mockito.when(reg.getTriggers()).thenReturn(new Trigger[1]);
52         schedulerRegistryAdapter.setRegistry(reg);
53         WorkflowScheduleService workflowScheduleService = Mockito.mock(WorkflowScheduleService.class);
54         schedulerRegistryAdapter.setWorkflowScheduleService(workflowScheduleService);
55         Mockito.when(workflowScheduleService.triggerWorkflowScheduling()).thenReturn(Collections.emptyList());
56
57         // Test constructor
58         ExternalAppConfig config = new ExternalAppConfig();
59         assertNotNull(config);
60
61         // Test set and get
62         config.setApplicationContext(ctx);
63         assertNotNull(config.viewResolver());
64         config.addResourceHandlers(registry);
65         assertNotNull(config.dataAccessService());
66         assertNotNull(config.addTileDefinitions());
67         config.addInterceptors(interceptor);
68         assertNotNull(config.cacheManager());
69         config.setSchedulerRegistryAdapter(schedulerRegistryAdapter);
70         assertNull(config.schedulerFactoryBean());
71         assertNotNull(config.loginStrategy());
72     }
73 }