1
|
package eu.etaxonomy.cdm.vaadin;
|
2
|
|
3
|
import javax.servlet.ServletContextEvent;
|
4
|
import javax.servlet.ServletContextListener;
|
5
|
import javax.servlet.ServletException;
|
6
|
|
7
|
import org.easymock.EasyMock;
|
8
|
import org.junit.Assert;
|
9
|
import org.junit.BeforeClass;
|
10
|
import org.junit.Ignore;
|
11
|
import org.springframework.mock.web.MockServletConfig;
|
12
|
import org.springframework.mock.web.MockServletContext;
|
13
|
import org.springframework.web.context.ContextLoaderListener;
|
14
|
import org.unitils.UnitilsJUnit4;
|
15
|
import org.unitils.database.DatabaseUnitils;
|
16
|
import org.unitils.database.annotations.Transactional;
|
17
|
import org.unitils.database.util.TransactionMode;
|
18
|
|
19
|
import com.vaadin.data.util.sqlcontainer.query.generator.filter.QueryBuilder;
|
20
|
import com.vaadin.server.DeploymentConfiguration;
|
21
|
import com.vaadin.server.ServiceException;
|
22
|
import com.vaadin.server.VaadinService;
|
23
|
import com.vaadin.server.VaadinServlet;
|
24
|
import com.vaadin.server.VaadinServletService;
|
25
|
import com.vaadin.server.VaadinSession;
|
26
|
|
27
|
import eu.etaxonomy.cdm.vaadin.util.CdmSQLStringDecorator;
|
28
|
|
29
|
@Ignore
|
30
|
@Transactional(TransactionMode.DISABLED)
|
31
|
public class CdmVaadinBaseTest extends UnitilsJUnit4 {
|
32
|
|
33
|
private static MockServletContext servletContext;
|
34
|
private static VaadinServlet vaadinServlet;
|
35
|
private static VaadinServletService vaadinService;
|
36
|
private static VaadinSession vaadinSession;
|
37
|
private static boolean isVaadinServletEnvCreated = false;
|
38
|
|
39
|
|
40
|
@BeforeClass
|
41
|
public static void setup() {
|
42
|
DatabaseUnitils.disableConstraints();
|
43
|
|
44
|
if(!isVaadinServletEnvCreated) {
|
45
|
createNewServletEnvironment();
|
46
|
}
|
47
|
QueryBuilder.setStringDecorator(new CdmSQLStringDecorator());
|
48
|
|
49
|
Assert.assertNotNull(vaadinServlet);
|
50
|
Assert.assertEquals(vaadinServlet, VaadinServlet.getCurrent());
|
51
|
|
52
|
Assert.assertNotNull(servletContext);
|
53
|
Assert.assertEquals(servletContext, VaadinServlet.getCurrent().getServletContext());
|
54
|
|
55
|
Assert.assertNotNull(vaadinSession);
|
56
|
Assert.assertEquals(vaadinSession, VaadinSession.getCurrent());
|
57
|
|
58
|
Assert.assertNotNull(vaadinService);
|
59
|
Assert.assertEquals(vaadinService, VaadinService.getCurrent());
|
60
|
}
|
61
|
|
62
|
|
63
|
public static void createNewServletEnvironment() {
|
64
|
servletContext = new MockServletContext("/webapp");
|
65
|
|
66
|
ServletContextListener listener = new ContextLoaderListener();
|
67
|
ServletContextEvent event = new ServletContextEvent(servletContext);
|
68
|
listener.contextInitialized(event);
|
69
|
|
70
|
MockServletConfig servletConfig = new MockServletConfig(servletContext);
|
71
|
vaadinServlet = new VaadinServlet();
|
72
|
|
73
|
|
74
|
try {
|
75
|
vaadinServlet.init(servletConfig);
|
76
|
} catch (ServletException e) {
|
77
|
throw new RuntimeException(e);
|
78
|
}
|
79
|
|
80
|
try {
|
81
|
vaadinService = new VaadinServletService(vaadinServlet,
|
82
|
EasyMock.createMock(DeploymentConfiguration.class));
|
83
|
} catch (ServiceException e) {
|
84
|
throw new RuntimeException(e);
|
85
|
}
|
86
|
VaadinService.setCurrent(vaadinService);
|
87
|
|
88
|
vaadinSession = new MockVaadinSession(vaadinService);
|
89
|
VaadinSession.setCurrent(vaadinSession);
|
90
|
|
91
|
isVaadinServletEnvCreated = true;
|
92
|
}
|
93
|
|
94
|
public static class MockVaadinSession extends VaadinSession {
|
95
|
MockVaadinSession(VaadinService service) {
|
96
|
super(service);
|
97
|
}
|
98
|
|
99
|
@Override
|
100
|
public boolean hasLock() {
|
101
|
return true;
|
102
|
}
|
103
|
}
|
104
|
}
|