Skip to content
Snippets Groups Projects
Commit 8348b6a4 authored by Lukas Malte Monnerjahn's avatar Lukas Malte Monnerjahn
Browse files

OZG-6239 KOP-2607 fix MsgBoxPort::getStatusList

parent 75a5f2c1
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,6 @@ import de.ozgcloud.xta.test.app.model.XtaMessageMetaData;
import genv3.de.xoev.transport.xta.x211.ContentType;
import genv3.de.xoev.transport.xta.x211.GenericContentContainer;
import genv3.eu.osci.ws.x2008.x05.transport.MsgBoxFetchRequest;
import genv3.eu.osci.ws.x2008.x05.transport.MsgBoxStatusListRequestType;
import genv3.eu.osci.ws.x2014.x10.transport.MessageMetaData;
import genv3.eu.osci.ws.x2014.x10.transport.QualifierType;
import jakarta.activation.DataHandler;
......@@ -78,18 +77,4 @@ public interface RequestMapper {
default String mapMessageIdFromMsgBoxFetchRequest(MsgBoxFetchRequest fetchRequest) {
return fetchRequest.getMsgSelector().getMessageID().getFirst().getValue();
}
default int mapMaxListItems(MsgBoxStatusListRequestType fetchRequest){
int maxListItems;
try{
maxListItems = fetchRequest.getMaxListItems().intValueExact();
}
catch (ArithmeticException e){
maxListItems = Integer.MAX_VALUE;
}
if (maxListItems <= 0){
maxListItems = Integer.MAX_VALUE;
}
return maxListItems;
}
}
......@@ -118,7 +118,7 @@ public class MsgBoxPortImpl implements MsgBoxPortType {
return statusListResponse;
}
int maxListItems = requestMapper.mapMaxListItems(statusListRequest);
int maxListItems = getMaxListItemsOrThrow(statusListRequest);
XtaMessageMetaDataListing messageMetaDataListing = messageService.getStatusList(msgBoxRequestId, maxListItems);
messageMetaDataListing.messages().forEach(
m -> statusListResponse.getMessageMetaData().add(responseMapper.mapMessageMetaDataFromXtaMessageMetaData(m))
......@@ -131,11 +131,24 @@ public class MsgBoxPortImpl implements MsgBoxPortType {
private void validateGetStatusListRequest(MsgBoxStatusListRequestType statusListRequest) throws XTAWSTechnicalProblemException {
if (!(
validator.isNotNull(statusListRequest.getListForm(), "listForm")
&& statusListRequest.getListForm().equalsIgnoreCase("MessageMetaData")
&& validator.isNotNull(statusListRequest.getMaxListItems(), "maxListItems"))) {
throw new XTAWSTechnicalProblemException("Invalid getStatusList request");
}
}
private int getMaxListItemsOrThrow(MsgBoxStatusListRequestType statusListRequest) throws XTAWSTechnicalProblemException {
try {
int maxListItems = statusListRequest.getMaxListItems().intValueExact();
if (maxListItems <= 0) {
throw new XTAWSTechnicalProblemException("Invalid maxListItems value");
}
return maxListItems;
} catch (ArithmeticException e) {
throw new XTAWSTechnicalProblemException("Invalid maxListItems value");
}
}
private MsgBoxResponseType createInvalidSearchArgsResponseHeader(String msgBoxRequestId) {
var responseHeader = new MsgBoxResponseType();
responseHeader.setMsgBoxRequestID(msgBoxRequestId);
......
......@@ -158,39 +158,4 @@ public class RequestMapperTest {
}
}
@Nested
class MapMaxListItems {
private MsgBoxStatusListRequestType fetchRequest;
@DisplayName("Should map max list items from MsgBoxStatusListRequestType")
@Test
void shouldMapMaxListItems() {
fetchRequest = MsgBoxStatusListRequestTypeTestFactory.create(10);
var maxListItems = requestMapper.mapMaxListItems(fetchRequest);
assertThat(maxListItems).isEqualTo(10);
}
@DisplayName("Should map unsupported negative max list items value to maximum integer value")
@Test
void shouldMapMaxListItemsToMaxValue() {
fetchRequest = MsgBoxStatusListRequestTypeTestFactory.create(-1);
var maxListItems = requestMapper.mapMaxListItems(fetchRequest);
assertThat(maxListItems).isEqualTo(Integer.MAX_VALUE);
}
@DisplayName("Should map unsupported large max list items value to maximum integer value")
@Test
void shouldMapMaxListItemsToMaxValueWhenOverflowing() {
fetchRequest = MsgBoxStatusListRequestTypeTestFactory.create(Long.MAX_VALUE);
var maxListItems = requestMapper.mapMaxListItems(fetchRequest);
assertThat(maxListItems).isEqualTo(Integer.MAX_VALUE);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment