Project

General

Profile

Revision 567de3cd

ID567de3cd5c06198c0dd462fd23600da5bbfcc601
Parent 0a5679a4
Child 9f65ce1c

Added by Andreas Kohlbecker almost 4 years ago

Revert "ref #6886 test to repoduce issue with users having only CREATE permission"

This reverts commit 3795d1bf926c9b126317a85d880235301a0a4b16.

View differences:

cdmlib-persistence/src/test/resources/log4j.properties
53 53

  
54 54

  
55 55
  ### ***HIBERNATE ************ ###
56
  
57
# supress HHH90000003
58
log4j.logger.org.hibernate.orm.deprecation=ERROR
59 56

  
60 57
#log4j.logger.org.hibernate=warn, file
61 58
#log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport = error
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/AllowEditingOwnEntitesIntegrationTest.java
1
/**
2
* Copyright (C) 2017 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.cdm.api.service;
10

  
11
import java.io.FileNotFoundException;
12

  
13
import org.hibernate.Session;
14
import org.junit.After;
15
import org.junit.Before;
16
import org.junit.Ignore;
17
import org.junit.Test;
18
import org.springframework.security.authentication.AuthenticationManager;
19
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
20
import org.springframework.security.core.Authentication;
21
import org.springframework.transaction.TransactionStatus;
22
import org.unitils.dbunit.annotation.DataSet;
23
import org.unitils.spring.annotation.SpringBean;
24

  
25
import eu.etaxonomy.cdm.api.application.CdmRepository;
26
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTestWithSecurity;
30

  
31
/**
32
 * @author a.kohlbecker
33
 * @since Aug 3, 2017
34
 *
35
 */
36
@DataSet
37
public class AllowEditingOwnEntitesIntegrationTest extends CdmTransactionalIntegrationTestWithSecurity{
38

  
39
    @SpringBean("cdmRepository")
40
    private CdmRepository repo;
41

  
42
    @SpringBean("conversationHolder")
43
    ConversationHolder conversationHolder;
44

  
45
    private Session session;
46

  
47
    private TransactionStatus tx;
48

  
49

  
50
    public void startSession(){
51
        session = repo.getSession();
52
        tx = repo.startTransaction();
53
    }
54

  
55
    public void endSession(){
56
        session.flush();
57
        repo.commitTransaction(tx);
58
    }
59

  
60
    @Before
61
    public void clearSession(){
62
        repo.getSession().clear();
63
    }
64

  
65
    @Override
66
    @After
67
    public void onTearDown() throws Exception {
68
        if(conversationHolder.isBound()){
69
            conversationHolder.unbind();
70
        }
71
    }
72

  
73
    public void authenticate(){
74

  
75
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("editor", "sPePhAz6");
76
        AuthenticationManager authenticationManager = repo.getAuthenticationManager();
77
        Authentication authentication = authenticationManager.authenticate(token);
78
    }
79

  
80
    @Test
81
    @DataSet
82
    public void longSession_merge_flush(){
83

  
84
       startSession();
85
       authenticate();
86
       Reference article = ReferenceFactory.newArticle();
87
       article.setTitle("Test");
88
       session.merge(article);
89
       session.flush();
90
       endSession();
91
    }
92

  
93
    @Test
94
    @DataSet
95
    public void longSession_merge_save_flush(){
96

  
97
       startSession();
98
       authenticate();
99

  
100
       Reference article = ReferenceFactory.newArticle();
101
       article.setTitle("Test");
102
       article = (Reference) session.merge(article);
103
       repo.getReferenceService().save(article);
104
       session.flush();
105
       endSession();
106
    }
107

  
108
    @Test
109
    @DataSet
110
    public void longSession_merge_saveOrUpdate_flush(){
111

  
112
       startSession();
113
       authenticate();
114

  
115
       Reference article = ReferenceFactory.newArticle();
116
       article.setTitle("Test");
117
       article = (Reference) session.merge(article);
118
       repo.getReferenceService().saveOrUpdate(article);
119
       session.flush();
120
       endSession();
121
    }
122

  
123
    @Test
124
    @DataSet
125
    @Ignore
126
    public void conversationHolder_merge_flush(){
127

  
128
        authenticate();
129

  
130
        conversationHolder.bind();
131
       conversationHolder.startTransaction();
132

  
133
       Reference article = ReferenceFactory.newArticle();
134
       article.setTitle("Test");
135
       article = (Reference) conversationHolder.getSession().merge(article);
136
       conversationHolder.getSession().flush();
137
       conversationHolder.commit(true);
138
    }
139

  
140
    /**
141
     * fails with org.springframework.security.authentication.BadCredentialsException: Bad credentials
142
     * during the session.flush() the hibernate
143
     */
144
    @Test
145
    @DataSet
146
    @Ignore
147
    public void conversationHolder_merge_save_flush(){
148

  
149
        authenticate();
150

  
151
       conversationHolder.bind();
152
       conversationHolder.startTransaction();
153

  
154
       Reference article = ReferenceFactory.newArticle();
155
       article.setTitle("Test");
156
       article = (Reference) conversationHolder.getSession().merge(article);
157
       repo.getReferenceService().save(article);
158
       conversationHolder.getSession().flush();
159
       conversationHolder.commit();
160
       conversationHolder.unbind();
161
    }
162

  
163
    @Test
164
    @DataSet
165
    @Ignore
166
    public void conversationHolder_merge_saveOrUpdate_flush(){
167

  
168
       authenticate();
169

  
170
       conversationHolder.bind();
171
       conversationHolder.startTransaction();
172

  
173
       Reference article = ReferenceFactory.newArticle();
174
       article.setTitle("Test");
175
       article = (Reference) conversationHolder.getSession().merge(article);
176
       repo.getReferenceService().saveOrUpdate(article);
177
       conversationHolder.getSession().flush();
178
       conversationHolder.commit();
179
       conversationHolder.unbind();
180
    }
181

  
182
    @Test
183
    @DataSet
184
    @Ignore
185
    public void conversationHolder_saveOrUpdate_flush(){
186

  
187
       conversationHolder.bind();
188
       conversationHolder.startTransaction();
189
       authenticate();
190

  
191
       Reference article = ReferenceFactory.newArticle();
192
       article.setTitle("Test");
193
       article = (Reference) conversationHolder.getSession().merge(article);
194
       repo.getReferenceService().saveOrUpdate(article);
195
       conversationHolder.getSession().flush();
196
       conversationHolder.commit();
197
       conversationHolder.unbind();
198
    }
199

  
200
    /**
201
     * {@inheritDoc}
202
     */
203
    @Override
204
    public void createTestDataSet() throws FileNotFoundException {
205
        // HAND CRAFTED TESTDATA
206
    }
207

  
208
}
cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/AllowEditingOwnEntitesIntegrationTest.xml
1
<?xml version='1.0' encoding='UTF-8'?>
2
<dataset  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../service/dataset.xsd">
3

  
4
  <GRANTEDAUTHORITYIMPL ID="1"  UUID="fa56073c-0ffd-4384-b459-b2f07e35b689" CREATED="2009-02-03 17:52:26.0" AUTHORITY="REFERENCE.[CREATE]"/>
5
  
6
  <USERACCOUNT USERNAME="editor" ID="1" CREATED="2009-06-18 13:47:59.0" UUID="e4acf200-63b6-11dd-ad8b-0800200c9a66" PASSWORD="9fb8ce1dfa9dca7214cfbb7e641b4227" ENABLED="true" ACCOUNTNONEXPIRED="true" CREDENTIALSNONEXPIRED="true" ACCOUNTNONLOCKED="true"/>
7
 
8
  <USERACCOUNT_GRANTEDAUTHORITYIMPL USER_ID="1" GRANTEDAUTHORITIES_ID="1" />
9
</dataset>
10

  
cdmlib-services/src/test/resources/eu/etaxonomy/cdm/applicationContext-test.xml
9 9
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
10 10
    ">
11 11

  
12
    <context:property-override location="classpath:override.properties"/>
12
   <context:property-override location="classpath:override.properties"/>
13 13

  
14
    <context:component-scan base-package="eu/etaxonomy/cdm/api/service"/>    
15
    <!-- No component scan for eu.etaxonomy.cdm.api.application, therefore we add the bean explicitly -->
16
    <bean id="cdmRepository" class="eu.etaxonomy.cdm.api.application.CdmRepository"/>
17
    <bean id="conversationHolder" class="eu.etaxonomy.cdm.api.conversation.ConversationHolder" scope="prototype"/>
14
   <context:component-scan base-package="eu/etaxonomy/cdm/api/service"/>
18 15
   
19 16
 <!--    <context:component-scan base-package="eu/etaxonomy/cdm/api/validation">
20 17
    </context:component-scan>

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)