X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Felk%2Fclient%2FElkConnectorImplTest.java;fp=ONAP-PAP-REST%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Felk%2FElkConnectorImplTest.java;h=8eb003ca81f181ec9bea9c2f7375cf9a55028c38;hp=87f56e284d04535129a840e903e701f6a7e1d9f6;hb=0154925df97446afa15ab60d59c57237dfa7b2e9;hpb=b536883546b9fa87bce50c7a6d030f6de3aafdce diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImplTest.java similarity index 71% rename from ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java rename to ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImplTest.java index 87f56e284..8eb003ca8 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImplTest.java @@ -18,8 +18,9 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.pap.xacml.rest.elk; +package org.onap.policy.pap.xacml.rest.elk.client; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -27,15 +28,14 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import io.searchbox.client.JestResult; - import java.io.IOException; import java.lang.reflect.Method; - +import java.util.HashMap; +import java.util.Map; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.onap.policy.pap.xacml.rest.elk.client.ElkConnector.PolicyIndexType; -import org.onap.policy.pap.xacml.rest.elk.client.ElkConnectorImpl; import org.onap.policy.rest.adapter.PolicyRestAdapter; public class ElkConnectorImplTest { @@ -143,4 +143,31 @@ public class ElkConnectorImplTest { impl.search(PolicyIndexType.config, "search", null); fail("Expected exception to be thrown"); } + + @Test + public void testImplNegCases() throws IOException { + ElkConnectorImpl impl = new ElkConnectorImpl(); + Map filter = new HashMap(); + assertThatThrownBy(() -> impl.isType(PolicyIndexType.config)).isInstanceOf(IOException.class); + assertThatThrownBy(() -> impl.isIndex()).isInstanceOf(IOException.class); + assertThatThrownBy(() -> impl.search(null, null)).isInstanceOf(IllegalArgumentException.class); + assertThatThrownBy(() -> impl.search(null, "")).isInstanceOf(IllegalArgumentException.class); + assertThatThrownBy(() -> impl.search(null, ";;;")).isInstanceOf(IllegalArgumentException.class); + assertThatThrownBy(() -> impl.search(null, "foo")).isInstanceOf(IllegalStateException.class); + assertThatThrownBy(() -> impl.search(PolicyIndexType.all, "foo")).isInstanceOf(IllegalStateException.class); + + assertThatThrownBy(() -> impl.search(null, null, null)).isInstanceOf(IllegalArgumentException.class); + assertThatThrownBy(() -> impl.search(null, null, filter)).isInstanceOf(IllegalArgumentException.class); + filter.put("key", "value"); + assertThatThrownBy(() -> impl.search(null, ";;;", filter)).isInstanceOf(IllegalArgumentException.class); + assertThatThrownBy(() -> impl.search(null, "foo", filter)).isInstanceOf(IllegalStateException.class); + assertThatThrownBy(() -> impl.search(PolicyIndexType.config, "foo", filter)) + .isInstanceOf(IllegalStateException.class); + + PolicyRestAdapter adapter = new PolicyRestAdapter(); + adapter.setNewFileName("scope.Decision_newFile"); + adapter.setConfigPolicyType("Config"); + assertThatThrownBy(() -> impl.put(adapter)).isInstanceOf(IOException.class); + assertThatThrownBy(() -> impl.delete(adapter)).isInstanceOf(IllegalStateException.class); + } }