Add more code to facilitate actor implementation
[policy/models.git] / models-interactions / model-actors / actor.test / src / test / java / org / onap / policy / controlloop / actor / test / BasicHttpOperationTest.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.test;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertSame;
26 import static org.junit.Assert.assertTrue;
27
28 import org.junit.Before;
29 import org.junit.Test;
30
31 public class BasicHttpOperationTest {
32     private static final String ACTOR = "my-actor";
33     private static final String OPERATION = "my-operation";
34
35     private BasicHttpOperation<String> oper;
36
37
38     @Before
39     public void setUp() throws Exception {
40         oper = new BasicHttpOperation<>(ACTOR, OPERATION);
41         oper.setUp();
42     }
43
44     @Test
45     public void testBasicHttpOperation() {
46         oper = new BasicHttpOperation<>();
47         assertEquals(BasicHttpOperation.DEFAULT_ACTOR, oper.actorName);
48         assertEquals(BasicHttpOperation.DEFAULT_OPERATION, oper.operationName);
49     }
50
51     @Test
52     public void testBasicHttpOperationStringString() {
53         assertEquals(ACTOR, oper.actorName);
54         assertEquals(OPERATION, oper.operationName);
55     }
56
57     @Test
58     public void testSetUp() {
59         assertNotNull(oper.client);
60         assertSame(oper.client, oper.factory.get(BasicHttpOperation.MY_CLIENT));
61         assertEquals(200, oper.rawResponse.getStatus());
62         assertNotNull(oper.future);
63         assertEquals(BasicHttpOperation.BASE_URI, oper.client.getBaseUrl());
64         assertNotNull(oper.context);
65         assertNotNull(oper.outcome);
66         assertTrue(oper.operator.isAlive());
67     }
68
69     @Test
70     public void testMakeContext() {
71         oper.makeContext();
72
73         assertTrue(oper.enrichment.isEmpty());
74
75         assertSame(BasicHttpOperation.REQ_ID, oper.event.getRequestId());
76         assertSame(oper.enrichment, oper.event.getAai());
77
78         assertSame(oper.event, oper.context.getEvent());
79
80         assertSame(oper.context, oper.params.getContext());
81         assertSame(oper.service, oper.params.getActorService());
82         assertEquals(ACTOR, oper.params.getActor());
83         assertEquals(OPERATION, oper.params.getOperation());
84         assertEquals(BasicHttpOperation.TARGET_ENTITY, oper.params.getTargetEntity());
85     }
86
87     @Test
88     public void testInitOperator() throws Exception {
89         oper.initOperator();
90
91         assertTrue(oper.operator.isAlive());
92         assertEquals(ACTOR + "." + OPERATION, oper.operator.getFullName());
93         assertEquals(ACTOR, oper.operator.getActorName());
94         assertEquals(OPERATION, oper.operator.getName());
95         assertSame(oper.client, oper.operator.getClient());
96         assertEquals(BasicHttpOperation.PATH, oper.operator.getPath());
97     }
98
99     @Test
100     public void testMakeEnrichment() {
101         assertTrue(oper.makeEnrichment().isEmpty());
102     }
103
104 }