Skip to content
Snippets Groups Projects
Commit 0302f3bf authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5666 throw exception if no rueckfrage exists

parent a4e007cc
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@ import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import de.ozgcloud.common.errorhandling.TechnicalException;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import io.grpc.stub.StreamObserver;
import lombok.RequiredArgsConstructor;
......@@ -79,7 +80,8 @@ class AntragraumGrpcService extends AntragraumServiceGrpc.AntragraumServiceImplB
Rueckfrage getRueckfrage(String samlToken, String postfachNachrichtId) {
return antragraumService.findRueckfragen(samlToken)
.filter(rueckfrage -> StringUtils.equals(rueckfrage.getId(), postfachNachrichtId))
.toList().getFirst();
.findFirst()
.orElseThrow(() -> new TechnicalException(String.format("No rueckfrage found for answer with id %s", postfachNachrichtId)));
}
PostfachNachricht enrichRueckfrageAnswer(PostfachNachricht answer, Rueckfrage rueckfrage) {
......
......@@ -37,6 +37,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import de.ozgcloud.common.errorhandling.TechnicalException;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.PostfachNachrichtTestFactory;
import io.grpc.stub.StreamObserver;
......@@ -183,6 +184,13 @@ class AntragraumGrpcServiceTest {
assertThat(rueckfrage).isEqualTo(matchingRueckfrage);
}
@Test
void shouldThrowExceptionIfNoRueckfrageExists() {
when(service.findRueckfragen(any())).thenReturn(Stream.empty());
assertThatThrownBy(() -> getRueckfrage()).isInstanceOf(TechnicalException.class);
}
private Rueckfrage getRueckfrage() {
return grpcService.getRueckfrage(GrpcSendRueckfrageAnswerRequestTestFactory.SAML_TOKEN,
GrpcRueckfrageAnswerTestFactory.RUECKFRAGE_ID);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment