aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
blob: eae2883c806ccddedb0aa517e13c003ffe17f84d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2021 Nordix Foundation.
 *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.clamp.acm.runtime.instantiation.rest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.acm.runtime.instantiation.AutomationCompositionInstantiationProvider;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.main.rest.InstantiationController;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionOrderStateResponse;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AutomationCompositionPrimedResponse;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstancePropertiesResponse;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;

/**
 * Class to perform unit test of {@link InstantiationController}}.
 *
 */
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations = {"classpath:application_test.properties"})
class InstantiationControllerTest extends CommonRestController {

    private static final String ID_NAME = "PMSH_Test_Instance";
    private static final String ID_VERSION = "1.2.3";

    private static final String AC_INSTANTIATION_CREATE_JSON =
        "src/test/resources/rest/acm/AutomationCompositions.json";

    private static final String AC_INSTANTIATION_UPDATE_JSON =
        "src/test/resources/rest/acm/AutomationCompositionsUpdate.json";

    private static final String AC_INSTANTIATION_CHANGE_STATE_JSON = "src/test/resources/rest/acm/PassiveCommand.json";

    private static final String TOSCA_TEMPLATE_YAML =
        "src/test/resources/rest/servicetemplates/pmsh_multiple_ac_tosca.yaml";

    private static final String INSTANTIATION_ENDPOINT = "instantiation";
    private static final String INSTANTIATION_COMMAND_ENDPOINT = "instantiation/command";
    private static final String PRIMING_ENDPOINT = "automationCompositionPriming";
    private static final String INSTANTIATION_PROPERTIES = "instanceProperties";
    private static final String INSTANTIATION_STATE = "instantiationState";

    private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();

    @Autowired
    private AutomationCompositionRepository automationCompositionRepository;

    @Autowired
    private ServiceTemplateProvider serviceTemplateProvider;

    @Autowired
    private AutomationCompositionInstantiationProvider instantiationProvider;

    @Autowired
    private ParticipantProvider participantProvider;

    @LocalServerPort
    private int randomServerPort;

    @BeforeAll
    public static void setUpBeforeClass() throws Exception {
        serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
    }

    @BeforeEach
    public void populateDb() throws Exception {
        createEntryInDB();
    }

    @BeforeEach
    public void setUpPort() {
        super.setHttpPrefix(randomServerPort);
    }

    @AfterEach
    public void cleanDatabase() throws Exception {
        deleteEntryInDB();
    }

    @Test
    void testSwagger() throws Exception {
        super.testSwagger(INSTANTIATION_ENDPOINT);
    }

    @Test
    void testCreate_Unauthorized() throws Exception {
        AutomationCompositions automationCompositions =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Unauthorized");

        assertUnauthorizedPost(INSTANTIATION_ENDPOINT, Entity.json(automationCompositions));
    }

    @Test
    void testQuery_Unauthorized() throws Exception {
        assertUnauthorizedGet(INSTANTIATION_ENDPOINT);
    }

    @Test
    void testUpdate_Unauthorized() throws Exception {
        AutomationCompositions automationCompositions =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_UPDATE_JSON, "Unauthorized");

