package org.laladev.moneyjinn.businesslogic.service.impl;

import javax.inject.Inject;

import org.junit.Test;
import org.laladev.moneyjinn.AbstractTest;
import org.laladev.moneyjinn.businesslogic.model.Contractpartner;
import org.laladev.moneyjinn.businesslogic.model.access.User;
import org.laladev.moneyjinn.businesslogic.model.access.UserID;
import org.laladev.moneyjinn.businesslogic.model.exception.BusinessException;
import org.laladev.moneyjinn.businesslogic.service.api.IContractpartnerService;

public class ContractpartnerServiceTest extends AbstractTest {
	@Inject
	private IContractpartnerService contractpartnerService;

	@Test(expected = IllegalArgumentException.class)
	public void test_validateNullUser_raisesException() {
		final Contractpartner contractpartner = new Contractpartner();

		this.contractpartnerService.validateContractpartner(contractpartner);
	}

	@Test(expected = BusinessException.class)
	public void test_createWithInvalidEntity_raisesException() {
		final Contractpartner contractpartner = new Contractpartner();
		contractpartner.setUser(new User(new UserID(1l)));

		this.contractpartnerService.createContractpartner(contractpartner);
	}

	@Test(expected = BusinessException.class)
	public void test_updateWithInvalidEntity_raisesException() {
		final Contractpartner contractpartner = new Contractpartner();
		contractpartner.setUser(new User(new UserID(1l)));

		this.contractpartnerService.updateContractpartner(contractpartner);
	}
}

@@ -81,16 +81,66 @@
 nject;%0A%0A
+import org.junit.Assert;%0Aimport org.junit.Ignore;%0A
 import o
@@ -259,24 +259,92 @@
 actpartner;%0A
+import org.laladev.moneyjinn.businesslogic.model.ContractpartnerID;%0A
 import org.l
@@ -614,16 +614,159 @@
 Service;
+%0Aimport org.laladev.moneyjinn.server.builder.ContractpartnerTransportBuilder;%0Aimport org.laladev.moneyjinn.server.builder.UserTransportBuilder;
 %0A%0Apublic
@@ -1345,33 +1345,33 @@
 ser(new UserID(1
-l
+L
 )));%0A%0A%09%09this.con
@@ -1655,82 +1655,1261 @@
 ID(1
-l)));%0A%0A%09%09this.contractpartnerService.updateContractpartner(contractpartner
+L)));%0A%0A%09%09this.contractpartnerService.updateContractpartner(contractpartner);%0A%09%7D%0A%0A%09@Test%0A%09@Ignore(%22this does not work yet - see wiki TODO list%22)%0A%09public void test_userAeditsContractpartner_userBsameGroupSeesCachedChange() %7B%0A%09%09final UserID user1ID = new UserID(UserTransportBuilder.USER1_ID);%0A%09%09final UserID user2ID = new UserID(UserTransportBuilder.USER2_ID);%0A%0A%09%09// this caches%0A%09%09Contractpartner contractpartner = this.contractpartnerService.getContractpartnerById(user1ID,%0A%09%09%09%09new ContractpartnerID(ContractpartnerTransportBuilder.CONTRACTPARTNER1_ID));%0A%0A%09%09contractpartner = this.contractpartnerService.getContractpartnerById(user2ID,%0A%09%09%09%09new ContractpartnerID(ContractpartnerTransportBuilder.CONTRACTPARTNER1_ID));%0A%0A%09%09final String name = String.valueOf(System.currentTimeMillis());%0A%0A%09%09contractpartner.getUser().setId(user2ID);%0A%09%09contractpartner.setName(name);%0A%0A%09%09// this should also modify the cache of user 1!%0A%09%09this.contractpartnerService.updateContractpartner(contractpartner);%0A%0A%09%09// this should now retrieve the changed cache entry!%0A%09%09contractpartner = this.contractpartnerService.getContractpartnerById(user1ID,%0A%09%09%09%09new ContractpartnerID(ContractpartnerTransportBuilder.CONTRACTPARTNER1_ID));%0A%0A%09%09Assert.assertEquals(name, contractpartner.getName()
 );%0A%09

implement Test to check group wide editing while caching