Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dspace-api/src/test/java/org/dspace/builder/ItemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public Item build() {

@Override
public void cleanup() throws Exception {
try (Context c = new Context()) {
try (Context c = new Context()) {
c.setDispatcher("noindex");
c.turnOffAuthorisationSystem();
// If the workspaceItem used to create this item still exists, delete it
Expand All @@ -413,7 +413,7 @@ public void cleanup() throws Exception {
delete(c, item);
}
c.complete();
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.dspace.content.service.CollectionService;
import org.dspace.content.service.CommunityService;
import org.dspace.content.service.ItemService;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.identifier.factory.IdentifierServiceFactory;
import org.dspace.identifier.service.IdentifierService;
import org.dspace.services.ConfigurationService;
Expand Down Expand Up @@ -80,6 +81,7 @@ public class ItemHandleCheckerIT extends AbstractIntegrationTestWithDatabase {
@Override
public void setUp() throws Exception {
super.setUp();
CoreServiceFactory.getInstance().getPluginService().clearNamedPluginClasses();
try {
//we have to create a new community in the database
context.turnOffAuthorisationSystem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.dspace.content.service.CommunityService;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.core.factory.CoreServiceFactory;
import org.dspace.identifier.factory.IdentifierServiceFactory;
import org.dspace.identifier.service.IdentifierService;
import org.junit.After;
Expand Down Expand Up @@ -96,6 +97,8 @@ public void setUp() throws Exception {

@Test
public void testPerform() throws IOException {
CoreServiceFactory.getInstance().getPluginService().clearNamedPluginClasses();

Curator curator = new Curator();
curator.addTask(TASK_NAME);
CuratorReportTest.ListReporter reporter = new CuratorReportTest.ListReporter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.Map;
import java.util.Random;
Expand All @@ -38,6 +39,7 @@
import org.dspace.core.I18nUtil;
import org.dspace.eperson.EPerson;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -56,7 +58,12 @@ public class BitstreamFormatRestRepositoryIT extends AbstractControllerIntegrati
@Autowired
private BitstreamFormatConverter bitstreamFormatConverter;

private final int DEFAULT_AMOUNT_FORMATS = 95;
private int DEFAULT_AMOUNT_FORMATS;

@Before
public void init() throws SQLException {
DEFAULT_AMOUNT_FORMATS = bitstreamFormatService.findAll(context).size();
}
Comment on lines +61 to +66
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFAULT_AMOUNT_FORMATS is no longer a constant (it’s assigned in @before), but it’s still named like a constant (ALL_CAPS). Rename it to a regular field name (e.g., defaultAmountFormats/initialAmountFormats) to match Java conventions and reduce confusion.

Copilot generated this review using guidance from organization custom instructions.

@Test
public void findAllPaginationTest() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
*/
package org.dspace.app.rest;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.zip.Deflater;

import org.apache.commons.codec.CharEncoding;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.io.IOUtils;
import org.dspace.app.rest.model.ItemRest;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
Expand Down Expand Up @@ -78,23 +78,22 @@ public void setUp() throws Exception {

@Test
public void downloadAllZip() throws Exception {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipArchiveOutputStream zip = new ZipArchiveOutputStream(byteArrayOutputStream);
zip.setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS);
zip.setLevel(Deflater.NO_COMPRESSION);
ZipArchiveEntry ze = new ZipArchiveEntry(bts.getName());
zip.putArchiveEntry(ze);
InputStream is = bitstreamService.retrieve(context, bts);
org.apache.commons.compress.utils.IOUtils.copy(is, zip);
zip.closeArchiveEntry();
is.close();
zip.close();
String bitstreamContent = "ThisIsSomeDummyText";

Comment on lines +81 to 82
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bitstreamContent is hardcoded again in this test method, duplicating the value used when creating the Bitstream in setUp(). To avoid future divergence (e.g., setUp changes but the assertion doesn’t), store the content in a shared constant/field or derive expected bytes by retrieving the bitstream content from bts.

Copilot uses AI. Check for mistakes.
String token = getAuthToken(admin.getEmail(), password);
getClient(token).perform(get(METADATABITSTREAM_ENDPOINT + "/" + publicItem.getID() +
byte[] responseBytes = getClient(token).perform(get(METADATABITSTREAM_ENDPOINT + "/" + publicItem.getID() +
"/" + ALL_ZIP_PATH).param(HANDLE_PARAM, publicItem.getHandle()))
.andExpect(status().isOk())
.andExpect(content().bytes(byteArrayOutputStream.toByteArray()));
.andReturn().getResponse().getContentAsByteArray();

// Verify the ZIP content by extracting and comparing the entry
try (ZipArchiveInputStream zipIn = new ZipArchiveInputStream(new ByteArrayInputStream(responseBytes))) {
ZipArchiveEntry entry = zipIn.getNextZipEntry();
// Verify entry name matches bitstream name
assertEquals(bts.getName(), entry.getName());
// Verify uncompressed content matches the original bitstream content
Comment on lines +90 to +94
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After calling getNextZipEntry(), the test assumes an entry exists. If the response is not a valid ZIP or is empty, entry will be null and the test will NPE on entry.getName(), which makes failures harder to diagnose. Add an assertion that the entry is non-null (and optionally assert there are no unexpected additional entries).

Copilot uses AI. Check for mistakes.
byte[] extractedBytes = org.apache.commons.compress.utils.IOUtils.toByteArray(zipIn);
assertArrayEquals(bitstreamContent.getBytes(CharEncoding.UTF_8), extractedBytes);
}
}
}
Loading