Skip to content

Commit 0fb3898

Browse files
committed
fix 2: system test
Signed-off-by: Aleksandar Stanchev <[email protected]>
1 parent 7d93e71 commit 0fb3898

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

system/src/test/java/org/eclipse/ditto/testing/system/connectivity/AbstractConnectivityResponseDiversionITestCases.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.eclipse.ditto.connectivity.model.Target;
4040
import org.eclipse.ditto.testing.common.categories.RequireSource;
4141
import org.eclipse.ditto.testing.common.matcher.StatusCodeSuccessfulMatcher;
42+
import org.eclipse.ditto.things.model.ThingBuilder;
43+
import org.eclipse.ditto.things.model.ThingId;
4244
import org.eclipse.ditto.things.model.signals.commands.ThingErrorResponse;
4345
import org.eclipse.ditto.things.model.signals.commands.modify.CreateThing;
4446
import org.eclipse.ditto.things.model.signals.commands.modify.CreateThingResponse;
@@ -129,12 +131,12 @@ public void divertResponseBasedOnConnectionHeaderMapping()
129131
// Given
130132
final String sendingConnectionName = cf.connectionName1;
131133
final String divertedConnectionName = cf.connectionName2;
132-
final CreateThing createThing = newCreateThing(sendingConnectionName, false);
133-
sendSignal(sendingConnectionName, createThing);
134+
final ThingId thingId = sendCreateThingAndEnsureResponseIsSentBack(cf.connectionName1,
135+
ThingBuilder.FromScratch::build);
134136

135137
final String correlationId = UUID.randomUUID().toString();
136138
// When: Send command with divert-response-to-connection header
137-
final RetrieveThing retrieveThing = RetrieveThing.of(createThing.getEntityId(),
139+
final RetrieveThing retrieveThing = RetrieveThing.of(thingId,
138140
DittoHeaders.newBuilder()
139141
.correlationId(correlationId)
140142
.schemaVersion(JsonSchemaVersion.V_2)
@@ -167,12 +169,12 @@ public void divertAndPreserveOriginalResponseInSourceConnection()
167169
// Given
168170
final String sendingConnectionName = cf.connectionName1;
169171
final String divertedConnectionName = cf.connectionName2;
170-
final CreateThing createThing = newCreateThing(sendingConnectionName, false);
171-
sendSignal(sendingConnectionName, createThing);
172+
final ThingId thingId = sendCreateThingAndEnsureResponseIsSentBack(sendingConnectionName,
173+
ThingBuilder.FromScratch::build);
172174

173175
final String correlationId = UUID.randomUUID().toString();
174176
// When: Send command with divert-response-to-connection header
175-
final RetrieveThing retrieveThing = RetrieveThing.of(createThing.getEntityId(),
177+
final RetrieveThing retrieveThing = RetrieveThing.of(thingId,
176178
DittoHeaders.newBuilder()
177179
.correlationId(correlationId)
178180
.schemaVersion(JsonSchemaVersion.V_2)
@@ -214,13 +216,13 @@ public void divertResponseBasedOnHeaderInTheMessageItself()
214216
// Given
215217
final String sendingConnectionName = cf.connectionName1;
216218
final String divertedConnectionName = cf.connectionName2;
217-
final CreateThing createThing = newCreateThing(sendingConnectionName, false);
218-
sendSignal(sendingConnectionName, createThing);
219+
final ThingId thingId = sendCreateThingAndEnsureResponseIsSentBack(cf.connectionName1,
220+
ThingBuilder.FromScratch::build);
219221

220222
final String correlationId = UUID.randomUUID().toString();
221223
final String divertAddress = getTargetAddress(targetConnection);
222224
// When: Send command with divert-response-to-connection header
223-
final RetrieveThing retrieveThing = RetrieveThing.of(createThing.getEntityId(),
225+
final RetrieveThing retrieveThing = RetrieveThing.of(thingId,
224226
DittoHeaders.newBuilder()
225227
.correlationId(correlationId)
226228
.schemaVersion(JsonSchemaVersion.V_2)
@@ -251,14 +253,14 @@ public void doNotPublishDivertedResponseIfNotAuthorized()
251253
// Given
252254
final String sendingConnectionName = cf.connectionName1;
253255
final String divertedConnectionName = cf.connectionName2;
254-
final CreateThing createThing = newCreateThing(sendingConnectionName, false);
255-
sendSignal(sendingConnectionName, createThing);
256+
final ThingId thingId = sendCreateThingAndEnsureResponseIsSentBack(cf.connectionName1,
257+
ThingBuilder.FromScratch::build);
256258

257259
prepareConnectionsForDiversion(sourceConnection, false, false, targetConnection, true);
258260

259261
final String correlationId = UUID.randomUUID().toString();
260262
final String divertAddress = getTargetAddress(targetConnection);
261-
final RetrieveThing retrieveThing = RetrieveThing.of(createThing.getEntityId(),
263+
final RetrieveThing retrieveThing = RetrieveThing.of(thingId,
262264
DittoHeaders.newBuilder()
263265
.correlationId(correlationId)
264266
.schemaVersion(JsonSchemaVersion.V_2)
@@ -282,20 +284,11 @@ public void testErrorResponseDiversion() throws ExecutionException, InterruptedE
282284
final Connection sourceConnection = getConnectionExistingByNameForUser(DIVERSION_SOURCE, getUsername());
283285
prepareConnectionsForDiversion(sourceConnection, true, false, targetConnection, true);
284286

285-
final CreateThing createThing = newCreateThing(cf.connectionName2, true);
286-
287-
final String correlationId = createThing.getDittoHeaders().getCorrelationId().get();
288-
final C responseConsumer = initResponseConsumer(cf.connectionName2, correlationId);
289-
sendSignal(cf.connectionName2, createThing);
290-
final M createResponse = consumeResponse(correlationId, responseConsumer);
291-
assertThat(createResponse).isNotNull();
292-
293-
final Signal<?> signal = PROTOCOL_ADAPTER.fromAdaptable(jsonifiableAdaptableFrom(createResponse));
294-
assertThat(signal).isInstanceOf(CreateThingResponse.class);
295-
287+
final ThingId thingId = sendCreateThingAndEnsureResponseIsSentBack(cf.connectionName1,
288+
ThingBuilder.FromScratch::build);
296289

297290
// Send command that will fail
298-
final RetrieveThing retrieveThing = RetrieveThing.of(createThing.getEntityId(),
291+
final RetrieveThing retrieveThing = RetrieveThing.of(thingId,
299292
DittoHeaders.newBuilder()
300293
.correlationId(createNewCorrelationId())
301294
.schemaVersion(JsonSchemaVersion.V_2)

0 commit comments

Comments
 (0)