        assertUnauthorizedPut(INSTANTIATION_ENDPOINT, Entity.json(automationCompositions));
    }

    @Test
    void testDelete_Unauthorized() throws Exception {
        assertUnauthorizedDelete(INSTANTIATION_ENDPOINT);
    }

    @Test
    void testCommand_Unauthorized() throws Exception {
        InstantiationCommand instantiationCommand =
            InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Unauthorized");

        assertUnauthorizedPut(INSTANTIATION_COMMAND_ENDPOINT, Entity.json(instantiationCommand));
    }

    @Test
    void testCreate() throws Exception {

        AutomationCompositions automationCompositionsFromRsc =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Create");

        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_ENDPOINT);
        Response resp = invocationBuilder.post(Entity.json(automationCompositionsFromRsc));
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
        InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
        InstantiationUtils.assertInstantiationResponse(instResponse, automationCompositionsFromRsc);

        for (AutomationComposition automationCompositionFromRsc : automationCompositionsFromRsc
            .getAutomationCompositionList()) {
            AutomationCompositions automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(
                automationCompositionFromRsc.getKey().getName(), automationCompositionFromRsc.getKey().getVersion());

            assertNotNull(automationCompositionsFromDb);
            assertThat(automationCompositionsFromDb.getAutomationCompositionList()).hasSize(1);
            assertEquals(automationCompositionFromRsc,
                automationCompositionsFromDb.getAutomationCompositionList().get(0));
        }

        invocationBuilder =
            super.sendRequest(PRIMING_ENDPOINT + "?name=" + "PMSHInstance0Create" + "&version=" + "1.0.1");
        Response rawresp = invocationBuilder.buildGet().invoke();
        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
        AutomationCompositionPrimedResponse primResponse =
            rawresp.readEntity(AutomationCompositionPrimedResponse.class);
        assertEquals(false, primResponse.getPrimedAutomationCompositionsList().get(0).isPrimed());
    }

    @Test
    void testCreateBadRequest() throws Exception {

        AutomationCompositions automationCompositionsFromRsc =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "CreateBadRequest");

        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_ENDPOINT);
        Response resp = invocationBuilder.post(Entity.json(automationCompositionsFromRsc));
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());

        // testing Bad Request: AC already defined
        resp = invocationBuilder.post(Entity.json(automationCompositionsFromRsc));
        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
        InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
        assertNotNull(instResponse.getErrorDetails());
        assertNull(instResponse.getAffectedAutomationCompositions());
    }

    @Test
    void testQuery_NoResultWithThisName() throws Exception {
        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_ENDPOINT + "?name=noResultWithThisName");
        Response rawresp = invocationBuilder.buildGet().invoke();
        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
        AutomationCompositions resp = rawresp.readEntity(AutomationCompositions.class);
        assertThat(resp.getAutomationCompositionList()).isEmpty();
    }

    @Test
    void testQuery() throws Exception {

        var automationCompositions =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Query");
        instantiationProvider.createAutomationCompositions(automationCompositions);

        for (AutomationComposition automationCompositionFromRsc : automationCompositions
            .getAutomationCompositionList()) {
            Invocation.Builder invocationBuilder =
                super.sendRequest(INSTANTIATION_ENDPOINT + "?name=" + automationCompositionFromRsc.getKey().getName());
            Response rawresp = invocationBuilder.buildGet().invoke();
            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
            AutomationCompositions automationCompositionsQuery = rawresp.readEntity(AutomationCompositions.class);
            assertNotNull(automationCompositionsQuery);
            assertThat(automationCompositionsQuery.getAutomationCompositionList()).hasSize(1);
            assertEquals(automationCompositionFromRsc,
                automationCompositionsQuery.getAutomationCompositionList().get(0));
        }
    }

    @Test
    void testUpdate() throws Exception {

        AutomationCompositions automationCompositionsCreate =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Update");

        var automationCompositions =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_UPDATE_JSON, "Update");
        instantiationProvider.createAutomationCompositions(automationCompositionsCreate);

        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_ENDPOINT);
        Response resp = invocationBuilder.put(Entity.json(automationCompositions));
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());

        InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
        InstantiationUtils.assertInstantiationResponse(instResponse, automationCompositions);

        for (AutomationComposition automationCompositionUpdate : automationCompositions
            .getAutomationCompositionList()) {
            AutomationCompositions automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(
                automationCompositionUpdate.getKey().getName(), automationCompositionUpdate.getKey().getVersion());

            assertNotNull(automationCompositionsFromDb);
            assertThat(automationCompositionsFromDb.getAutomationCompositionList()).hasSize(1);
            assertEquals(automationCompositionUpdate,
                automationCompositionsFromDb.getAutomationCompositionList().get(0));
        }
    }

    @Test
    void testDelete_NoResultWithThisName() throws Exception {
        Invocation.Builder invocationBuilder =
            super.sendRequest(INSTANTIATION_ENDPOINT + "?name=noResultWithThisName&version=1.0.1");
        Response resp = invocationBuilder.delete();
        assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus());
        InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
        assertNotNull(instResponse.getErrorDetails());
        assertNull(instResponse.getAffectedAutomationCompositions());
    }

    @Test
    void testDelete() throws Exception {

        AutomationCompositions automationCompositionsFromRsc =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Delete");

        instantiationProvider.createAutomationCompositions(automationCompositionsFromRsc);

        for (AutomationComposition automationCompositionFromRsc : automationCompositionsFromRsc
            .getAutomationCompositionList()) {
            Invocation.Builder invocationBuilder =
                super.sendRequest(INSTANTIATION_ENDPOINT + "?name=" + automationCompositionFromRsc.getKey().getName()
                    + "&version=" + automationCompositionFromRsc.getKey().getVersion());
            Response resp = invocationBuilder.delete();
            assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
            InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
            InstantiationUtils.assertInstantiationResponse(instResponse, automationCompositionFromRsc);

            AutomationCompositions automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(
                automationCompositionFromRsc.getKey().getName(), automationCompositionFromRsc.getKey().getVersion());
            assertThat(automationCompositionsFromDb.getAutomationCompositionList()).isEmpty();
        }
    }

    @Test
    void testDeleteBadRequest() throws Exception {

        AutomationCompositions automationCompositionsFromRsc =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "DelBadRequest");

        instantiationProvider.createAutomationCompositions(automationCompositionsFromRsc);

        for (AutomationComposition automationCompositionFromRsc : automationCompositionsFromRsc
            .getAutomationCompositionList()) {
            Invocation.Builder invocationBuilder =
                super.sendRequest(INSTANTIATION_ENDPOINT + "?name=" + automationCompositionFromRsc.getKey().getName());
            Response resp = invocationBuilder.delete();
            assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
        }
    }

    @Test
    void testCreateInstanceProperties() throws Exception {
        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
        Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
        var instancePropertyList = resp.readEntity(InstancePropertiesResponse.class);
        assertNull(instancePropertyList.getErrorDetails());
        var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
        assertEquals(id, instancePropertyList.getAffectedInstanceProperties().get(0));

        invocationBuilder = super.sendRequest(INSTANTIATION_ENDPOINT);
        resp = invocationBuilder.get();
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
        var automationCompositionsGet = resp.readEntity(AutomationCompositions.class);
        assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1);
    }

    @Test
    void testDeleteInstanceProperties() throws Exception {
        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
        Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());

        invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + ID_NAME + "&version=" + ID_VERSION);
        resp = invocationBuilder.delete();
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
        var instanceResponse = resp.readEntity(InstantiationResponse.class);
        assertEquals(ID_NAME, instanceResponse.getAffectedAutomationCompositions().get(0).getName());
        AutomationCompositions automationCompositionsGet =
            instantiationProvider.getAutomationCompositions(ID_NAME, ID_VERSION);
        assertThat(automationCompositionsGet.getAutomationCompositionList()).isEmpty();
    }

    @Test
    void testDeleteInstancePropertiesBadRequest() throws Exception {
        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
        Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());

        invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + ID_NAME);
        resp = invocationBuilder.delete();
        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
    }

    @Test
    void testDeleteInstancePropertiesPassiveMode() throws Exception {
        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
        Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());

        var automationCompositions =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Command");
        instantiationProvider.createAutomationCompositions(automationCompositions);

        var participants = CommonTestData.createParticipants();
        for (var participant : participants) {
            participantProvider.saveParticipant(participant);
        }

        InstantiationCommand command =
            InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Command");

        invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
        resp = invocationBuilder.put(Entity.json(command));
        assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus());
        InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
        InstantiationUtils.assertInstantiationResponse(instResponse, command);

        // check passive state on DB and delete properties
        for (ToscaConceptIdentifier toscaConceptIdentifier : command.getAutomationCompositionIdentifierList()) {
            AutomationCompositions automationCompositionsGet = instantiationProvider
                .getAutomationCompositions(toscaConceptIdentifier.getName(), toscaConceptIdentifier.getVersion());
            assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1);
            assertEquals(command.getOrderedState(),
                automationCompositionsGet.getAutomationCompositionList().get(0).getOrderedState());

            invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + toscaConceptIdentifier.getName()
                + "&version=" + toscaConceptIdentifier.getVersion());
            resp = invocationBuilder.delete();
            assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
        }
    }

    @Test
    void testCommand_NotFound1() throws Exception {
        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
        Response resp = invocationBuilder.put(Entity.json(new InstantiationCommand()));
        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
    }

    @Test
    void testCommand_NotFound2() throws Exception {
        InstantiationCommand command =
            InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Command");
        command.setOrderedState(null);

        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
        Response resp = invocationBuilder.put(Entity.json(command));
        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
    }

    @Test
    void testCommand() throws Exception {
        var automationCompositions =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Command");
        instantiationProvider.createAutomationCompositions(automationCompositions);

        var participants = CommonTestData.createParticipants();
        for (var participant : participants) {
            participantProvider.saveParticipant(participant);
        }

        InstantiationCommand command =
            InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Command");

        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
        Response resp = invocationBuilder.put(Entity.json(command));
        assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus());
        InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
        InstantiationUtils.assertInstantiationResponse(instResponse, command);

        // check passive state on DB
        for (ToscaConceptIdentifier toscaConceptIdentifier : command.getAutomationCompositionIdentifierList()) {
            AutomationCompositions automationCompositionsGet = instantiationProvider
                .getAutomationCompositions(toscaConceptIdentifier.getName(), toscaConceptIdentifier.getVersion());
            assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1);
            assertEquals(command.getOrderedState(),
                automationCompositionsGet.getAutomationCompositionList().get(0).getOrderedState());
        }
    }

    @Test
    void testIntanceProperties() throws Exception {
        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
        Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
        var instancePropertyList = resp.readEntity(InstancePropertiesResponse.class);
        assertNull(instancePropertyList.getErrorDetails());
        var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
        assertEquals(id, instancePropertyList.getAffectedInstanceProperties().get(0));

        invocationBuilder = super.sendRequest(INSTANTIATION_STATE + "?name=" + ID_NAME + "&version=" + ID_VERSION);
        resp = invocationBuilder.buildGet().invoke();
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
        var instanceOrderState = resp.readEntity(AutomationCompositionOrderStateResponse.class);
        assertEquals(AutomationCompositionOrderedState.UNINITIALISED, instanceOrderState.getOrderedState());
        assertEquals(ID_NAME, instanceOrderState.getAutomationCompositionIdentifierList().get(0).getName());
        AutomationCompositions automationCompositionsGet =
            instantiationProvider.getAutomationCompositions(ID_NAME, ID_VERSION);
        assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1);

        invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + ID_NAME + "&version=" + ID_VERSION);
        resp = invocationBuilder.delete();
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
        var instanceResponse = resp.readEntity(InstantiationResponse.class);
        assertEquals(ID_NAME, instanceResponse.getAffectedAutomationCompositions().get(0).getName());
        automationCompositionsGet = instantiationProvider.getAutomationCompositions(ID_NAME, ID_VERSION);
        assertThat(automationCompositionsGet.getAutomationCompositionList()).isEmpty();
    }

    @Test
    void testChangeOrderStateFromUninitializedPassiveMode() throws Exception {
        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
        Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());

        var automationCompositions =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "CommandPassive");
        instantiationProvider.createAutomationCompositions(automationCompositions);

        var participants = CommonTestData.createParticipants();
        for (var participant : participants) {
            participantProvider.saveParticipant(participant);
        }

        InstantiationCommand command = InstantiationUtils
            .getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "CommandPassive");

        invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
        resp = invocationBuilder.put(Entity.json(command));
        assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus());
        InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
        InstantiationUtils.assertInstantiationResponse(instResponse, command);
    }

    @Test
    void testChangeOrderStateWithoutRegisteredParticipants() throws Exception {
        Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
        Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
        assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());

        var automationCompositions =
            InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "CommandPassive");
        instantiationProvider.createAutomationCompositions(automationCompositions);

        InstantiationCommand command = InstantiationUtils
            .getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "CommandPassive");

        invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
        resp = invocationBuilder.put(Entity.json(command));
        assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
    }

    private synchronized void deleteEntryInDB() throws Exception {
        automationCompositionRepository.deleteAll();
        var list = serviceTemplateProvider.getAllServiceTemplates();
        if (!list.isEmpty()) {
            serviceTemplateProvider.deleteServiceTemplate(list.get(0).getName(), list.get(0).getVersion());
        }
    }

    private synchronized void createEntryInDB() throws Exception {
        deleteEntryInDB();
        serviceTemplateProvider.createServiceTemplate(serviceTemplate);
    }
}