Changes for checkstyle 8.32
[policy/apex-pdp.git] / testsuites / performance / performance-benchmark-test / src / test / java / org / onap / policy / apex / testsuites / performance / benchmark / eventgenerator / EventGeneratorEndpointTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25
26 import javax.inject.Provider;
27 import javax.ws.rs.core.Response;
28 import org.glassfish.grizzly.http.server.Request;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
35 import org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.events.OutputEvent;
36
37 /**
38  * Test the EventGeneratorEndpoint class.
39  *
40  */
41 public class EventGeneratorEndpointTest {
42     @Mock
43     private Provider<Request> httpRequestProviderMock;
44
45     @Mock
46     private Request httpRequestMock;
47
48     /**
49      * Set up mocking of the engine service facade.
50      *
51      * @throws ApexException on engine service facade setup errors
52      */
53     @Before
54     public void initializeMocking() throws ApexException {
55         MockitoAnnotations.initMocks(this);
56
57         Mockito.doReturn(httpRequestMock).when(httpRequestProviderMock).get();
58
59         Mockito.doReturn("zooby").when(httpRequestMock).getRemoteHost();
60         Mockito.doReturn(12345).when(httpRequestMock).getRemotePort();
61
62     }
63
64     @Test
65     public void testEventGeneratorEndpointGetStats() {
66         EventGeneratorEndpoint.clearEventGenerationStats();
67         EventGeneratorEndpoint.setFinished(false);
68
69         EventGeneratorEndpoint egep = new EventGeneratorEndpoint(null);
70         assertNotNull(egep);
71
72         Response stats = egep.serviceGetStats();
73         assertEquals(200, stats.getStatus());
74     }
75
76     @Test
77     public void testEventGeneratorEndpointGetEventsZeroBatchCount() {
78         EventGeneratorParameters incomingParameters = new EventGeneratorParameters();
79         incomingParameters.setBatchCount(1);
80
81         EventGeneratorEndpoint.setParameters(incomingParameters);
82         EventGeneratorEndpoint.clearEventGenerationStats();
83         EventGeneratorEndpoint.setFinished(false);
84
85         EventGeneratorEndpoint egep = new EventGeneratorEndpoint(httpRequestProviderMock);
86         assertNotNull(egep);
87
88         Response events = egep.getEvents();
89         assertEquals(200, events.getStatus());
90
91         incomingParameters.setBatchCount(1);
92         events = egep.getEvents();
93         assertEquals(204, events.getStatus());
94     }
95
96     @Test
97     public void testEventGeneratorEndpointPostBadEvent() {
98         EventGeneratorParameters incomingParameters = new EventGeneratorParameters();
99         incomingParameters.setBatchCount(1);
100
101         EventGeneratorEndpoint.setParameters(incomingParameters);
102         EventGeneratorEndpoint.clearEventGenerationStats();
103         EventGeneratorEndpoint.setFinished(false);
104
105         EventGeneratorEndpoint egep = new EventGeneratorEndpoint(httpRequestProviderMock);
106         assertNotNull(egep);
107
108         OutputEvent oe = new OutputEvent();
109         oe.setTestSlogan("99-99: Whatever");
110
111         Response events = egep.postEventResponse(oe.asJson());
112         assertEquals(409, events.getStatus());
113     }
114 }