From ed90c41083a7e1bc5786855fe05902b2eba5136f Mon Sep 17 00:00:00 2001 From: Mayank Choudhary Date: Tue, 4 Jun 2024 09:12:26 +0530 Subject: [PATCH] refactor: Refactor commander (#2983) * Resolved issue #2978 Refactor Commander * Fixed checkstyle issues --------- Co-authored-by: Mayankchoudhary294 --- commander/pom.xml | 93 ++-- .../com/iluwatar/commander/AppAllCases.java | 403 ++++++++++++++++++ .../commander/AppEmployeeDbFailCases.java | 92 ---- .../commander/AppMessagingFailCases.java | 138 ------ .../commander/AppPaymentFailCases.java | 102 ----- .../iluwatar/commander/AppQueueFailCases.java | 137 ------ .../commander/AppShippingFailCases.java | 114 ----- .../com/iluwatar/commander/Commander.java | 7 +- .../com/iluwatar/commander/CommanderTest.java | 30 ++ 9 files changed, 464 insertions(+), 652 deletions(-) create mode 100644 commander/src/main/java/com/iluwatar/commander/AppAllCases.java delete mode 100644 commander/src/main/java/com/iluwatar/commander/AppEmployeeDbFailCases.java delete mode 100644 commander/src/main/java/com/iluwatar/commander/AppMessagingFailCases.java delete mode 100644 commander/src/main/java/com/iluwatar/commander/AppPaymentFailCases.java delete mode 100644 commander/src/main/java/com/iluwatar/commander/AppQueueFailCases.java delete mode 100644 commander/src/main/java/com/iluwatar/commander/AppShippingFailCases.java diff --git a/commander/pom.xml b/commander/pom.xml index 5de5e562a..dde95c225 100644 --- a/commander/pom.xml +++ b/commander/pom.xml @@ -39,70 +39,33 @@ junit-jupiter-engine test + + org.slf4j + slf4j-api + ${slf4j.version} + - - - - org.apache.maven.plugins - maven-assembly-plugin - - - Employee - - - - com.iluwatar.commander.AppEmployeeDbFailCases - - - ${project.artifactId}-EmployeeDBFailCase - - - - Message - - - - com.iluwatar.commander.AppMessagingFailCases - - - ${project.artifactId}-MessagingFailCase - - - - Payment - - - - com.iluwatar.commander.AppPaymentFailCases - - - ${project.artifactId}-PaymentFailCase - - - - Queue - - - - com.iluwatar.commander.AppQueueFailCases - - - ${project.artifactId}-QueueFailCase - - - - Shipping - - - - com.iluwatar.commander.AppShippingFailCases - - - ${project.artifactId}-ShippingFailCase - - - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + allCases + + + + com.iluwatar.commander.AppAllCases + + + ${project.artifactId}-AllCases + + + + + + + diff --git a/commander/src/main/java/com/iluwatar/commander/AppAllCases.java b/commander/src/main/java/com/iluwatar/commander/AppAllCases.java new file mode 100644 index 000000000..e9a9bffc7 --- /dev/null +++ b/commander/src/main/java/com/iluwatar/commander/AppAllCases.java @@ -0,0 +1,403 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 Ilkka Seppälä + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.iluwatar.commander; + +import com.iluwatar.commander.employeehandle.EmployeeDatabase; +import com.iluwatar.commander.employeehandle.EmployeeHandle; +import com.iluwatar.commander.exceptions.DatabaseUnavailableException; +import com.iluwatar.commander.exceptions.ItemUnavailableException; +import com.iluwatar.commander.exceptions.PaymentDetailsErrorException; +import com.iluwatar.commander.messagingservice.MessagingDatabase; +import com.iluwatar.commander.messagingservice.MessagingService; +import com.iluwatar.commander.paymentservice.PaymentDatabase; +import com.iluwatar.commander.paymentservice.PaymentService; +import com.iluwatar.commander.queue.QueueDatabase; +import com.iluwatar.commander.shippingservice.ShippingDatabase; +import com.iluwatar.commander.shippingservice.ShippingService; + +/** + * The {@code AppAllCases} class tests various scenarios for the microservices involved + * in the order placement process. This class consolidates previously separated cases + * into a single class to manage different success and failure scenarios for each service. + * + *

The application consists of abstract classes {@link Database} and {@link Service} + * which are extended by all the databases and services. Each service has a corresponding + * database to be updated and receives requests from an external user through the + * {@link Commander} class. There are 5 microservices: + *

+ * + *

Retries are managed using the {@link Retry} class, ensuring idempotence by performing + * checks before making requests to services and updating the {@link Order} class fields + * upon request success or definitive failure. + * + *

This class tests the following scenarios: + *

+ * + *

Each scenario is encapsulated in a corresponding method that sets up the service + * conditions and tests the order placement process. + * + *

The main method executes all success and failure cases to verify the application's + * behavior under different conditions. + * + *

Usage: + *

+ * {@code
+ * public static void main(String[] args) {
+ *     AppAllCases app = new AppAllCases();
+ *     app.testAllScenarios();
+ * }
+ * }
+ * 
+ */ + +public class AppAllCases { + private static final RetryParams retryParams = RetryParams.DEFAULT; + private static final TimeLimits timeLimits = TimeLimits.DEFAULT; + + // Employee Database Fail Case + void employeeDatabaseUnavailableCase() { + var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var ss = new ShippingService(new ShippingDatabase()); + var ms = new MessagingService(new MessagingDatabase()); + var eh = new EmployeeHandle(new EmployeeDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var qdb = new QueueDatabase(new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException()); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + // Employee Database Success Case + void employeeDbSuccessCase() { + var ps = new PaymentService(new PaymentDatabase()); + var ss = new ShippingService(new ShippingDatabase(), new ItemUnavailableException()); + var ms = new MessagingService(new MessagingDatabase()); + var eh = new EmployeeHandle(new EmployeeDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var qdb = new QueueDatabase(); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + // Messaging Database Fail Cases + void messagingDatabaseUnavailableCasePaymentSuccess() { + var ps = new PaymentService(new PaymentDatabase()); + var ss = new ShippingService(new ShippingDatabase()); + var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + void messagingDatabaseUnavailableCasePaymentError() { + var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var ss = new ShippingService(new ShippingDatabase()); + var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + + void messagingDatabaseUnavailableCasePaymentFailure() { + var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var ss = new ShippingService(new ShippingDatabase()); + var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException()); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + // Messaging Database Success Case + void messagingSuccessCase() { + var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var ss = new ShippingService(new ShippingDatabase()); + var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + // Payment Database Fail Cases + void paymentNotPossibleCase() { + var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), + new PaymentDetailsErrorException()); + var ss = new ShippingService(new ShippingDatabase()); + var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(new DatabaseUnavailableException()); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + void paymentDatabaseUnavailableCase() { + var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var ss = new ShippingService(new ShippingDatabase()); + var ms = new MessagingService(new MessagingDatabase()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + // Payment Database Success Case + void paymentSuccessCase() { + var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var ss = new ShippingService(new ShippingDatabase()); + var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(new DatabaseUnavailableException()); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + // Queue Database Fail Cases + void queuePaymentTaskDatabaseUnavailableCase() { + var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var ss = new ShippingService(new ShippingDatabase()); + var ms = new MessagingService(new MessagingDatabase()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException()); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + void queueMessageTaskDatabaseUnavailableCase() { + var ps = new PaymentService(new PaymentDatabase()); + var ss = new ShippingService(new ShippingDatabase()); + var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException()); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + void queueEmployeeDbTaskDatabaseUnavailableCase() { + var ps = new PaymentService(new PaymentDatabase()); + var ss = new ShippingService(new ShippingDatabase(), new ItemUnavailableException()); + var ms = new MessagingService(new MessagingDatabase()); + var eh = new EmployeeHandle(new EmployeeDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var qdb = + new QueueDatabase(new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException()); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + // Queue Database Success Cases + void queueSuccessCase() { + var ps = new PaymentService(new PaymentDatabase()); + var ss = new ShippingService(new ShippingDatabase(), new ItemUnavailableException()); + var ms = new MessagingService(new MessagingDatabase()); + var eh = new EmployeeHandle(new EmployeeDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var qdb = new QueueDatabase(); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + // Shipping Database Fail Cases + void itemUnavailableCase() { + var ps = new PaymentService(new PaymentDatabase()); + var ss = new ShippingService(new ShippingDatabase(), new ItemUnavailableException()); + var ms = new MessagingService(new MessagingDatabase()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + void shippingDatabaseUnavailableCase() { + var ps = new PaymentService(new PaymentDatabase()); + var ss = new ShippingService(new ShippingDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException(), + new DatabaseUnavailableException(), new DatabaseUnavailableException()); + var ms = new MessagingService(new MessagingDatabase()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + void shippingItemNotPossibleCase() { + var ps = new PaymentService(new PaymentDatabase()); + var ss = new ShippingService(new ShippingDatabase(), new ItemUnavailableException()); + var ms = new MessagingService(new MessagingDatabase()); + var eh = new EmployeeHandle(new EmployeeDatabase()); + var qdb = new QueueDatabase(); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + // Shipping Database Success Cases + void shippingSuccessCase() { + var ps = new PaymentService(new PaymentDatabase()); + var ss = new ShippingService(new ShippingDatabase(), new ItemUnavailableException()); + var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException()); + var eh = new EmployeeHandle(new EmployeeDatabase(), new DatabaseUnavailableException(), + new DatabaseUnavailableException()); + var qdb = new QueueDatabase(); + var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); + var user = new User("Jim", "ABCD"); + var order = new Order(user, "book", 10f); + c.placeOrder(order); + } + + /** + * Program entry point. + * @param args command line arguments + */ + public static void main(String[] args) { + AppAllCases app = new AppAllCases(); + + // Employee Database cases + app.employeeDatabaseUnavailableCase(); + app.employeeDbSuccessCase(); + + // Messaging Database cases + app.messagingDatabaseUnavailableCasePaymentSuccess(); + app.messagingDatabaseUnavailableCasePaymentError(); + app.messagingDatabaseUnavailableCasePaymentFailure(); + app.messagingSuccessCase(); + + //Payment Database cases + app.paymentNotPossibleCase(); + app.paymentDatabaseUnavailableCase(); + app.paymentSuccessCase(); + + // Queue Database cases + app.queuePaymentTaskDatabaseUnavailableCase(); + app.queueMessageTaskDatabaseUnavailableCase(); + app.queueEmployeeDbTaskDatabaseUnavailableCase(); + app.queueSuccessCase(); + + // Shipping Database cases + app.itemUnavailableCase(); + app.shippingDatabaseUnavailableCase(); + app.shippingItemNotPossibleCase(); + app.shippingSuccessCase(); + } +} \ No newline at end of file diff --git a/commander/src/main/java/com/iluwatar/commander/AppEmployeeDbFailCases.java b/commander/src/main/java/com/iluwatar/commander/AppEmployeeDbFailCases.java deleted file mode 100644 index a4b9d4ab6..000000000 --- a/commander/src/main/java/com/iluwatar/commander/AppEmployeeDbFailCases.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). - * - * The MIT License - * Copyright © 2014-2022 Ilkka Seppälä - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package com.iluwatar.commander; - -import com.iluwatar.commander.employeehandle.EmployeeDatabase; -import com.iluwatar.commander.employeehandle.EmployeeHandle; -import com.iluwatar.commander.exceptions.DatabaseUnavailableException; -import com.iluwatar.commander.exceptions.ItemUnavailableException; -import com.iluwatar.commander.messagingservice.MessagingDatabase; -import com.iluwatar.commander.messagingservice.MessagingService; -import com.iluwatar.commander.paymentservice.PaymentDatabase; -import com.iluwatar.commander.paymentservice.PaymentService; -import com.iluwatar.commander.queue.QueueDatabase; -import com.iluwatar.commander.shippingservice.ShippingDatabase; -import com.iluwatar.commander.shippingservice.ShippingService; - -/** - * AppEmployeeDbFailCases class looks at possible cases when Employee handle service is - * available/unavailable. - */ -public class AppEmployeeDbFailCases { - private static final RetryParams retryParams = RetryParams.DEFAULT; - - private static final TimeLimits timeLimits = TimeLimits.DEFAULT; - - void employeeDatabaseUnavailableCase() { - var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var ss = new ShippingService(new ShippingDatabase()); - var ms = new MessagingService(new MessagingDatabase()); - var eh = new EmployeeHandle(new EmployeeDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var qdb = - new QueueDatabase(new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException()); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void employeeDbSuccessCase() { - var ps = new PaymentService(new PaymentDatabase()); - var ss = new ShippingService(new ShippingDatabase(), new ItemUnavailableException()); - var ms = new MessagingService(new MessagingDatabase()); - var eh = new EmployeeHandle(new EmployeeDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var qdb = new QueueDatabase(); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - /** - * Program entry point. - * - * @param args command line args - */ - - public static void main(String[] args) { - var aefc = new AppEmployeeDbFailCases(); - aefc.employeeDbSuccessCase(); - } -} \ No newline at end of file diff --git a/commander/src/main/java/com/iluwatar/commander/AppMessagingFailCases.java b/commander/src/main/java/com/iluwatar/commander/AppMessagingFailCases.java deleted file mode 100644 index f7c58e0ae..000000000 --- a/commander/src/main/java/com/iluwatar/commander/AppMessagingFailCases.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). - * - * The MIT License - * Copyright © 2014-2022 Ilkka Seppälä - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package com.iluwatar.commander; - -import com.iluwatar.commander.employeehandle.EmployeeDatabase; -import com.iluwatar.commander.employeehandle.EmployeeHandle; -import com.iluwatar.commander.exceptions.DatabaseUnavailableException; -import com.iluwatar.commander.messagingservice.MessagingDatabase; -import com.iluwatar.commander.messagingservice.MessagingService; -import com.iluwatar.commander.paymentservice.PaymentDatabase; -import com.iluwatar.commander.paymentservice.PaymentService; -import com.iluwatar.commander.queue.QueueDatabase; -import com.iluwatar.commander.shippingservice.ShippingDatabase; -import com.iluwatar.commander.shippingservice.ShippingService; - -/** - * AppMessagingFailCases class looks at possible cases when Messaging service is - * available/unavailable. - */ - -public class AppMessagingFailCases { - private static final RetryParams retryParams = RetryParams.DEFAULT; - - private static final TimeLimits timeLimits = TimeLimits.DEFAULT; - - - void messagingDatabaseUnavailableCasePaymentSuccess() { - //rest is successful - var ps = new PaymentService(new PaymentDatabase()); - var ss = new ShippingService(new ShippingDatabase()); - var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = new QueueDatabase(); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void messagingDatabaseUnavailableCasePaymentError() { - //rest is successful - var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var ss = new ShippingService(new ShippingDatabase()); - var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = new QueueDatabase(); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void messagingDatabaseUnavailableCasePaymentFailure() { - //rest is successful - var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var ss = new ShippingService(new ShippingDatabase()); - var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = - new QueueDatabase(new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException()); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void messagingSuccessCase() { - //done here - var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var ss = new ShippingService(new ShippingDatabase()); - var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = new QueueDatabase(); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - /** - * Program entry point. - * - * @param args command line args - */ - - public static void main(String[] args) { - var amfc = new AppMessagingFailCases(); - amfc.messagingSuccessCase(); - } -} \ No newline at end of file diff --git a/commander/src/main/java/com/iluwatar/commander/AppPaymentFailCases.java b/commander/src/main/java/com/iluwatar/commander/AppPaymentFailCases.java deleted file mode 100644 index 02c7db04b..000000000 --- a/commander/src/main/java/com/iluwatar/commander/AppPaymentFailCases.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). - * - * The MIT License - * Copyright © 2014-2022 Ilkka Seppälä - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package com.iluwatar.commander; - -import com.iluwatar.commander.employeehandle.EmployeeDatabase; -import com.iluwatar.commander.employeehandle.EmployeeHandle; -import com.iluwatar.commander.exceptions.DatabaseUnavailableException; -import com.iluwatar.commander.exceptions.PaymentDetailsErrorException; -import com.iluwatar.commander.messagingservice.MessagingDatabase; -import com.iluwatar.commander.messagingservice.MessagingService; -import com.iluwatar.commander.paymentservice.PaymentDatabase; -import com.iluwatar.commander.paymentservice.PaymentService; -import com.iluwatar.commander.queue.QueueDatabase; -import com.iluwatar.commander.shippingservice.ShippingDatabase; -import com.iluwatar.commander.shippingservice.ShippingService; - -/** - * AppPaymentFailCases class looks at possible cases when Payment service is available/unavailable. - */ - -public class AppPaymentFailCases { - private static final RetryParams retryParams = RetryParams.DEFAULT; - - private static final TimeLimits timeLimits = TimeLimits.DEFAULT; - - void paymentNotPossibleCase() { - var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), - new PaymentDetailsErrorException()); - var ss = new ShippingService(new ShippingDatabase()); - var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = new QueueDatabase(new DatabaseUnavailableException()); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void paymentDatabaseUnavailableCase() { - //rest is successful - var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var ss = new ShippingService(new ShippingDatabase()); - var ms = new MessagingService(new MessagingDatabase()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = new QueueDatabase(); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void paymentSuccessCase() { - //goes to message after 2 retries maybe - rest is successful for now - var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var ss = new ShippingService(new ShippingDatabase()); - var ms = - new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = new QueueDatabase(new DatabaseUnavailableException()); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - /** - * Program entry point. - * - * @param args command line args - */ - - public static void main(String[] args) { - var apfc = new AppPaymentFailCases(); - apfc.paymentSuccessCase(); - } -} \ No newline at end of file diff --git a/commander/src/main/java/com/iluwatar/commander/AppQueueFailCases.java b/commander/src/main/java/com/iluwatar/commander/AppQueueFailCases.java deleted file mode 100644 index 5c5050272..000000000 --- a/commander/src/main/java/com/iluwatar/commander/AppQueueFailCases.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). - * - * The MIT License - * Copyright © 2014-2022 Ilkka Seppälä - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package com.iluwatar.commander; - -import com.iluwatar.commander.employeehandle.EmployeeDatabase; -import com.iluwatar.commander.employeehandle.EmployeeHandle; -import com.iluwatar.commander.exceptions.DatabaseUnavailableException; -import com.iluwatar.commander.exceptions.ItemUnavailableException; -import com.iluwatar.commander.messagingservice.MessagingDatabase; -import com.iluwatar.commander.messagingservice.MessagingService; -import com.iluwatar.commander.paymentservice.PaymentDatabase; -import com.iluwatar.commander.paymentservice.PaymentService; -import com.iluwatar.commander.queue.QueueDatabase; -import com.iluwatar.commander.shippingservice.ShippingDatabase; -import com.iluwatar.commander.shippingservice.ShippingService; - -/** - * AppQueueFailCases class looks at possible cases when Queue Database is available/unavailable. - */ - -public class AppQueueFailCases { - private static final RetryParams retryParams = RetryParams.DEFAULT; - - private static final TimeLimits timeLimits = TimeLimits.DEFAULT; - - - void queuePaymentTaskDatabaseUnavailableCase() { - var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var ss = new ShippingService(new ShippingDatabase()); - var ms = new MessagingService(new MessagingDatabase()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = - new QueueDatabase(new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException()); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void queueMessageTaskDatabaseUnavailableCase() { - var ps = new PaymentService(new PaymentDatabase()); - var ss = new ShippingService(new ShippingDatabase()); - var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = - new QueueDatabase(new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException()); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void queueEmployeeDbTaskDatabaseUnavailableCase() { - var ps = new PaymentService(new PaymentDatabase()); - var ss = new ShippingService(new ShippingDatabase(), new ItemUnavailableException()); - var ms = new MessagingService(new MessagingDatabase()); - var eh = new EmployeeHandle(new EmployeeDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var qdb = - new QueueDatabase(new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException()); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void queueSuccessCase() { - var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var ss = new ShippingService(new ShippingDatabase()); - var ms = - new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = - new QueueDatabase(new DatabaseUnavailableException(), new DatabaseUnavailableException()); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - /** - * Program entry point. - * - * @param args command line args - */ - - public static void main(String[] args) { - var aqfc = new AppQueueFailCases(); - aqfc.queueSuccessCase(); - } -} diff --git a/commander/src/main/java/com/iluwatar/commander/AppShippingFailCases.java b/commander/src/main/java/com/iluwatar/commander/AppShippingFailCases.java deleted file mode 100644 index e15b1a911..000000000 --- a/commander/src/main/java/com/iluwatar/commander/AppShippingFailCases.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). - * - * The MIT License - * Copyright © 2014-2022 Ilkka Seppälä - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package com.iluwatar.commander; - -import com.iluwatar.commander.employeehandle.EmployeeDatabase; -import com.iluwatar.commander.employeehandle.EmployeeHandle; -import com.iluwatar.commander.exceptions.DatabaseUnavailableException; -import com.iluwatar.commander.exceptions.ItemUnavailableException; -import com.iluwatar.commander.exceptions.ShippingNotPossibleException; -import com.iluwatar.commander.messagingservice.MessagingDatabase; -import com.iluwatar.commander.messagingservice.MessagingService; -import com.iluwatar.commander.paymentservice.PaymentDatabase; -import com.iluwatar.commander.paymentservice.PaymentService; -import com.iluwatar.commander.queue.QueueDatabase; -import com.iluwatar.commander.shippingservice.ShippingDatabase; -import com.iluwatar.commander.shippingservice.ShippingService; - -/** - * AppShippingFailCases class looks at possible cases when Shipping service is - * available/unavailable. - */ - -public class AppShippingFailCases { - - private static final RetryParams retryParams = RetryParams.DEFAULT; - private static final TimeLimits timeLimits = TimeLimits.DEFAULT; - - void itemUnavailableCase() { - var ps = new PaymentService(new PaymentDatabase()); - var ss = new ShippingService(new ShippingDatabase(), new ItemUnavailableException()); - var ms = new MessagingService(new MessagingDatabase()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = new QueueDatabase(); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void shippingNotPossibleCase() { - var ps = new PaymentService(new PaymentDatabase()); - var ss = new ShippingService(new ShippingDatabase(), new ShippingNotPossibleException()); - var ms = new MessagingService(new MessagingDatabase()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = new QueueDatabase(); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void shippingDatabaseUnavailableCase() { - //rest is successful - var ps = new PaymentService(new PaymentDatabase()); - var ss = new ShippingService(new ShippingDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var ms = new MessagingService(new MessagingDatabase()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = new QueueDatabase(); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - void shippingSuccessCase() { - //goes to payment after 2 retries maybe - rest is successful for now - var ps = new PaymentService(new PaymentDatabase(), new DatabaseUnavailableException()); - var ss = new ShippingService(new ShippingDatabase(), new DatabaseUnavailableException(), - new DatabaseUnavailableException()); - var ms = new MessagingService(new MessagingDatabase(), new DatabaseUnavailableException()); - var eh = new EmployeeHandle(new EmployeeDatabase()); - var qdb = new QueueDatabase(); - var c = new Commander(eh, ps, ss, ms, qdb, retryParams, timeLimits); - var user = new User("Jim", "ABCD"); - var order = new Order(user, "book", 10f); - c.placeOrder(order); - } - - /** - * Program entry point. - * - * @param args command line args - */ - - public static void main(String[] args) { - var asfc = new AppShippingFailCases(); - asfc.shippingSuccessCase(); - } -} diff --git a/commander/src/main/java/com/iluwatar/commander/Commander.java b/commander/src/main/java/com/iluwatar/commander/Commander.java index 42f1cabc4..24648bce3 100644 --- a/commander/src/main/java/com/iluwatar/commander/Commander.java +++ b/commander/src/main/java/com/iluwatar/commander/Commander.java @@ -67,10 +67,9 @@ import org.slf4j.LoggerFactory; * {@link ShippingService}, {@link PaymentService}, {@link MessagingService}, {@link EmployeeHandle} * and a {@link QueueDatabase}. We use retries to execute any instruction using {@link Retry} class, * and idempotence is ensured by going through some checks before making requests to services and - * making change in {@link Order} class fields if request succeeds or definitively fails. There are - * 5 classes - {@link AppShippingFailCases}, {@link AppPaymentFailCases}, {@link - * AppMessagingFailCases}, {@link AppQueueFailCases} and {@link AppEmployeeDbFailCases}, which look - * at the different scenarios that may be encountered during the placing of an order.

+ * making change in {@link Order} class fields if request succeeds or definitively fails. There is + * a single class {@link AppAllCases} that looks at the different scenarios that may be encountered + * during the placing of an order, including both success and failure cases for each service.

*/ public class Commander { diff --git a/commander/src/test/java/com/iluwatar/commander/CommanderTest.java b/commander/src/test/java/com/iluwatar/commander/CommanderTest.java index f6c2351fe..87d065a30 100644 --- a/commander/src/test/java/com/iluwatar/commander/CommanderTest.java +++ b/commander/src/test/java/com/iluwatar/commander/CommanderTest.java @@ -52,6 +52,8 @@ class CommanderTest { private static final List exceptionList = new ArrayList<>(); + private static final AppAllCases appAllCases = new AppAllCases(); + static { exceptionList.add(new DatabaseUnavailableException()); exceptionList.add(new ShippingNotPossibleException()); @@ -592,4 +594,32 @@ class CommanderTest { } } + @Test + void testAllSuccessCases() throws Exception{ + appAllCases.employeeDbSuccessCase(); + appAllCases.messagingSuccessCase(); + appAllCases.paymentSuccessCase(); + appAllCases.queueSuccessCase(); + appAllCases.shippingSuccessCase(); + } + + @Test + void testAllUnavailableCase() throws Exception { + appAllCases.employeeDatabaseUnavailableCase(); + appAllCases.messagingDatabaseUnavailableCasePaymentSuccess(); + appAllCases.messagingDatabaseUnavailableCasePaymentError(); + appAllCases.messagingDatabaseUnavailableCasePaymentFailure(); + appAllCases.paymentDatabaseUnavailableCase(); + appAllCases.queuePaymentTaskDatabaseUnavailableCase(); + appAllCases.queueMessageTaskDatabaseUnavailableCase(); + appAllCases.queueEmployeeDbTaskDatabaseUnavailableCase(); + appAllCases.itemUnavailableCase(); + appAllCases.shippingDatabaseUnavailableCase(); + } + + @Test + void testAllNotPossibleCase() throws Exception { + appAllCases.paymentNotPossibleCase(); + appAllCases.shippingItemNotPossibleCase(); + } } \ No newline at end of file