mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-08 10:34:25 +00:00
Move logging of test methods to Abstract*Test classes in dspace-api. That way they work for **both** dspace-server-webapp and dspace-api tests.
(cherry picked from commit bd20c9262b
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
68b800f070
commit
68266cd3c1
@@ -21,8 +21,12 @@ import org.dspace.builder.AbstractBuilder;
|
|||||||
import org.dspace.discovery.SearchUtils;
|
import org.dspace.discovery.SearchUtils;
|
||||||
import org.dspace.servicemanager.DSpaceKernelImpl;
|
import org.dspace.servicemanager.DSpaceKernelImpl;
|
||||||
import org.dspace.servicemanager.DSpaceKernelInit;
|
import org.dspace.servicemanager.DSpaceKernelInit;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.rules.TestName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract Test class copied from DSpace API
|
* Abstract Test class copied from DSpace API
|
||||||
@@ -46,6 +50,12 @@ public class AbstractDSpaceIntegrationTest {
|
|||||||
*/
|
*/
|
||||||
protected static DSpaceKernelImpl kernelImpl;
|
protected static DSpaceKernelImpl kernelImpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain the TestName from JUnit, so that we can print it out in the test logs (see below)
|
||||||
|
*/
|
||||||
|
@Rule
|
||||||
|
public TestName testName = new TestName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
*/
|
*/
|
||||||
@@ -90,6 +100,20 @@ public class AbstractDSpaceIntegrationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void printTestMethodBefore() {
|
||||||
|
// Log the test method being executed. Put lines around it to make it stand out.
|
||||||
|
log.info("---");
|
||||||
|
log.info("Starting execution of test method: {}()", testName.getMethodName());
|
||||||
|
log.info("---");
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void printTestMethodAfter() {
|
||||||
|
// Log the test method just completed.
|
||||||
|
log.info("Finished execution of test method: {}()", testName.getMethodName());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be run after all tests finish as per @AfterClass. It
|
* This method will be run after all tests finish as per @AfterClass. It
|
||||||
* will clean resources initialized by the @BeforeClass methods.
|
* will clean resources initialized by the @BeforeClass methods.
|
||||||
|
@@ -18,9 +18,13 @@ import java.util.TimeZone;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.servicemanager.DSpaceKernelImpl;
|
import org.dspace.servicemanager.DSpaceKernelImpl;
|
||||||
import org.dspace.servicemanager.DSpaceKernelInit;
|
import org.dspace.servicemanager.DSpaceKernelInit;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.rules.TestName;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
@@ -62,6 +66,12 @@ public class AbstractDSpaceTest {
|
|||||||
*/
|
*/
|
||||||
protected static DSpaceKernelImpl kernelImpl;
|
protected static DSpaceKernelImpl kernelImpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain the TestName from JUnit, so that we can print it out in the test logs (see below)
|
||||||
|
*/
|
||||||
|
@Rule
|
||||||
|
public TestName testName = new TestName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be run before the first test as per @BeforeClass. It will
|
* This method will be run before the first test as per @BeforeClass. It will
|
||||||
* initialize shared resources required for all tests of this class.
|
* initialize shared resources required for all tests of this class.
|
||||||
@@ -94,6 +104,19 @@ public class AbstractDSpaceTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void printTestMethodBefore() {
|
||||||
|
// Log the test method being executed. Put lines around it to make it stand out.
|
||||||
|
log.info("---");
|
||||||
|
log.info("Starting execution of test method: {}()", testName.getMethodName());
|
||||||
|
log.info("---");
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void printTestMethodAfter() {
|
||||||
|
// Log the test method just completed.
|
||||||
|
log.info("Finished execution of test method: {}()", testName.getMethodName());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be run after all tests finish as per @AfterClass. It
|
* This method will be run after all tests finish as per @AfterClass. It
|
||||||
|
@@ -39,7 +39,6 @@ import org.springframework.http.converter.HttpMessageConverter;
|
|||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.TestExecutionListeners;
|
|
||||||
import org.springframework.test.context.TestPropertySource;
|
import org.springframework.test.context.TestPropertySource;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
@@ -75,9 +74,6 @@ import org.springframework.web.context.WebApplicationContext;
|
|||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
// Load our src/test/resources/application-test.properties to override some settings in default application.properties
|
// Load our src/test/resources/application-test.properties to override some settings in default application.properties
|
||||||
@TestPropertySource(locations = "classpath:application-test.properties")
|
@TestPropertySource(locations = "classpath:application-test.properties")
|
||||||
// Enable our custom Logging listener to log when each test method starts/stops
|
|
||||||
@TestExecutionListeners(listeners = {LoggingTestExecutionListener.class},
|
|
||||||
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
|
|
||||||
public class AbstractControllerIntegrationTest extends AbstractIntegrationTestWithDatabase {
|
public class AbstractControllerIntegrationTest extends AbstractIntegrationTestWithDatabase {
|
||||||
|
|
||||||
protected static final String AUTHORIZATION_HEADER = "Authorization";
|
protected static final String AUTHORIZATION_HEADER = "Authorization";
|
||||||
|
@@ -22,7 +22,6 @@ import org.springframework.http.HttpEntity;
|
|||||||
import org.springframework.http.RequestEntity;
|
import org.springframework.http.RequestEntity;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.TestExecutionListeners;
|
|
||||||
import org.springframework.test.context.TestPropertySource;
|
import org.springframework.test.context.TestPropertySource;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
@@ -52,9 +51,6 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
@ContextConfiguration(initializers = { DSpaceKernelInitializer.class, DSpaceConfigurationInitializer.class })
|
@ContextConfiguration(initializers = { DSpaceKernelInitializer.class, DSpaceConfigurationInitializer.class })
|
||||||
// Load our src/test/resources/application-test.properties to override some settings in default application.properties
|
// Load our src/test/resources/application-test.properties to override some settings in default application.properties
|
||||||
@TestPropertySource(locations = "classpath:application-test.properties")
|
@TestPropertySource(locations = "classpath:application-test.properties")
|
||||||
// Enable our custom Logging listener to log when each test method starts/stops
|
|
||||||
@TestExecutionListeners(listeners = {LoggingTestExecutionListener.class},
|
|
||||||
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
|
|
||||||
public class AbstractWebClientIntegrationTest extends AbstractIntegrationTestWithDatabase {
|
public class AbstractWebClientIntegrationTest extends AbstractIntegrationTestWithDatabase {
|
||||||
// (Random) port chosen for test web server
|
// (Random) port chosen for test web server
|
||||||
@LocalServerPort
|
@LocalServerPort
|
||||||
|
@@ -1,44 +0,0 @@
|
|||||||
/**
|
|
||||||
* The contents of this file are subject to the license and copyright
|
|
||||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
|
||||||
* tree and available online at
|
|
||||||
*
|
|
||||||
* http://www.dspace.org/license/
|
|
||||||
*/
|
|
||||||
package org.dspace.app.rest.test;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.springframework.test.context.TestContext;
|
|
||||||
import org.springframework.test.context.support.AbstractTestExecutionListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom DSpace TestExecutionListener which logs messages whenever a specific Test Case (i.e. test method) has
|
|
||||||
* started or ended execution. This makes Test environment logs easier to read/understand as you know which method has
|
|
||||||
* caused errors, etc.
|
|
||||||
*/
|
|
||||||
public class LoggingTestExecutionListener extends AbstractTestExecutionListener {
|
|
||||||
|
|
||||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(LoggingTestExecutionListener.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Before each test method is run
|
|
||||||
* @param testContext
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void beforeTestMethod(TestContext testContext) {
|
|
||||||
// Log the test method being executed. Put lines around it to make it stand out.
|
|
||||||
log.info("---");
|
|
||||||
log.info("Starting execution of test method: {}()", testContext.getTestMethod().getName());
|
|
||||||
log.info("---");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* After each test method is run
|
|
||||||
* @param testContext
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void afterTestMethod(TestContext testContext) {
|
|
||||||
// Log the test method just completed.
|
|
||||||
log.info("Finished execution of test method: {}()", testContext.getTestMethod().getName());
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user