effbb6e0210c184570a89a60490b3db72f205373
[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  * ================================================================================
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 RerouteOperationTest extends BasicSdncOperation {
40     private static final String MY_SERVICE = "my-service";
41     private static final String MY_NETWORK = "my-network";
42
43     private RerouteOperation oper;
44
45     public RerouteOperationTest() {
46         super(DEFAULT_ACTOR, RerouteOperation.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     @Override
63     @Before
64     public void setUp() throws Exception {
65         super.setUp();
66         oper = new RerouteOperation(params, config);
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:network-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 RerouteOperation(params, config);
80
81         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
82         oper.setProperty(OperationProperties.ENRICHMENT_NETWORK_ID, MY_NETWORK);
83
84         outcome = oper.start().get();
85         assertEquals(OperationResult.SUCCESS, outcome.getResult());
86         assertTrue(outcome.getResponse() instanceof SdncResponse);
87     }
88
89     @Test
90     public void testConstructor() {
91         assertEquals(DEFAULT_ACTOR, oper.getActorName());
92         assertEquals(RerouteOperation.NAME, oper.getName());
93     }
94
95     @Test
96     public void testGetPropertyNames() {
97         // @formatter:off
98         assertThat(oper.getPropertyNames()).isEqualTo(
99                         List.of(
100                             OperationProperties.ENRICHMENT_SERVICE_ID,
101                             OperationProperties.ENRICHMENT_NETWORK_ID));
102         // @formatter:on
103     }
104
105     @Test
106     public void testMakeRequest() throws Exception {
107         oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE);
108         oper.setProperty(OperationProperties.ENRICHMENT_NETWORK_ID, MY_NETWORK);
109
110         verifyRequest("reroute.json", verifyOperation(oper), IGNORE_FIELDS);
111     }
112 }