Add property lists to Actors
[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 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 RerouteOperationTest extends BasicSdncOperation {
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     @Before
63     public void setUp() throws Exception {
64         super.setUp();
65         oper = new RerouteOperation(params, config);
66     }
67
68     /**
69      * Tests "success" case with simulator.
70      */
71     @Test
72     public void testSuccess() throws Exception {
73         HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
74                         .path("GENERIC-RESOURCE-API:network-topology-operation").build();
75         config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
76
77         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
78         oper = new RerouteOperation(params, config);
79
80         outcome = oper.start().get();
81         assertEquals(PolicyResult.SUCCESS, outcome.getResult());
82         assertTrue(outcome.getResponse() instanceof SdncResponse);
83     }
84
85     @Test
86     public void testConstructor() {
87         assertEquals(DEFAULT_ACTOR, oper.getActorName());
88         assertEquals(RerouteOperation.NAME, oper.getName());
89     }
90
91     @Test
92     public void testGetPropertyNames() {
93         // @formatter:off
94         assertThat(oper.getPropertyNames()).isEqualTo(
95                         List.of(
96                             OperationProperties.ENRICHMENT_SERVICE_ID,
97                             OperationProperties.ENRICHMENT_NETWORK_ID));
98         // @formatter:on
99     }
100
101     @Test
102     public void testMakeRequest() throws Exception {
103         oper.generateSubRequestId(1);
104         SdncRequest request = oper.makeRequest(1);
105         assertEquals("my-service", request.getNsInstanceId());
106         assertEquals(REQ_ID, request.getRequestId());
107         assertEquals("/my-path/", request.getUrl());
108         assertEquals(oper.getSubRequestId(), request.getHealRequest().getRequestHeaderInfo().getSvcRequestId());
109
110         verifyRequest("reroute.json", request, IGNORE_FIELDS);
111
112         verifyMissing(RerouteOperation.SERVICE_ID_KEY, "service", RerouteOperation::new);
113         verifyMissing(RerouteOperation.NETWORK_ID_KEY, "network", RerouteOperation::new);
114
115         // perform the operation
116         makeContext();
117         verifyRequest("reroute.json", verifyOperation(oper), IGNORE_FIELDS);
118     }
119
120     @Override
121     protected Map<String, String> makeEnrichment() {
122         return Map.of(RerouteOperation.SERVICE_ID_KEY, "my-service", RerouteOperation.NETWORK_ID_KEY, "my-network");
123     }
124 }