forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf1e9da
commit 432aea7
Showing
3 changed files
with
23 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
dspace-server-webapp/src/test/data/dspaceFolder/atmire-versions.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"this" : "is for testing" | ||
} |
36 changes: 14 additions & 22 deletions
36
dspace-server-webapp/src/test/java/org/dspace/app/rest/AtmireVersionsControllerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,50 @@ | ||
package org.dspace.app.rest; | ||
|
||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import java.io.IOException; | ||
|
||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest; | ||
import org.junit.Ignore; | ||
import org.dspace.services.ConfigurationService; | ||
import org.dspace.services.factory.DSpaceServicesFactory; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
|
||
|
||
public class AtmireVersionsControllerIT extends AbstractControllerIntegrationTest { | ||
|
||
|
||
@Autowired | ||
private AtmireVersionsController atmireVersionsController; | ||
|
||
private final ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); | ||
@Override | ||
public void destroy() throws Exception { | ||
configurationService.setProperty(AtmireVersionsController.CONFIG_DIR, null); | ||
super.destroy(); | ||
} | ||
|
||
@Test | ||
@Ignore | ||
public void test_unauthorisedUserReadsversioning() throws Exception { | ||
// no token given to ensure the request is not authorised | ||
getClient().perform(get("/api/atmire-versions")) | ||
.andExpect(status().isUnauthorized()); | ||
} | ||
|
||
@Test | ||
@Ignore | ||
public void test_adminReadsNotExistingFile() throws Exception { | ||
when(atmireVersionsController.readFileAsJson(anyString())).thenThrow(new IOException("file not found")); | ||
configurationService.setProperty(AtmireVersionsController.CONFIG_DIR, "/something/wrong/"); | ||
|
||
String token = getAuthToken(admin.getEmail(), password); | ||
getClient(token).perform(get("/api/atmire-versions")) | ||
.andExpect(status().isNotFound()); | ||
} | ||
|
||
|
||
@Test | ||
public void test_adminReadsVersioningFile() throws Exception { | ||
|
||
when(atmireVersionsController.readFileAsJson(anyString())).thenReturn("{ 'some':'json' }"); | ||
configurationService.setProperty(AtmireVersionsController.CONFIG_DIR, "src/test/data/dspaceFolder/"); | ||
|
||
String token = getAuthToken(admin.getEmail(), password); | ||
getClient(token).perform(get("/api/atmire-versions")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string("{ 'some':'json' }")) | ||
.andExpect(header().string("Content-Type", MediaType.APPLICATION_JSON_VALUE)) | ||
.andExpect(header().string("filename", AtmireVersionsController.ATMIRE_VERSIONS_FILE)) | ||
.andExpect(header().string("size", ""+AtmireVersionsController.BUFFER_SIZE)); | ||
.andExpect(content().string("{\"this\":\"is for testing\"}")) | ||
.andExpect(header().string("Content-Type", "application/json;charset=UTF-8")) | ||
.andExpect(header().string("Content-Disposition", | ||
String.format("attachment;filename=\"%s\"",AtmireVersionsController.ATMIRE_VERSIONS_FILE))); | ||
} | ||
} |