com.mtvnet.boxspring.testing.AbstractBoxSpringIntegrationTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boxspring-test-support Show documentation
Show all versions of boxspring-test-support Show documentation
Classes for assisting in testing with BoxSpring.
The newest version!
/**
* Copyright (c) 2009, MTV Networks. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.mtvnet.boxspring.testing;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import com.mtvnet.boxspring.path.LayeredResourcePathedXmlApplicationContext;
/**
* Abstract base class for writing integration tests that use a BoxSpring
* container.
*
* @author edelsonj
*
*/
public abstract class AbstractBoxSpringIntegrationTest {
/**
* The ApplicationContext instance that tests should use.
*/
protected LayeredResourcePathedXmlApplicationContext context;
/**
* Close the context to avoid any residual JMX issues.
*/
@After
public final void closeBoxSpringContext() {
context.close();
}
/**
* Create a BoxSpring application context using the classpath and any
* additional resource roots specified.
*
* @throws Exception if something goes wrong
*/
@Before
public final void setupBoxSpringContext() throws Exception {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
List rootResources = new ArrayList();
rootResources.addAll(Arrays.asList(resolver.getResources("classpath*:META-INF/spring/")));
for (String stage : getStages()) {
rootResources.addAll(Arrays.asList(resolver.getResources("classpath*:META-INF/spring-"
+ stage + "/")));
}
Resource[] additionalResources = getAdditionalResourceRoots();
if (additionalResources != null) {
rootResources.addAll(Arrays.asList(additionalResources));
}
context = new LayeredResourcePathedXmlApplicationContext(rootResources
.toArray(new Resource[0]), getFileNames());
context.refresh();
}
/**
* Hook method for subclasses to specify stages to use when testing. These
* will be automatically prepended with 'classpath*:META-INF/spring-' and
* added to the resource root list. These are added before those
* provided in getAdditionalResourceRoots().
*
* @return the stages to include in the configuration layout.
*/
protected String[] getStages() {
return new String[] { "test" };
}
/**
* Hook method for subclasses to specify an additional set of resource
* roots.
*
* @return the additional resource roots for testing.
*/
protected Resource[] getAdditionalResourceRoots() {
return null;
}
/**
* Hook method for subclasses to specify an alternate set of file names. The
* default is applicationContext.xml.
*
* @return the file names for the test container.
*/
protected String[] getFileNames() {
return new String[] { "applicationContext.xml" };
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy