Address sonar issues in policy-management
[policy/drools-pdp.git] / policy-management / src / test / java / org / onap / policy / drools / controller / internal / NullDroolsControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.drools.controller.internal;
22
23 import static org.assertj.core.api.Assertions.assertThatCode;
24
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.onap.policy.common.utils.gson.GsonTestUtils;
28 import org.onap.policy.drools.controller.DroolsController;
29 import org.onap.policy.drools.controller.DroolsControllerConstants;
30
31 public class NullDroolsControllerTest {
32
33     @Test
34     public void testStart() {
35         DroolsController controller = new NullDroolsController();
36         controller.start();
37         Assert.assertFalse(controller.isAlive());
38         controller.stop();
39         Assert.assertFalse(controller.isAlive());
40         controller.shutdown();
41         Assert.assertFalse(controller.isAlive());
42         controller.halt();
43         Assert.assertFalse(controller.isAlive());
44     }
45
46     @Test
47     public void testSerialize() {
48         assertThatCode(() -> new GsonTestUtils().compareGson(new NullDroolsController(),
49                         NullDroolsControllerTest.class)).doesNotThrowAnyException();
50     }
51
52     @Test
53     public void testLock() {
54         DroolsController controller = new NullDroolsController();
55         controller.lock();
56         Assert.assertFalse(controller.isLocked());
57         controller.unlock();
58         Assert.assertFalse(controller.isLocked());
59     }
60
61     @Test
62     public void getGroupId() {
63         Assert.assertEquals(DroolsControllerConstants.NO_GROUP_ID, new NullDroolsController().getGroupId());
64     }
65
66     @Test
67     public void getArtifactId() {
68         Assert.assertEquals(DroolsControllerConstants.NO_ARTIFACT_ID, new NullDroolsController().getArtifactId());
69     }
70
71     @Test
72     public void getVersion() {
73         Assert.assertEquals(DroolsControllerConstants.NO_VERSION, new NullDroolsController().getVersion());
74     }
75
76     @Test
77     public void getSessionNames() {
78         Assert.assertTrue(new NullDroolsController().getSessionNames().isEmpty());
79     }
80
81     @Test
82     public void getCanonicalSessionNames() {
83         Assert.assertTrue(new NullDroolsController().getCanonicalSessionNames().isEmpty());
84     }
85
86     @Test
87     public void offer() {
88         Assert.assertFalse(new NullDroolsController().offer(null, null));
89     }
90
91     @Test(expected = IllegalStateException.class)
92     public void deliver() {
93         new NullDroolsController().deliver(null, null);
94     }
95
96     @Test
97     public void getRecentSourceEvents() {
98         Assert.assertTrue(new NullDroolsController().getRecentSourceEvents().length == 0);
99     }
100
101     @Test
102     public void getRecentSinkEvents() {
103         Assert.assertTrue(new NullDroolsController().getRecentSinkEvents().length == 0);
104     }
105
106     @Test
107     public void getContainer() {
108         Assert.assertNull(new NullDroolsController().getContainer());
109     }
110
111     @Test
112     public void getDomains() {
113         Assert.assertTrue(new NullDroolsController().getBaseDomainNames().isEmpty());
114     }
115
116     @Test(expected = IllegalStateException.class)
117     public void ownsCoder() {
118         new NullDroolsController().ownsCoder(null, 0);
119     }
120
121     @Test(expected = IllegalArgumentException.class)
122     public void fetchModelClass() {
123         new NullDroolsController().fetchModelClass(this.getClass().getName());
124     }
125
126     @Test
127     public void isBrained() {
128         Assert.assertFalse(new NullDroolsController().isBrained());
129     }
130
131     @Test
132     public void stringify() {
133         Assert.assertNotNull(new NullDroolsController().toString());
134     }
135
136     @Test(expected = IllegalArgumentException.class)
137     public void updateToVersion() {
138         new NullDroolsController().updateToVersion(null, null, null, null, null);
139     }
140
141     @Test
142     public void factClassNames() {
143         Assert.assertTrue(new NullDroolsController().factClassNames(null).isEmpty());
144     }
145
146     @Test
147     public void factCount() {
148         Assert.assertTrue(new NullDroolsController().factCount(null) == 0);
149     }
150
151     @Test
152     public void facts() {
153         Assert.assertTrue(new NullDroolsController().facts(null, null, true).isEmpty());
154     }
155
156     @Test
157     public void factQuery() {
158         Assert.assertTrue(new NullDroolsController().factQuery(null, null, null, false).isEmpty());
159     }
160 }