62c19b80a7fd6432cdb11036a8671d803b3fa0e0
[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.mockito.ArgumentMatchers.any;
27 import static org.mockito.Mockito.when;
28
29 import javax.ws.rs.client.InvocationCallback;
30 import javax.ws.rs.core.Response;
31 import org.junit.Before;
32 import org.junit.Test;
33
34 public class BasicHttpOperationTest {
35     private static final String ACTOR = "my-actor";
36     private static final String OPERATION = "my-operation";
37
38     private BasicHttpOperation oper;
39
40
41     @Before
42     public void setUp() throws Exception {
43         oper = new BasicHttpOperation(ACTOR, OPERATION);
44         oper.setUpBasic();
45     }
46
47     @Test
48     public void testBasicHttpOperation() {
49         oper = new BasicHttpOperation();
50         assertEquals(BasicOperation.DEFAULT_ACTOR, oper.actorName);
51         assertEquals(BasicOperation.DEFAULT_OPERATION, oper.operationName);
52     }
53
54     @Test
55     public void testBasicHttpOperationStringString() {
56         assertEquals(ACTOR, oper.actorName);
57         assertEquals(OPERATION, oper.operationName);
58     }
59
60     @Test
61     public void testSetUp() throws Exception {
62         assertNotNull(oper.client);
63         assertSame(oper.client, oper.factory.get(BasicHttpOperation.MY_CLIENT));
64         assertEquals(200, oper.rawResponse.getStatus());
65         assertNotNull(oper.future);
66         assertEquals(BasicHttpOperation.BASE_URI, oper.client.getBaseUrl());
67         assertNotNull(oper.outcome);
68         assertNotNull(oper.executor);
69     }
70
71     @Test
72     public void testInitOperator() throws Exception {
73         oper.initConfig();
74
75         assertSame(oper.client, oper.config.getClient());
76         assertEquals(BasicHttpOperation.PATH, oper.config.getPath());
77     }
78
79     @Test
80     public void testProvideResponse() throws Exception {
81         InvocationCallback<Response> cb = new InvocationCallback<>() {
82             @Override
83             public void completed(Response response) {
84                 // do nothing
85             }
86
87             @Override
88             public void failed(Throwable throwable) {
89                 // do nothing
90             }
91         };
92
93
94         when(oper.client.get(any(), any(), any())).thenAnswer(oper.provideResponse(oper.rawResponse));
95
96         assertSame(oper.rawResponse, oper.client.get(cb, null, null).get());
97     }
98 }