Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional tests to OrderServiceTests suite #90

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions src/test/java/csse/OrderServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import csse.orders.OrderService;
import csse.orders.PurchaseOrder;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -32,24 +29,27 @@ public class OrderServiceTests {
@Autowired
private OrderService orderService;

private Logger logger = LoggerFactory.getLogger(OrderServiceTests.class);
private List<PurchaseOrder> testOrdersList = new ArrayList<>();
private PurchaseOrder testOrder;
private static Logger logger = LoggerFactory.getLogger(OrderServiceTests.class);
private static PurchaseOrder testOrder, allItemsReceivedOrder;

@Before
public void setUp() throws IOException {
@BeforeClass
public static void setUp() throws IOException {

// Load dummy order data from json file
ObjectMapper mapper = new ObjectMapper();
TypeReference<PurchaseOrder> typeReference = new TypeReference<PurchaseOrder>(){};
InputStream inputStream = TypeReference.class.getResourceAsStream("/json/order.json");
testOrder = mapper.readValue(inputStream, typeReference);
InputStream inputStream1 = TypeReference.class.getResourceAsStream("/json/order.json");
InputStream inputStream2 = TypeReference.class.getResourceAsStream("/json/allItemsReceivedOrder.json");
testOrder = mapper.readValue(inputStream1, typeReference);
allItemsReceivedOrder = mapper.readValue(inputStream2, typeReference);
logger.info("Loaded dummy order data");
inputStream1.close();
inputStream2.close();

}

@After
public void tearDown() {
public void tearDowns() {
// Clean orders database
orderService.cleanDatabase();
}
Expand All @@ -61,4 +61,21 @@ public void setsOrderIdOnSave() throws Exception {
Assert.assertNotNull("After creation OrderID should not be null", savedOrder.get_id());
}

@Test
public void negativeAllOrdersItemsAreDelivered() throws Exception {
logger.info("Running negativeAllOrdersItemsAreDelivered()");
boolean itemsReceived = orderService.allItemsReceived(testOrder);
Assert.assertFalse("allItemsReceived should return false if " +
"some items are not delivered", itemsReceived);
}

@Test
public void positiveAllOrdersItemsAreDelivered() throws Exception {
logger.info("Running positiveAllOrdersItemsAreDelivered()");
boolean itemsReceived = orderService.allItemsReceived(allItemsReceivedOrder);
Assert.assertTrue("allItemsReceived should return true if " +
"all items are delivered", itemsReceived);

}

}
85 changes: 85 additions & 0 deletions src/test/resources/json/allItemsReceivedOrder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"purchaseRequest": {
"requestLineItems": [
{
"item": {
"itemName": "Steel Bars123",
"supplier": {
"supplierName": "Macsons and Sons",
"email": "[email protected]",
"address": "malabe",
"contactNumber": "0112987465",
"items": null,
"_id": "5bab942a4417c949fc4aa5ea"
},
"category": "BEAMS",
"price": 1234,
"description": null,
"_id": "5bab9bc9eedb450004eaad20"
},
"quantity": 5,
"pocreated": true
},
{
"item": {
"itemName": "Tin tacks",
"supplier": {
"supplierName": "Siripalas",
"email": "[email protected]",
"address": "malabe",
"contactNumber": "0112547465",
"items": null,
"_id": "5bab94434417c949fc4aa5eb"
},
"category": "NAILS",
"price": 3,
"description": null,
"_id": "5bab9bd5eedb450004eaad21"
},
"quantity": 5,
"pocreated": true
}
],
"purchaseOrders": null,
"requestStatus": "ORDERED",
"requestedBy": "Saman",
"deliveryAddress": "Kaduwela",
"createdOn": 1537963037627,
"neededOn": 1537833600000,
"id": "5bab741d4417c929f07ab4c6",
"draftRequest": false
},
"supplier": {
"supplierName": "Macsons and Sons",
"email": "[email protected]",
"address": "malabe",
"contactNumber": "0112987465",
"items": null,
"_id": "5bab942a4417c949fc4aa5ea"
},
"createdOn": 1538065290904,
"status": "PENDING_DELIVERY",
"orderItems": [
{
"item": {
"itemName": "Steel Bars123",
"supplier": {
"supplierName": "Macsons and Sons",
"email": "[email protected]",
"address": "malabe",
"contactNumber": "0112987465",
"items": null,
"_id": "5bab942a4417c949fc4aa5ea"
},
"category": "BEAMS",
"price": 1234,
"description": null,
"_id": "5bab9bc9eedb450004eaad20"
},
"quantity": 5,
"orderLinePrice": 6170,
"received": true
}
],
"totalPrice": 6170
}