Commit 3c1a2f05 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

test checking if anonymojus account can read map details with proper access level

parent 0a5aeab3
......@@ -8,6 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({ ConfigurationControllerIntegrationTest.class,
CommentControllerIntegrationTest.class,
FileControllerIntegrationTest.class,
MapControllerIntegrationTest.class,
OverlayControllerIntegrationTest.class,
PluginControllerIntegrationTest.class,
ProjectControllerIntegrationTest.class,
......
package lcsb.mapviewer.web;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
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.mock.web.MockHttpSession;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.transaction.annotation.Transactional;
import com.google.gson.JsonParser;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.interfaces.IUserService;
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@Rollback
public class MapControllerIntegrationTest extends ControllerIntegrationTest {
private static final String TEST_PROJECT = "test_project";
Logger logger = LogManager.getLogger();
private static final String ADMIN_PASSWORD = "admin_pass";
private static final String ADMIN_LOGIN = "admin_user";
@Autowired
private IUserService userService;
private User anonymous;
private Project project;
private ModelData map;
@Before
public void setup() {
project = createProject(TEST_PROJECT);
map = project.getModels().iterator().next();
anonymous = userService.getUserByLogin(Configuration.ANONYMOUS_LOGIN);
}
@Test
public void testGetAllProjectsAsAdmin() throws Exception {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/models/*/bioEntities/elements/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
String response = mockMvc.perform(request)
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
int elements = new JsonParser()
.parse(response)
.getAsJsonArray().size();
assertTrue("user should be able to access elements", elements > 0);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment