Skip to content

Commit 2c5b30a

Browse files
committed
some binary stream api v2 integration tests
1 parent 5bdbc7b commit 2c5b30a

File tree

4 files changed

+175
-2
lines changed

4 files changed

+175
-2
lines changed

dsf-bpe/dsf-bpe-server/src/test/java/dev/dsf/bpe/integration/PluginV2IntegrationTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package dev.dsf.bpe.integration;
22

3+
import static org.junit.Assert.assertNotNull;
4+
35
import java.io.IOException;
46
import java.nio.file.Files;
57
import java.nio.file.Path;
68
import java.nio.file.Paths;
79
import java.security.cert.X509Certificate;
810
import java.util.List;
911

12+
import org.hl7.fhir.r4.model.Binary;
1013
import org.junit.BeforeClass;
1114
import org.junit.Test;
1215

@@ -16,6 +19,8 @@
1619
import de.hsheilbronn.mi.utils.crypto.io.KeyStoreWriter;
1720
import de.hsheilbronn.mi.utils.crypto.io.PemWriter;
1821
import de.hsheilbronn.mi.utils.crypto.keystore.KeyStoreCreator;
22+
import dev.dsf.fhir.authorization.read.ReadAccessHelperImpl;
23+
import jakarta.ws.rs.core.MediaType;
1924

2025
public class PluginV2IntegrationTest extends AbstractPluginIntegrationTest
2126
{
@@ -204,4 +209,17 @@ public void startEnvironmentVariableTest() throws Exception
204209
{
205210
executePluginTest(createTestTask("EnvironmentVariableTest"));
206211
}
212+
213+
@Test
214+
public void startDsfClientTest() throws Exception
215+
{
216+
Binary binary = new Binary();
217+
new ReadAccessHelperImpl().addLocal(binary);
218+
binary.setData(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
219+
binary.setContentType(MediaType.APPLICATION_OCTET_STREAM);
220+
Binary created = getWebserviceClient().create(binary);
221+
assertNotNull(created);
222+
223+
executePluginTest(createTestTask("DsfClientTest"));
224+
}
207225
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package dev.dsf.bpe.test.service;
2+
3+
import static dev.dsf.bpe.test.PluginTestExecutor.expectNotNull;
4+
import static dev.dsf.bpe.test.PluginTestExecutor.expectNull;
5+
import static dev.dsf.bpe.test.PluginTestExecutor.expectSame;
6+
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
import org.hl7.fhir.r4.model.Binary;
11+
import org.hl7.fhir.r4.model.Bundle;
12+
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
13+
import org.hl7.fhir.r4.model.IdType;
14+
15+
import dev.dsf.bpe.test.AbstractTest;
16+
import dev.dsf.bpe.test.PluginTest;
17+
import dev.dsf.bpe.v2.ProcessPluginApi;
18+
import dev.dsf.bpe.v2.activity.ServiceTask;
19+
import dev.dsf.bpe.v2.client.dsf.BinaryInputStream;
20+
import dev.dsf.bpe.v2.client.dsf.DsfClient;
21+
import dev.dsf.bpe.v2.error.ErrorBoundaryEvent;
22+
import dev.dsf.bpe.v2.variables.Variables;
23+
import jakarta.ws.rs.core.MediaType;
24+
25+
public class DsfClientTest extends AbstractTest implements ServiceTask
26+
{
27+
@Override
28+
public void execute(ProcessPluginApi api, Variables variables) throws ErrorBoundaryEvent, Exception
29+
{
30+
DsfClient localDsfClient = api.getDsfClientProvider().getLocalDsfClient();
31+
32+
Bundle search = localDsfClient.search(Binary.class, Map.of("_count", List.of("1")));
33+
IdType testBinaryId = search.getEntry().stream().filter(BundleEntryComponent::hasResource)
34+
.map(BundleEntryComponent::getResource).filter(r -> r instanceof Binary).map(r -> r.getIdElement())
35+
.findFirst().get();
36+
37+
executeTests(api, variables, localDsfClient, testBinaryId);
38+
}
39+
40+
@PluginTest
41+
public void downloadFull(DsfClient localDsfClient, IdType testBinaryId) throws Exception
42+
{
43+
try (BinaryInputStream binary = localDsfClient.readBinary(testBinaryId.getIdPart(),
44+
MediaType.APPLICATION_OCTET_STREAM_TYPE))
45+
{
46+
expectNotNull(binary);
47+
expectSame(10, binary.getContentLength());
48+
expectNull(binary.getRange());
49+
50+
byte[] allBytes = binary.readAllBytes();
51+
expectSame(10, allBytes.length);
52+
expectSame(0, allBytes[0]);
53+
expectSame(1, allBytes[1]);
54+
expectSame(2, allBytes[2]);
55+
expectSame(3, allBytes[3]);
56+
expectSame(4, allBytes[4]);
57+
expectSame(5, allBytes[5]);
58+
expectSame(6, allBytes[6]);
59+
expectSame(7, allBytes[7]);
60+
expectSame(8, allBytes[8]);
61+
expectSame(9, allBytes[9]);
62+
}
63+
}
64+
65+
@PluginTest
66+
public void downloadFullVersion(DsfClient localDsfClient, IdType testBinaryId) throws Exception
67+
{
68+
try (BinaryInputStream binary = localDsfClient.readBinary(testBinaryId.getIdPart(),
69+
testBinaryId.getVersionIdPart(), MediaType.APPLICATION_OCTET_STREAM_TYPE))
70+
{
71+
expectNotNull(binary);
72+
expectSame(10, binary.getContentLength());
73+
expectNull(binary.getRange());
74+
75+
byte[] allBytes = binary.readAllBytes();
76+
expectSame(10, allBytes.length);
77+
expectSame(0, allBytes[0]);
78+
expectSame(1, allBytes[1]);
79+
expectSame(2, allBytes[2]);
80+
expectSame(3, allBytes[3]);
81+
expectSame(4, allBytes[4]);
82+
expectSame(5, allBytes[5]);
83+
expectSame(6, allBytes[6]);
84+
expectSame(7, allBytes[7]);
85+
expectSame(8, allBytes[8]);
86+
expectSame(9, allBytes[9]);
87+
}
88+
}
89+
90+
@PluginTest
91+
public void downloadRange(DsfClient localDsfClient, IdType testBinaryId) throws Exception
92+
{
93+
try (BinaryInputStream binary = localDsfClient.readBinary(testBinaryId.getIdPart(),
94+
MediaType.APPLICATION_OCTET_STREAM_TYPE, 0L, 1L))
95+
{
96+
expectNotNull(binary);
97+
expectSame(2, binary.getContentLength());
98+
expectNotNull(binary.getRange());
99+
expectSame(0, binary.getRange().start());
100+
expectSame(1, binary.getRange().end());
101+
expectSame(10, binary.getRange().size());
102+
103+
byte[] allBytes = binary.readAllBytes();
104+
expectSame(2, allBytes.length);
105+
expectSame(0, allBytes[0]);
106+
expectSame(1, allBytes[1]);
107+
}
108+
}
109+
110+
@PluginTest
111+
public void downloadRangeVerion(DsfClient localDsfClient, IdType testBinaryId) throws Exception
112+
{
113+
try (BinaryInputStream binary = localDsfClient.readBinary(testBinaryId.getIdPart(),
114+
testBinaryId.getVersionIdPart(), MediaType.APPLICATION_OCTET_STREAM_TYPE, 0L, 1L))
115+
{
116+
expectNotNull(binary);
117+
expectSame(2, binary.getContentLength());
118+
expectNotNull(binary.getRange());
119+
expectSame(0, binary.getRange().start());
120+
expectSame(1, binary.getRange().end());
121+
expectSame(10, binary.getRange().size());
122+
123+
byte[] allBytes = binary.readAllBytes();
124+
expectSame(2, allBytes.length);
125+
expectSame(0, allBytes[0]);
126+
expectSame(1, allBytes[1]);
127+
}
128+
}
129+
}

dsf-bpe/dsf-bpe-test-plugin-v2/src/main/java/dev/dsf/bpe/test/spring/config/Config.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import dev.dsf.bpe.test.service.ContinueSendTest;
1919
import dev.dsf.bpe.test.service.ContinueSendTestEvaluate;
2020
import dev.dsf.bpe.test.service.CryptoServiceTest;
21+
import dev.dsf.bpe.test.service.DsfClientTest;
2122
import dev.dsf.bpe.test.service.EndpointProviderTest;
2223
import dev.dsf.bpe.test.service.EnvironmentVariableTest;
2324
import dev.dsf.bpe.test.service.ErrorBoundaryEventTestThrow;
@@ -63,7 +64,8 @@ public static ActivityPrototypeBeanCreator activityPrototypeBeanCreator()
6364
FieldInjectionTest.class, ErrorBoundaryEventTestThrow.class, ErrorBoundaryEventTestVerify.class,
6465
ExceptionTest.class, ContinueSendTest.class, ContinueSendTestSend.class, ContinueSendTestEvaluate.class,
6566
JsonVariableTestSet.class, JsonVariableTestGet.class, CryptoServiceTest.class,
66-
MimetypeServiceTest.class, FhirBinaryVariableTestSet.class, FhirBinaryVariableTestGet.class);
67+
MimetypeServiceTest.class, FhirBinaryVariableTestSet.class, FhirBinaryVariableTestGet.class,
68+
DsfClientTest.class);
6769
}
6870

6971
@Bean

dsf-bpe/dsf-bpe-test-plugin-v2/src/main/resources/bpe/test.bpmn

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1yb5vw3" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.31.0">
2+
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1yb5vw3" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.34.0">
33
<bpmn:process id="dsfdev_test" isExecutable="true" camunda:versionTag="#{version}">
44
<bpmn:startEvent id="StartEvent">
55
<bpmn:outgoing>Flow_112zq99</bpmn:outgoing>
@@ -37,6 +37,7 @@
3737
<bpmn:outgoing>Flow_1gkrz8f</bpmn:outgoing>
3838
<bpmn:outgoing>Flow_151zxir</bpmn:outgoing>
3939
<bpmn:outgoing>Flow_1bo772x</bpmn:outgoing>
40+
<bpmn:outgoing>Flow_1gipugc</bpmn:outgoing>
4041
</bpmn:exclusiveGateway>
4142
<bpmn:sequenceFlow id="Flow_1bqddk1" sourceRef="TestActivitySelector" targetRef="Gateway_0eszi2t" />
4243
<bpmn:sequenceFlow id="Flow_14rzc0j" sourceRef="Gateway_0eszi2t" targetRef="ProxyTest">
@@ -62,6 +63,7 @@
6263
<bpmn:incoming>Flow_1le3eld</bpmn:incoming>
6364
<bpmn:incoming>Flow_1ic3b4h</bpmn:incoming>
6465
<bpmn:incoming>Flow_01nnroq</bpmn:incoming>
66+
<bpmn:incoming>Flow_04z1f6i</bpmn:incoming>
6567
<bpmn:outgoing>Flow_0a1kwg9</bpmn:outgoing>
6668
</bpmn:exclusiveGateway>
6769
<bpmn:sequenceFlow id="Flow_08zzudo" sourceRef="ProxyTest" targetRef="Gateway_056f6tw" />
@@ -280,6 +282,14 @@
280282
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${testActivity == 'EnvironmentVariableTest'}</bpmn:conditionExpression>
281283
</bpmn:sequenceFlow>
282284
<bpmn:sequenceFlow id="Flow_01nnroq" sourceRef="EnvironmentVariableTest" targetRef="Gateway_056f6tw" />
285+
<bpmn:serviceTask id="DsfClientTest" name="DsfClientTest" camunda:class="dev.dsf.bpe.test.service.DsfClientTest">
286+
<bpmn:incoming>Flow_1gipugc</bpmn:incoming>
287+
<bpmn:outgoing>Flow_04z1f6i</bpmn:outgoing>
288+
</bpmn:serviceTask>
289+
<bpmn:sequenceFlow id="Flow_1gipugc" sourceRef="Gateway_0eszi2t" targetRef="DsfClientTest">
290+
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${testActivity == 'DsfClientTest'}</bpmn:conditionExpression>
291+
</bpmn:sequenceFlow>
292+
<bpmn:sequenceFlow id="Flow_04z1f6i" sourceRef="DsfClientTest" targetRef="Gateway_056f6tw" />
283293
</bpmn:process>
284294
<bpmn:message id="Message_1nn2wdw" name="start" />
285295
<bpmn:message id="Message_2iq6v5e" name="proxyTest" />
@@ -399,6 +409,10 @@
399409
<dc:Bounds x="480" y="1720" width="100" height="80" />
400410
<bpmndi:BPMNLabel />
401411
</bpmndi:BPMNShape>
412+
<bpmndi:BPMNShape id="BPMNShape_0og1ky5" bpmnElement="DsfClientTest">
413+
<dc:Bounds x="480" y="1830" width="100" height="80" />
414+
<bpmndi:BPMNLabel />
415+
</bpmndi:BPMNShape>
402416
<bpmndi:BPMNShape id="Event_1w9i7ga_di" bpmnElement="Event_1dnlmzp">
403417
<dc:Bounds x="562" y="912" width="36" height="36" />
404418
</bpmndi:BPMNShape>
@@ -610,6 +624,16 @@
610624
<di:waypoint x="1180" y="1760" />
611625
<di:waypoint x="1180" y="145" />
612626
</bpmndi:BPMNEdge>
627+
<bpmndi:BPMNEdge id="Flow_1gipugc_di" bpmnElement="Flow_1gipugc">
628+
<di:waypoint x="410" y="145" />
629+
<di:waypoint x="410" y="1870" />
630+
<di:waypoint x="480" y="1870" />
631+
</bpmndi:BPMNEdge>
632+
<bpmndi:BPMNEdge id="Flow_04z1f6i_di" bpmnElement="Flow_04z1f6i">
633+
<di:waypoint x="580" y="1870" />
634+
<di:waypoint x="1180" y="1870" />
635+
<di:waypoint x="1180" y="145" />
636+
</bpmndi:BPMNEdge>
613637
</bpmndi:BPMNPlane>
614638
</bpmndi:BPMNDiagram>
615639
</bpmn:definitions>

0 commit comments

Comments
 (0)