001/**
002 * Copyright 2004-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.kpme.pm.report.group;
017
018import java.util.HashMap;
019import java.util.HashSet;
020import java.util.Map;
021import java.util.Set;
022
023import org.joda.time.DateTime;
024import org.joda.time.LocalDate;
025import org.junit.Assert;
026import org.junit.Test;
027import org.kuali.kpme.core.api.groupkey.HrGroupKey;
028import org.kuali.kpme.core.api.mo.EffectiveKey;
029import org.kuali.kpme.core.groupkey.HrGroupKeyBoTest;
030import org.kuali.kpme.pm.api.positionreportgroup.PositionReportGroup;
031import org.kuali.kpme.pm.positionreportgroup.PositionReportGroupBo;
032
033public class PositionReportGroupBoTest {
034
035        private static Map<String, PositionReportGroup> testPositionReportGroupBos;
036        public static PositionReportGroup.Builder positionReportGroupBuilder = PositionReportGroup.Builder.create("TST-PSTNRPTGRP");
037        public static EffectiveKey.Builder positionReportGroupKeyBuilder = EffectiveKey.Builder.create();
038        
039        static {
040                testPositionReportGroupBos = new HashMap<String, PositionReportGroup>();
041                
042                positionReportGroupBuilder.setDescription("Testing Immutable PositionReportGroup");
043                positionReportGroupBuilder.setPositionReportGroup("TST-PSTNRPTGRP");
044                positionReportGroupBuilder.setUserPrincipalId("admin");
045                
046                positionReportGroupBuilder.setPmPositionReportGroupId("KPME_TEST_0001");
047                positionReportGroupBuilder.setVersionNumber(1L);
048                positionReportGroupBuilder.setObjectId("0804716a-cbb7-11e3-9cd3-51a754ad6a0a");
049                positionReportGroupBuilder.setActive(true);
050                positionReportGroupBuilder.setId(positionReportGroupBuilder.getPmPositionReportGroupId());
051                positionReportGroupBuilder.setEffectiveLocalDate(new LocalDate(2012, 3, 1));
052                positionReportGroupBuilder.setCreateTime(DateTime.now());
053                
054                // now populate the derived key object builder
055                positionReportGroupKeyBuilder.setGroupKeyCode("ISU-IA");
056                positionReportGroupKeyBuilder.setGroupKey(HrGroupKey.Builder.create(HrGroupKeyBoTest.getTestHrGroupKey("ISU-IA")));
057                positionReportGroupKeyBuilder.setOwnerId(positionReportGroupBuilder.getPmPositionReportGroupId());
058                positionReportGroupKeyBuilder.setId("derived key object 01");
059                positionReportGroupKeyBuilder.setEffectiveLocalDateOfOwner(positionReportGroupBuilder.getEffectiveLocalDate());
060                
061                Set<EffectiveKey.Builder> keyBuilders = new HashSet<EffectiveKey.Builder>();
062                keyBuilders.add(positionReportGroupKeyBuilder);
063                positionReportGroupBuilder.setEffectiveKeySet(keyBuilders);
064                
065                testPositionReportGroupBos.put(positionReportGroupBuilder.getPositionReportGroup(), positionReportGroupBuilder.build());
066        }
067        
068    @Test
069    public void testNotEqualsWithGroup() {
070        PositionReportGroup im1 = PositionReportGroupBoTest.getPositionReportGroup("TST-PSTNRPTGRP");
071        PositionReportGroupBo bo1 = PositionReportGroupBo.from(im1);
072        Assert.assertFalse(bo1.equals(im1));
073        Assert.assertFalse(im1.equals(bo1));
074        PositionReportGroup im2 = PositionReportGroupBo.to(bo1);
075        PositionReportGroupBo bo2 = PositionReportGroupBo.from(im2);
076        PositionReportGroup im3 = PositionReportGroupBo.to(bo2);
077        Assert.assertEquals(im2, im3);
078    }
079
080    public static PositionReportGroup getPositionReportGroup(String positionReportGroup) {
081        return testPositionReportGroupBos.get(positionReportGroup);
082    }
083        
084}