Skip to content

Commit

Permalink
Test for boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Oct 8, 2015
1 parent 94bff2b commit 9e8f915
Showing 1 changed file with 51 additions and 1 deletion.
Expand Up @@ -49,6 +49,7 @@
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.SearchResultMetadata;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand All @@ -58,6 +59,7 @@
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.util.MidPointAsserts;
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.DOMUtil;
Expand Down Expand Up @@ -322,6 +324,7 @@ public void test110GetJack() throws Exception {
display("Shadow", shadow);
assertAccountShadow(shadow, toDn(ACCOUNT_JACK_UID));
assertLockout(shadow, LockoutStatusType.NORMAL);
assertPasswordAllowChange(shadow, null);
jackAccountOid = shadow.getOid();

IntegrationTestTools.assertAssociation(shadow, getAssociationGroupQName(), groupPiratesOid);
Expand Down Expand Up @@ -466,6 +469,7 @@ public void test200AssignAccountBarbossa() throws Exception {
assertEquals("Wrong ICFS UID", MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes()), accountBarbossaIcfUid);

assertLdapPassword(USER_BARBOSSA_USERNAME, "deadjacktellnotales");
assertPasswordAllowChange(shadow, null);

ResourceAttribute<Long> createTimestampAttribute = ShadowUtil.getAttribute(shadow, new QName(MidPointConstants.NS_RI, "createTimestamp"));
assertNotNull("No createTimestamp in "+shadow, createTimestampAttribute);
Expand Down Expand Up @@ -600,7 +604,48 @@ public void test239EnableBarbossa() throws Exception {
PrismObject<ShadowType> shadow = getObject(ShadowType.class, shadowOid);
assertAdministrativeStatus(shadow, ActivationStatusType.ENABLED);
}


/**
* passwordAllowChange is a boolean attribute
*/
@Test
public void test240ModifyAccountBarbossaPasswordAllowChangeFalse() throws Exception {
final String TEST_NAME = "test240ModifyAccountBarbossaPasswordAllowChangeFalse";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

ObjectDelta<ShadowType> delta = ObjectDelta.createEmptyModifyDelta(ShadowType.class, accountBarbossaOid, prismContext);
QName attrQName = new QName(MidPointConstants.NS_RI, "passwordAllowChange");
ResourceAttributeDefinition<Boolean> attrDef = accountObjectClassDefinition.findAttributeDefinition(attrQName);
PropertyDelta<Boolean> attrDelta = PropertyDelta.createModificationReplaceProperty(
new ItemPath(ShadowType.F_ATTRIBUTES, attrQName), attrDef, Boolean.FALSE);
delta.addModification(attrDelta);

// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
assertAttribute(entry, "passwordAllowChange", "FALSE");

PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
String shadowOid = getSingleLinkOid(user);
assertEquals("Shadows have moved", accountBarbossaOid, shadowOid);

PrismObject<ShadowType> shadow = getObject(ShadowType.class, shadowOid);
display("Shadow after", shadow);
assertPasswordAllowChange(shadow, false);

}

/**
* This should create account with a group. And disabled.
*/
Expand Down Expand Up @@ -1011,6 +1056,11 @@ protected void assertAccountShadow(PrismObject<ShadowType> shadow, String dn) th
assertTrue("Unexpected chars in primary ID: '"+primaryId+"'", primaryId.matches("[a-z0-9]+"));
}

protected void assertPasswordAllowChange(PrismObject<ShadowType> shadow, Boolean expected) throws SchemaException {
Boolean passwordAllowChange = ShadowUtil.getAttributeValue(shadow, new QName(MidPointConstants.NS_RI, "passwordAllowChange"));
assertEquals("Wrong passwordAllowChange in "+shadow, expected, passwordAllowChange);
}

private void makeBadLoginAttempt(String uid) throws LdapException {
LdapNetworkConnection conn = ldapConnect(toDn(uid), "thisIsAwRoNgPASSW0RD");
if (conn.isAuthenticated()) {
Expand Down

0 comments on commit 9e8f915

Please sign in to comment.