1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
40
41
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
62
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 }