Skip to content
Snippets Groups Projects
Commit b9c02b5f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

creating project was crashing

parent 0ce36e62
No related branches found
No related tags found
1 merge request!860Resolve "Comment table changes"
......@@ -75,24 +75,28 @@ public class UserService implements IUserService {
@Override
public void grantUserPrivilege(User user, PrivilegeType type) {
user = getUserByLogin(user.getLogin());
user.addPrivilege(privilegeService.getPrivilege(type));
userDao.update(user);
}
@Override
public void grantUserPrivilege(User user, PrivilegeType type, String objectId) {
user = getUserByLogin(user.getLogin());
user.addPrivilege(privilegeService.getPrivilege(type, objectId));
userDao.update(user);
}
@Override
public void revokeUserPrivilege(User user, PrivilegeType type) {
user = getUserByLogin(user.getLogin());
user.removePrivilege(privilegeService.getPrivilege(type));
userDao.update(user);
}
@Override
public void revokeUserPrivilege(User user, PrivilegeType type, String objectId) {
user = getUserByLogin(user.getLogin());
user.removePrivilege(privilegeService.getPrivilege(type, objectId));
userDao.update(user);
}
......
......@@ -20,6 +20,7 @@ import org.junit.runners.Suite.SuiteClasses;
PluginControllerIntegrationTest.class,
ProjectControllerIntegrationTest.class,
ProjectControllerIntegrationTestForAsyncCalls.class,
ProjectControllerIntegrationTestWithoutTransaction.class,
PublicationsControllerIntegrationTest.class,
ReactionControllerIntegrationTest.class,
SpringSecurityGeneralIntegrationTest.class,
......
......@@ -27,6 +27,7 @@ import org.springframework.web.context.WebApplicationContext;
import lcsb.mapviewer.common.MinervaLoggerAppender;
import lcsb.mapviewer.common.UnitTestFailedWatcher;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectStatus;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.model.ModelData;
......@@ -232,4 +233,33 @@ abstract public class ControllerIntegrationTest {
});
}
protected UploadedFileEntry createFileInSeparateThread(String content, User user) throws Exception {
return callInSeparateThread(() -> {
return createFile(content, user);
});
}
protected void waitForProjectToFinishLoading(String projectId) throws InterruptedException {
Project project;
do {
project = projectDao.getProjectByProjectId(projectId);
projectDao.evict(project);
Thread.sleep(100);
} while (project.getStatus() != ProjectStatus.DONE);
}
public void removeProjectInSeparateThread(Project project) throws Exception {
removeProjectInSeparateThread(project.getProjectId());
}
public void removeProjectInSeparateThread(String projectId) throws Exception {
callInSeparateThread(() -> {
Project project = projectDao.getProjectByProjectId(projectId);
if (project != null) {
projectDao.delete(project);
}
return null;
});
}
}
......@@ -101,15 +101,6 @@ public class ProjectControllerIntegrationTestForAsyncCalls extends ControllerInt
}
}
private void waitForProjectToFinishLoading(String projectId) throws InterruptedException {
Project project;
do {
project = projectDao.getProjectByProjectId(projectId);
projectDao.evict(project);
Thread.sleep(100);
} while (project.getStatus() != ProjectStatus.DONE);
}
private void waitForProjectToFinishRemoving(String projectId) throws InterruptedException {
Project project;
do {
......@@ -377,11 +368,6 @@ public class ProjectControllerIntegrationTestForAsyncCalls extends ControllerInt
}
}
private UploadedFileEntry createFileInSeparateThread(String content, User user) throws Exception {
return callInSeparateThread(() -> {
return createFile(content, user);
});
}
private User createCuratorInSeparateThread(String login, String password) throws Exception {
return callInSeparateThread(() -> {
......@@ -401,18 +387,4 @@ public class ProjectControllerIntegrationTestForAsyncCalls extends ControllerInt
});
}
private void removeProjectInSeparateThread(Project project) throws Exception {
removeProjectInSeparateThread(project.getProjectId());
}
private void removeProjectInSeparateThread(String projectId) throws Exception {
callInSeparateThread(() -> {
Project project = projectDao.getProjectByProjectId(projectId);
if (project != null) {
projectDao.delete(project);
}
return null;
});
}
}
package lcsb.mapviewer.web;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.RequestBuilder;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.interfaces.IUserService;
@RunWith(SpringJUnit4ClassRunner.class)
public class ProjectControllerIntegrationTestWithoutTransaction extends ControllerIntegrationTest {
private static final String BUILT_IN_ADMIN_PASSWORD = "admin";
private static final String BUILT_IN_ADMIN_LOGIN = "admin";
private static final String TEST_PROJECT = "test_project";
Logger logger = LogManager.getLogger();
@Autowired
private IUserService userService;
@Before
public void setup() {
}
@Test
public void addProjectAsCurator() throws Exception {
User admin = userService.getUserByLogin(BUILT_IN_ADMIN_LOGIN);
try {
UploadedFileEntry fileEntry = createFileInSeparateThread(
new String(Files.readAllBytes(Paths.get("./src/test/resources/generic.xml")), "UTF-8"),
admin);
String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("file-id", String.valueOf(fileEntry.getId())),
new BasicNameValuePair("mapCanvasType", "OPEN_LAYERS"),
new BasicNameValuePair("parser",
"lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser"))));
RequestBuilder request = post("/projects/" + TEST_PROJECT)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(createSession(BUILT_IN_ADMIN_LOGIN, BUILT_IN_ADMIN_PASSWORD));
mockMvc.perform(request).andExpect(status().is2xxSuccessful());
} finally {
callInSeparateThread(()->{
try {
waitForProjectToFinishLoading(TEST_PROJECT);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
});
removeProjectInSeparateThread(TEST_PROJECT);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment