2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2023 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
27 import jakarta.inject.Provider;
28 import jakarta.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.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
37 import org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.events.OutputEvent;
40 * Test the EventGeneratorEndpoint class.
43 @RunWith(MockitoJUnitRunner.class)
44 public class EventGeneratorEndpointTest {
46 private Provider<Request> httpRequestProviderMock;
49 private Request httpRequestMock;
52 * Set up mocking of the engine service facade.
54 * @throws ApexException on engine service facade setup errors
57 public void initializeMocking() throws ApexException {
59 Mockito.doReturn(httpRequestMock).when(httpRequestProviderMock).get();
61 Mockito.doReturn("zooby").when(httpRequestMock).getRemoteHost();
62 Mockito.doReturn(12345).when(httpRequestMock).getRemotePort();
67 public void testEventGeneratorEndpointGetStats() {
68 EventGeneratorEndpoint.clearEventGenerationStats();
69 EventGeneratorEndpoint.setFinished(false);
71 EventGeneratorEndpoint egep = new EventGeneratorEndpoint(null);
74 Response stats = egep.serviceGetStats();
75 assertEquals(200, stats.getStatus());
79 public void testEventGeneratorEndpointGetEventsZeroBatchCount() {
80 EventGeneratorParameters incomingParameters = new EventGeneratorParameters();
81 incomingParameters.setBatchCount(1);
83 EventGeneratorEndpoint.setParameters(incomingParameters);
84 EventGeneratorEndpoint.clearEventGenerationStats();
85 EventGeneratorEndpoint.setFinished(false);
87 EventGeneratorEndpoint egep = new EventGeneratorEndpoint(httpRequestProviderMock);
90 Response events = egep.getEvents();
91 assertEquals(200, events.getStatus());
93 incomingParameters.setBatchCount(1);
94 events = egep.getEvents();
95 assertEquals(204, events.getStatus());
99 public void testEventGeneratorEndpointPostBadEvent() {
100 EventGeneratorParameters incomingParameters = new EventGeneratorParameters();
101 incomingParameters.setBatchCount(1);
103 EventGeneratorEndpoint.setParameters(incomingParameters);
104 EventGeneratorEndpoint.clearEventGenerationStats();
105 EventGeneratorEndpoint.setFinished(false);
107 EventGeneratorEndpoint egep = new EventGeneratorEndpoint(httpRequestProviderMock);
110 OutputEvent oe = new OutputEvent();
111 oe.setTestSlogan("99-99: Whatever");
113 Response events = egep.postEventResponse(oe.asJson());
114 assertEquals(409, events.getStatus());