Project

General

Profile

Download (2.47 KB) Statistics
| Branch: | Tag: | Revision:
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 org.apache.log4j.Logger;
12
import org.junit.After;
13
import org.junit.Before;
14
import org.springframework.security.core.userdetails.UserDetails;
15
import org.springframework.security.core.userdetails.UsernameNotFoundException;
16

    
17
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
18
import eu.etaxonomy.cdm.api.service.IUserService;
19
import eu.etaxonomy.cdm.model.common.User;
20
import eu.etaxonomy.taxeditor.remoting.cache.ConversationalTransientEntityCacher;
21
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
22
import eu.etaxonomy.taxeditor.session.MockSessionOwner;
23

    
24
/**
25
 * @author cmathew
26
 * @date 12 Jun 2015
27
 *
28
 */
29
public abstract class RemotingSessionAwareTest extends BaseRemotingTest {
30

    
31
    private static final Logger logger = Logger.getLogger(RemotingSessionAwareTest.class);
32

    
33
    protected ConversationalTransientEntityCacher cacher;
34
    protected MockSessionOwner sessionOwner;
35

    
36
    private static String extraUsername = "Someone";
37
    private static String extraPassword = "Password";
38

    
39

    
40
    private IUserService userService = getRemoteApplicationController().getUserService();
41

    
42
    @Before
43
    public void initializeSession() {
44

    
45
        sessionOwner = new MockSessionOwner();
46
        logger.info("created mock session owner : " + sessionOwner);
47
        ICdmEntitySession cdmEntitySession = cdmEntitySessionManager.newSession(sessionOwner, true);
48
        CdmApplicationState.getCurrentDataChangeService().register(sessionOwner);
49
        sessionOwner.setCdmEntitySession(cdmEntitySession);
50
        cacher = getCacher(sessionOwner);
51

    
52
        UserDetails extraUser = null;
53

    
54
        try {
55
            extraUser = userService.loadUserByUsername(extraUsername);
56
        } catch (UsernameNotFoundException unfe) {
57
            User user = User.NewInstance(extraUsername, extraPassword);
58
            userService.createUser(user);
59
        }
60

    
61

    
62
    }
63

    
64
    @After
65
    public void postSessionAwareTest() {
66
        sessionOwner.dispose();
67
        CdmApplicationState.getCurrentDataChangeService().unregister(sessionOwner);
68
        logger.info("disposed of mock session owner : " + sessionOwner);
69
    }
70

    
71

    
72
    protected static void authenticateExtraUser() {
73
        authenticate(extraUsername, extraPassword);
74
    }
75

    
76
}
(5-5/8)