39
39
import org .eclipse .ditto .connectivity .model .Target ;
40
40
import org .eclipse .ditto .testing .common .categories .RequireSource ;
41
41
import org .eclipse .ditto .testing .common .matcher .StatusCodeSuccessfulMatcher ;
42
+ import org .eclipse .ditto .things .model .ThingBuilder ;
43
+ import org .eclipse .ditto .things .model .ThingId ;
42
44
import org .eclipse .ditto .things .model .signals .commands .ThingErrorResponse ;
43
45
import org .eclipse .ditto .things .model .signals .commands .modify .CreateThing ;
44
46
import org .eclipse .ditto .things .model .signals .commands .modify .CreateThingResponse ;
@@ -129,12 +131,12 @@ public void divertResponseBasedOnConnectionHeaderMapping()
129
131
// Given
130
132
final String sendingConnectionName = cf .connectionName1 ;
131
133
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 );
134
136
135
137
final String correlationId = UUID .randomUUID ().toString ();
136
138
// When: Send command with divert-response-to-connection header
137
- final RetrieveThing retrieveThing = RetrieveThing .of (createThing . getEntityId () ,
139
+ final RetrieveThing retrieveThing = RetrieveThing .of (thingId ,
138
140
DittoHeaders .newBuilder ()
139
141
.correlationId (correlationId )
140
142
.schemaVersion (JsonSchemaVersion .V_2 )
@@ -167,12 +169,12 @@ public void divertAndPreserveOriginalResponseInSourceConnection()
167
169
// Given
168
170
final String sendingConnectionName = cf .connectionName1 ;
169
171
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 );
172
174
173
175
final String correlationId = UUID .randomUUID ().toString ();
174
176
// When: Send command with divert-response-to-connection header
175
- final RetrieveThing retrieveThing = RetrieveThing .of (createThing . getEntityId () ,
177
+ final RetrieveThing retrieveThing = RetrieveThing .of (thingId ,
176
178
DittoHeaders .newBuilder ()
177
179
.correlationId (correlationId )
178
180
.schemaVersion (JsonSchemaVersion .V_2 )
@@ -214,13 +216,13 @@ public void divertResponseBasedOnHeaderInTheMessageItself()
214
216
// Given
215
217
final String sendingConnectionName = cf .connectionName1 ;
216
218
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 );
219
221
220
222
final String correlationId = UUID .randomUUID ().toString ();
221
223
final String divertAddress = getTargetAddress (targetConnection );
222
224
// When: Send command with divert-response-to-connection header
223
- final RetrieveThing retrieveThing = RetrieveThing .of (createThing . getEntityId () ,
225
+ final RetrieveThing retrieveThing = RetrieveThing .of (thingId ,
224
226
DittoHeaders .newBuilder ()
225
227
.correlationId (correlationId )
226
228
.schemaVersion (JsonSchemaVersion .V_2 )
@@ -251,14 +253,14 @@ public void doNotPublishDivertedResponseIfNotAuthorized()
251
253
// Given
252
254
final String sendingConnectionName = cf .connectionName1 ;
253
255
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 );
256
258
257
259
prepareConnectionsForDiversion (sourceConnection , false , false , targetConnection , true );
258
260
259
261
final String correlationId = UUID .randomUUID ().toString ();
260
262
final String divertAddress = getTargetAddress (targetConnection );
261
- final RetrieveThing retrieveThing = RetrieveThing .of (createThing . getEntityId () ,
263
+ final RetrieveThing retrieveThing = RetrieveThing .of (thingId ,
262
264
DittoHeaders .newBuilder ()
263
265
.correlationId (correlationId )
264
266
.schemaVersion (JsonSchemaVersion .V_2 )
@@ -282,20 +284,11 @@ public void testErrorResponseDiversion() throws ExecutionException, InterruptedE
282
284
final Connection sourceConnection = getConnectionExistingByNameForUser (DIVERSION_SOURCE , getUsername ());
283
285
prepareConnectionsForDiversion (sourceConnection , true , false , targetConnection , true );
284
286
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 );
296
289
297
290
// Send command that will fail
298
- final RetrieveThing retrieveThing = RetrieveThing .of (createThing . getEntityId () ,
291
+ final RetrieveThing retrieveThing = RetrieveThing .of (thingId ,
299
292
DittoHeaders .newBuilder ()
300
293
.correlationId (createNewCorrelationId ())
301
294
.schemaVersion (JsonSchemaVersion .V_2 )
0 commit comments