• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JUnit testing for REST

 
simon tiberius
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my question is related to
http://www.coderanch.com/t/597308/Web-Services/java/REST#2724791

I'm trying to implement a RESTful java web services, and I have some question:
I'm making an online shopping web services with following spec (this is just the basics):
1. Customer : CustomerID, Name, Address, PhoneNumber
2. Order (by Customer) : OrderID, CustomerID, CreationDate, GrandTotal (from Parts)
3. Part (by Order) : OrderID, PartID, UnitCost, Quantity, LineTotal (Unit * Quantity)

Now, think specifically about these User Stories related to the Orders (not Customers, not Parts):
1. Customer lists orders to know which orders she has placed
2. Customer creates a new order to be fulfilled.
3. Customer views an existing order to get a reminder of what was ordered
4. Customer updates an order (add or delete parts, or changes quantity) when she realizes it is incorrect.
5. Customer can delete an order that is no longer needed (let’s not worry about if the order has been processed now)

I'm quite new with JUnit. I'm already familiar with @Before, @BeforeClass, @Test and have been using JUnit for some time now. Right now I want to test specifically the "placing an order" part. what should I focus my testing on for this part? security? if so, what's the best practice for that? are mock object and stub used here?thanks
 
simon tiberius
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
right now I just want to test the correctness of a customer updates his order. how do I do this? mock objects or stubs? so, something like this:
I'm using JSON format because it's easier to desribe the object although the object that will be tested is java object (Order class and Part class). This JSON format represents the state of the Java objects and the changes during order update:

order = {orderid:1, customerid:7, creationdate:'2012/10/10', calculatedamount:125.00
, part:[{orderid:1, partid:5, unitcost:10, quantity:5}, {orderid:1, partid:6, unitcost:25, quantity:3}]
};

let's say I update the quantity for partid 5 to 7 and quantity for partid 6 to 5

order = {orderid:1, customerid:7, creationdate:'2012/10/10', calculatedamount:195.00
, part:[{orderid:1, partid:5, unitcost:10, quantity:7}, {orderid:1, partid:6, unitcost:25, quantity:5}]
};

all updated property are bold. what is the technique in JUnit for this? the object is Java object, not JSON, because what's being tested is the method in the service for updating order. so this is not javascript test, but a java method test. thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34668
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't a right/wrong answer between mocks and stubs. I generally use mocks first because I want more control.

As for the JSON, you can either assert against the String or the Java object itself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic