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

Fixed and revised test case to be able to build the project. #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,79 +1,65 @@
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<Customer> 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
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<Customer> customerCollection = crmService.search(joshlongUserId, "josh" ) ;
Assert.assertTrue( "there should be at least" , customerCollection.size() > 0);
Collection<Customer> 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<Customer> 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<Customer> 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<Customer> customerCollection = crmService.loadCustomerAccounts(joshlong.getId());
Assert.assertEquals(6, customerCollection.size());
}
}