2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\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 * ================================================================================
\r
20 package org.openecomp.portalapp.portal.test.framework;
\r
22 import java.io.IOException;
\r
24 import org.junit.Before;
\r
25 import org.junit.Test;
\r
26 import org.junit.runner.RunWith;
\r
27 import org.openecomp.portalsdk.core.conf.AppConfig;
\r
28 //import org.openecomp.portalapp.conf.ExternalAppConfig;
\r
29 //import org.openecomp.portalapp.conf.HibernateMappingLocations;
\r
30 import org.openecomp.portalsdk.core.conf.HibernateConfiguration;
\r
31 import org.openecomp.portalsdk.core.conf.HibernateMappingLocatable;
\r
32 import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager;
\r
33 import org.openecomp.portalsdk.core.util.CacheManager;
\r
34 import org.openecomp.portalsdk.core.util.SystemProperties;
\r
35 import org.springframework.beans.factory.annotation.Autowired;
\r
36 import org.springframework.context.annotation.Bean;
\r
37 import org.springframework.context.annotation.ComponentScan;
\r
38 import org.springframework.context.annotation.Configuration;
\r
39 import org.springframework.context.annotation.FilterType;
\r
40 import org.springframework.context.annotation.Profile;
\r
41 import org.springframework.core.io.ClassPathResource;
\r
42 import org.springframework.core.io.Resource;
\r
43 import org.springframework.test.context.ActiveProfiles;
\r
44 import org.springframework.test.context.ContextConfiguration;
\r
45 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
\r
46 import org.springframework.test.context.transaction.TransactionConfiguration;
\r
47 import org.springframework.test.context.web.AnnotationConfigWebContextLoader;
\r
48 import org.springframework.test.context.web.WebAppConfiguration;
\r
49 import org.springframework.test.web.servlet.MockMvc;
\r
50 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
\r
51 import org.springframework.transaction.annotation.Transactional;
\r
52 import org.springframework.web.context.WebApplicationContext;
\r
53 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
\r
57 * In order to write a unit test, 1. inherit this class 2. place the "war"
\r
58 * folder on your test class's classpath 3. run the test with the following VM
\r
59 * argument; This is important because when starting the application from
\r
60 * Container, the System Properties file (SystemProperties.java) can have the
\r
61 * direct path but, when running from the Mock Junit container, the path should
\r
62 * be prefixed with "classpath" to enable the mock container to search for the
\r
63 * file in the classpath -Dcontainer.classpath="classpath:"
\r
66 @SuppressWarnings("deprecation")
\r
67 @RunWith(SpringJUnit4ClassRunner.class)
\r
68 @WebAppConfiguration
\r
69 @ContextConfiguration(loader = AnnotationConfigWebContextLoader.class, classes = { MockAppConfig.class })
\r
70 @ActiveProfiles(value = "test")
\r
71 public class ApplicationCommonContextTestSuite {
\r
74 public WebApplicationContext wac;
\r
76 private MockMvc mockMvc;
\r
79 public void setup() {
\r
80 if (mockMvc == null) {
\r
81 this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
\r
86 public Object getBean(String name) {
\r
87 return this.wac.getBean(name);
\r
90 public MockMvc getMockMvc() {
\r
94 public void setMockMvc(MockMvc mockMvc) {
\r
95 this.mockMvc = mockMvc;
\r
98 public WebApplicationContext getWebApplicationContext() {
\r
105 @ComponentScan(basePackages = "org.openecomp", excludeFilters = {
\r
106 // the following source configurations should not be scanned; instead of
\r
107 // using Exclusion filter, we can use the @Profile annotation to exclude
\r
109 @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalsdk.core.controller.LogoutController*"),
\r
110 @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalsdk.core.controller.SDKLoginController*"),
\r
111 @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalapp.conf.ExternalAppConfig*"),
\r
112 @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.*.*InitUebHandler*") })
\r
114 class MockAppConfig extends AppConfig {
\r
117 HibernateMappingLocatable locatable() {
\r
118 return new MockHibernateMappingLocations();
\r
122 HibernateConfiguration hibConfiguration() {
\r
123 return new HibernateConfiguration();
\r
127 public SystemProperties systemProperties() {
\r
128 return new MockSystemProperties();
\r
132 public AbstractCacheManager cacheManager() {
\r
133 return new CacheManager() {
\r
135 public void configure() throws IOException {
\r
141 public String[] tileDefinitions() {
\r
142 return new String[] { "classpath:/WEB-INF/fusion/defs/definitions.xml",
\r
143 "classpath:/WEB-INF/defs/definitions.xml" };
\r
146 public void addInterceptors(InterceptorRegistry registry) {
\r
147 // registry.addInterceptor(new
\r
148 // SessionTimeoutInterceptor()).excludePathPatterns(getExcludeUrlPathsForSessionTimeout());
\r
149 // registry.addInterceptor(resourceInterceptor());
\r
152 public static class MockSystemProperties extends SystemProperties {
\r
154 public MockSystemProperties() {
\r
162 class MockHibernateMappingLocations implements HibernateMappingLocatable {
\r
164 public Resource[] getMappingLocations() {
\r
165 return new Resource[] { new ClassPathResource("WEB-INF/fusion/orm/Fusion.hbm.xml"),
\r
166 new ClassPathResource("WEB-INF/fusion/orm/EP.hbm.xml"),
\r
167 new ClassPathResource("WEB-INF/fusion/orm/Workflow.hbm.xml") };
\r
171 public String[] getPackagesToScan() {
\r
172 return new String[] { "org.openecomp", "src" };
\r