diff options
Diffstat (limited to 'applications/common/src/test')
3 files changed, 63 insertions, 3 deletions
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java index 9a0eb6de..29eb2a0c 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java @@ -19,6 +19,7 @@ package org.onap.policy.pdp.xacml.application.common.operationshistory; import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -198,6 +199,13 @@ public class CountRecentOperationsPipTest { } @Test + public void testShutdown() { + pipEngine.shutdown(); + assertThatExceptionOfType(PIPException.class).isThrownBy(() -> pipEngine.getAttributes(pipRequest, pipFinder)) + .withMessageContaining("Engine is shutdown"); + } + + @Test public void testGetCountFromDb() throws Exception { // // Configure it using properties diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePipTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePipTest.java index f4ed1a3b..e0dc7cd4 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePipTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePipTest.java @@ -18,13 +18,20 @@ package org.onap.policy.pdp.xacml.application.common.operationshistory; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; +import com.att.research.xacml.api.Status; import com.att.research.xacml.api.pip.PIPException; import com.att.research.xacml.api.pip.PIPFinder; import com.att.research.xacml.api.pip.PIPRequest; +import com.att.research.xacml.api.pip.PIPResponse; import com.att.research.xacml.std.pip.StdPIPResponse; import java.io.FileInputStream; import java.lang.reflect.Method; @@ -40,6 +47,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.onap.policy.pdp.xacml.application.common.ToscaDictionary; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,6 +66,12 @@ public class GetOperationOutcomePipTest { @Mock private PIPFinder pipFinder; + @Mock + private PIPResponse resp1; + + @Mock + private Status okStatus; + /** * Create an instance of our engine and also the persistence * factory. @@ -124,7 +138,6 @@ public class GetOperationOutcomePipTest { pipEngine.configure("issuer", properties); LOGGER.info("PIP configured now creating our entity manager"); LOGGER.info("properties {}", properties); - } @Test @@ -153,6 +166,24 @@ public class GetOperationOutcomePipTest { } @Test + public void testGetAttributes() throws Exception { + // + // + // + when(pipRequest.getIssuer()).thenReturn(ToscaDictionary.GUARD_ISSUER_PREFIX + "clname:clfoo"); + when(pipFinder.getMatchingAttributes(any(), eq(pipEngine))).thenReturn(resp1); + when(resp1.getStatus()).thenReturn(okStatus); + when(okStatus.isOk()).thenReturn(true); + + assertNotEquals(StdPIPResponse.PIP_RESPONSE_EMPTY, pipEngine.getAttributes(pipRequest, pipFinder)); + + pipEngine.shutdown(); + + assertThatExceptionOfType(PIPException.class).isThrownBy(() -> pipEngine.getAttributes(pipRequest, pipFinder)) + .withMessageContaining("Engine is shutdown"); + } + + @Test public void testGetOutcomeFromDb() throws Exception { // // Use reflection to run getCountFromDB @@ -162,13 +193,18 @@ public class GetOperationOutcomePipTest { String.class); method.setAccessible(true); // + // Test pipEngine + // + String outcome = (String) method.invoke(pipEngine, "testcl1", "testtarget1"); + assertThat(outcome).isNull(); + // // Insert entry // insertEntry("testcl1", "testtarget1", "1"); // // Test pipEngine // - String outcome = (String) method.invoke(pipEngine, "testcl1", "testtarget1"); + outcome = (String) method.invoke(pipEngine, "testcl1", "testtarget1"); // // outcome should be "1" // @@ -190,6 +226,13 @@ public class GetOperationOutcomePipTest { outcome = (String) method.invoke(pipEngine, "testcl1", "testtarget2"); assertEquals("4", outcome); + + // + // Shut it down + // + pipEngine.shutdown(); + + assertThat(method.invoke(pipEngine, "testcl1", "testtarget2")).isNull(); } private void insertEntry(String cl, String target, String outcome) { diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPipTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPipTest.java index 1a9901b5..a0f85730 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPipTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPipTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,8 @@ package org.onap.policy.pdp.xacml.application.common.std; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; @@ -299,6 +301,13 @@ public class StdOnapPipTest { assertEquals(0, resp.getAttributes().size()); } + @Test + public void testShutdown() { + assertThatCode(() -> pip.shutdown()).doesNotThrowAnyException(); + assertThatExceptionOfType(PIPException.class).isThrownBy(() -> pip.configure("foo", new Properties())) + .withMessageContaining("Engine is shutdown"); + } + private class MyPip extends StdOnapPip { @Override |