Set sub request ID before start callback
[policy/models.git] / models-interactions / model-actors / actor.sdnc / src / test / java / org / onap / policy / controlloop / actor / sdnc / BandwidthOnDemandOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop.actor.sdnc;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.Map;
26 import org.junit.AfterClass;
27 import org.junit.Before;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
31 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
32 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
33 import org.onap.policy.controlloop.policy.PolicyResult;
34 import org.onap.policy.sdnc.SdncRequest;
35
36 public class BandwidthOnDemandOperationTest extends BasicSdncOperation {
37
38     private BandwidthOnDemandOperation oper;
39
40     public BandwidthOnDemandOperationTest() {
41         super(DEFAULT_ACTOR, BandwidthOnDemandOperation.NAME);
42     }
43
44     @BeforeClass
45     public static void setUpBeforeClass() throws Exception {
46         initBeforeClass();
47     }
48
49     @AfterClass
50     public static void tearDownAfterClass() {
51         destroyAfterClass();
52     }
53
54     /**
55      * Set up.
56      */
57     @Before
58     public void setUp() throws Exception {
59         super.setUp();
60         oper = new BandwidthOnDemandOperation(params, config);
61     }
62
63     @Test
64     public void testConstructor() {
65         assertEquals(DEFAULT_ACTOR, oper.getActorName());
66         assertEquals(BandwidthOnDemandOperation.NAME, oper.getName());
67     }
68
69     /**
70      * Tests "success" case with simulator.
71      */
72     @Test
73     public void testSuccess() throws Exception {
74         HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
75                         .path("GENERIC-RESOURCE-API:vf-module-topology-operation").build();
76         config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
77
78         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
79         oper = new BandwidthOnDemandOperation(params, config);
80
81         outcome = oper.start().get();
82         assertEquals(PolicyResult.SUCCESS, outcome.getResult());
83     }
84
85     @Test
86     public void testMakeRequest() throws Exception {
87         oper.generateSubRequestId(1);
88         SdncRequest request = oper.makeRequest(1);
89         assertEquals("my-service", request.getNsInstanceId());
90         assertEquals(REQ_ID, request.getRequestId());
91         assertEquals("/my-path/", request.getUrl());
92         assertEquals(oper.getSubRequestId(), request.getHealRequest().getRequestHeaderInfo().getSvcRequestId());
93
94         verifyRequest("bod.json", request, IGNORE_FIELDS);
95
96         verifyMissing(BandwidthOnDemandOperation.SERVICE_ID_KEY, "service", BandwidthOnDemandOperation::new);
97
98         // perform the operation
99         makeContext();
100         verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS);
101     }
102
103     @Override
104     protected Map<String, String> makeEnrichment() {
105         return Map.of(BandwidthOnDemandOperation.SERVICE_ID_KEY, "my-service", BandwidthOnDemandOperation.VNF_ID,
106                         "my-vnf");
107     }
108 }