2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.controlloop.actor.sdnc;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
27 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.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;
41 public class RerouteOperationTest extends BasicSdncOperation {
43 private RerouteOperation oper;
45 public RerouteOperationTest() {
46 super(DEFAULT_ACTOR, RerouteOperation.NAME);
50 public static void setUpBeforeClass() throws Exception {
55 public static void tearDownAfterClass() {
63 public void setUp() throws Exception {
65 oper = new RerouteOperation(params, config);
69 * Tests "success" case with simulator.
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());
77 params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
78 oper = new RerouteOperation(params, config);
80 outcome = oper.start().get();
81 assertEquals(PolicyResult.SUCCESS, outcome.getResult());
82 assertTrue(outcome.getResponse() instanceof SdncResponse);
86 public void testConstructor() {
87 assertEquals(DEFAULT_ACTOR, oper.getActorName());
88 assertEquals(RerouteOperation.NAME, oper.getName());
92 public void testGetPropertyNames() {
94 assertThat(oper.getPropertyNames()).isEqualTo(
96 OperationProperties.ENRICHMENT_SERVICE_ID,
97 OperationProperties.ENRICHMENT_NETWORK_ID));
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());
110 verifyRequest("reroute.json", request, IGNORE_FIELDS);
112 verifyMissing(RerouteOperation.SERVICE_ID_KEY, "service", RerouteOperation::new);
113 verifyMissing(RerouteOperation.NETWORK_ID_KEY, "network", RerouteOperation::new);
115 // perform the operation
117 verifyRequest("reroute.json", verifyOperation(oper), IGNORE_FIELDS);
121 protected Map<String, String> makeEnrichment() {
122 return Map.of(RerouteOperation.SERVICE_ID_KEY, "my-service", RerouteOperation.NETWORK_ID_KEY, "my-network");