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