Test new actors against simulators
[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.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25
26 import java.util.Map;
27 import org.junit.AfterClass;
28 import org.junit.Before;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
32 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
33 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
34 import org.onap.policy.controlloop.policy.PolicyResult;
35 import org.onap.policy.sdnc.SdncRequest;
36
37 public class RerouteOperationTest extends BasicSdncOperation {
38
39     private RerouteOperation oper;
40
41     public RerouteOperationTest() {
42         super(DEFAULT_ACTOR, RerouteOperation.NAME);
43     }
44
45     @BeforeClass
46     public static void setUpBeforeClass() throws Exception {
47         initBeforeClass();
48     }
49
50     @AfterClass
51     public static void tearDownAfterClass() {
52         destroyAfterClass();
53     }
54
55     /**
56      * Set up.
57      */
58     @Before
59     public void setUp() throws Exception {
60         super.setUp();
61         oper = new RerouteOperation(params, config);
62     }
63
64     /**
65      * Tests "success" case with simulator.
66      */
67     @Test
68     public void testSuccess() throws Exception {
69         HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
70                         .path("GENERIC-RESOURCE-API:network-topology-operation").build();
71         config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
72
73         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
74         oper = new RerouteOperation(params, config);
75
76         outcome = oper.start().get();
77         assertEquals(PolicyResult.SUCCESS, outcome.getResult());
78     }
79
80     @Test
81     public void testConstructor() {
82         assertEquals(DEFAULT_ACTOR, oper.getActorName());
83         assertEquals(RerouteOperation.NAME, oper.getName());
84     }
85
86     @Test
87     public void testMakeRequest() throws Exception {
88         SdncRequest request = oper.makeRequest(1);
89         assertEquals("my-service", request.getNsInstanceId());
90         assertEquals(REQ_ID, request.getRequestId());
91         assertEquals("/my-path/", request.getUrl());
92         assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId());
93
94         verifyRequest("reroute.json", request, IGNORE_FIELDS);
95
96         verifyMissing(RerouteOperation.SERVICE_ID_KEY, "service", RerouteOperation::new);
97         verifyMissing(RerouteOperation.NETWORK_ID_KEY, "network", RerouteOperation::new);
98
99         // perform the operation
100         makeContext();
101         verifyRequest("reroute.json", verifyOperation(oper), IGNORE_FIELDS);
102     }
103
104     @Override
105     protected Map<String, String> makeEnrichment() {
106         return Map.of(RerouteOperation.SERVICE_ID_KEY, "my-service", RerouteOperation.NETWORK_ID_KEY, "my-network");
107     }
108 }