2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software 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.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalapp.core;
40 import java.io.IOException;
42 import org.junit.Before;
43 import org.junit.runner.RunWith;
44 import org.onap.portalsdk.core.conf.AppConfig;
45 import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
46 import org.onap.portalsdk.core.util.CacheManager;
47 import org.onap.portalsdk.core.util.SystemProperties;
48 import org.springframework.beans.factory.annotation.Autowired;
49 import org.springframework.context.annotation.Bean;
50 import org.springframework.context.annotation.ComponentScan;
51 import org.springframework.context.annotation.Configuration;
52 import org.springframework.context.annotation.Profile;
53 import org.springframework.test.context.ActiveProfiles;
54 import org.springframework.test.context.ContextConfiguration;
55 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
56 import org.springframework.test.context.web.AnnotationConfigWebContextLoader;
57 import org.springframework.test.context.web.WebAppConfiguration;
58 import org.springframework.test.web.servlet.MockMvc;
59 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
60 import org.springframework.web.context.WebApplicationContext;
61 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
64 * In order to write a unit test, 1. inherit this class - See SanityTest.java 2.
65 * place the "war" folder on your test class's classpath 3. run the test with
66 * the following VM argument; This is important because when starting the
67 * application from Container, the System Properties file
68 * (SystemProperties.java) can have the direct path but, when running from the
69 * Mock Junit container, the path should be prefixed with "classpath" to enable
70 * the mock container to search for the file in the classpath
71 * -Dcontainer.classpath="classpath:"
74 @RunWith(SpringJUnit4ClassRunner.class)
76 @ContextConfiguration(loader = AnnotationConfigWebContextLoader.class, classes = { MockAppConfig.class })
77 @ActiveProfiles(value = "test")
78 public class MockApplicationContextTestSuite {
81 public WebApplicationContext wac;
83 private MockMvc mockMvc;
87 if (mockMvc == null) {
88 this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
93 public Object getBean(String name) {
94 return this.wac.getBean(name);
97 public MockMvc getMockMvc() {
101 public void setMockMvc(MockMvc mockMvc) {
102 this.mockMvc = mockMvc;
105 public WebApplicationContext getWebApplicationContext() {
112 @ComponentScan(basePackages = "org.onap", excludeFilters = {})
114 class MockAppConfig extends AppConfig {
117 public SystemProperties systemProperties() {
118 return new MockSystemProperties();
122 public AbstractCacheManager cacheManager() {
123 return new CacheManager() {
125 public void configure() throws IOException {
131 protected String[] tileDefinitions() {
132 return new String[] { "classpath:/WEB-INF/fusion/defs/definitions.xml",
133 "classpath:/WEB-INF/defs/definitions.xml" };
137 public void addInterceptors(InterceptorRegistry registry) {
138 // registry.addInterceptor(new
139 // SessionTimeoutInterceptor()).excludePathPatterns(getExcludeUrlPathsForSessionTimeout());
140 // registry.addInterceptor(resourceInterceptor());
143 public static class MockSystemProperties extends SystemProperties {
145 public MockSystemProperties() {