Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test for bitstream with null value for sizebytes #774

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ public BitstreamRest importBitstreamForExistingFile(HttpServletRequest request)

Boolean deleted = Boolean.parseBoolean(deletedString);
//set size bytes
bitstream.setSizeBytes(bitstreamRest.getSizeBytes());
if (!Objects.isNull(bitstreamRest.getSizeBytes())) {
Paurikova2 marked this conversation as resolved.
Show resolved Hide resolved
bitstream.setSizeBytes(bitstreamRest.getSizeBytes());
} else {
log.info("SizeBytes is null. Bitstream UUID: " + bitstream.getID());
}
//set checksum
bitstream.setChecksum(bitstreamRest.getCheckSum().getValue());
//set checksum algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,41 @@ public void importBitstreamForExistingFileValidationErrorTest() throws Exception
assertEquals(bitstreamService.findAll(context).size(), 0);
}

@Test
public void importDeletedBitstreamTest() throws Exception {
//input data
ObjectNode checksumNode = jsonNodeFactory.objectNode();
checksumNode.set("checkSumAlgorithm", null);
checksumNode.set("value", null);
ObjectNode node = jsonNodeFactory.objectNode();
node.set("sizeBytes", null);
node.set("checkSum", checksumNode);

//create new bitstream for existing file
ObjectMapper mapper = new ObjectMapper();
uuid = UUID.fromString(read( getClient(token).perform(post("/api/clarin/import/core/bitstream")
.content(mapper.writeValueAsBytes(node))
.contentType(contentType)
.param("internal_id", internalId)
.param("storeNumber", "0")
.param("deleted", "true"))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString(),
"$.id"));

bitstream = bitstreamService.find(context, uuid);
assertEquals(bitstream.getSizeBytes(), 0);
assertEquals(bitstream.getInternalId(), internalId);
assertEquals(bitstream.getStoreNumber(), 0);
assertEquals(bitstream.getSequenceID(), -1);
assertEquals(bitstream.isDeleted(), true);

//clean all
context.turnOffAuthorisationSystem();
BitstreamBuilder.deleteBitstream(uuid);
context.restoreAuthSystemState();
}

private void checkCreatedBitstream(UUID uuid, String internalId, int storeNumber,
String bitstreamFormat, int sequence, boolean deleted, long sizeBytes,
String checkSum) throws SQLException {
Expand Down
Loading