2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.pap.xacml.rest.elk;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
29 import io.searchbox.client.JestResult;
31 import java.io.IOException;
32 import java.lang.reflect.Method;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37 import org.onap.policy.pap.xacml.rest.elk.client.ElkConnector.PolicyIndexType;
38 import org.onap.policy.pap.xacml.rest.elk.client.ElkConnectorImpl;
39 import org.onap.policy.rest.adapter.PolicyRestAdapter;
41 public class ElkConnectorImplTest {
44 public void isAlphaNumericTest() {
46 Method method = ElkConnectorImpl.class.getDeclaredMethod("isAlphaNumeric", String.class);
47 method.setAccessible(true);
48 assertTrue((boolean) method.invoke(new ElkConnectorImpl(), "abc123"));
49 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123*"));
50 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123{}"));
51 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123\n"));
52 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123<"));
53 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123:"));
54 } catch (Exception e) {
60 public void searchTest() {
61 JestResult r1 = null, r2 = null, r3 = null, r4 = null;
63 // Should always work if the above test passes and ELK server is up
65 r1 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123");
66 } catch (Exception e) {
67 // ELK server is down. Don't continue the test
68 if (e instanceof IllegalStateException) {
76 r2 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The_quick_brown_fox_jumps_over_the_lazy_dog");
77 } catch (Exception e) {
81 // Should throw exception
83 r3 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123{}");
84 } catch (Exception e) {
85 if (!(e instanceof IllegalArgumentException)) {
90 // Should throw exception
92 r4 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The quick brown fox jumps over the lazy dog");
93 } catch (Exception e) {
94 if (!(e instanceof IllegalArgumentException)) {
106 public ExpectedException thrown = ExpectedException.none();
109 public void testDelete() {
110 thrown.expect(NullPointerException.class);
112 ElkConnectorImpl impl = new ElkConnectorImpl();
113 PolicyRestAdapter adapter = new PolicyRestAdapter();
114 impl.delete(adapter);
115 fail("Expected exception to be thrown");
119 public void testPut() throws IOException {
120 thrown.expect(NullPointerException.class);
122 ElkConnectorImpl impl = new ElkConnectorImpl();
123 PolicyRestAdapter adapter = new PolicyRestAdapter();
125 fail("Expected exception to be thrown");
129 public void testUpdate() {
130 thrown.expect(IllegalStateException.class);
132 ElkConnectorImpl impl = new ElkConnectorImpl();
133 PolicyRestAdapter adapter = new PolicyRestAdapter();
134 impl.update(adapter);
135 fail("Expected exception to be thrown");
139 public void testSearchWithFilter() {
140 thrown.expect(IllegalStateException.class);
142 ElkConnectorImpl impl = new ElkConnectorImpl();
143 impl.search(PolicyIndexType.config, "search", null);
144 fail("Expected exception to be thrown");