1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.earncode.group;
17
18 import static org.mockito.Matchers.anyString;
19 import static org.mockito.Mockito.mock;
20 import static org.mockito.Mockito.when;
21
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.joda.time.DateTime;
28 import org.joda.time.LocalDate;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.kuali.kpme.core.api.earncode.EarnCode;
33 import org.kuali.kpme.core.api.earncode.group.EarnCodeGroup;
34 import org.kuali.kpme.core.api.earncode.group.EarnCodeGroupDefinition;
35 import org.kuali.kpme.core.api.earncode.service.EarnCodeService;
36 import org.kuali.kpme.core.earncode.EarnCodeBoTest;
37 import org.kuali.rice.kim.api.identity.IdentityService;
38 import org.kuali.rice.kim.api.identity.name.EntityName;
39 import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
40 import org.mockito.Mockito;
41
42
43 public class EarnCodeGroupBoTest {
44
45 private static Map<String, EarnCodeGroup> testEarnCodeGroupBos;
46 private static EarnCodeService mockEarnCodeService;
47 public static EarnCodeGroup.Builder earnCodeGroupBuilder = EarnCodeGroup.Builder.create("TST-ECG");
48 static {
49 List<EarnCodeGroupDefinition.Builder> earnCodeGroupDefinitions = new ArrayList<EarnCodeGroupDefinition.Builder>();
50 earnCodeGroupDefinitions.add(EarnCodeGroupDefinition.Builder.create(EarnCodeGroupDefinitionBoTest.getEarnCodeGroupDefinition("TST-EarnCode")));
51
52 testEarnCodeGroupBos = new HashMap<String, EarnCodeGroup>();
53
54 earnCodeGroupBuilder.setEarnCodeGroup("TST-ECG");
55 earnCodeGroupBuilder.setDescr("Testing Immutable EarnCodeGroup");
56 earnCodeGroupBuilder.setWarningText("This is the warning test for earncodegroup");
57 earnCodeGroupBuilder.setHrEarnCodeGroupId("KPME_TEST_0001");
58 earnCodeGroupBuilder.setVersionNumber(1L);
59 earnCodeGroupBuilder.setObjectId("0804716a-cbb7-11e3-9cd3-51a754ad6a0a");
60 earnCodeGroupBuilder.setActive(true);
61 earnCodeGroupBuilder.setId(earnCodeGroupBuilder.getHrEarnCodeGroupId());
62 earnCodeGroupBuilder.setEffectiveLocalDate(new LocalDate(2012, 3, 1));
63 earnCodeGroupBuilder.setCreateTime(DateTime.now());
64 earnCodeGroupBuilder.setUserPrincipalId("admin");
65 earnCodeGroupBuilder.setEarnCodeGroups(earnCodeGroupDefinitions);
66 testEarnCodeGroupBos.put(earnCodeGroupBuilder.getEarnCodeGroup(), earnCodeGroupBuilder.build());
67
68 }
69
70 @Before
71 public void setup() throws Exception {
72
73 EarnCode earnCode = EarnCodeBoTest.getTestEarnCode("TST-EarnCode");
74 mockEarnCodeService = mock(EarnCodeService.class);
75 {
76 when( mockEarnCodeService.getEarnCode(anyString(), Mockito.any(LocalDate.class))).thenReturn(earnCode);
77 }
78 }
79
80 @Test
81 public void testNotEqualsWithGroup() {
82 EarnCodeGroup immutable = EarnCodeGroupBoTest.getEarnCodeGroup("TST-ECG");
83 EarnCodeGroupBo bo = EarnCodeGroupBo.from(immutable);
84 bo.getEarnCodeGroups().get(0).setEarnCodeService(mockEarnCodeService);
85 Assert.assertFalse(bo.equals(immutable));
86 Assert.assertFalse(immutable.equals(bo));
87 Assert.assertEquals(immutable, EarnCodeGroupBo.to(bo));
88 }
89
90 public static EarnCodeGroup getEarnCodeGroup(String earnCodeGroup) {
91 return testEarnCodeGroupBos.get(earnCodeGroup);
92 }
93 }