2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.fusion.core;
\r
23 import java.io.IOException;
\r
25 import org.junit.Before;
\r
26 import org.junit.runner.RunWith;
\r
27 import org.springframework.beans.factory.annotation.Autowired;
\r
28 import org.springframework.context.annotation.Bean;
\r
29 import org.springframework.context.annotation.ComponentScan;
\r
30 import org.springframework.context.annotation.Configuration;
\r
31 import org.springframework.context.annotation.Profile;
\r
32 import org.springframework.test.context.ActiveProfiles;
\r
33 import org.springframework.test.context.ContextConfiguration;
\r
34 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
\r
35 import org.springframework.test.context.web.AnnotationConfigWebContextLoader;
\r
36 import org.springframework.test.context.web.WebAppConfiguration;
\r
37 import org.springframework.test.web.servlet.MockMvc;
\r
38 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
\r
39 import org.springframework.web.context.WebApplicationContext;
\r
40 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
\r
42 import org.openecomp.portalsdk.core.conf.AppConfig;
\r
43 import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager;
\r
44 import org.openecomp.portalsdk.core.util.SystemProperties;
\r
45 import org.openecomp.portalsdk.core.util.CacheManager;
\r
51 * In order to write a unit test,
\r
52 * 1. inherit this class - See SanityTest.java
\r
53 * 2. place the "war" folder on your test class's classpath
\r
54 * 3. run the test with the following VM argument; This is important because when starting the application from Container, the System Properties file (SystemProperties.java) can have the direct path
\r
55 * but, when running from the Mock Junit container, the path should be prefixed with "classpath" to enable the mock container to search for the file in the classpath
\r
56 * -Dcontainer.classpath="classpath:"
\r
60 @RunWith(SpringJUnit4ClassRunner.class)
\r
61 @WebAppConfiguration
\r
62 @ContextConfiguration(loader = AnnotationConfigWebContextLoader.class, classes = {MockAppConfig.class})
\r
63 @ActiveProfiles(value="test")
\r
64 public class MockApplicationContextTestSuite {
\r
68 public WebApplicationContext wac;
\r
70 /** The mock mvc. */
\r
71 private MockMvc mockMvc;
\r
77 public void setup() {
\r
78 if(mockMvc == null) {
\r
79 this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
\r
87 * @param name the name
\r
90 public Object getBean(String name) {
\r
91 return this.wac.getBean(name);
\r
96 * Gets the mock mvc.
\r
98 * @return the mock mvc
\r
100 public MockMvc getMockMvc() {
\r
105 * Sets the mock mvc.
\r
107 * @param mockMvc the new mock mvc
\r
109 public void setMockMvc(MockMvc mockMvc) {
\r
110 this.mockMvc = mockMvc;
\r
114 * Gets the web application context.
\r
116 * @return the web application context
\r
118 public WebApplicationContext getWebApplicationContext() {
\r
129 @ComponentScan(basePackages = "org.openecomp",
\r
131 // the following source configurations should not be scanned; instead of using Exclusion filter, we can use the @Profile annotation to exclude them
\r
132 // see AppConfig class
\r
133 //@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalsdk.core.*AppConfig*")//,
\r
134 //@ComponentScan.Filter(type = FilterType.REGEX, pattern = org.openecomp.*.*AppConfig*")
\r
138 class MockAppConfig extends AppConfig {
\r
141 public SystemProperties systemProperties(){
\r
142 return new MockSystemProperties();
\r
146 public AbstractCacheManager cacheManager() {
\r
147 return new CacheManager() {
\r
149 public void configure() throws IOException {
\r
155 protected String[] tileDefinitions() {
\r
156 return new String[] {"classpath:/WEB-INF/fusion/defs/definitions.xml", "classpath:/WEB-INF/defs/definitions.xml"};
\r
160 public void addInterceptors(InterceptorRegistry registry) {
\r
161 //registry.addInterceptor(new SessionTimeoutInterceptor()).excludePathPatterns(getExcludeUrlPathsForSessionTimeout());
\r
162 //registry.addInterceptor(resourceInterceptor());
\r
165 public static class MockSystemProperties extends SystemProperties {
\r
167 public MockSystemProperties() {
\r