1
|
/**
|
2
|
* Copyright (C) 2015 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.httpinvoker;
|
10
|
|
11
|
import java.util.UUID;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.junit.After;
|
15
|
import org.junit.Before;
|
16
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
19
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
20
|
import eu.etaxonomy.cdm.model.common.Group;
|
21
|
import eu.etaxonomy.cdm.model.common.User;
|
22
|
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
|
23
|
import eu.etaxonomy.taxeditor.remoting.cache.ConversationalTransientEntityCacher;
|
24
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
25
|
import eu.etaxonomy.taxeditor.session.MockSessionOwner;
|
26
|
|
27
|
/**
|
28
|
* @author cmathew
|
29
|
* @date 12 Jun 2015
|
30
|
*
|
31
|
*/
|
32
|
public abstract class RemotingSessionAwareTest extends BaseRemotingTest {
|
33
|
|
34
|
private static final Logger logger = Logger.getLogger(RemotingSessionAwareTest.class);
|
35
|
|
36
|
protected ConversationalTransientEntityCacher cacher;
|
37
|
protected MockSessionOwner sessionOwner;
|
38
|
|
39
|
private static String extraUsername = "Someone";
|
40
|
private static String extraPassword = "Password";
|
41
|
private static UUID editorGroupUuid = UUID.fromString("22e5e8af-b99c-4884-a92f-71978efd3770");
|
42
|
|
43
|
|
44
|
private IUserService userService = getRemoteApplicationController().getUserService();
|
45
|
|
46
|
@Before
|
47
|
public void initializeSession() {
|
48
|
|
49
|
sessionOwner = new MockSessionOwner();
|
50
|
logger.info("created mock session owner : " + sessionOwner);
|
51
|
ICdmEntitySession cdmEntitySession = cdmEntitySessionManager.newSession(sessionOwner, true);
|
52
|
CdmApplicationState.getCurrentDataChangeService().register(sessionOwner);
|
53
|
sessionOwner.setCdmEntitySession(cdmEntitySession);
|
54
|
cacher = getCacher(sessionOwner);
|
55
|
|
56
|
User extraUser = null;
|
57
|
|
58
|
try {
|
59
|
extraUser = (User) userService.loadUserByUsername(extraUsername);
|
60
|
Group editorGroup = getRemoteApplicationController().getGroupService().find(editorGroupUuid);
|
61
|
if (!extraUser.getGroups().contains(editorGroup)){
|
62
|
extraUser.getGroups().add(editorGroup);
|
63
|
userService.merge(extraUser, true);
|
64
|
}
|
65
|
} catch (UsernameNotFoundException unfe) {
|
66
|
User user = User.NewInstance(extraUsername, extraPassword);
|
67
|
userService.createUser(user);
|
68
|
Group editorGroup = getRemoteApplicationController().getGroupService().find(editorGroupUuid);
|
69
|
user = userService.load(user.getUuid());
|
70
|
user.getGroups().add(editorGroup);
|
71
|
MergeResult<User> result = userService.merge(user, true);
|
72
|
user = result.getMergedEntity();
|
73
|
}
|
74
|
|
75
|
|
76
|
}
|
77
|
|
78
|
@After
|
79
|
public void postSessionAwareTest() {
|
80
|
sessionOwner.dispose();
|
81
|
CdmApplicationState.getCurrentDataChangeService().unregister(sessionOwner);
|
82
|
logger.info("disposed of mock session owner : " + sessionOwner);
|
83
|
}
|
84
|
|
85
|
|
86
|
protected static void authenticateExtraUser() {
|
87
|
authenticate(extraUsername, extraPassword);
|
88
|
}
|
89
|
|
90
|
}
|