Merge "Make Actors event-agnostic"
[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 org.junit.AfterClass;
29 import org.junit.Before;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
33 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
34 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
35 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
36 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
37 import org.onap.policy.sdnc.SdncResponse;
38
39 public class BandwidthOnDemandOperationTest extends BasicSdncOperation {
40     private static final String MY_SERVICE = "my-service";
41     private static final String MY_VNF = "my-vnf";
42     private static final String MY_BANDWIDTH = "my-bandwidth";
43     private static final String MY_CHANGE_TIME = "my-change-time";
44
45     private BandwidthOnDemandOperation oper;
46
47     public BandwidthOnDemandOperationTest() {
48         super(DEFAULT_ACTOR, BandwidthOnDemandOperation.NAME);
49     }
50
51     @BeforeClass
52     public static void setUpBeforeClass() throws Exception {
53         initBeforeClass();
54     }
55
56     @AfterClass
57     public static void tearDownAfterClass() {
58         destroyAfterClass();
59     }
60
61     /**
62      * Set up.
63      */
64     @Override
65     @Before
66     public void setUp() throws Exception {
67         super.setUp();
68         oper = new BandwidthOnDemandOperation(params, config);
69     }
70
71     @Test
72     public void testConstructor() {
73         assertEquals(DEFAULT_ACTOR, oper.getActorName());
74         assertEquals(BandwidthOnDemandOperation.NAME, oper.getName());
75     }
76
77     @Test
78     public void testGetPropertyNames() {
79         // @formatter:off
80         assertThat(oper.getPropertyNames()).isEqualTo(
81                         List.of(
82                             OperationProperties.ENRICHMENT_SERVICE_ID,
83                             OperationProperties.ENRICHMENT_BANDWIDTH,
84                             OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME,
85                             OperationProperties.ENRICHMENT_VNF_ID));
86
87         // @formatter:on
88     }
89
90     /**
91      * Tests "success" case with simulator.
92      */
93     @Test
94     public void testSuccess() throws Exception {
95         HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
96                         .path("GENERIC-RESOURCE-API:vf-module-topology-operation").build();
97         config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
98
99         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).preprocessed(true).build();
100         oper = new BandwidthOnDemandOperation(params, config);
101
102         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
103         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
104         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME);
105         oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF);
106
107         outcome = oper.start().get();
108         assertEquals(OperationResult.SUCCESS, outcome.getResult());
109         assertTrue(outcome.getResponse() instanceof SdncResponse);
110     }
111
112     @Test
113     public void testMakeRequest() throws Exception {
114         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
115         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH);
116         oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME);
117         oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF);
118
119         verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS);
120     }
121 }