Upgrade and clean up dependencies
[policy/models.git] / models-interactions / model-actors / actor.sdnc / src / test / java / org / onap / policy / controlloop / actor / sdnc / RerouteOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2023 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.controlloop.actor.sdnc;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
27
28 import java.util.List;
29 import org.junit.AfterClass;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
36 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
37 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
38 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
39 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
40 import org.onap.policy.sdnc.SdncResponse;
41
42 @RunWith(MockitoJUnitRunner.class)
43 public class RerouteOperationTest extends BasicSdncOperation {
44     private static final String MY_SERVICE = "my-service";
45     private static final String MY_NETWORK = "my-network";
46
47     private RerouteOperation oper;
48
49     public RerouteOperationTest() {
50         super(DEFAULT_ACTOR, RerouteOperation.NAME);
51     }
52
53     @BeforeClass
54     public static void setUpBeforeClass() throws Exception {
55         initBeforeClass();
56     }
57
58     @AfterClass
59     public static void tearDownAfterClass() {
60         destroyAfterClass();
61     }
62
63     /**
64      * Set up.
65      */
66     @Override
67     @Before
68     public void setUp() throws Exception {
69         super.setUp();
70         oper = new RerouteOperation(params, config);
71     }
72
73     /**
74      * Tests "success" case with simulator.
75      */
76     @Test
77     public void testSuccess() throws Exception {
78         HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
79                         .path("GENERIC-RESOURCE-API:network-topology-operation").build();
80         config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
81
82         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
83         oper = new RerouteOperation(params, config);
84
85         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
86         oper.setProperty(OperationProperties.ENRICHMENT_NETWORK_ID, MY_NETWORK);
87
88         outcome = oper.start().get();
89         assertEquals(OperationResult.SUCCESS, outcome.getResult());
90         assertTrue(outcome.getResponse() instanceof SdncResponse);
91     }
92
93     @Test
94     public void testConstructor() {
95         assertEquals(DEFAULT_ACTOR, oper.getActorName());
96         assertEquals(RerouteOperation.NAME, oper.getName());
97     }
98
99     @Test
100     public void testGetPropertyNames() {
101         // @formatter:off
102         assertThat(oper.getPropertyNames()).isEqualTo(
103                         List.of(
104                             OperationProperties.ENRICHMENT_SERVICE_ID,
105                             OperationProperties.ENRICHMENT_NETWORK_ID));
106         // @formatter:on
107     }
108
109     @Test
110     public void testMakeRequest() throws Exception {
111         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
112         oper.setProperty(OperationProperties.ENRICHMENT_NETWORK_ID, MY_NETWORK);
113
114         verifyRequest("reroute.json", verifyOperation(oper), IGNORE_FIELDS);
115     }
116 }