Project

General

Profile

Download (2.46 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.httpinvoker;
11

    
12
import org.apache.log4j.Logger;
13
import org.junit.After;
14
import org.junit.Before;
15
import org.springframework.security.core.userdetails.UserDetails;
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.User;
21
import eu.etaxonomy.taxeditor.remoting.cache.CdmTransientEntityCacher;
22
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
23
import eu.etaxonomy.taxeditor.session.MockSessionOwner;
24

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

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

    
34
    protected CdmTransientEntityCacher cacher;
35
    protected MockSessionOwner sessionOwner;
36

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

    
40

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

    
43
    @Before
44
    public void initializeSession() {
45

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

    
53
        UserDetails extraUser = null;
54

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

    
62

    
63
    }
64

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

    
72

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

    
77
}
(6-6/9)