Skip to content

Commit

Permalink
Merge pull request #36 from Qorder/issueOrderTotalPrice
Browse files Browse the repository at this point in the history
Completed issue #35
  • Loading branch information
gregoavg committed Dec 31, 2013
2 parents 0b02343 + 0353c5b commit ba910ad
Show file tree
Hide file tree
Showing 8 changed files with 407 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class OrderViewDTO {

private String dateTime;

private String totalPrice;

private List<ProductHolderDTO> orderedProducts = new ArrayList<ProductHolderDTO>();

public void setId(Long id) {
Expand Down Expand Up @@ -49,4 +51,14 @@ public void add(ProductHolderDTO productHolderDTO) {
this.orderedProducts.add(productHolderDTO);
}

public String getTotalPrice() {
return totalPrice;
}

public void setTotalPrice(String totalPrice) {
this.totalPrice = totalPrice;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public OrderViewDTO map(Order source, OrderViewDTO target) {
target.setId(source.getId());
target.setTableNumber(source.getTableNumber());
target.setDateTime(source.getDateTime());
target.setTotalPrice(source.getTotalPrice().toString());
for(ProductHolder productHolder : source.getOrderList())
{
ProductHolderDTO productHolderDTO = new ProductHolderToProductHolderDTOMapper().map(productHolder, new ProductHolderDTO());
Expand Down
18 changes: 18 additions & 0 deletions QorderWS/src/main/java/com/qorder/qorderws/model/order/Order.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.qorder.qorderws.model.order;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -44,6 +45,9 @@ public class Order {
@ManyToOne(targetEntity = Business.class)
@JoinColumn(name = "BUSINESS_ID")
private Business business;

@Column(name = "TOTAL_PRICE")
private BigDecimal totalPrice = new BigDecimal(0);

public long getId() {
return id;
Expand Down Expand Up @@ -89,4 +93,18 @@ public void add(ProductHolder productHolder) {
orderList.add(productHolder);
}

public BigDecimal getTotalPrice() {
for(ProductHolder productHolder : orderList)
{
totalPrice = totalPrice.add(productHolder.getProduct().getPrice());
}
return totalPrice;
}

public void setTotalPrice(BigDecimal totalPrice) {
this.totalPrice = totalPrice;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,35 @@ public void setNotes(String notes) {
this.notes = notes;

}


@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((notes == null) ? 0 : notes.hashCode());
result = prime * result + ((product == null) ? 0 : product.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ProductHolder other = (ProductHolder) obj;
if (notes == null) {
if (other.notes != null)
return false;
} else if (!notes.equals(other.notes))
return false;
if (product == null) {
if (other.product != null)
return false;
} else if (!product.equals(other.product))
return false;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class Product {
@GeneratedValue
@Column(name = "PRODUCT_ID")
private long id;

@Column(name = "NAME")
private String name;

@Column(name = "PRICE")
private BigDecimal price;

Expand Down Expand Up @@ -79,4 +79,41 @@ public void addDescription(String description) {
this.descriptions.add(description);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((descriptions == null) ? 0 : descriptions.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((price == null) ? 0 : price.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Product other = (Product) obj;
if (descriptions == null) {
if (other.descriptions != null)
return false;
} else if (!descriptions.equals(other.descriptions))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (price == null) {
if (other.price != null)
return false;
} else if (!price.equals(other.price))
return false;
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.qorder.qorderws.entities;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({ ProductEqualityTest.class, ProductHolderEqualityTest.class })
public class AllEntitiesEqualityTests {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.qorder.qorderws.entities;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.math.BigDecimal;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.qorder.qorderws.model.product.Product;

public class ProductEqualityTest {

private Product product1;

private Product product2;

@Before
public void setUp() throws Exception {
product1 = new Product();
product2 = new Product();
}

@After
public void tearDown() throws Exception {
product1 = null;
product2 = null;
}

@Test
public void SuccessfulProductEqualitytest() {
System.out.println("Successful product equality test");

product1.setName("ProductName");
product1.setPrice(BigDecimal.valueOf(1.1));
product1.addDescription("Description 1");
product1.addDescription("Description 2");

product2.setName("ProductName");
product2.setPrice(BigDecimal.valueOf(1.1));
product2.addDescription("Description 1");
product2.addDescription("Description 2");

boolean equalityResult = product1.equals(product2);
assertTrue(equalityResult);
}

@Test
public void FailProductEqualitytestByName() {
System.out.println("Failed product equality test by name");

product1.setName("ProductName");
product1.setPrice(BigDecimal.valueOf(1.1));
product1.addDescription("Description 1");
product1.addDescription("Description 2");


product2.setName("OtherProductName");
product2.setPrice(BigDecimal.valueOf(1.1));
product2.addDescription("Description 1");
product2.addDescription("Description 2");

boolean equalityResult = product1.equals(product2);
assertFalse(equalityResult);
}

@Test
public void FailProductEqualitytestByPrice() {
System.out.println("Failed product equality test by price");

product1.setName("ProductName");
product1.setPrice(BigDecimal.valueOf(1.1));
product1.addDescription("Description 1");
product1.addDescription("Description 2");

product2.setName("ProductName");
product2.setPrice(BigDecimal.valueOf(2.1));
product2.addDescription("Description 1");
product2.addDescription("Description 2");

boolean equalityResult = product1.equals(product2);
assertFalse(equalityResult);
}

@Test
public void FailProductEqualitytestByOneMoreDescription() {
System.out.println("Failed product equality test by one more description");

product1.setName("ProductName");
product1.setPrice(BigDecimal.valueOf(1.1));
product1.addDescription("Description 1");
product1.addDescription("Description 2");
product1.addDescription("Description 3");

product2.setName("ProductName");
product2.setPrice(BigDecimal.valueOf(1.1));
product2.addDescription("Description 1");
product2.addDescription("Description 2");

boolean equalityResult = product1.equals(product2);
assertFalse(equalityResult);
}

@Test
public void FailProductEqualitytestByOneLessDescription() {
System.out.println("Failed product equality test by one less description");

product1.setName("ProductName");
product1.setPrice(BigDecimal.valueOf(1.1));
product1.addDescription("Description 1");

product2.setName("ProductName");
product2.setPrice(BigDecimal.valueOf(1.1));
product2.addDescription("Description 1");
product2.addDescription("Description 2");

boolean equalityResult = product1.equals(product2);
assertFalse(equalityResult);
}

@Test
public void FailProductEqualitytestByNullProductName() {
System.out.println("Failed product equality test by one less description");

product1.setName(null);
product1.setPrice(BigDecimal.valueOf(1.1));
product1.addDescription("Description 1");
product1.addDescription("Description 2");

product2.setName("ProductName");
product2.setPrice(BigDecimal.valueOf(1.1));
product2.addDescription("Description 1");
product2.addDescription("Description 2");

boolean equalityResult = product1.equals(product2);
assertFalse(equalityResult);
}

@Test
public void FailProductEqualitytestByNullDescriptionList() {
System.out.println("Failed product equality test by one less description");

product1.setName(null);
product1.setPrice(BigDecimal.valueOf(1.1));
product1.setDescriptions(null);

product2.setName("ProductName");
product2.setPrice(BigDecimal.valueOf(1.1));
product2.addDescription("Description 1");
product2.addDescription("Description 2");

boolean equalityResult = product1.equals(product2);
assertFalse(equalityResult);
}




}
Loading

0 comments on commit ba910ad

Please sign in to comment.