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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
26 import javax.inject.Provider;
27 import javax.ws.rs.core.Response;
29 import org.glassfish.grizzly.http.server.Request;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.MockitoAnnotations;
35 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
36 import org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.events.OutputEvent;
39 * Test the EventGeneratorEndpoint class.
42 public class EventGeneratorEndpointTest {
44 private Provider<Request> httpRequestProviderMock;
47 private Request httpRequestMock;
50 * Set up mocking of the engine service facade.
52 * @throws ApexException on engine service facade setup errors
55 public void initializeMocking() throws ApexException {
56 MockitoAnnotations.initMocks(this);
58 Mockito.doReturn(httpRequestMock).when(httpRequestProviderMock).get();
60 Mockito.doReturn("zooby").when(httpRequestMock).getRemoteHost();
61 Mockito.doReturn(12345).when(httpRequestMock).getRemotePort();
66 public void testEventGeneratorEndpointGetStats() {
67 EventGeneratorEndpoint.clearEventGenerationStats();
68 EventGeneratorEndpoint.setFinished(false);
70 EventGeneratorEndpoint egep = new EventGeneratorEndpoint(null);
73 Response stats = egep.serviceGetStats();
74 assertEquals(200, stats.getStatus());
78 public void testEventGeneratorEndpointGetEventsZeroBatchCount() {
79 EventGeneratorParameters incomingParameters = new EventGeneratorParameters();
80 incomingParameters.setBatchCount(1);
82 EventGeneratorEndpoint.setParameters(incomingParameters);
83 EventGeneratorEndpoint.clearEventGenerationStats();
84 EventGeneratorEndpoint.setFinished(false);
86 EventGeneratorEndpoint egep = new EventGeneratorEndpoint(httpRequestProviderMock);
89 Response events = egep.getEvents();
90 assertEquals(200, events.getStatus());
92 incomingParameters.setBatchCount(1);
93 events = egep.getEvents();
94 assertEquals(204, events.getStatus());
98 public void testEventGeneratorEndpointPostBadEvent() {
99 EventGeneratorParameters incomingParameters = new EventGeneratorParameters();
100 incomingParameters.setBatchCount(1);
102 EventGeneratorEndpoint.setParameters(incomingParameters);
103 EventGeneratorEndpoint.clearEventGenerationStats();
104 EventGeneratorEndpoint.setFinished(false);
106 EventGeneratorEndpoint egep = new EventGeneratorEndpoint(httpRequestProviderMock);
109 OutputEvent oe = new OutputEvent();
110 oe.setTestSlogan("99-99: Whatever");
112 Response events = egep.postEventResponse(oe.asJson());
113 assertEquals(409, events.getStatus());