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 |
|
}
|
Revert "ref #6886 test to repoduce issue with users having only CREATE permission"
This reverts commit 3795d1bf926c9b126317a85d880235301a0a4b16.