1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.pm.position.funding;
17
18 import static org.mockito.Mockito.mock;
19 import static org.mockito.Mockito.when;
20
21 import java.math.BigDecimal;
22 import java.util.Date;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.joda.time.LocalDate;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.kuali.kpme.core.kfs.coa.businessobject.Account;
31 import org.kuali.kpme.pm.api.position.funding.PositionFunding;
32 import org.kuali.kpme.pm.position.PositionBo;
33 import org.kuali.rice.krad.service.BusinessObjectService;
34 import org.mockito.Mockito;
35
36 public class PositionFundingBoTest {
37
38 private static BusinessObjectService businessObjectService;
39 private static Map<String, PositionFunding> testPositionFundingBos;
40 public static PositionFunding.Builder PositionFundingBuilder = PositionFunding.Builder.create();
41 private static final LocalDate currentTime = new LocalDate();
42
43 static {
44 testPositionFundingBos = new HashMap<String, PositionFunding>();
45 PositionFundingBuilder.setAccount("9999");
46 PositionFundingBuilder.setHrPositionId("TST-PSTNID");
47 PositionFundingBuilder.setAmount(new BigDecimal(100));
48 PositionFundingBuilder.setPmPositionFunctionId("TST-PSTNFUNDING");
49 PositionFundingBuilder.setChart("MC");
50 PositionFundingBuilder.setVersionNumber(1L);
51 PositionFundingBuilder.setEffectiveLocalDateOfOwner(currentTime);
52 PositionFundingBuilder.setObjectId("0804716a-cbb7-11e3-9cd3-51a754ad6a0a");
53 PositionFundingBuilder.setObjectCode("9000");
54 PositionFundingBuilder.setPercent(new BigDecimal(100));
55 testPositionFundingBos.put(PositionFundingBuilder.getAccount(), PositionFundingBuilder.build());
56 }
57
58 @Test
59 public void testNotEqualsWithGroup() {
60 PositionFunding immutable = PositionFundingBoTest.getPositionFunding("9999");
61 PositionFundingBo bo = PositionFundingBo.from(immutable);
62 PositionBo positionBo = new PositionBo();
63 positionBo.setEffectiveLocalDate(currentTime);
64 bo.setOwner(positionBo);
65 bo.setBusinessObjectService(businessObjectService);
66 Assert.assertFalse(bo.equals(immutable));
67 Assert.assertFalse(immutable.equals(bo));
68 Assert.assertEquals(immutable, PositionFundingBo.to(bo));
69 }
70
71 @Before
72 public void setup() throws Exception {
73
74 Account account = new Account();
75 account.setAccountNumber("9999");
76 account.setChartOfAccountsCode("MC");
77 account.setActive(true);
78
79 businessObjectService = mock(BusinessObjectService.class);
80 {
81 when( businessObjectService.findByPrimaryKey(Mockito.any(Class.class), Mockito.anyMap())).thenReturn(account);
82 }
83 }
84
85 public static PositionFunding getPositionFunding(String account) {
86 return testPositionFundingBos.get(account);
87 }
88 }