Merge "Point to parent SNAPSHOT"
[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 import static org.junit.Assert.assertTrue;
25
26 import java.util.Map;
27 import org.junit.AfterClass;
28 import org.junit.Before;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
32 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
33 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
34 import org.onap.policy.controlloop.policy.PolicyResult;
35 import org.onap.policy.sdnc.SdncRequest;
36 import org.onap.policy.sdnc.SdncResponse;
37
38 public class BandwidthOnDemandOperationTest extends BasicSdncOperation {
39
40     private BandwidthOnDemandOperation oper;
41
42     public BandwidthOnDemandOperationTest() {
43         super(DEFAULT_ACTOR, BandwidthOnDemandOperation.NAME);
44     }
45
46     @BeforeClass
47     public static void setUpBeforeClass() throws Exception {
48         initBeforeClass();
49     }
50
51     @AfterClass
52     public static void tearDownAfterClass() {
53         destroyAfterClass();
54     }
55
56     /**
57      * Set up.
58      */
59     @Before
60     public void setUp() throws Exception {
61         super.setUp();
62         oper = new BandwidthOnDemandOperation(params, config);
63     }
64
65     @Test
66     public void testConstructor() {
67         assertEquals(DEFAULT_ACTOR, oper.getActorName());
68         assertEquals(BandwidthOnDemandOperation.NAME, oper.getName());
69     }
70
71     /**
72      * Tests "success" case with simulator.
73      */
74     @Test
75     public void testSuccess() throws Exception {
76         HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
77                         .path("GENERIC-RESOURCE-API:vf-module-topology-operation").build();
78         config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
79
80         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
81         oper = new BandwidthOnDemandOperation(params, config);
82
83         outcome = oper.start().get();
84         assertEquals(PolicyResult.SUCCESS, outcome.getResult());
85         assertTrue(outcome.getResponse() instanceof SdncResponse);
86     }
87
88     @Test
89     public void testMakeRequest() throws Exception {
90         oper.generateSubRequestId(1);
91         SdncRequest request = oper.makeRequest(1);
92         assertEquals("my-service", request.getNsInstanceId());
93         assertEquals(REQ_ID, request.getRequestId());
94         assertEquals("/my-path/", request.getUrl());
95         assertEquals(oper.getSubRequestId(), request.getHealRequest().getRequestHeaderInfo().getSvcRequestId());
96
97         verifyRequest("bod.json", request, IGNORE_FIELDS);
98
99         verifyMissing(BandwidthOnDemandOperation.SERVICE_ID_KEY, "service", BandwidthOnDemandOperation::new);
100
101         // perform the operation
102         makeContext();
103         verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS);
104     }
105
106     @Override
107     protected Map<String, String> makeEnrichment() {
108         return Map.of(BandwidthOnDemandOperation.SERVICE_ID_KEY, "my-service", BandwidthOnDemandOperation.VNF_ID,
109                         "my-vnf");
110     }
111 }