2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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;
28 import io.searchbox.client.JestResult;
30 import java.io.IOException;
31 import java.lang.reflect.Method;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.ExpectedException;
36 import org.onap.policy.pap.xacml.rest.elk.client.ElkConnector.PolicyIndexType;
37 import org.onap.policy.pap.xacml.rest.elk.client.ElkConnectorImpl;
38 import org.onap.policy.rest.adapter.PolicyRestAdapter;
40 public class ElkConnectorImplTest {
43 public void isAlphaNumericTest() {
45 Method method = ElkConnectorImpl.class.getDeclaredMethod("isAlphaNumeric", String.class);
46 method.setAccessible(true);
47 assertTrue((boolean) method.invoke(new ElkConnectorImpl(), "abc123"));
48 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123*"));
49 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123{}"));
50 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123\n"));
51 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123<"));
52 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123:"));
53 } catch (Exception e) {
59 public void searchTest(){
60 JestResult r1=null, r2=null, r3=null, r4=null;
62 // Should always work if the above test passes and ELK server is up
64 r1 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123");
65 } catch (Exception e) {
66 // ELK server is down. Don't continue the test
67 if(e instanceof IllegalStateException){
75 r2 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The_quick_brown_fox_jumps_over_the_lazy_dog");
76 } catch (Exception e) {
80 // Should throw exception
82 r3 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123{}");
83 } catch (Exception e) {
84 if(! (e instanceof IllegalArgumentException)){
89 // Should throw exception
91 r4 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The quick brown fox jumps over the lazy dog");
92 } catch (Exception e) {
93 if(! (e instanceof IllegalArgumentException)){
105 public ExpectedException thrown = ExpectedException.none();
108 public void testDelete() {
109 thrown.expect(NullPointerException.class);
111 ElkConnectorImpl impl = new ElkConnectorImpl();
112 PolicyRestAdapter adapter = new PolicyRestAdapter();
113 impl.delete(adapter);
114 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");