2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2024 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.drools.controller.internal;
24 import static org.assertj.core.api.Assertions.assertThatCode;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertFalse;
27 import static org.junit.jupiter.api.Assertions.assertNotNull;
28 import static org.junit.jupiter.api.Assertions.assertNull;
29 import static org.junit.jupiter.api.Assertions.assertThrows;
30 import static org.junit.jupiter.api.Assertions.assertTrue;
32 import org.junit.jupiter.api.Test;
33 import org.onap.policy.common.utils.gson.GsonTestUtils;
34 import org.onap.policy.drools.controller.DroolsController;
35 import org.onap.policy.drools.controller.DroolsControllerConstants;
37 class NullDroolsControllerTest {
41 DroolsController controller = new NullDroolsController();
43 assertFalse(controller.isAlive());
45 assertFalse(controller.isAlive());
46 controller.shutdown();
47 assertFalse(controller.isAlive());
49 assertFalse(controller.isAlive());
53 void testSerialize() {
54 assertThatCode(() -> new GsonTestUtils().compareGson(new NullDroolsController(),
55 NullDroolsControllerTest.class)).doesNotThrowAnyException();
60 DroolsController controller = new NullDroolsController();
62 assertFalse(controller.isLocked());
64 assertFalse(controller.isLocked());
69 assertEquals(DroolsControllerConstants.NO_GROUP_ID, new NullDroolsController().getGroupId());
73 void getArtifactId() {
74 assertEquals(DroolsControllerConstants.NO_ARTIFACT_ID, new NullDroolsController().getArtifactId());
79 assertEquals(DroolsControllerConstants.NO_VERSION, new NullDroolsController().getVersion());
83 void getSessionNames() {
84 assertTrue(new NullDroolsController().getSessionNames().isEmpty());
88 void getCanonicalSessionNames() {
89 assertTrue(new NullDroolsController().getCanonicalSessionNames().isEmpty());
94 assertFalse(new NullDroolsController().offer(null, null));
99 var controller = new NullDroolsController();
100 assertThrows(IllegalStateException.class, () -> controller.deliver(null, null));
104 void getRecentSourceEvents() {
105 assertEquals(0, new NullDroolsController().getRecentSourceEvents().length);
109 void getRecentSinkEvents() {
110 assertEquals(0, new NullDroolsController().getRecentSinkEvents().length);
114 void getContainer() {
115 assertNull(new NullDroolsController().getContainer());
120 assertTrue(new NullDroolsController().getBaseDomainNames().isEmpty());
125 var controller = new NullDroolsController();
126 assertThrows(IllegalStateException.class, () -> controller.ownsCoder(null, 0));
130 void fetchModelClass() {
131 var controller = new NullDroolsController();
132 var className = this.getClass().getName();
133 assertThrows(IllegalArgumentException.class, () -> controller.fetchModelClass(className));
138 assertFalse(new NullDroolsController().isBrained());
143 assertNotNull(new NullDroolsController().toString());
147 void updateToVersion() {
148 var controller = new NullDroolsController();
149 assertThrows(IllegalArgumentException.class, () ->
150 controller.updateToVersion(null, null, null, null, null));
154 void factClassNames() {
155 assertTrue(new NullDroolsController().factClassNames(null).isEmpty());
160 assertEquals(0, new NullDroolsController().factCount(null));
165 assertTrue(new NullDroolsController().facts(null, null, true).isEmpty());
170 assertTrue(new NullDroolsController().factQuery(null, null, null, false).isEmpty());
175 Object o1 = new Object();
176 assertFalse(new NullDroolsController().exists("blah", o1));
177 assertFalse(new NullDroolsController().exists(o1));