summaryrefslogtreecommitdiffstats
path: root/core/core-deployment/src
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2020-07-08 14:33:48 +0100
committerwaynedunican <wayne.dunican@est.tech>2020-07-20 15:47:29 +0100
commitd19067ce13765b7f98bcefb26b1bb469282c6624 (patch)
tree463f2eaa7164a2eb311bb9a1e5c88b91e101a955 /core/core-deployment/src
parentcb4b9a2e27266c03fa6aa82165608999bf21e36a (diff)
Replace try/catch with assertj - apex-pdp
Replaced try/catch blocks apex-pdp with assertj assertions. Part III of changes. Issue-ID: POLICY-2451 Change-Id: I77ee4140cdfc2066f463459f92163677c3e34ef2 Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'core/core-deployment/src')
-rw-r--r--core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/BatchDeployerTest.java107
-rw-r--r--core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DeploymentClientTest.java28
-rw-r--r--core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/EngineServiceFacadeTest.java170
-rw-r--r--core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java110
4 files changed, 128 insertions, 287 deletions
diff --git a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/BatchDeployerTest.java b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/BatchDeployerTest.java
index 000acab75..ab44f900d 100644
--- a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/BatchDeployerTest.java
+++ b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/BatchDeployerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * 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.
@@ -21,8 +21,7 @@
package org.onap.policy.apex.core.deployment;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -43,39 +42,27 @@ import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
public class BatchDeployerTest {
@Test
public void testBatchDeployerBad() {
- try {
- final String[] eventArgs = { "-h" };
-
- BatchDeployer.main(eventArgs);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("invalid arguments: [-h]", exc.getMessage().substring(0, 23));
- }
+ final String[] eventArgs = { "-h" };
+
+ assertThatThrownBy(() -> BatchDeployer.main(eventArgs))
+ .hasMessageContaining("invalid arguments: [-h]");
}
@Test
public void testBatchDeployerBadPort() {
- try {
- final String[] eventArgs = { "localhost", "aport", "afile" };
-
- BatchDeployer.main(eventArgs);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("argument port is invalid", exc.getMessage().substring(0, 24));
- }
+ final String[] eventArgs = { "localhost", "aport", "afile" };
+
+ assertThatThrownBy(() -> BatchDeployer.main(eventArgs))
+ .hasMessage("argument port is invalid");
}
@Test
public void testBatchDeployerOk() {
- try {
- final String[] eventArgs = { "Host", "43443",
- "src/test/resources/models/SamplePolicyModelJAVASCRIPT.json" };
-
- BatchDeployer.main(eventArgs);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("model deployment failed on parameters Host 43443", exc.getMessage());
- }
+ final String[] eventArgs = { "Host", "43443",
+ "src/test/resources/models/SamplePolicyModelJAVASCRIPT.json" };
+
+ assertThatThrownBy(() -> BatchDeployer.main(eventArgs))
+ .hasMessage("model deployment failed on parameters Host 43443");
}
@Test
@@ -88,13 +75,7 @@ public class BatchDeployerTest {
// We are testing towards a dummy client, make it return a failed initiation
dummyDeploymentClient.setInitSuccessful(false);
- try {
- deployer.init();
- fail("test should throw an exception");
- } catch (ApexDeploymentException ade) {
- assertEquals("model deployment failed on parameters localhost 12345", ade.getMessage());
- }
-
+ assertThatThrownBy(deployer::init).hasMessage("model deployment failed on parameters localhost 12345");
// Wait until the connection to the server closes following the bad connection
// attempt
Awaitility.await().atLeast(Duration.ofMillis(100));
@@ -103,14 +84,8 @@ public class BatchDeployerTest {
dummyDeploymentClient.setInitSuccessful(true);
deployer.init();
- try {
- deployer.deployModel("src/test/resources/models/SmallModel.json", false, false);
- fail("test should throw an exception");
- } catch (ApexException ade) {
- assertEquals("could not deploy apex model from src/test/resources/models/SmallModel.json",
- ade.getMessage());
- }
-
+ assertThatThrownBy(() -> deployer.deployModel("src/test/resources/models/SmallModel.json", false, false))
+ .hasMessage("could not deploy apex model from src/test/resources/models/SmallModel.json");
deployer.deployModel("src/test/resources/models/SmallModel.json", false, false);
deployer.close();
@@ -126,18 +101,14 @@ public class BatchDeployerTest {
deployer.getEngineServiceFacade().setDeploymentClient(dummyDeploymentClient);
dummyDeploymentClient.setInitSuccessful(false);
- try {
- deployer.init();
- fail("test should throw an exception");
- } catch (ApexDeploymentException ade) {
- assertEquals("model deployment failed on parameters localhost 12345", ade.getMessage());
- }
-
+ assertThatThrownBy(deployer::init)
+ .hasMessage("model deployment failed on parameters localhost 12345");
// Wait until the connection to the server closes following the bad connection
// attempt
Awaitility.await().atLeast(Duration.ofMillis(100));
dummyDeploymentClient.setInitSuccessful(true);
+
deployer.init();
final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
@@ -145,12 +116,8 @@ public class BatchDeployerTest {
final AxPolicyModel apexPolicyModel = modelReader
.read(new FileInputStream(new File("src/test/resources/models/SmallModel.json")));
- try {
- deployer.deployModel(apexPolicyModel, false, false);
- fail("test should throw an exception");
- } catch (ApexException ade) {
- assertEquals("failed response Operation failed received from serverlocalhost:12345", ade.getMessage());
- }
+ assertThatThrownBy(() -> deployer.deployModel(apexPolicyModel, false, false))
+ .hasMessage("failed response Operation failed received from serverlocalhost:12345");
deployer.deployModel(apexPolicyModel, false, false);
@@ -164,19 +131,12 @@ public class BatchDeployerTest {
BatchDeployer deployer = new BatchDeployer("localhost", 12345, new PrintStream(baosOut, true));
deployer.getEngineServiceFacade().setDeploymentClient(new DummyDeploymentClient("aHost", 54553));
- try {
- deployer.deployModel("src/test/resources/models/SamplePolicyModelJAVASCRIPT.json", false, false);
- fail("test should throw an exception");
- } catch (ApexException ade) {
- assertEquals("could not deploy apex model, deployer is not initialized", ade.getMessage());
- }
-
- try {
- deployer.deployModel("src/test/resources/models/SamplePolicyModelJAVASCRIPT.json", false, false);
- fail("test should throw an exception");
- } catch (ApexException ade) {
- assertEquals("could not deploy apex model, deployer is not initialized", ade.getMessage());
- }
+ assertThatThrownBy(() -> deployer.deployModel("src/test/resources/models/SamplePolicyModelJAVASCRIPT.json",
+ false, false))
+ .hasMessage("could not deploy apex model, deployer is not initialized");
+ assertThatThrownBy(() -> deployer.deployModel("src/test/resources/models/SamplePolicyModelJAVASCRIPT.json",
+ false, false))
+ .hasMessage("could not deploy apex model, deployer is not initialized");
deployer.close();
}
@@ -193,13 +153,8 @@ public class BatchDeployerTest {
final AxPolicyModel apexPolicyModel = modelReader
.read(new FileInputStream(new File("src/test/resources/models/SmallModel.json")));
- try {
- deployer.deployModel(apexPolicyModel, false, false);
- fail("test should throw an exception");
- } catch (ApexException ade) {
- assertEquals("failed response Operation failed received from serverlocalhost:12345", ade.getMessage());
- }
-
+ assertThatThrownBy(() -> deployer.deployModel(apexPolicyModel, false, false))
+ .hasMessage("failed response Operation failed received from serverlocalhost:12345");
deployer.close();
}
}
diff --git a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DeploymentClientTest.java b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DeploymentClientTest.java
index ddbcf2176..96b553a30 100644
--- a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DeploymentClientTest.java
+++ b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DeploymentClientTest.java
@@ -6,26 +6,26 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.core.deployment;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyObject;
import java.lang.reflect.Field;
@@ -76,9 +76,9 @@ public class DeploymentClientTest {
Mockito.doNothing().when(mockService).addMessageListener(messageListener.capture());
Mockito.doNothing().when(mockService).startConnection();
-
+
Mockito.doNothing().when(mockService).send((MessageHolder<Message>) anyObject());
-
+
Thread clientThread = new Thread(deploymentClient);
clientThread.start();
@@ -86,7 +86,7 @@ public class DeploymentClientTest {
assertTrue(deploymentClient.isStarted());
assertTrue(clientThread.isAlive());
-
+
AxArtifactKey engineKey = new AxArtifactKey("MyEngine", "0.0.1");
GetEngineStatus getEngineStatus = new GetEngineStatus(engineKey);
deploymentClient.sendMessage(new GetEngineStatus(engineKey));
@@ -94,20 +94,16 @@ public class DeploymentClientTest {
Response response = new Response(engineKey, true, getEngineStatus);
List<Message> messageList = new ArrayList<>();
messageList.add(response);
-
+
MessageBlock<Message> responseBlock = new MessageBlock<>(messageList, null);
messageListener.getValue().onMessage(responseBlock);
-
- try {
- messageListener.getValue().onMessage("StringMessage");
- fail("test should throw an exception here");
- } catch (UnsupportedOperationException use) {
- assertEquals("String mesages are not supported on the EngDep protocol", use.getMessage());
- }
+
+ assertThatThrownBy(() -> messageListener.getValue().onMessage("StringMessage"))
+ .hasMessage("String mesages are not supported on the EngDep protocol");
await().atMost(300, TimeUnit.MILLISECONDS).until(() -> deploymentClient.getMessagesReceived() == 2);
assertEquals(2, deploymentClient.getMessagesReceived());
-
+
deploymentClient.stopClient();
}
diff --git a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/EngineServiceFacadeTest.java b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/EngineServiceFacadeTest.java
index fb2ef4459..6e0826c3f 100644
--- a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/EngineServiceFacadeTest.java
+++ b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/EngineServiceFacadeTest.java
@@ -21,9 +21,9 @@
package org.onap.policy.apex.core.deployment;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
@@ -43,23 +43,15 @@ public class EngineServiceFacadeTest {
// First init should fail due to our dummy client
dummyDeploymentClient.setInitSuccessful(false);
- try {
- facade.init();
- fail("could not handshake with server localhost:51273");
- } catch (final Exception ade) {
- assertEquals("could not handshake with server localhost:51273", ade.getMessage());
- }
-
+ assertThatThrownBy(facade::init)
+ .hasMessage("could not handshake with server localhost:51273");
assertNull(facade.getKey());
assertNull(facade.getApexModelKey());
assertNull(facade.getEngineKeyArray());
- try {
- facade.deployModel("src/test/resources/models/SamplePolicyModelJAVASCRIPT.json", false, false);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("could not deploy apex model, deployer is not initialized", ade.getMessage());
- }
+ assertThatThrownBy(() -> facade.deployModel("src/test/resources/models/SamplePolicyModelJAVASCRIPT.json",
+ false, false))
+ .hasMessage("could not deploy apex model, deployer is not initialized");
// Second init should work
dummyDeploymentClient.setInitSuccessful(true);
@@ -69,126 +61,78 @@ public class EngineServiceFacadeTest {
assertEquals("Model:0.0.1", facade.getApexModelKey().getId());
assertEquals("Engine:0.0.1", facade.getEngineKeyArray()[0].getId());
- try {
- facade.deployModel("src/test/resources/models/NonExistantModel.json", false, false);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("could not create apex model, could not read from file "
- + "src/test/resources/models/NonExistantModel.json", ade.getMessage());
- }
-
- try {
- facade.deployModel("src/test/resources/models/JunkModel.json", false, false);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("could not deploy apex model from src/test/resources/models/JunkModel.json", ade.getMessage());
- }
+ assertThatThrownBy(() -> facade.deployModel("src/test/resources/models/NonExistantModel.json",
+ false, false))
+ .hasMessage("could not create apex model, could not read from file "
+ + "src/test/resources/models/NonExistantModel.json");
+ assertThatThrownBy(() -> facade.deployModel("src/test/resources/models/JunkModel.json",
+ false, false))
+ .hasMessage("could not deploy apex model from src/test/resources/models/JunkModel.json");
InputStream badStream = new ByteArrayInputStream("".getBytes());
- try {
- facade.deployModel("MyModel", badStream, false, false);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("format of input for Apex concept is neither JSON nor XML", ade.getMessage());
- }
-
+ assertThatThrownBy(() -> facade.deployModel("MyModel", badStream, false, false))
+ .hasMessage("format of input for Apex concept is neither JSON nor XML");
InputStream closedStream = new ByteArrayInputStream("".getBytes());
closedStream.close();
- try {
- facade.deployModel("MyModel", closedStream, false, false);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("format of input for Apex concept is neither JSON nor XML", ade.getMessage());
- }
-
- try {
- facade.deployModel("src/test/resources/models/SmallModel.json", false, false);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("could not deploy apex model from src/test/resources/models/SmallModel.json",
- ade.getMessage());
- }
+ assertThatThrownBy(() -> facade.deployModel("MyModel", closedStream, false, false))
+ .hasMessage("format of input for Apex concept is neither JSON nor XML");
+ assertThatThrownBy(() -> facade.deployModel("src/test/resources/models/SmallModel.json", false, false))
+ .hasMessage("could not deploy apex model from src/test/resources/models/SmallModel.json");
facade.deployModel("src/test/resources/models/SmallModel.json", false, false);
- try {
- facade.startEngine(facade.getEngineKeyArray()[0]);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
- }
-
+ assertThatThrownBy(() -> facade.startEngine(facade.getEngineKeyArray()[0]))
+ .hasMessage("failed response Operation failed received from serverlocalhost:51273");
facade.startEngine(facade.getEngineKeyArray()[0]);
- try {
- facade.stopEngine(facade.getEngineKeyArray()[0]);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
- }
-
+ assertThatThrownBy(() -> facade.stopEngine(facade.getEngineKeyArray()[0]))
+ .hasMessage("failed response Operation failed received from serverlocalhost:51273");
facade.stopEngine(facade.getEngineKeyArray()[0]);
- try {
- facade.startPerioidicEvents(facade.getEngineKeyArray()[0], 1000);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
- }
-
+ assertThatThrownBy(() -> facade.startPerioidicEvents(facade.getEngineKeyArray()[0], 1000))
+ .hasMessage("failed response Operation failed received from serverlocalhost:51273");
facade.startPerioidicEvents(facade.getEngineKeyArray()[0], 1000);
- try {
- facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
- }
-
+ assertThatThrownBy(() -> facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]))
+ .hasMessage("failed response Operation failed received from serverlocalhost:51273");
facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]);
- try {
- facade.getEngineStatus(facade.getEngineKeyArray()[0]);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
- }
-
+ assertThatThrownBy(() -> facade.getEngineStatus(facade.getEngineKeyArray()[0]))
+ .hasMessage("failed response Operation failed received from serverlocalhost:51273");
facade.getEngineStatus(facade.getEngineKeyArray()[0]);
- try {
- facade.getEngineInfo(facade.getEngineKeyArray()[0]);
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
- }
-
+ assertThatThrownBy(() -> facade.getEngineInfo(facade.getEngineKeyArray()[0]))
+ .hasMessage("failed response Operation failed received from serverlocalhost:51273");
facade.getEngineInfo(facade.getEngineKeyArray()[0]);
- try {
- facade.getEngineStatus(new AxArtifactKey("ReturnBadMessage", "0.0.1"));
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("response received from server is of incorrect type "
+ assertThatThrownBy(() -> facade.getEngineStatus(new AxArtifactKey("ReturnBadMessage", "0.0.1")))
+ .hasMessage("response received from server is of incorrect type "
+ "org.onap.policy.apex.core.protocols.engdep.messages.GetEngineStatus, should be of type "
- + "org.onap.policy.apex.core.protocols.engdep.messages.Response", ade.getMessage());
- }
-
- try {
- facade.getEngineStatus(new AxArtifactKey("ReturnBadResponse", "0.0.1"));
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("response received is not correct response to sent message GET_ENGINE_STATUS",
- ade.getMessage());
- }
-
- try {
- facade.getEngineStatus(new AxArtifactKey("DoNotRespond", "0.0.1"));
- fail("test should throw an exception here");
- } catch (final Exception ade) {
- assertEquals("no response received to sent message GET_ENGINE_STATUS", ade.getMessage());
- }
+ + "org.onap.policy.apex.core.protocols.engdep.messages.Response");
+ assertThatThrownBy(() -> facade.getEngineStatus(new AxArtifactKey("ReturnBadResponse", "0.0.1")))
+ .hasMessage("response received is not correct response to sent message GET_ENGINE_STATUS");
+ assertThatThrownBy(() -> facade.getEngineStatus(new AxArtifactKey("DoNotRespond", "0.0.1")))
+ .hasMessage("no response received to sent message GET_ENGINE_STATUS");
+ assertThatThrownBy(() -> facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]))
+ .hasMessage("failed response Operation failed received from serverlocalhost:51273");
+
+ facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]);
+
+ facade.getEngineStatus(facade.getEngineKeyArray()[0]);
+
+ assertThatThrownBy(() -> facade.getEngineInfo(facade.getEngineKeyArray()[0]))
+ .hasMessage("failed response Operation failed received from serverlocalhost:51273");
+
+ facade.getEngineInfo(facade.getEngineKeyArray()[0]);
+ assertThatThrownBy(() -> facade.getEngineStatus(new AxArtifactKey("ReturnBadMessage", "0.0.1")))
+ .hasMessage("response received from server is of incorrect type "
+ + "org.onap.policy.apex.core.protocols.engdep.messages.GetEngineStatus, should be of type "
+ + "org.onap.policy.apex.core.protocols.engdep.messages.Response");
+ assertThatThrownBy(() -> facade.getEngineStatus(new AxArtifactKey("ReturnBadResponse", "0.0.1")))
+ .hasMessage("response received is not correct response to sent message GET_ENGINE_STATUS");
+ assertThatThrownBy(() -> facade.getEngineStatus(new AxArtifactKey("DoNotRespond", "0.0.1")))
+ .hasMessage("no response received to sent message GET_ENGINE_STATUS");
facade.close();
}
}
diff --git a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java
index 3444eb7fd..99c95465f 100644
--- a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java
+++ b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java
@@ -21,9 +21,8 @@
package org.onap.policy.apex.core.deployment;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -37,26 +36,18 @@ import org.junit.Test;
public class PeriodicEventManagerTest {
@Test
public void testPeroidicEventManagerBad() {
- try {
- final String[] eventArgs = { "-h" };
+ final String[] eventArgs = { "-h" };
- PeriodicEventManager.main(eventArgs);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("invalid arguments: [-h]", exc.getMessage().substring(0, 23));
- }
+ assertThatThrownBy(() -> PeriodicEventManager.main(eventArgs))
+ .hasMessageContaining("invalid arguments: [-h]");
}
@Test
public void testPeroidicEventManagerOk() {
- try {
- final String[] eventArgs = { "Host", "43443", "start", "1000" };
+ final String[] eventArgs = { "Host", "43443", "start", "1000" };
- PeriodicEventManager.main(eventArgs);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("periodic event setting failed on parameters Host 43443 true", exc.getMessage());
- }
+ assertThatThrownBy(() -> PeriodicEventManager.main(eventArgs))
+ .hasMessage("periodic event setting failed on parameters Host 43443 true");
}
@Test
@@ -107,54 +98,31 @@ public class PeriodicEventManagerTest {
}
@Test
- public void testPeroidicEventManagerStart() {
+ public void testPeroidicEventManagerStart() throws ApexDeploymentException {
final String[] eventArgs = { "localhost", "12345", "start", "1000" };
final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
PeriodicEventManager peManager = null;
final DummyDeploymentClient dummyDeploymentClient = new DummyDeploymentClient("aHost", 54553);
- try {
- peManager = new PeriodicEventManager(eventArgs, new PrintStream(baosOut, true));
- peManager.getEngineServiceFacade().setDeploymentClient(dummyDeploymentClient);
- } catch (ApexDeploymentException ade) {
- fail("test should not throw an exception");
- }
+ peManager = new PeriodicEventManager(eventArgs, new PrintStream(baosOut, true));
+ peManager.getEngineServiceFacade().setDeploymentClient(dummyDeploymentClient);
dummyDeploymentClient.setInitSuccessful(false);
- try {
- peManager.init();
- fail("test should throw an exception");
- } catch (ApexDeploymentException ade) {
- assertEquals("periodic event setting failed on parameters localhost 12345 true", ade.getMessage());
- }
-
+ assertThatThrownBy(peManager::init)
+ .hasMessage("periodic event setting failed on parameters localhost 12345 true");
dummyDeploymentClient.setInitSuccessful(true);
- try {
- peManager.init();
- } catch (ApexDeploymentException ade) {
- ade.printStackTrace();
- fail("test should not throw an exception");
- }
-
- try {
- peManager.runCommand();
- fail("test should throw an exception");
- } catch (ApexDeploymentException ade) {
- assertEquals("failed response Operation failed received from serverlocalhost:12345", ade.getMessage());
- }
+ peManager.init();
- try {
- peManager.runCommand();
- } catch (ApexDeploymentException ade) {
- fail("test should not throw an exception");
- }
+ assertThatThrownBy(peManager::runCommand)
+ .hasMessage("failed response Operation failed received from serverlocalhost:12345");
peManager.close();
}
@Test
public void testPeroidicEventManagerStop() throws ApexDeploymentException {
+
final String[] eventArgs = { "localhost", "12345", "stop", "1000" };
final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
@@ -165,23 +133,13 @@ public class PeriodicEventManagerTest {
peManager.getEngineServiceFacade().setDeploymentClient(dummyDeploymentClient);
dummyDeploymentClient.setInitSuccessful(false);
- try {
- peManager.init();
- fail("test should throw an exception");
- } catch (ApexDeploymentException ade) {
- assertEquals("periodic event setting failed on parameters localhost 12345 false", ade.getMessage());
- }
-
+ assertThatThrownBy(peManager::init)
+ .hasMessage("periodic event setting failed on parameters localhost 12345 false");
dummyDeploymentClient.setInitSuccessful(true);
peManager.init();
- try {
- peManager.runCommand();
- fail("test should throw an exception");
- } catch (ApexDeploymentException ade) {
- assertEquals("failed response Operation failed received from serverlocalhost:12345", ade.getMessage());
- }
-
+ assertThatThrownBy(peManager::runCommand)
+ .hasMessage("failed response Operation failed received from serverlocalhost:12345");
peManager.runCommand();
peManager.close();
@@ -189,6 +147,7 @@ public class PeriodicEventManagerTest {
@Test
public void testPeroidicEventManagerStartUninitialized() throws ApexDeploymentException {
+
final String[] eventArgs = { "localhost", "12345", "start", "1000" };
final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
@@ -199,26 +158,18 @@ public class PeriodicEventManagerTest {
peManager.getEngineServiceFacade().setDeploymentClient(dummyDeploymentClient);
dummyDeploymentClient.setInitSuccessful(false);
- try {
- peManager.runCommand();
- fail("test should throw an exception");
- } catch (ApexDeploymentException ade) {
- assertEquals("connection to apex is not initialized", ade.getMessage());
- }
-
+ assertThatThrownBy(peManager::runCommand)
+ .hasMessage("connection to apex is not initialized");
dummyDeploymentClient.setInitSuccessful(true);
- try {
- peManager.runCommand();
- fail("test should throw an exception");
- } catch (ApexDeploymentException ade) {
- assertEquals("connection to apex is not initialized", ade.getMessage());
- }
+ assertThatThrownBy(peManager::runCommand)
+ .hasMessage("connection to apex is not initialized");
peManager.close();
}
@Test
public void testPeroidicEventManagerStopUninitialized() throws ApexDeploymentException {
+
final String[] eventArgs = { "localhost", "12345", "stop", "1000" };
final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
@@ -227,13 +178,8 @@ public class PeriodicEventManagerTest {
peManager = new PeriodicEventManager(eventArgs, new PrintStream(baosOut, true));
peManager.getEngineServiceFacade().setDeploymentClient(new DummyDeploymentClient("aHost", 54553));
- try {
- peManager.runCommand();
- fail("test should throw an exception");
- } catch (ApexDeploymentException ade) {
- assertEquals("connection to apex is not initialized", ade.getMessage());
- }
-
+ assertThatThrownBy(peManager::runCommand)
+ .hasMessage("connection to apex is not initialized");
peManager.close();
}