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

OZG-5237 Moved buildRequest from ClientAttributeService to ClientAttributeRemoteService

parent 30403919
No related branches found
No related tags found
No related merge requests found
...@@ -15,3 +15,4 @@ target/ ...@@ -15,3 +15,4 @@ target/
.attach** .attach**
.factorypath .factorypath
.vscode*
...@@ -26,17 +26,37 @@ package de.ozgcloud.alfa.common.clientattribute; ...@@ -26,17 +26,37 @@ package de.ozgcloud.alfa.common.clientattribute;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import de.ozgcloud.alfa.common.GrpcUtil; import de.ozgcloud.alfa.common.GrpcUtil;
import de.ozgcloud.alfa.common.errorhandling.FunctionalException;
import de.ozgcloud.vorgang.grpc.clientAttribute.ClientAttributeServiceGrpc.ClientAttributeServiceBlockingStub; import de.ozgcloud.vorgang.grpc.clientAttribute.ClientAttributeServiceGrpc.ClientAttributeServiceBlockingStub;
import de.ozgcloud.vorgang.grpc.clientAttribute.GrpcClientAttribute;
import de.ozgcloud.vorgang.grpc.clientAttribute.GrpcClientAttributeValue;
import de.ozgcloud.vorgang.grpc.clientAttribute.GrpcUpdateClientAttributeRequest; import de.ozgcloud.vorgang.grpc.clientAttribute.GrpcUpdateClientAttributeRequest;
import lombok.extern.log4j.Log4j2;
import net.devh.boot.grpc.client.inject.GrpcClient; import net.devh.boot.grpc.client.inject.GrpcClient;
@Service @Service
@Log4j2
class ClientAttributeRemoteService { class ClientAttributeRemoteService {
@GrpcClient(GrpcUtil.VORGANG_MANAGER_GRPC_CLIENT) @GrpcClient(GrpcUtil.VORGANG_MANAGER_GRPC_CLIENT)
private ClientAttributeServiceBlockingStub service; private ClientAttributeServiceBlockingStub service;
void resetPostfachNachricht(GrpcUpdateClientAttributeRequest request) { void setBooleanReadOnlyClientAttribute(String vorgangId, String clientName, String attributeName) {
service.update(request); try {
service.update(buildRequest(vorgangId, false, clientName, attributeName));
} catch (FunctionalException e) {
LOG.error("Error on resetting new Postfachnachrichten.", e);
}
} }
GrpcUpdateClientAttributeRequest buildRequest(String vorgangId, boolean value, String clientName, String attributeName) {
return GrpcUpdateClientAttributeRequest.newBuilder()
.setVorgangId(vorgangId)
.setAttribute(
GrpcClientAttribute.newBuilder().setValue(
GrpcClientAttributeValue.newBuilder().setBoolValue(value).build())
.setClientName(clientName)
.setAttributeName(attributeName)
.build())
.build();
}
} }
...@@ -23,40 +23,21 @@ ...@@ -23,40 +23,21 @@
*/ */
package de.ozgcloud.alfa.common.clientattribute; package de.ozgcloud.alfa.common.clientattribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import de.ozgcloud.vorgang.grpc.clientAttribute.GrpcClientAttribute; import lombok.RequiredArgsConstructor;
import de.ozgcloud.vorgang.grpc.clientAttribute.GrpcClientAttributeValue;
import de.ozgcloud.vorgang.grpc.clientAttribute.GrpcUpdateClientAttributeRequest;
@Service @Service
@RequiredArgsConstructor
public class ClientAttributeService { public class ClientAttributeService {
public static final String HAS_NEW_POSTFACH_NACHRICHT_ATTRIBUTE_NAME = "hasNewPostfachNachricht"; public static final String HAS_NEW_POSTFACH_NACHRICHT_ATTRIBUTE_NAME = "hasNewPostfachNachricht";
static final String ORIGINAL_CLIENT_NAME = "OzgCloud_NachrichtenManager"; static final String ORIGINAL_CLIENT_NAME = "OzgCloud_NachrichtenManager";
@Autowired private final ClientAttributeRemoteService remoteService;
private ClientAttributeRemoteService remoteService;
public void resetPostfachNachricht(String vorgangId) { public void resetPostfachNachricht(String vorgangId) {
remoteService.resetPostfachNachricht(buildResetNewPostfachNachricht(vorgangId)); remoteService.setBooleanReadOnlyClientAttribute(vorgangId, ORIGINAL_CLIENT_NAME, HAS_NEW_POSTFACH_NACHRICHT_ATTRIBUTE_NAME);
}
GrpcUpdateClientAttributeRequest buildResetNewPostfachNachricht(String vorgangId) {
return buildRequest(vorgangId, false, HAS_NEW_POSTFACH_NACHRICHT_ATTRIBUTE_NAME);
}
private GrpcUpdateClientAttributeRequest buildRequest(String vorgangId, boolean value, String attributeName) {
return GrpcUpdateClientAttributeRequest.newBuilder()
.setVorgangId(vorgangId)
.setAttribute(
GrpcClientAttribute.newBuilder().setValue(
GrpcClientAttributeValue.newBuilder().setBoolValue(value).build())
.setClientName(ORIGINAL_CLIENT_NAME)
.setAttributeName(attributeName)
.build())
.build();
} }
} }
...@@ -23,32 +23,103 @@ ...@@ -23,32 +23,103 @@
*/ */
package de.ozgcloud.alfa.common.clientattribute; package de.ozgcloud.alfa.common.clientattribute;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
import de.ozgcloud.alfa.common.errorhandling.FunctionalException;
import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
import de.ozgcloud.vorgang.grpc.clientAttribute.ClientAttributeServiceGrpc.ClientAttributeServiceBlockingStub; import de.ozgcloud.vorgang.grpc.clientAttribute.ClientAttributeServiceGrpc.ClientAttributeServiceBlockingStub;
import de.ozgcloud.vorgang.grpc.clientAttribute.GrpcUpdateClientAttributeRequest;
class ClientAttributeRemoteServiceTest { class ClientAttributeRemoteServiceTest {
@Nested private static final String CLIENT_NAME = "OzgCloud_NachrichtenManager";
class TestResetNewPostfachNachricht { private static final String ATTRIBUTE = "hasNewPostfachNachricht";
@Spy
@InjectMocks @Spy
private ClientAttributeRemoteService service; @InjectMocks
private ClientAttributeRemoteService service;
@Mock
private ClientAttributeServiceBlockingStub serviceStub;
@Mock @Mock
private ClientAttributeServiceBlockingStub serviceStub; private GrpcUpdateClientAttributeRequest request;
@Nested
class TestSetBooleanReadOnlyClientAttribute {
@BeforeEach
void mockBuildRequest() {
doReturn(request).when(service).buildRequest(VorgangHeaderTestFactory.ID, false, CLIENT_NAME, ATTRIBUTE);
}
@Test @Test
void shouldCallServiceStub() { void shouldCallServiceStub() {
service.resetPostfachNachricht(any()); callSetBooleanReadOnlyClientAttribute();
verify(serviceStub).update(request);
}
@Test
void shouldCatchFunctionalException() {
when(serviceStub.update(any())).thenThrow(new FunctionalException(() -> "Error"));
assertDoesNotThrow(() -> callSetBooleanReadOnlyClientAttribute());
}
private void callSetBooleanReadOnlyClientAttribute() {
service.setBooleanReadOnlyClientAttribute(VorgangHeaderTestFactory.ID, CLIENT_NAME, ATTRIBUTE);
}
}
@Nested
class TestBuildRequest {
@Test
void shouldHaveAttribute() {
GrpcUpdateClientAttributeRequest request = callBuildRequest();
assertThat(request.getAttribute()).isNotNull();
}
@Test
void shouldHaveVorgangId() {
GrpcUpdateClientAttributeRequest request = callBuildRequest();
assertThat(request.getVorgangId()).isEqualTo(VorgangHeaderTestFactory.ID);
}
@Test
void shouldHaveAttributeName() {
GrpcUpdateClientAttributeRequest request = callBuildRequest();
assertThat(request.getAttribute().getAttributeName()).isEqualTo(ClientAttributeService.HAS_NEW_POSTFACH_NACHRICHT_ATTRIBUTE_NAME);
}
@Test
void shouldHaveClientName() {
GrpcUpdateClientAttributeRequest request = callBuildRequest();
assertThat(request.getAttribute().getClientName()).isEqualTo(ClientAttributeService.ORIGINAL_CLIENT_NAME);
}
@Test
void shouldHaveAttributeValue() {
GrpcUpdateClientAttributeRequest request = callBuildRequest();
assertThat(request.getAttribute().getValue()).isNotNull();
assertThat(request.getAttribute().getValue().getBoolValue()).isFalse();
}
verify(serviceStub).update(any()); private GrpcUpdateClientAttributeRequest callBuildRequest() {
return service.buildRequest(VorgangHeaderTestFactory.ID, false, CLIENT_NAME, ATTRIBUTE);
} }
} }
} }
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
*/ */
package de.ozgcloud.alfa.common.clientattribute; package de.ozgcloud.alfa.common.clientattribute;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
...@@ -34,12 +32,11 @@ import org.mockito.Mock; ...@@ -34,12 +32,11 @@ import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory; import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
import de.ozgcloud.vorgang.grpc.clientAttribute.GrpcUpdateClientAttributeRequest;
class ClientAttributeServiceTest { class ClientAttributeServiceTest {
@Spy @Spy
@InjectMocks @InjectMocks
private ClientAttributeService service = new ClientAttributeService(); private ClientAttributeService service;
@Mock @Mock
private ClientAttributeRemoteService remoteService; private ClientAttributeRemoteService remoteService;
...@@ -49,47 +46,8 @@ class ClientAttributeServiceTest { ...@@ -49,47 +46,8 @@ class ClientAttributeServiceTest {
void shouldCallRemoteService() { void shouldCallRemoteService() {
service.resetPostfachNachricht(VorgangHeaderTestFactory.ID); service.resetPostfachNachricht(VorgangHeaderTestFactory.ID);
verify(remoteService).resetPostfachNachricht(any()); verify(remoteService).setBooleanReadOnlyClientAttribute(VorgangHeaderTestFactory.ID, ClientAttributeService.ORIGINAL_CLIENT_NAME,
} ClientAttributeService.HAS_NEW_POSTFACH_NACHRICHT_ATTRIBUTE_NAME);
}
@Nested
class BuildRequest {
@Test
void shouldHaveAttribute() {
GrpcUpdateClientAttributeRequest request = service.buildResetNewPostfachNachricht(VorgangHeaderTestFactory.ID);
assertThat(request.getAttribute()).isNotNull();
}
@Test
void shouldHaveVorgangId() {
GrpcUpdateClientAttributeRequest request = service.buildResetNewPostfachNachricht(VorgangHeaderTestFactory.ID);
assertThat(request.getVorgangId()).isEqualTo(VorgangHeaderTestFactory.ID);
}
@Test
void shouldHaveAttributeName() {
GrpcUpdateClientAttributeRequest request = service.buildResetNewPostfachNachricht(VorgangHeaderTestFactory.ID);
assertThat(request.getAttribute().getAttributeName()).isEqualTo(ClientAttributeService.HAS_NEW_POSTFACH_NACHRICHT_ATTRIBUTE_NAME);
}
@Test
void shouldHaveClientName() {
GrpcUpdateClientAttributeRequest request = service.buildResetNewPostfachNachricht(VorgangHeaderTestFactory.ID);
assertThat(request.getAttribute().getClientName()).isEqualTo(ClientAttributeService.ORIGINAL_CLIENT_NAME);
}
@Test
void shouldHaveAttributeValue() {
GrpcUpdateClientAttributeRequest request = service.buildResetNewPostfachNachricht(VorgangHeaderTestFactory.ID);
assertThat(request.getAttribute().getValue()).isNotNull();
assertThat(request.getAttribute().getValue().getBoolValue()).isFalse();
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment