aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at/gv
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-09 14:11:47 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-09 14:11:47 +0200
commit8aba1b4f18f5fbfebdf239b4b4945b628e439905 (patch)
tree0004115e44b8d6ddf48542b7413d4f54fa76dc27 /src/test/java/at/gv
parent65163646205b6e05139485fe957bceabe531f447 (diff)
downloadmoa-zs-8aba1b4f18f5fbfebdf239b4b4945b628e439905.tar.gz
moa-zs-8aba1b4f18f5fbfebdf239b4b4945b628e439905.tar.bz2
moa-zs-8aba1b4f18f5fbfebdf239b4b4945b628e439905.zip
Refactor Needles Interfaces and Rename "process" to "backend"
Reason: - Interfaces with a single method can be replaced with interfaces from java.util.function. - Less interfaces = less code = less maintenance! - Spring can inject beans by name so we name dependencies correctly to prevent ambiguity. Others: - Rename process to backend since backend gives a better description of its components.
Diffstat (limited to 'src/test/java/at/gv')
-rw-r--r--src/test/java/at/gv/egiz/moazs/DeliveryRequestBackendTest.java (renamed from src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java)27
-rw-r--r--src/test/java/at/gv/egiz/moazs/ITMoaSPSSSignatureVerifierTest.java9
-rw-r--r--src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java8
-rw-r--r--src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java4
4 files changed, 21 insertions, 27 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java b/src/test/java/at/gv/egiz/moazs/DeliveryRequestBackendTest.java
index e245eb1..ed63489 100644
--- a/src/test/java/at/gv/egiz/moazs/SingleThreadedDeliveryPipelineTest.java
+++ b/src/test/java/at/gv/egiz/moazs/DeliveryRequestBackendTest.java
@@ -1,13 +1,12 @@
package at.gv.egiz.moazs;
-import at.gv.egiz.moazs.process.DeliveryPipeline;
-import at.gv.egiz.moazs.process.SingleThreadedDeliveryPipeline;
-import at.gv.egiz.moazs.client.TnvzHelper;
-import at.gv.egiz.moazs.scheme.*;
import at.gv.egiz.moazs.client.ClientFactory;
+import at.gv.egiz.moazs.client.TnvzHelper;
+import at.gv.egiz.moazs.backend.DeliveryRequestBackend;
+import at.gv.egiz.moazs.backend.SignatureVerifier;
import at.gv.egiz.moazs.repository.DeliveryRepository;
import at.gv.egiz.moazs.repository.InMemoryDeliveryRepository;
-import at.gv.egiz.moazs.verify.MoaSPSSSignatureVerifier;
+import at.gv.egiz.moazs.scheme.Mzs2MsgConverter;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
import at.gv.zustellung.msg.xsd.App2ZusePort;
import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType;
@@ -35,7 +34,7 @@ import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
-public class SingleThreadedDeliveryPipelineTest {
+public class DeliveryRequestBackendTest {
private DeliveryRepository repository = new InMemoryDeliveryRepository(100);
@@ -55,14 +54,14 @@ public class SingleThreadedDeliveryPipelineTest {
private Mzs2MsgConverter converter;
@Mock
- private MoaSPSSSignatureVerifier verifier;
+ private SignatureVerifier verifier;
- private DeliveryPipeline pipeline;
+ private DeliveryRequestBackend pipeline;
@Before
public void setup() {
- pipeline = new SingleThreadedDeliveryPipeline(
+ pipeline = new DeliveryRequestBackend(
repository,
tnvzHelper,
converter,
@@ -75,7 +74,7 @@ public class SingleThreadedDeliveryPipelineTest {
var appDeliveryID = "no-tnvz-request";
var expectedStatus = setupMocks(appDeliveryID, false);
- pipeline.processRequest(appDeliveryID);
+ pipeline.accept(appDeliveryID);
verifyZeroInteractions(tnvzHelper);
var response = repository.retrieveResponse(getResponseID(appDeliveryID)).get();
@@ -91,7 +90,7 @@ public class SingleThreadedDeliveryPipelineTest {
when(tnvzHelper.performQueryPersonRequest(any(), any(), any()))
.thenThrow(buildMzsException("400", appDeliveryID));
- pipeline.processRequest(appDeliveryID);
+ pipeline.accept(appDeliveryID);
var responseID = getResponseID(appDeliveryID);
var response = repository.retrieveResponse(responseID).get();
@@ -108,7 +107,7 @@ public class SingleThreadedDeliveryPipelineTest {
var appDeliveryID = "tnvz-request";
var expectedStatus = setupMocks(appDeliveryID, true);
- pipeline.processRequest(appDeliveryID);
+ pipeline.accept(appDeliveryID);
var response = repository.retrieveResponse(getResponseID(appDeliveryID)).get();
var actualStatus = (DeliveryRequestStatusType) response.getResponse();
@@ -119,9 +118,9 @@ public class SingleThreadedDeliveryPipelineTest {
public void rejectInvalidSignature() {
var appDeliveryID = "invalid-signature";
setupMocks(appDeliveryID, true);
- doThrow(moaZSException("Signature Invalid!")).when(verifier).verify(any());
+ doThrow(moaZSException("Signature Invalid!")).when(verifier).accept(any());
- pipeline.processRequest(appDeliveryID);
+ pipeline.accept(appDeliveryID);
var response = repository.retrieveResponse(getResponseID(appDeliveryID)).get();
var status = (DeliveryRequestStatusType) response.getResponse();
var actualCode = status.getError().getErrorInfo().getCode();
diff --git a/src/test/java/at/gv/egiz/moazs/ITMoaSPSSSignatureVerifierTest.java b/src/test/java/at/gv/egiz/moazs/ITMoaSPSSSignatureVerifierTest.java
index 2c6b978..34f4e1b 100644
--- a/src/test/java/at/gv/egiz/moazs/ITMoaSPSSSignatureVerifierTest.java
+++ b/src/test/java/at/gv/egiz/moazs/ITMoaSPSSSignatureVerifierTest.java
@@ -1,8 +1,7 @@
package at.gv.egiz.moazs;
import at.gv.egiz.eid.authhandler.modules.sigverify.moasig.api.ISignatureVerificationService;
-import at.gv.egiz.moazs.verify.MoaSPSSSignatureVerifier;
-import at.gv.egiz.moazs.verify.SignatureVerifier;
+import at.gv.egiz.moazs.backend.SignatureVerifier;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,7 +26,7 @@ import java.nio.file.Files;
@Bean
public SignatureVerifier verifier(@Autowired ISignatureVerificationService service){
- return new MoaSPSSSignatureVerifier(service, "test-trust-profile", true);
+ return new SignatureVerifier(service, "test-trust-profile", true);
}
}
@@ -41,7 +40,7 @@ import java.nio.file.Files;
var path = resourcesPath + "valid-signed-delivery-response.xml";
var signature = Files.readAllBytes(new File(path).toPath());
- verifier.verify(signature);
+ verifier.accept(signature);
}
@Test(expected = MoaZSException.class)
@@ -50,7 +49,7 @@ import java.nio.file.Files;
var path = resourcesPath + "invalid-signed-delivery-response.xml";
var signature = Files.readAllBytes(new File(path).toPath());
- verifier.verify(signature);
+ verifier.accept(signature);
}
}
diff --git a/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java b/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java
index a93c720..e9b4f70 100644
--- a/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java
+++ b/src/test/java/at/gv/egiz/moazs/ITMzsServiceTest.java
@@ -1,12 +1,9 @@
package at.gv.egiz.moazs;
-import at.gv.egiz.moazs.process.DeliveryPipeline;
import at.gv.egiz.moazs.repository.DeliveryRepository;
import at.gv.egiz.moazs.scheme.RequestStatusResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -25,6 +22,7 @@ import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Paths;
import java.util.GregorianCalendar;
+import java.util.function.Consumer;
import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.Success.successBuilder;
import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusType.deliveryRequestStatusTypeBuilder;
@@ -40,8 +38,6 @@ public class ITMzsServiceTest {
private final String basePath = "src/test/resources/at/gv/egiz/moazs/ITMzsServiceTest/";
- private final static Logger logger = LoggerFactory.getLogger(ITMzsServiceTest.class);
-
@TestConfiguration
public static class TestConfig {
@@ -50,7 +46,7 @@ public class ITMzsServiceTest {
@Bean
@Primary
- public DeliveryPipeline deliveryPipelineThatAlwaysSucceeds() {
+ public Consumer<String> deliveryPipelineThatAlwaysSucceeds() {
return appDeliveryId -> {
var success = successBuilder()
diff --git a/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java b/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java
index ca501c8..9ddd37e 100644
--- a/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java
+++ b/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java
@@ -1,6 +1,6 @@
package at.gv.egiz.moazs;
-import at.gv.egiz.moazs.process.SaveResponseToFileSink;
+import at.gv.egiz.moazs.backend.SaveResponseToFileSink;
import at.gv.egiz.moazs.repository.DeliveryRepository;
import at.gv.egiz.moazs.scheme.Marshaller;
import at.gv.egiz.moazs.scheme.RequestStatusResponse;
@@ -63,7 +63,7 @@ public class SaveResponseToFileSinkTest {
var fileContent = "<xml>some content</xml>";
var status = setupMocks(fileContent);
- sink.handle(status)
+ sink.apply(status)
.thenRun(() -> assertFilesCreatedAndContentMatches(fileContent));
}