diff options
Diffstat (limited to 'plugins/plugins-executor/plugins-executor-java')
2 files changed, 44 insertions, 112 deletions
diff --git a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java index 8d7cca3aa..7f263245c 100644 --- a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java +++ b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +21,9 @@ package org.onap.policy.apex.plugins.executor.java; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; import java.util.HashMap; import java.util.Map; @@ -36,6 +37,7 @@ import org.onap.policy.apex.context.parameters.DistributorParameters; import org.onap.policy.apex.context.parameters.LockManagerParameters; import org.onap.policy.apex.context.parameters.PersistorParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; import org.onap.policy.apex.model.policymodel.concepts.AxTask; import org.onap.policy.common.parameters.ParameterService; @@ -66,73 +68,37 @@ public class JavaTaskExecutorTest { } @Test - public void testJavaTaskExecutor() { + public void testJavaTaskExecutor() throws ContextException, StateMachineException { JavaTaskExecutor jte = new JavaTaskExecutor(); assertNotNull(jte); - try { - jte.prepare(); - fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals(java.lang.NullPointerException.class, jteException.getClass()); - } - + assertThatThrownBy(jte::prepare) + .isInstanceOf(java.lang.NullPointerException.class); AxTask task = new AxTask(); ApexInternalContext internalContext = null; - try { - internalContext = new ApexInternalContext(new AxPolicyModel()); - } catch (ContextException e) { - fail("test should not throw an exception here"); - } - jte.setContext(null, task, internalContext); + internalContext = new ApexInternalContext(new AxPolicyModel()); - try { - jte.prepare(); - fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals("instantiation error on Java class \"\"", jteException.getMessage()); - } + jte.setContext(null, task, internalContext); + assertThatThrownBy(jte::prepare) + .hasMessage("instantiation error on Java class \"\""); task.getTaskLogic().setLogic("java.lang.String"); - try { - jte.prepare(); - } catch (Exception jteException) { - fail("test should not throw an exception here"); - } - - try { - jte.execute(-1, new Properties(), null); - fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals(java.lang.NullPointerException.class, jteException.getClass()); - } + jte.prepare(); + assertThatThrownBy(() -> jte.execute(-1, new Properties(), null)) + .isInstanceOf(java.lang.NullPointerException.class); Map<String, Object> incomingParameters = new HashMap<>(); - try { - jte.execute(-1, new Properties(), incomingParameters); - fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals("task logic failed to run for task \"NULL:0.0.0\"", jteException.getMessage()); - } - + assertThatThrownBy(() -> jte.execute(-1, new Properties(), incomingParameters)) + .hasMessage("task logic failed to run for task \"NULL:0.0.0\""); task.getTaskLogic().setLogic("org.onap.policy.apex.plugins.executor.java.DummyJavaTaskLogic"); - try { - jte.prepare(); - jte.execute(-1, new Properties(), incomingParameters); - fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0", - jteException.getMessage()); - } + jte.prepare(); + assertThatThrownBy(() -> jte.execute(-1, new Properties(), incomingParameters)) + .hasMessage("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0"); + jte.prepare(); + Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters); + assertEquals(0, returnMap.size()); + jte.cleanUp(); - try { - jte.prepare(); - Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters); - assertEquals(0, returnMap.size()); - jte.cleanUp(); - } catch (Exception jteException) { - fail("test should not throw an exception here"); - } } } diff --git a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java index 38792c409..61acecd9b 100644 --- a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java +++ b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +21,9 @@ package org.onap.policy.apex.plugins.executor.java; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; import java.util.Properties; import org.junit.After; @@ -35,6 +36,7 @@ import org.onap.policy.apex.context.parameters.LockManagerParameters; import org.onap.policy.apex.context.parameters.PersistorParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; import org.onap.policy.apex.core.engine.event.EnEvent; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; @@ -67,76 +69,40 @@ public class JavaTaskSelectExecutorTest { } @Test - public void testJavaTaskSelectExecutor() { + public void testJavaTaskSelectExecutor() throws StateMachineException, ContextException { JavaTaskSelectExecutor jtse = new JavaTaskSelectExecutor(); assertNotNull(jtse); - try { - jtse.prepare(); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals(java.lang.NullPointerException.class, jtseException.getClass()); - } - + assertThatThrownBy(jtse::prepare) + .isInstanceOf(java.lang.NullPointerException.class); AxState state = new AxState(); ApexInternalContext internalContext = null; - try { - internalContext = new ApexInternalContext(new AxPolicyModel()); - } catch (ContextException e) { - fail("test should not throw an exception here"); - } + internalContext = new ApexInternalContext(new AxPolicyModel()); jtse.setContext(null, state, internalContext); - try { - jtse.prepare(); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals("instantiation error on Java class \"\"", jtseException.getMessage()); - } - + assertThatThrownBy(jtse::prepare) + .hasMessage("instantiation error on Java class \"\""); state.getTaskSelectionLogic().setLogic("java.lang.String"); - try { - jtse.prepare(); - } catch (Exception jtseException) { - fail("test should not throw an exception here"); - } - - try { - jtse.execute(-1, new Properties(), null); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals(java.lang.NullPointerException.class, jtseException.getClass()); - } + jtse.prepare(); + assertThatThrownBy(() -> jtse.execute(-1, new Properties(), null)) + .isInstanceOf(java.lang.NullPointerException.class); AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1")); EnEvent event = new EnEvent(axEvent); - try { - jtse.execute(-1, new Properties(), event); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals("task selection logic failed to run for state \"NULL:0.0.0:NULL:NULL\"", - jtseException.getMessage()); - } - + assertThatThrownBy(() -> jtse.execute(-1, new Properties(), event)) + .hasMessage("task selection logic failed to run for state \"NULL:0.0.0:NULL:NULL\""); state.getTaskSelectionLogic() .setLogic("org.onap.policy.apex.plugins.executor.java.DummyJavaTaskSelectionLogic"); - try { - jtse.prepare(); + + jtse.prepare(); + assertThatThrownBy(() -> { jtse.execute(-1, new Properties(), event); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"", - jtseException.getMessage()); - } + }).hasMessage("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\""); - try { - jtse.prepare(); - AxArtifactKey taskKey = jtse.execute(0, new Properties(), event); - assertEquals("NULL:0.0.0", taskKey.getId()); - jtse.cleanUp(); - } catch (Exception jtseException) { - fail("test should not throw an exception here"); - } + jtse.prepare(); + AxArtifactKey taskKey = jtse.execute(0, new Properties(), event); + assertEquals("NULL:0.0.0", taskKey.getId()); + jtse.cleanUp(); } } |