From 2910e9d89c1bdcbaf60794de322de3f41acd85f7 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Thu, 29 Aug 2013 15:23:48 +0200 Subject: [PATCH] Fixed and revised test case to be able to build the project. --- .../jl/crm/services/TestCustomerService.java | 62 +++++++------------ 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/code/web/services/src/test/java/com/jl/crm/services/TestCustomerService.java b/code/web/services/src/test/java/com/jl/crm/services/TestCustomerService.java index 409d7c1c..2a45d191 100644 --- a/code/web/services/src/test/java/com/jl/crm/services/TestCustomerService.java +++ b/code/web/services/src/test/java/com/jl/crm/services/TestCustomerService.java @@ -1,46 +1,33 @@ package com.jl.crm.services; -import org.junit.*; +import java.util.Collection; + +import javax.inject.Inject; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.transaction.annotation.Transactional; -import javax.inject.Inject; -import java.util.Collection; - -@RunWith (SpringJUnit4ClassRunner.class) -@ContextConfiguration (classes = ServiceConfiguration.class) +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = ServiceConfiguration.class) @Transactional @TransactionConfiguration public class TestCustomerService { - private CrmService crmService; - private User joshlong; - @Inject - public void setCrmService(CrmService crmService) { - this.crmService = crmService; - } + @Inject private CrmService crmService; @Before public void begin() throws Throwable { String joshlongUserName = "joshlong"; joshlong = crmService.findUserByUsername(joshlongUserName); - if (null == joshlong){ - joshlong = crmService.createUser(joshlongUserName, "cowbell", "josh", "Long"); - } Assert.assertNotNull(joshlong); - - Collection customersSet = crmService.loadCustomerAccounts(this.joshlong.getId()); - int sizeOfCustomersForUser = customersSet.size(); - for (Customer customer : customersSet) { - crmService.removeAccount(this.joshlong.getId(), customer.getId()); - sizeOfCustomersForUser = sizeOfCustomersForUser - 1; - Assert.assertEquals(crmService.loadCustomerAccounts(this.joshlong.getId()).size(), sizeOfCustomersForUser); - } } @Test @@ -48,32 +35,31 @@ public void testCreateUser() throws Throwable { Assert.assertNotNull(this.joshlong); } - @Inject private CustomerRepository customerRepository ; - - @Test public void testCustomerSearch () throws Throwable { - long joshlongUserId = this.joshlong.getId(); + @Test + public void testCustomerSearch() throws Throwable { - Collection customerCollection = crmService.search(joshlongUserId, "josh" ) ; - Assert.assertTrue( "there should be at least" , customerCollection.size() > 0); + Collection customerCollection = crmService.loadCustomerAccounts(joshlong.getId()); + Assert.assertEquals("there should be 4 customers for user josh", 4, customerCollection.size()); + } + @Test + public void testCustomerSearchForSpecificUsernamePattern() throws Throwable { + Collection customerCollection = crmService.search(joshlong.getId(), "josh"); + Assert.assertEquals("there should be 1 customer with username like 'josh' for user josh", 1, + customerCollection.size()); } @Test public void testCreatingCustomer() throws Throwable { - long joshlongUserId = this.joshlong.getId(); - - Collection customerCollection; - - Customer janeDoe = this.crmService.addAccount(joshlongUserId, "Jane", "Doe"); + Customer janeDoe = this.crmService.addAccount(joshlong.getId(), "Jane", "Doe"); Assert.assertNotNull(janeDoe); - Customer johnDoe = this.crmService.addAccount(joshlongUserId, "John", "Doe"); + Customer johnDoe = this.crmService.addAccount(joshlong.getId(), "John", "Doe"); Assert.assertNotNull(johnDoe); - customerCollection = crmService.loadCustomerAccounts(this.joshlong.getId()); - Assert.assertEquals(customerCollection.size(), 2); - + Collection customerCollection = crmService.loadCustomerAccounts(joshlong.getId()); + Assert.assertEquals(6, customerCollection.size()); } }