001 /**
002 * Copyright 2005-2013 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 */
016 package org.kuali.rice.kim.impl.common;
017
018 import org.junit.Before;
019 import org.junit.Test;
020 import org.kuali.rice.kim.api.common.attribute.KimAttribute;
021 import org.kuali.rice.kim.api.common.attribute.KimAttributeContract;
022 import org.kuali.rice.kim.api.type.KimType;
023 import org.kuali.rice.kim.api.type.KimTypeAttributeContract;
024 import org.kuali.rice.kim.api.type.KimTypeContract;
025 import org.kuali.rice.kim.api.type.KimTypeInfoService;
026 import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo;
027 import org.kuali.rice.kim.impl.group.GroupAttributeBo;
028 import org.kuali.rice.kim.impl.type.KimTypeBo;
029
030 import java.util.ArrayList;
031 import java.util.HashMap;
032 import java.util.List;
033 import java.util.Map;
034
035 import static org.junit.Assert.*;
036 import static org.mockito.Mockito.*;
037
038
039 public class KimAttributeDataBoTest {
040
041 private static KimTypeContract mockKimTypeContract;
042 private static KimAttributeContract mockKimAttributeContract;
043
044 private KimTypeInfoService mockInfoService;
045
046 private static KimType create() {
047 return KimType.Builder.create(mockKimTypeContract).build();
048 }
049
050 private static KimAttribute createKimAttribute() {
051 return KimAttribute.Builder.create(mockKimAttributeContract).build();
052 }
053
054 @Before
055 public void setup() throws Exception {
056
057 mockKimAttributeContract = mock(KimAttributeContract.class);
058 {
059 Long versionNumber = 1L;
060 String attributeName = "one";
061 String namespaceCode = "namespaceCode";
062 String id = "id_one";
063 when( mockKimAttributeContract.getVersionNumber()).thenReturn(versionNumber);
064 when( mockKimAttributeContract.getAttributeName()).thenReturn(attributeName);
065 when( mockKimAttributeContract.getNamespaceCode()).thenReturn(namespaceCode);
066 when( mockKimAttributeContract.getId() ).thenReturn(id);
067 }
068
069 KimTypeAttributeContract one = mock(KimTypeAttributeContract.class);
070 {
071 String id = "one";
072 Long versionNumber = 1L;
073 KimAttribute attribute = createKimAttribute();
074 when(one.getKimAttribute()).thenReturn(attribute);
075 when(one.getId()).thenReturn(id);
076 when(one.getVersionNumber()).thenReturn(versionNumber);
077 }
078
079
080 mockKimTypeContract = mock(KimTypeContract.class);
081 {
082 String id = new String("27");
083 String serviceName = "barService";
084 String namespaceCode ="NAMESPACE CODE";
085 String name = "mock Kim Type Contract";
086 Long versionNumber = 1L;
087 String objectId = "1";
088 List attributeDefinitions = new ArrayList<KimTypeAttributeContract>();
089 attributeDefinitions.add(one);
090 when(mockKimTypeContract.getId()).thenReturn(id);
091 when(mockKimTypeContract.getServiceName()).thenReturn(serviceName);
092 when(mockKimTypeContract.getNamespaceCode()).thenReturn(namespaceCode);
093 when(mockKimTypeContract.getName()).thenReturn(name);
094 when(mockKimTypeContract.getVersionNumber()).thenReturn(versionNumber);
095 when(mockKimTypeContract.getObjectId()).thenReturn(objectId);
096 when(mockKimTypeContract.getAttributeDefinitions()).thenReturn(attributeDefinitions);
097 }
098
099 KimType kimType = create();
100 mockInfoService = mock(KimTypeInfoService.class);
101 {
102 when( mockInfoService.getKimType(anyString()) ).thenReturn(kimType);
103 }
104
105 }
106
107 @Test
108 public void testKimAttributeDataBo() {
109 KimType kimType = create();
110 Map<String,String> attributes = new HashMap<String,String>(); //{organizationCode=COMP, chartOfAccountsCode=BL}
111 attributes.put("one","one");
112
113 String kimTypeId = "27";
114
115 assertEquals(kimType.getId(), "27");
116
117 KimAttributeDataBo.setKimTypeInfoService(mockInfoService);
118
119 GroupAttributeBo groupQualifier = KimAttributeDataBo.createFrom(GroupAttributeBo.class, attributes, kimTypeId).get(0);
120
121 assertNotNull(groupQualifier.getKimType());
122 assertEquals(groupQualifier.getKimType().getId(), KimTypeBo.from(kimType).getId());
123
124 }
125
126 }