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;
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;
38 * Test the EventGeneratorEndpoint class.
41 public class EventGeneratorEndpointTest {
43 private Provider<Request> httpRequestProviderMock;
46 private Request httpRequestMock;
49 * Set up mocking of the engine service facade.
51 * @throws ApexException on engine service facade setup errors
54 public void initializeMocking() throws ApexException {
55 MockitoAnnotations.initMocks(this);
57 Mockito.doReturn(httpRequestMock).when(httpRequestProviderMock).get();
59 Mockito.doReturn("zooby").when(httpRequestMock).getRemoteHost();
60 Mockito.doReturn(12345).when(httpRequestMock).getRemotePort();
65 public void testEventGeneratorEndpointGetStats() {
66 EventGeneratorEndpoint.clearEventGenerationStats();
67 EventGeneratorEndpoint.setFinished(false);
69 EventGeneratorEndpoint egep = new EventGeneratorEndpoint(null);
72 Response stats = egep.serviceGetStats();
73 assertEquals(200, stats.getStatus());
77 public void testEventGeneratorEndpointGetEventsZeroBatchCount() {
78 EventGeneratorParameters incomingParameters = new EventGeneratorParameters();
79 incomingParameters.setBatchCount(1);
81 EventGeneratorEndpoint.setParameters(incomingParameters);
82 EventGeneratorEndpoint.clearEventGenerationStats();
83 EventGeneratorEndpoint.setFinished(false);
85 EventGeneratorEndpoint egep = new EventGeneratorEndpoint(httpRequestProviderMock);
88 Response events = egep.getEvents();
89 assertEquals(200, events.getStatus());
91 incomingParameters.setBatchCount(1);
92 events = egep.getEvents();
93 assertEquals(204, events.getStatus());
97 public void testEventGeneratorEndpointPostBadEvent() {
98 EventGeneratorParameters incomingParameters = new EventGeneratorParameters();
99 incomingParameters.setBatchCount(1);
101 EventGeneratorEndpoint.setParameters(incomingParameters);
102 EventGeneratorEndpoint.clearEventGenerationStats();
103 EventGeneratorEndpoint.setFinished(false);
105 EventGeneratorEndpoint egep = new EventGeneratorEndpoint(httpRequestProviderMock);
108 OutputEvent oe = new OutputEvent();
109 oe.setTestSlogan("99-99: Whatever");
111 Response events = egep.postEventResponse(oe.asJson());
112 assertEquals(409, events.getStatus());