Skip to content

Commit

Permalink
BXC-4430 working on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sharonluong committed Feb 22, 2024
1 parent 1de3f04 commit 508d7d5
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

import edu.unc.lib.boxc.auth.api.Permission;
import edu.unc.lib.boxc.auth.api.exceptions.AccessRestrictionException;
import edu.unc.lib.boxc.auth.api.models.AccessGroupSet;
import edu.unc.lib.boxc.auth.api.services.AccessControlService;
import edu.unc.lib.boxc.auth.fcrepo.models.AccessGroupSetImpl;
import edu.unc.lib.boxc.auth.fcrepo.services.GroupsThreadStore;
import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader;
import edu.unc.lib.boxc.model.api.objects.WorkObject;
import edu.unc.lib.boxc.model.api.ResourceType;
import edu.unc.lib.boxc.model.api.ids.PID;
import edu.unc.lib.boxc.model.api.services.RepositoryObjectFactory;
import edu.unc.lib.boxc.model.fcrepo.ids.PIDs;
import edu.unc.lib.boxc.search.solr.models.ContentObjectSolrRecord;
import edu.unc.lib.boxc.web.services.rest.exceptions.RestResponseEntityExceptionHandler;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.http.MediaType;
Expand All @@ -23,24 +28,31 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class ViewSettingIT extends AbstractAPIIT{
public class ViewSettingIT {
@InjectMocks
private ViewSettingController controller;
@Mock
private AccessControlService accessControlService;
private MockMvc mockMvc;
private AutoCloseable closeable;
private WorkObject workObject;
private ContentObjectSolrRecord workObject;
private final static String USERNAME = "test_user";
private final static AccessGroupSet GROUPS = new AccessGroupSetImpl("adminGroup");
private static final String OBJECT_ID = "f277bb38-272c-471c-a28a-9887a1328a1f";
private static final PID OBJECT_PID = PIDs.get(OBJECT_ID);

@BeforeEach
public void setup() {
closeable = openMocks(this);
mockMvc = MockMvcBuilders.standaloneSetup(controller)
.setControllerAdvice(new RestResponseEntityExceptionHandler())
.build();
workObject = new ContentObjectSolrRecord();
workObject.setId(OBJECT_ID);
workObject.setResourceType(ResourceType.Work.name());
workObject.setTitle("Test Work");
GroupsThreadStore.storeUsername(USERNAME);
GroupsThreadStore.storeGroups(GROUPS);
workObject = repositoryObjectFactory.createWorkObject(null);
}

@AfterEach
Expand All @@ -58,7 +70,7 @@ public void testGetViewSettingNoPermission() throws Exception {
doThrow(new AccessRestrictionException()).when(accessControlService)
.assertHasAccess(eq(workObject.getPid()), any(), eq(Permission.viewHidden));

mockMvc.perform(get("/edit/viewSettings/" + workObject.getPid())
mockMvc.perform(get("/edit/viewSettings/" + OBJECT_ID)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isForbidden());
}
Expand Down

0 comments on commit 508d7d5

Please sign in to comment.