2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.lang.reflect.Method;
32 import org.junit.Test;
33 import org.onap.policy.pap.xacml.rest.elk.client.ElkConnector.PolicyIndexType;
34 import org.onap.policy.pap.xacml.rest.elk.client.ElkConnectorImpl;
36 public class ElkConnectorImplTest {
39 public void isAlphaNumericTest() {
41 Method method = ElkConnectorImpl.class.getDeclaredMethod("isAlphaNumeric", String.class);
42 method.setAccessible(true);
43 assertTrue((boolean) method.invoke(new ElkConnectorImpl(), "abc123"));
44 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123*"));
45 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123{}"));
46 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123\n"));
47 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123<"));
48 assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123:"));
49 } catch (Exception e) {
55 public void searchTest(){
56 JestResult r1=null, r2=null, r3=null, r4=null;
58 // Should always work if the above test passes and ELK server is up
60 r1 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123");
61 } catch (Exception e) {
62 // ELK server is down. Don't continue the test
63 if(e instanceof IllegalStateException){
71 r2 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The_quick_brown_fox_jumps_over_the_lazy_dog");
72 } catch (Exception e) {
76 // Should throw exception
78 r3 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123{}");
79 } catch (Exception e) {
80 if(! (e instanceof IllegalArgumentException)){
85 // Should throw exception
87 r4 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The quick brown fox jumps over the lazy dog");
88 } catch (Exception e) {
89 if(! (e instanceof IllegalArgumentException)){