2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
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.gui.editors.apex.rest.handling;
23 import static org.assertj.core.api.Assertions.assertThat;
25 import java.util.Random;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.Mockito;
29 import org.onap.policy.apex.model.modelapi.ApexApiResult;
30 import org.onap.policy.apex.model.modelapi.ApexModel;
32 public class KeyInfoHandlerTest {
33 private final Random random = new Random();
34 private KeyInfoHandler handler;
38 handler = new KeyInfoHandler();
42 public void testExecuteRestCommand() {
43 final var sessionId = random.nextInt();
44 final var session = new RestSession(sessionId);
45 final var commandType = RestCommandType.EVENT;
46 final var command = RestCommand.ANALYSE;
48 final var actual = handler.executeRestCommand(session, commandType, command);
50 assertThat(actual.getResult()).isEqualTo(ApexApiResult.Result.FAILED);
51 assertThat(actual.getMessage()).contains(Integer.toString(sessionId));
52 assertThat(actual.getMessage()).contains(commandType.toString());
53 assertThat(actual.getMessage()).contains(command.toString());
57 public void testExecuteRestCommandWithJsonString() {
58 final var sessionId = random.nextInt();
59 final var session = new RestSession(sessionId);
60 final var commandType = RestCommandType.EVENT;
61 final var command = RestCommand.ANALYSE;
62 final var emptyString = "";
64 final var actual = handler.executeRestCommand(session, commandType, command, emptyString);
66 assertThat(actual.getResult()).isEqualTo(ApexApiResult.Result.FAILED);
67 assertThat(actual.getMessage()).contains(Integer.toString(sessionId));
68 assertThat(actual.getMessage()).contains(commandType.toString());
69 assertThat(actual.getMessage()).contains(command.toString());
73 public void testExecuteRestCommandWithNameAndVersion() {
74 final var sessionId = random.nextInt();
75 final var session = new RestSession(sessionId);
76 final var commandType = RestCommandType.EVENT;
77 final var command = RestCommand.ANALYSE;
79 final var version = "";
81 final var actual = handler.executeRestCommand(session, commandType, command, name, version);
83 assertThat(actual.getResult()).isEqualTo(ApexApiResult.Result.FAILED);
84 assertThat(actual.getMessage()).contains(Integer.toString(sessionId));
85 assertThat(actual.getMessage()).contains(commandType.toString());
86 assertThat(actual.getMessage()).contains(command.toString());
90 public void testExecuteRestCommandWithNameAndVersion2() {
91 final var session = Mockito.mock(RestSession.class);
92 final var commandType = RestCommandType.KEY_INFO;
93 final var command = RestCommand.LIST;
95 final var version = "version";
96 final var expected = new ApexApiResult();
97 final var apexModel = Mockito.mock(ApexModel.class);
99 Mockito.when(session.getApexModel()).thenReturn(apexModel);
100 Mockito.when(apexModel.listKeyInformation(null, version)).thenReturn(expected);
102 final var actual = handler.executeRestCommand(session, commandType, command, name, version);
104 assertThat(actual).isEqualTo(expected);