use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test102GetAccount.
// test101 in the subclasses
@Test
public void test102GetAccount() throws Exception {
final String TEST_NAME = "test102GetAccount";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
rememberShadowFetchOperationCount();
XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
// WHEN
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, null, result);
// THEN
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
assertShadowFetchOperationCountIncrement(1);
XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
display("Retrieved account shadow", shadow);
assertNotNull("No dummy account", shadow);
checkAccountWill(shadow, result, startTs, endTs);
PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
checkRepoAccountShadowWill(shadowRepo, startTs, endTs);
checkConsistency(shadow);
assertCachingMetadata(shadow, false, startTs, endTs);
// MID-3860
assertShadowPasswordMetadata(shadow, true, lastPasswordModifyStart, lastPasswordModifyEnd, null, null);
assertSteadyResource();
}
use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test100AddAccountWill.
@Test
public void test100AddAccountWill() throws Exception {
final String TEST_NAME = "test100AddAccountWill";
displayTestTile(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
syncServiceMock.reset();
PrismObject<ShadowType> account = prismContext.parseObject(getAccountWillFile());
account.checkConsistence();
display("Adding shadow", account);
XMLGregorianCalendar start = clock.currentTimeXMLGregorianCalendar();
// WHEN
displayWhen(TEST_NAME);
String addedObjectOid = provisioningService.addObject(account, null, null, task, result);
// THEN
displayThen(TEST_NAME);
assertSuccess(result);
XMLGregorianCalendar end = clock.currentTimeXMLGregorianCalendar();
assertEquals(ACCOUNT_WILL_OID, addedObjectOid);
account.checkConsistence();
PrismObject<ShadowType> accountRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
// Added account is slightly different case. Even not-returned-by-default attributes are stored in the cache.
checkRepoAccountShadowWill(accountRepo, start, end);
willIcfUid = getIcfUid(accountRepo);
display("Will ICF UID", willIcfUid);
assertNotNull("No will ICF UID", willIcfUid);
ActivationType activationRepo = accountRepo.asObjectable().getActivation();
if (supportsActivation()) {
assertNotNull("No activation in " + accountRepo + " (repo)", activationRepo);
assertEquals("Wrong activation enableTimestamp in " + accountRepo + " (repo)", ACCOUNT_WILL_ENABLE_TIMESTAMP, activationRepo.getEnableTimestamp());
} else {
assertNull("Activation sneaked in (repo)", activationRepo);
}
syncServiceMock.assertNotifySuccessOnly();
PrismObject<ShadowType> accountProvisioning = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, task, result);
XMLGregorianCalendar tsAfterRead = clock.currentTimeXMLGregorianCalendar();
display("Account provisioning", accountProvisioning);
ShadowType accountTypeProvisioning = accountProvisioning.asObjectable();
display("account from provisioning", accountTypeProvisioning);
assertShadowName(accountProvisioning, ACCOUNT_WILL_USERNAME);
assertEquals("Wrong kind (provisioning)", ShadowKindType.ACCOUNT, accountTypeProvisioning.getKind());
assertAttribute(accountProvisioning, SchemaConstants.ICFS_NAME, transformNameFromResource(ACCOUNT_WILL_USERNAME));
assertAttribute(accountProvisioning, getUidMatchingRule(), SchemaConstants.ICFS_UID, willIcfUid);
ActivationType activationProvisioning = accountTypeProvisioning.getActivation();
if (supportsActivation()) {
assertNotNull("No activation in " + accountProvisioning + " (provisioning)", activationProvisioning);
assertEquals("Wrong activation administrativeStatus in " + accountProvisioning + " (provisioning)", ActivationStatusType.ENABLED, activationProvisioning.getAdministrativeStatus());
TestUtil.assertEqualsTimestamp("Wrong activation enableTimestamp in " + accountProvisioning + " (provisioning)", ACCOUNT_WILL_ENABLE_TIMESTAMP, activationProvisioning.getEnableTimestamp());
} else {
assertNull("Activation sneaked in (provisioning)", activationProvisioning);
}
assertNull("The _PASSSWORD_ attribute sneaked into shadow", ShadowUtil.getAttributeValues(accountTypeProvisioning, new QName(SchemaConstants.NS_ICF_SCHEMA, "password")));
// Check if the account was created in the dummy resource
DummyAccount dummyAccount = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
assertNotNull("No dummy account", dummyAccount);
assertEquals("Username is wrong", transformNameFromResource(ACCOUNT_WILL_USERNAME), dummyAccount.getName());
assertEquals("Fullname is wrong", "Will Turner", dummyAccount.getAttributeValue("fullname"));
assertTrue("The account is not enabled", dummyAccount.isEnabled());
assertEquals("Wrong password", "3lizab3th", dummyAccount.getPassword());
// Check if the shadow is still in the repo (e.g. that the consistency or sync haven't removed it)
PrismObject<ShadowType> shadowFromRepo = repositoryService.getObject(ShadowType.class, addedObjectOid, null, result);
assertNotNull("Shadow was not created in the repository", shadowFromRepo);
display("Repository shadow", shadowFromRepo.debugDump());
checkRepoAccountShadow(shadowFromRepo);
checkRepoAccountShadowWill(shadowFromRepo, end, tsAfterRead);
// MID-3860
assertShadowPasswordMetadata(shadowFromRepo, true, start, end, null, null);
assertNoShadowPassword(shadowFromRepo);
lastPasswordModifyStart = start;
lastPasswordModifyEnd = end;
checkConsistency(accountProvisioning);
assertSteadyResource();
}
use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class XMLGregorianCalendarType method asXMLGregorianCalendar.
/**
* Converts a java.util.Date into an instance of XMLGregorianCalendar
*
* @param date Instance of java.util.Date or a null reference
* @return XMLGregorianCalendar instance whose value is based upon the
* value in the date parameter. If the date parameter is null then
* this method will simply return null.
*/
public static XMLGregorianCalendar asXMLGregorianCalendar(java.util.Date date) {
if (date == null) {
return null;
} else {
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(date.getTime());
return df.newXMLGregorianCalendar(gc);
}
}
use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class XMLGregorianCalendarType method nullSafeSet.
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
XMLGregorianCalendar calendar = (XMLGregorianCalendar) value;
Date date = null;
if (calendar != null) {
date = asDate(calendar);
}
HIBERNATE_TYPE.nullSafeSet(st, date, index, session);
}
use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.
the class TestNotifications method test100ModifyUserAddAccount.
@Test
public void test100ModifyUserAddAccount() throws Exception {
final String TEST_NAME = "test100ModifyUserAddAccount";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestNotifications.class.getName() + ".test100ModifyUserAddAccount");
task.setChannel(SchemaConstants.CHANNEL_GUI_USER_URI);
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
// WHEN
TestUtil.displayWhen(TEST_NAME);
modifyUserAddAccount(USER_JACK_OID, ACCOUNT_JACK_DUMMY_FILE, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
assertShadowFetchOperationCountIncrement(0);
// Check accountRef
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
assertUserJack(userJack);
UserType userJackType = userJack.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userJackType.getLinkRef().size());
ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0);
accountJackOid = accountRefType.getOid();
assertFalse("No accountRef oid", StringUtils.isBlank(accountJackOid));
PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
assertEquals("OID mismatch in accountRefValue", accountJackOid, accountRefValue.getOid());
assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountJackOid, "jack");
assertEnableTimestampShadow(accountShadow, startTime, endTime);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountJackOid, "jack", "Jack Sparrow");
// Check account in dummy resource
assertDefaultDummyAccount("jack", "Jack Sparrow", true);
assertDummyScriptsAdd(userJack, accountModel, getDummyResourceType());
notificationManager.setDisabled(true);
// Check notifications
display("Dummy transport messages", dummyTransport);
checkDummyTransportMessages("accountPasswordNotifier", 1);
checkDummyTransportMessages("userPasswordNotifier", 0);
checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 1);
checkDummyTransportMessages("simpleUserNotifier", 0);
checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
List<Message> pwdMessages = dummyTransport.getMessages("dummy:accountPasswordNotifier");
// number of messages was already checked
Message pwdMessage = pwdMessages.get(0);
assertEquals("Invalid list of recipients", Collections.singletonList("recipient@evolveum.com"), pwdMessage.getTo());
assertEquals("Wrong message body", "Password for account jack on Dummy Resource is: deadmentellnotales", pwdMessage.getBody());
List<Message> addMessages = dummyTransport.getMessages("dummy:simpleAccountNotifier-ADD-SUCCESS");
// number of messages was already checked
Message addMessage = addMessages.get(0);
assertEquals("Invalid list of recipients", Collections.singletonList("recipient@evolveum.com"), addMessage.getTo());
assertEquals("Wrong message body", "Notification about account-related operation\n" + "\n" + "Owner: Jack Sparrow (jack, oid c0c010c0-d34d-b33f-f00d-111111111111)\n" + "Resource: Dummy Resource (oid 10000000-0000-0000-0000-000000000004)\n" + "\n" + "An account has been successfully created on the resource with attributes:\n" + " - UID: jack\n" + " - Username: jack\n" + " - Location: Caribbean\n" + " - Quote: Arr!\n" + " - Drink: rum\n" + " - Weapon: rum\n" + " - Full Name: Jack Sparrow\n" + " - Password:\n" + " - value: (protected string)\n" + " - Administrative status: ENABLED\n" + "\n" + "Channel: http://midpoint.evolveum.com/xml/ns/public/gui/channels-3#user", addMessage.getBody());
assertSteadyResources();
}
Aggregations