| margaretha | fde771a | 2017-11-14 15:02:10 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.config; |
| 2 | |
| abcpro1 | edce8f9 | 2022-11-08 21:41:18 +0000 | [diff] [blame] | 3 | import org.glassfish.jersey.server.ResourceConfig; |
| 4 | import org.glassfish.jersey.servlet.ServletContainer; |
| 5 | import org.glassfish.jersey.test.DeploymentContext; |
| 6 | import org.glassfish.jersey.test.JerseyTest; |
| 7 | import org.glassfish.jersey.test.ServletDeploymentContext; |
| 8 | import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory; |
| 9 | import org.glassfish.jersey.test.spi.TestContainerException; |
| 10 | import org.glassfish.jersey.test.spi.TestContainerFactory; |
| Marc Kupietz | d43a98d | 2023-09-22 17:11:46 +0200 | [diff] [blame] | 11 | import org.junit.jupiter.api.BeforeEach; |
| 12 | import org.junit.jupiter.api.extension.ExtendWith; |
| margaretha | 1960ea5 | 2023-02-28 11:20:15 +0100 | [diff] [blame] | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.context.support.GenericApplicationContext; |
| 15 | import org.springframework.test.annotation.DirtiesContext; |
| 16 | import org.springframework.test.annotation.DirtiesContext.ClassMode; |
| 17 | import org.springframework.test.context.ContextConfiguration; |
| Marc Kupietz | d43a98d | 2023-09-22 17:11:46 +0200 | [diff] [blame] | 18 | import org.springframework.test.context.junit.jupiter.SpringExtension; |
| margaretha | 1960ea5 | 2023-02-28 11:20:15 +0100 | [diff] [blame] | 19 | import org.springframework.web.context.support.GenericWebApplicationContext; |
| margaretha | fde771a | 2017-11-14 15:02:10 +0100 | [diff] [blame] | 20 | |
| margaretha | 1960ea5 | 2023-02-28 11:20:15 +0100 | [diff] [blame] | 21 | @DirtiesContext(classMode = ClassMode.BEFORE_CLASS) |
| Marc Kupietz | d43a98d | 2023-09-22 17:11:46 +0200 | [diff] [blame] | 22 | @ExtendWith(SpringExtension.class) |
| margaretha | fde771a | 2017-11-14 15:02:10 +0100 | [diff] [blame] | 23 | @ContextConfiguration("classpath:test-config.xml") |
| 24 | public abstract class SpringJerseyTest extends JerseyTest { |
| 25 | |
| margaretha | 3d55b00 | 2019-03-19 12:00:44 +0100 | [diff] [blame] | 26 | public final static String API_VERSION = "v1.0"; |
| margaretha | 9e53bb2 | 2018-09-14 19:39:15 +0200 | [diff] [blame] | 27 | |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 28 | @Autowired |
| margaretha | 1097acc | 2018-05-02 18:33:24 +0200 | [diff] [blame] | 29 | protected GenericApplicationContext applicationContext; |
| margaretha | b4ce660 | 2018-04-26 20:23:57 +0200 | [diff] [blame] | 30 | |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame^] | 31 | public static String[] classPackages = new String[] { |
| 32 | "de.ids_mannheim.korap.web", "de.ids_mannheim.korap.core.web", |
| 33 | "de.ids_mannheim.korap.test", "com.fasterxml.jackson.jaxrs.json" }; |
| margaretha | fde771a | 2017-11-14 15:02:10 +0100 | [diff] [blame] | 34 | |
| margaretha | fde771a | 2017-11-14 15:02:10 +0100 | [diff] [blame] | 35 | @Override |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame^] | 36 | protected TestContainerFactory getTestContainerFactory () |
| 37 | throws TestContainerException { |
| margaretha | fde771a | 2017-11-14 15:02:10 +0100 | [diff] [blame] | 38 | return new GrizzlyWebTestContainerFactory(); |
| 39 | } |
| 40 | |
| Marc Kupietz | d43a98d | 2023-09-22 17:11:46 +0200 | [diff] [blame] | 41 | @BeforeEach |
| margaretha | fde771a | 2017-11-14 15:02:10 +0100 | [diff] [blame] | 42 | @Override |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame^] | 43 | public void setUp () throws Exception { |
| Marc Kupietz | d43a98d | 2023-09-22 17:11:46 +0200 | [diff] [blame] | 44 | GenericWebApplicationContext genericContext = new GenericWebApplicationContext(); |
| margaretha | 9e53bb2 | 2018-09-14 19:39:15 +0200 | [diff] [blame] | 45 | genericContext.setParent(this.applicationContext); |
| 46 | genericContext.setClassLoader(this.applicationContext.getClassLoader()); |
| margaretha | 9e53bb2 | 2018-09-14 19:39:15 +0200 | [diff] [blame] | 47 | StaticContextLoaderListener.applicationContext = genericContext; |
| margaretha | 1097acc | 2018-05-02 18:33:24 +0200 | [diff] [blame] | 48 | super.setUp(); |
| 49 | } |
| 50 | |
| 51 | @Override |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame^] | 52 | protected DeploymentContext configureDeployment () { |
| 53 | return ServletDeploymentContext |
| 54 | .forServlet(new ServletContainer( |
| 55 | new ResourceConfig().packages(classPackages))) |
| 56 | .addListener(StaticContextLoaderListener.class) |
| 57 | .contextParam("adminToken", "secret").build(); |
| margaretha | fde771a | 2017-11-14 15:02:10 +0100 | [diff] [blame] | 58 | } |
| margaretha | fde771a | 2017-11-14 15:02:10 +0100 | [diff] [blame] | 59 | } |