public void testAttributeDefSave() { // cant create without privs GrouperSession.stopQuietly(this.grouperSession); this.grouperSession = GrouperSession.start(SubjectTestHelper.SUBJ0); try { new AttributeDefSave(this.grouperSession).assignName("top:b").save(); fail("shouldnt get here"); } catch (Exception e) { // good } // grant privs GrouperSession.stopQuietly(this.grouperSession); this.grouperSession = GrouperSession.startRootSession(); this.top.grantPriv(SubjectTestHelper.SUBJ0, NamingPrivilege.CREATE); AttributeDefSave attributeDefSave = new AttributeDefSave(this.grouperSession).assignName("top:b"); AttributeDef attributeDef = attributeDefSave.save(); assertEquals("top:b", attributeDef.getName()); assertNull(attributeDef.getDescription()); assertFalse(attributeDef.isMultiValued()); assertEquals(SaveResultType.INSERT, attributeDefSave.getSaveResultType()); // update attributeDefSave = new AttributeDefSave(this.grouperSession) .assignName("top:b") .assignDescription("whatever") .assignValueType(AttributeDefValueType.string) .assignMultiValued(true); attributeDef = attributeDefSave.save(); assertEquals(SaveResultType.UPDATE, attributeDefSave.getSaveResultType()); assertEquals("whatever", attributeDef.getDescription()); assertTrue(attributeDef.isMultiValued()); // no change attributeDefSave = new AttributeDefSave(this.grouperSession) .assignName("top:b") .assignDescription("whatever") .assignValueType(AttributeDefValueType.string) .assignMultiValued(true); attributeDef = attributeDefSave.save(); assertEquals(SaveResultType.NO_CHANGE, attributeDefSave.getSaveResultType()); assertEquals("whatever", attributeDef.getDescription()); assertTrue(attributeDef.isMultiValued()); }
private AttributeModel(AttributeDef def) throws QuickFixException { this.name = def.getName(); this.description = def.getDescription(); this.type = def.getTypeDef().getName().toLowerCase(); this.required = def.isRequired(); if (def.getDefaultValue() != null) { this.defaultValue = def.getDefaultValue().getValue().toString(); } else { this.defaultValue = null; } DefDescriptor<?> parentDesc = def.getParentDescriptor(); if (parentDesc == null || parentDesc.equals(ComponentDefModel.this.descriptor)) { this.parentName = null; this.parentDefType = null; } else { this.parentName = parentDesc.getNamespace() + ":" + parentDesc.getName(); this.parentDefType = parentDesc.getDefType().name().toLowerCase(); } }