Project

General

Profile

Download (2.4 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.session.ICdmEntitySession;
21
import eu.etaxonomy.taxeditor.session.MockSessionOwner;
22

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

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

    
32
    protected eu.etaxonomy.cdm.cache.CdmTransientEntityCacher cacher;
33
    protected MockSessionOwner sessionOwner;
34

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

    
38

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

    
41
    @Before
42
    public void initializeSession() {
43

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

    
51
        UserDetails extraUser = null;
52

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

    
60

    
61
    }
62

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

    
70

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

    
75
}
(5-5/8)