use of com.evolveum.midpoint.xml.ns._public.common.common_3.ImportOptionsType in project midpoint by Evolveum.
the class MiscSchemaUtil method getDefaultImportOptions.
public static ImportOptionsType getDefaultImportOptions() {
ImportOptionsType options = new ImportOptionsType();
options.setOverwrite(false);
options.setValidateStaticSchema(false);
options.setValidateDynamicSchema(false);
options.setEncryptProtectedValues(true);
options.setFetchResourceSchema(false);
options.setSummarizeErrors(true);
options.setSummarizeSucceses(true);
return options;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ImportOptionsType in project midpoint by Evolveum.
the class ImportTest method test005ImportUsersWithOverwrite.
// Import the same thing again, this time with overwrite option. This should go well.
@Test
public void test005ImportUsersWithOverwrite() throws Exception {
TestUtil.displayTestTile(this, "test005ImportUsersWithOverwrite");
// GIVEN
Task task = taskManager.createTaskInstance();
OperationResult result = new OperationResult(ImportTest.class.getName() + "test005ImportUsersWithOverwrite");
FileInputStream stream = new FileInputStream(IMPORT_USERS_OVERWRITE_FILE);
ImportOptionsType options = getDefaultImportOptions();
options.setOverwrite(true);
dummyAuditService.clear();
// WHEN
modelService.importObjectsFromStream(stream, options, task, result);
// THEN
result.computeStatus();
display("Result after import with overwrite", result);
TestUtil.assertSuccess("Import failed (result)", result, 2);
// list all users
List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, new ObjectQuery(), null, task, result);
// Three old users, one new
assertEquals(5, users.size());
for (PrismObject<UserType> user : users) {
UserType userType = user.asObjectable();
if (userType.getName().equals("jack")) {
// OID and all the attributes should be the same
assertEquals(USER_JACK_OID, userType.getOid());
PrismAsserts.assertEqualsPolyString("wrong givenName", "Jack", userType.getGivenName());
PrismAsserts.assertEqualsPolyString("wrong familyName", "Sparrow", userType.getFamilyName());
PrismAsserts.assertEqualsPolyString("wrong fullName", "Cpt. Jack Sparrow", userType.getFullName());
}
if (userType.getName().equals("will")) {
// OID should be the same, and there should be an employee type
assertEquals(USER_WILL_OID, userType.getOid());
assertTrue("Wrong Will's employee type", userType.getEmployeeType().contains("legendary"));
}
if (userType.getName().equals("guybrush")) {
// OID may be different, there should be a locality attribute
guybrushOid = userType.getOid();
assertNotNull(guybrushOid);
PrismAsserts.assertEqualsPolyString("Guybrush is not in the Caribbean", "Deep in the Caribbean", userType.getLocality());
}
if (userType.getName().equals("ht")) {
// Herman should be here now
hermanOid = userType.getOid();
assertNotNull(hermanOid);
PrismAsserts.assertEqualsPolyString("Herman is confused", "Herman Toothrot", userType.getFullName());
PrismAsserts.assertEqualsPolyString("Herman is confused", "Herman", userType.getGivenName());
PrismAsserts.assertEqualsPolyString("Herman is confused", "Toothrot", userType.getFamilyName());
}
}
assertUsers(5);
// Check audit
display("Audit", dummyAuditService);
// 1 failed, 7 succeeded
dummyAuditService.assertRecords(8);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ImportOptionsType in project midpoint by Evolveum.
the class ImportTest method test031ReimportResource.
@Test
public void test031ReimportResource() throws Exception {
final String TEST_NAME = "test031ReimportResource";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(ImportTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
FileInputStream stream = new FileInputStream(RESOURCE_DUMMY_CHANGED_FILE);
ImportOptionsType options = getDefaultImportOptions();
options.setOverwrite(true);
IntegrationTestTools.assertNoRepoCache();
dummyAuditService.clear();
// WHEN
modelService.importObjectsFromStream(stream, options, task, result);
// THEN
result.computeStatus();
display("Result after import", result);
TestUtil.assertSuccess("Import of " + RESOURCE_DUMMY_CHANGED_FILE + " has failed (result)", result, 2);
IntegrationTestTools.assertNoRepoCache();
PrismObject<ResourceType> repoResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
display("Reimported resource (repo)", repoResource);
assertDummyResource(repoResource, true);
IntegrationTestTools.assertNoRepoCache();
MidPointAsserts.assertVersionIncrease(importedRepoResource, repoResource);
PrismObject<ResourceType> resource = modelService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, task, result);
display("Reimported resource (model)", resource);
IntegrationTestTools.assertNoRepoCache();
assertDummyResource(resource, false);
MidPointAsserts.assertVersionIncrease(importedResource, resource);
ResourceType resourceType = resource.asObjectable();
assertNull("Synchronization not gone", resourceType.getSynchronization());
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(1);
dummyAuditService.assertHasDelta(ChangeType.ADD, ResourceType.class);
dummyAuditService.assertExecutionSuccess();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ImportOptionsType in project midpoint by Evolveum.
the class PostInitialDataImport method importObject.
/**
* @return true if it was success, otherwise false
*/
private boolean importObject(File file, Task task, OperationResult mainResult) {
OperationResult result = mainResult.createSubresult(OPERATION_IMPORT_OBJECT);
try {
LOGGER.info("Starting post-initial import of file {}.", file.getName());
ImportOptionsType options = new ImportOptionsType();
options.overwrite(true);
options.setModelExecutionOptions(new ModelExecuteOptionsType(prismContext).raw(false));
model.importObjectsFromFile(file, options, task, result);
result.recordSuccess();
return true;
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import object from file {}: ", e, file.getName(), e.getMessage());
result.recordFatalError(e);
LOGGER.info("\n{}", result.debugDump());
return false;
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ImportOptionsType in project midpoint by Evolveum.
the class ImportTest method test040ImportUserHermanNoEncryption.
@Test
public void test040ImportUserHermanNoEncryption() throws Exception {
final String TEST_NAME = "test040ImportUserHermanNoEncryption";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
InternalsConfig.readEncryptionChecks = false;
Task task = taskManager.createTaskInstance();
OperationResult result = new OperationResult(ImportTest.class.getName() + "." + TEST_NAME);
FileInputStream stream = new FileInputStream(USER_HERMAN_FILE);
ImportOptionsType importOptions = getDefaultImportOptions();
importOptions.setEncryptProtectedValues(false);
dummyAuditService.clear();
// WHEN
modelService.importObjectsFromStream(stream, importOptions, task, result);
// THEN
result.computeStatus();
display("Result after good import", result);
TestUtil.assertSuccess("Import has failed (result)", result);
// Check import with fixed OID
PrismObject<UserType> userHerman = getUser(USER_HERMAN_OID);
display("Herman", userHerman);
assertUser(userHerman, USER_HERMAN_OID, USER_HERMAN_USERNAME, "Herman Toothrot", "Herman", "Toothrot");
// Check if the password was NOT encrypted
ProtectedStringType protectedString = userHerman.asObjectable().getCredentials().getPassword().getValue();
assertEquals("Er? Pirate sectrets still hidden?", "m0nk3y", protectedString.getClearValue());
assertNull("Er? Encrypted data together with clear value?", protectedString.getEncryptedDataType());
assertUsers(6);
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(1);
dummyAuditService.assertHasDelta(ChangeType.ADD, UserType.class);
dummyAuditService.assertExecutionSuccess();
}
Aggregations