View Javadoc
1   /**
2    * Copyright 2005-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.rice.kim.test.service;
17  
18  import java.util.Collections;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.junit.Test;
24  import org.kuali.rice.kim.api.common.attribute.KimAttribute;
25  import org.kuali.rice.kim.api.group.Group;
26  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
27  import org.kuali.rice.kim.api.type.KimType;
28  import org.kuali.rice.kim.api.type.KimTypeAttribute;
29  import org.kuali.rice.kim.impl.common.attribute.KimAttributeBo;
30  import org.kuali.rice.kim.impl.type.KimTypeAttributeBo;
31  import org.kuali.rice.kim.impl.type.KimTypeBo;
32  import org.kuali.rice.kim.test.KIMTestCase;
33  import org.kuali.rice.krad.service.KRADServiceLocator;
34  import org.kuali.rice.test.BaselineTestCase;
35  
36  import static org.junit.Assert.*;
37  
38  /**
39   * Unit test for {@link org.kuali.rice.kim.api.group.GroupService}
40   *
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   *
43   */
44  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
45  public class GroupUpdateServiceApiCustomTest extends KIMTestCase {
46  
47      private static final String NAMESPACE = "KUALI";
48      private static final String KIM_ATTRIBUTE_ID = "KS-KRIM-ATTR-DEFN-1003";
49      private static final String KIM_ATTRIBUTE_LABEL = "Hold Authorization Org Id";
50      private static final String KIM_ATTRIBUTE_NAME = "org.kuali.student.hold.authorization.orgId";
51      private static final String KIM_ATTRIBUTE_VALUE = "ORGID-128487550";
52      private static final String KIM_ATTRIBUTE_COMPONENT_NAME = "org.kuali.rice.student.bo.KualiStudentKimAttributes";
53      private static final String KIM_TYPE_ID = "KS-KRIM-TYP-1011";
54      private static final String KIM_TYPE_NAME = "KS Hold Org Authorization Group Type";
55      private static final String KIM_TYPE_SERVICE_NAME = "kimGroupTypeService";
56      private static final String KIM_TYPE_ATTRIBUTE_ID = "KS-KRIM-TYP-ATTR-1027";
57      private static final String GROUP_NAME = "gAwAttrs";
58  
59      @Test
60      public void testCreateGroupWithCustomKimTypeAttributes() {
61          // This test needs to be run in separate test class
62          // with @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
63          KimAttribute.Builder kimAttribute = KimAttribute.Builder.create(KIM_ATTRIBUTE_COMPONENT_NAME,
64                  KIM_ATTRIBUTE_NAME, NAMESPACE);
65          kimAttribute.setAttributeLabel(KIM_ATTRIBUTE_LABEL);
66          kimAttribute.setId(KIM_ATTRIBUTE_ID);
67          kimAttribute.setActive(true);
68          KimAttributeBo kimAddrBo = KRADServiceLocator.getDataObjectService().save(KimAttributeBo.from(kimAttribute.build()));
69  
70          KimType.Builder kimTypeBuilder = KimType.Builder.create();
71          kimTypeBuilder.setId(KIM_TYPE_ID);
72          kimTypeBuilder.setName(KIM_TYPE_NAME);
73          kimTypeBuilder.setNamespaceCode(NAMESPACE);
74          kimTypeBuilder.setServiceName(KIM_TYPE_SERVICE_NAME);
75          kimTypeBuilder.setActive(true);
76          KimTypeBo kimTypeBo = KRADServiceLocator.getDataObjectService().save(KimTypeBo.from(kimTypeBuilder.build()));
77  
78          KimTypeAttribute.Builder kimTypeAttributeBuilder = KimTypeAttribute.Builder.create();
79          kimTypeAttributeBuilder.setId(KIM_TYPE_ATTRIBUTE_ID);
80          kimTypeAttributeBuilder.setActive(true);
81          kimTypeAttributeBuilder.setSortCode("a");
82          kimTypeAttributeBuilder.setKimTypeId(KIM_TYPE_ID);
83          kimTypeAttributeBuilder.setKimAttribute(kimAttribute);
84          KimTypeAttributeBo kimTypeAttrBo = KRADServiceLocator.getDataObjectService().save(KimTypeAttributeBo.from(kimTypeAttributeBuilder.build()));
85  
86          kimTypeBuilder = KimType.Builder.create(KimApiServiceLocator.getKimTypeInfoService().getKimType(KIM_TYPE_ID));
87          kimTypeAttributeBuilder = KimTypeAttribute.Builder.create(kimTypeAttrBo);
88          List<KimTypeAttribute.Builder> attrList = Collections.singletonList(kimTypeAttributeBuilder);
89          kimTypeBuilder.setAttributeDefinitions(attrList);
90  
91          kimTypeBo = KRADServiceLocator.getDataObjectService().save(KimTypeBo.from(kimTypeBuilder.build()));
92          KRADServiceLocator.getDataObjectService().flush(KimTypeBo.class);
93  
94          Map<String, String> attributes = new HashMap<String, String>();
95          attributes.put(KIM_ATTRIBUTE_NAME, KIM_ATTRIBUTE_VALUE);
96  
97          Group.Builder groupInfo = Group.Builder.create(NAMESPACE, GROUP_NAME, KIM_TYPE_ID);
98          groupInfo.setAttributes(attributes);
99          groupInfo.setActive(true);
100         groupInfo.setDescription(KIM_ATTRIBUTE_LABEL + " " + KIM_ATTRIBUTE_VALUE);
101         Group group = KimApiServiceLocator.getGroupService().createGroup(groupInfo.build());
102 
103         Group result = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(NAMESPACE, GROUP_NAME);
104         assertEquals(groupInfo.isActive(), result.isActive());
105         assertTrue(groupInfo.getNamespaceCode().equals(result.getNamespaceCode()));
106         assertTrue(groupInfo.getName().equals(result.getName()));
107         assertTrue(groupInfo.getKimTypeId().equals(result.getKimTypeId()));
108         assertEquals(1, result.getAttributes().size());
109         assertTrue(result.getAttributes().get(KIM_ATTRIBUTE_NAME).contains(KIM_ATTRIBUTE_VALUE));
110     }
111 }