View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.pm.position;
17  
18  import static org.mockito.Mockito.mock;
19  import static org.mockito.Mockito.when;
20  
21  import java.util.ArrayList;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  
26  import org.joda.time.DateTime;
27  import org.junit.Assert;
28  import org.junit.Before;
29  import org.junit.Test;
30  import org.kuali.kpme.core.api.groupkey.HrGroupKey;
31  import org.kuali.kpme.core.groupkey.HrGroupKeyBoTest;
32  import org.kuali.kpme.core.kfs.coa.businessobject.Account;
33  import org.kuali.kpme.pm.api.classification.qual.ClassificationQualification;
34  import org.kuali.kpme.pm.api.position.Position;
35  import org.kuali.kpme.pm.api.position.PositionDuty;
36  import org.kuali.kpme.pm.api.position.PositionQualification;
37  import org.kuali.kpme.pm.api.position.PstnFlag;
38  import org.kuali.kpme.pm.api.position.funding.PositionFunding;
39  import org.kuali.kpme.pm.api.positiondepartment.PositionDepartment;
40  import org.kuali.kpme.pm.api.positionresponsibility.PositionResponsibility;
41  import org.kuali.kpme.pm.classification.ClassificationBo;
42  import org.kuali.kpme.pm.classification.qual.ClassificationQualificationBoTest;
43  import org.kuali.kpme.pm.position.funding.PositionFundingBoTest;
44  import org.kuali.kpme.pm.positionresponsibility.PositionResponsibilityBoTest;
45  import org.kuali.rice.krad.service.BusinessObjectService;
46  
47  public class PositionBoTest {
48  	private static Map<String, Position> testPositionBos;
49  	public static Position.Builder builder = Position.Builder.create("1", "ISU-IA");
50  	
51  	private BusinessObjectService mockBusinessObjectService;
52  
53  	static {
54  		testPositionBos = new HashMap<String, Position>();
55  
56  		builder.setActive(true);
57  		builder.setBenefitsEligible("N");
58  		builder.setCategory("category");
59  		builder.setClassificationTitle("classTitle");
60  		builder.setContract("contract");
61  		builder.setContractType("contractType");
62  		builder.setCreateTime(DateTime.now());
63  		builder.setDescription("desc");
64  		builder.setGroupKeyCode("ISU-IA");
65  		builder.setGroupKey(HrGroupKey.Builder.create(HrGroupKeyBoTest.getTestHrGroupKey("ISU-IA")));
66  		builder.setHrPositionId("KPME_TEST_00001");
67  		builder.setId(builder.getHrPositionId());
68  		builder.setLeaveEligible("leaveEligible");
69  		builder.setMaxPoolHeadCount(0);
70  		builder.setObjectId("0804716a-cbb7-11e3-9cd3-51a754ad6a0a");
71  		builder.setPayGrade("XH");
72  		builder.setPayStep("YY");
73  		builder.setPositionNumber("1");
74          builder.setPositionClass("positionClass");
75          builder.setAppointmentType("appt");
76          builder.setReportsToWorkingTitle("rptToWorkTitle");
77          builder.setPrimaryDepartment("dept1");
78          builder.setProcess("process");
79  
80  
81  		builder.setPmPositionClassId("KPME_TEST_2000");
82  		
83  		List<PositionResponsibility.Builder> positionResponsilityList = new ArrayList<PositionResponsibility.Builder>();
84  		PositionResponsibility.Builder responsibilityBuilder = PositionResponsibility.Builder.create(PositionResponsibilityBoTest.getPositionResponsibility("TST-PSTNRESPOPT"));
85  		responsibilityBuilder.setHrPositionId(builder.getHrPositionId());
86  		positionResponsilityList.add(responsibilityBuilder);
87  		builder.setPositionResponsibilityList(positionResponsilityList);
88  		
89  		
90  		List<PositionDepartment.Builder> positionDeptList = new ArrayList<PositionDepartment.Builder>();
91  		PositionDepartment.Builder deptBuilder = PositionDepartment.Builder.create(PositionDataBoTest.getPositionDepartment("TST-PSTNDEPT"));
92  		deptBuilder.setHrPositionId(builder.getHrPositionId());
93  		positionDeptList.add(deptBuilder);
94  		builder.setDepartmentList(positionDeptList);
95  		
96  		List<PstnFlag.Builder> pstnFlagList = new ArrayList<PstnFlag.Builder>();
97  		PstnFlag.Builder flagBuilder = PstnFlag.Builder.create(PstnFlagBoTest.getPstnFlag("TST-PSTNFLAG"));
98  		flagBuilder.setHrPositionId(builder.getHrPositionId());
99  		pstnFlagList.add(flagBuilder);
100 		builder.setFlagList(pstnFlagList);
101 		
102 		List<PositionDuty.Builder> positionDutyList = new ArrayList<PositionDuty.Builder>();
103 		PositionDuty.Builder dutyBuilder = PositionDuty.Builder.create(PositionDutyBoTest.getPositionDutyBo("TST-PSTNDUTY"));
104 		dutyBuilder.setHrPositionId(builder.getHrPositionId());
105 		positionDutyList.add(dutyBuilder);
106 		builder.setDutyList(positionDutyList);
107 		
108 		List<PositionFunding.Builder> positionFundingList = new ArrayList<PositionFunding.Builder>();
109 		PositionFunding.Builder fundingBuilder = PositionFunding.Builder.create(PositionFundingBoTest.getPositionFunding("9999"));
110 		fundingBuilder.setHrPositionId(builder.getHrPositionId());
111 		fundingBuilder.setAccount("KPME_TEST_ACCOUNT");
112 		positionFundingList.add(fundingBuilder);
113 		builder.setFundingList(positionFundingList);
114 
115 		List<PositionQualification.Builder> positionQualificationList = new ArrayList<PositionQualification.Builder>();
116 		PositionQualification.Builder qualificationBuilder = PositionQualification.Builder.create(PositionQualificationBoTest.getPositionQualificationBo("TST-PSTNQLFCTN"));
117 		qualificationBuilder.setHrPositionId(builder.getHrPositionId());
118 		positionQualificationList.add(qualificationBuilder);
119 		builder.setQualificationList(positionQualificationList);
120 		
121 		List<ClassificationQualification.Builder> classificationQualificationList = new ArrayList<ClassificationQualification.Builder>();
122 		ClassificationQualification.Builder classQualBuilder = ClassificationQualification.Builder.create(ClassificationQualificationBoTest.getClassificationQualificationBo("TST-CLASSFCTNQLFCTN"));
123 		classQualBuilder.setPmPositionClassId("KPME_TEST_2000");
124 		classificationQualificationList.add(classQualBuilder);
125 		builder.setRequiredQualList(classificationQualificationList);
126 						
127 		testPositionBos.put("TST-PSTN", builder.build());
128 	}
129 	
130 	@Test
131     public void testNotEqualsWithGroup() {
132     	Position immutable = PositionBoTest.getPosition("TST-PSTN");
133     	PositionBo bo = PositionBo.from(immutable);
134         Assert.assertFalse(bo.equals(immutable));
135         Assert.assertFalse(immutable.equals(bo));
136        
137         // this is simply to prevent invocations of refresh reference 
138     	ClassificationBo classificationBo = new ClassificationBo();
139     	bo.getRequiredQualList().get(0).setOwner(classificationBo);
140     	
141     	bo.getFundingList().get(0).setBusinessObjectService(mockBusinessObjectService);
142         Position im2 = PositionBo.to(bo);
143         PositionBo bo2 = PositionBo.from(im2);
144         
145         // this is simply to prevent invocations of refresh reference 
146         bo2.getRequiredQualList().get(0).setOwner(classificationBo);
147         
148         bo2.getFundingList().get(0).setBusinessObjectService(mockBusinessObjectService);
149         Position im3 = PositionBo.to(bo2);
150         
151         Assert.assertEquals(im2, im3);
152     }
153 
154     public static Position getPosition(String Position) {
155         Position position = testPositionBos.get(Position);
156         return position;
157     }
158     
159     @Before
160     public void setup() throws Exception {
161         
162         Account account = new Account();
163     	account.setAccountNumber("KPME_TEST_ACCOUNT");
164     	account.setChartOfAccountsCode("MC");
165     	account.setActive(true);
166     	
167     	Map<String, String> fields = new HashMap<String, String>();
168 		fields.put("accountNumber", "KPME_TEST_ACCOUNT");
169 		fields.put("active", "true");
170     	
171     	mockBusinessObjectService = mock(BusinessObjectService.class);
172         {
173             when(mockBusinessObjectService.findByPrimaryKey(Account.class, fields)).thenReturn(account);
174         }
175     }
176 
177 }