@Test public void test020GetResourceBroken() throws Exception { TestUtil.displayTestTile(this, "test020GetResourceBroken"); // GIVEN Task task = taskManager.createTaskInstance( TestModelServiceContract.class.getName() + ".test020GetResourceBroken"); OperationResult result = task.getResult(); // WHEN PrismObject<ResourceType> resource = modelService.getObject(ResourceType.class, RESOURCE_CSVFILE_BROKEN_OID, null, task, result); // THEN display("getObject resource", resource); result.computeStatus(); display("getObject result", result); TestUtil.assertSuccess("getObject result", result); OperationResultType fetchResult = resource.asObjectable().getFetchResult(); TestUtil.assertSuccess("resource.fetchResult", fetchResult); // TODO: better asserts assertNotNull("Null resource", resource); }
@Test public void test380DisableJackInBackgroundSimple() throws Exception { final String TEST_NAME = "test380DisableJackInBackgroundSimple"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); // WHEN Task task = taskManager.createTaskInstance(); task.setOwner(getUser(USER_ADMINISTRATOR_OID)); scriptingExpressionEvaluator.evaluateExpressionInBackground( UserType.COMPLEX_TYPE, ObjectQueryUtil.createOrigNameQuery("jack", prismContext).getFilter(), "disable", task, result); waitForTaskFinish(task.getOid(), false); task.refresh(result); // THEN IntegrationTestTools.display(task.getResult()); TestUtil.assertSuccess(task.getResult()); PrismObject<UserType> jack = getUser(USER_JACK_OID); IntegrationTestTools.display("jack after disable script", jack); assertAdministrativeStatusDisabled(jack); }
@Test public void test340ModifyJackBack() throws Exception { final String TEST_NAME = "test340ModifyJackBack"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<ScriptingExpressionType> expression = parseAnyData(MODIFY_JACK_BACK_FILE); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression( expression.getAnyValue().getValue(), result); // THEN assertNoOutputData(output); IntegrationTestTools.display("stdout", output.getConsoleOutput()); IntegrationTestTools.display(result); result.computeStatus(); TestUtil.assertSuccess(result); assertEquals( "Modified user:c0c010c0-d34d-b33f-f00d-111111111111(jack)\n", output.getConsoleOutput()); assertEquals( "Caribbean", searchObjectByName(UserType.class, "jack").asObjectable().getLocality().getOrig()); }
@Override protected void assertStepSyncToken(String syncTaskOid, int step, long tsStart, long tsEnd) throws ObjectNotFoundException, SchemaException { OperationResult result = new OperationResult(AbstractIntegrationTest.class.getName() + ".assertSyncToken"); Task task = taskManager.getTask(syncTaskOid, result); result.computeStatus(); TestUtil.assertSuccess(result); PrismProperty<String> syncTokenProperty = task.getExtensionProperty(SchemaConstants.SYNC_TOKEN); assertNotNull("No sync token in " + task, syncTokenProperty); String syncToken = syncTokenProperty.getRealValue(); assertNotNull("No sync token in " + task, syncToken); IntegrationTestTools.display("Sync token", syncToken); GeneralizedTime syncTokenGt; try { syncTokenGt = new GeneralizedTime(syncToken); } catch (ParseException e) { throw new RuntimeException(e.getMessage(), e); } TestUtil.assertBetween( "Wrong time in sync token: " + syncToken, roundTsDown(tsStart), roundTsUp(tsEnd), syncTokenGt.getCalendar().getTimeInMillis()); }
@Test public void test410TestResource() throws Exception { final String TEST_NAME = "test410TestResource"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<ScriptingExpressionType> expression = parseAnyData(TEST_DUMMY_RESOURCE_FILE); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression( expression.getAnyValue().getValue(), result); // THEN IntegrationTestTools.display("output", output.getFinalOutput()); IntegrationTestTools.display("stdout", output.getConsoleOutput()); ResourceType dummy = modelService .getObject( ResourceType.class, RESOURCE_DUMMY_OID, null, taskManager.createTaskInstance(), result) .asObjectable(); IntegrationTestTools.display("dummy resource after test connection", dummy.asPrismObject()); IntegrationTestTools.display(result); result.computeStatus(); TestUtil.assertSuccess(result); assertEquals(1, output.getFinalOutput().getData().size()); assertEquals( "Tested resource:10000000-0000-0000-0000-000000000004(Dummy Resource): SUCCESS\n", output.getConsoleOutput()); }
@Test public void test420NotificationAboutJack() throws Exception { final String TEST_NAME = "test420NotificationAboutJack"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<ScriptingExpressionType> expression = parseAnyData(NOTIFICATION_ABOUT_JACK_FILE); prepareNotifications(); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression( expression.getAnyValue().getValue(), result); // THEN IntegrationTestTools.display("output", output.getFinalOutput()); IntegrationTestTools.display("stdout", output.getConsoleOutput()); result.computeStatus(); TestUtil.assertSuccess(result); assertEquals(0, output.getFinalOutput().getData().size()); assertEquals("Produced 1 event(s)\n", output.getConsoleOutput()); IntegrationTestTools.display("Dummy transport", dummyTransport); checkDummyTransportMessages("Custom", 1); Message m = dummyTransport.getMessages("dummy:Custom").get(0); assertEquals("Wrong message body", "jack/" + USER_JACK_OID, m.getBody()); assertEquals("Wrong message subject", "Ad hoc notification", m.getSubject()); }
protected void setDefaultUserTemplate(String userTemplateOid) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { PrismObjectDefinition<SystemConfigurationType> objectDefinition = prismContext .getSchemaRegistry() .findObjectDefinitionByCompileTimeClass(SystemConfigurationType.class); Collection<? extends ItemDelta> modifications; if (userTemplateOid == null) { modifications = ReferenceDelta.createModificationReplaceCollection( SystemConfigurationType.F_DEFAULT_USER_TEMPLATE_REF, objectDefinition, null); } else { PrismReferenceValue userTemplateRefVal = new PrismReferenceValue(userTemplateOid); modifications = ReferenceDelta.createModificationReplaceCollection( SystemConfigurationType.F_DEFAULT_USER_TEMPLATE_REF, objectDefinition, userTemplateRefVal); } OperationResult result = new OperationResult("Aplying default user template"); repositoryService.modifyObject( SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), modifications, result); display("Aplying default user template result", result); result.computeStatus(); TestUtil.assertSuccess("Aplying default user template failed (result)", result); }
@Test public void test102GetAccountMurrayRaw() throws Exception { TestUtil.displayTestTile(this, "test102GetAccountMurrayRaw"); // GIVEN Task task = taskManager.createTaskInstance( TestModelServiceContract.class.getName() + ".test102GetAccountMurrayRaw"); OperationResult result = task.getResult(); Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw()); // WHEN PrismObject<ShadowType> account = modelService.getObject( ShadowType.class, ACCOUNT_SHADOW_MURRAY_CSVFILE_OID, options, task, result); display("getObject account", account); result.computeStatus(); display("getObject result", result); TestUtil.assertSuccess("getObject result", result); // TODO: better asserts assertNotNull("Null resource", account); }
@Test public void test360AssignToJack() throws Exception { final String TEST_NAME = "test360AssignToJack"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<ScriptingExpressionType> expression = parseAnyData(ASSIGN_TO_JACK_FILE); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression( expression.getAnyValue().getValue(), result); // THEN assertNoOutputData(output); IntegrationTestTools.display("stdout", output.getConsoleOutput()); IntegrationTestTools.display(result); result.computeStatus(); TestUtil.assertSuccess(result); // assertEquals("Recomputed user:c0c010c0-d34d-b33f-f00d-111111111111(jack)\n", // output.getConsoleOutput()); PrismObject<UserType> jack = getUser(USER_JACK_OID); IntegrationTestTools.display("jack after assignments creation", jack); assertAssignedAccount(jack, "10000000-0000-0000-0000-000000000104"); assertAssignedRole(jack, "12345678-d34d-b33f-f00d-55555555cccc"); }
protected void assertMonkeyIslandOrgSanity(int expectedFictional) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException { Task task = taskManager.createTaskInstance( AbstractInitializedModelIntegrationTest.class.getName() + ".assertMonkeyIslandOrgSanity"); OperationResult result = task.getResult(); PrismObject<OrgType> orgGovernorOffice = modelService.getObject(OrgType.class, ORG_GOVERNOR_OFFICE_OID, null, task, result); result.computeStatus(); TestUtil.assertSuccess(result); OrgType orgGovernorOfficeType = orgGovernorOffice.asObjectable(); assertEquals( "Wrong governor office name", PrismTestUtil.createPolyStringType("F0001"), orgGovernorOfficeType.getName()); List<PrismObject<OrgType>> governorSubOrgs = searchOrg(ORG_GOVERNOR_OFFICE_OID, OrgFilter.Scope.ONE_LEVEL, task, result); if (verbose) display("governor suborgs", governorSubOrgs); assertEquals("Unexpected number of governor suborgs", 3, governorSubOrgs.size()); List<PrismObject<OrgType>> functionalOrgs = searchOrg(ORG_GOVERNOR_OFFICE_OID, OrgFilter.Scope.SUBTREE, task, result); if (verbose) display("functional orgs (null)", functionalOrgs); assertEquals( "Unexpected number of functional orgs (null)", NUM_FUNCTIONAL_ORGS - 1 + expectedFictional, functionalOrgs.size()); List<PrismObject<OrgType>> prootSubOrgs = searchOrg(ORG_PROJECT_ROOT_OID, OrgFilter.Scope.ONE_LEVEL, task, result); if (verbose) display("project root suborgs", prootSubOrgs); assertEquals("Unexpected number of governor suborgs", 2, prootSubOrgs.size()); List<PrismObject<OrgType>> projectOrgs = searchOrg(ORG_PROJECT_ROOT_OID, OrgFilter.Scope.SUBTREE, task, result); if (verbose) display("project orgs (null)", projectOrgs); assertEquals( "Unexpected number of functional orgs (null)", NUM_PROJECT_ORGS - 1, projectOrgs.size()); PrismObject<OrgType> orgScummBar = modelService.getObject(OrgType.class, ORG_SCUMM_BAR_OID, null, task, result); List<AssignmentType> scummBarInducements = orgScummBar.asObjectable().getInducement(); assertEquals( "Unexpected number of scumm bar inducements: " + scummBarInducements, 1, scummBarInducements.size()); ResultHandler<OrgType> handler = getOrgSanityCheckHandler(); if (handler != null) { modelService.searchObjectsIterative(OrgType.class, null, handler, null, task, result); } }
@Test public void test400PurgeSchema() throws Exception { final String TEST_NAME = "test400PurgeSchema"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); Task task = taskManager.createTaskInstance(); PrismProperty<ScriptingExpressionType> expression = parseAnyData(PURGE_DUMMY_BLACK_SCHEMA_FILE); // ResourceType dummy = modelService.getObject(ResourceType.class, // RESOURCE_DUMMY_BLACK_OID, null, task, result).asObjectable(); // IntegrationTestTools.display("dummy resource before purge schema", // dummy.asPrismObject()); // IntegrationTestTools.display("elements: " + // dummy.getSchema().getDefinition().getAny().get(0).getElementsByTagName("*").getLength()); // IntegrationTestTools.display("schema as XML: " + // DOMUtil.printDom(dummy.getSchema().getDefinition().getAny().get(0))); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression( expression.getAnyValue().getValue(), result); // THEN IntegrationTestTools.display("output", output.getFinalOutput()); IntegrationTestTools.display("stdout", output.getConsoleOutput()); IntegrationTestTools.display(result); result.computeStatus(); TestUtil.assertSuccess(result); assertEquals(1, output.getFinalOutput().getData().size()); // dummy = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_BLACK_OID, // null, result).asObjectable(); // IntegrationTestTools.display("dummy resource from repo", dummy.asPrismObject()); // IntegrationTestTools.display("elements: " + // dummy.getSchema().getDefinition().getAny().get(0).getElementsByTagName("*").getLength()); // IntegrationTestTools.display("schema as XML: " + // DOMUtil.printDom(dummy.getSchema().getDefinition().getAny().get(0))); // AssertJUnit.assertNull("Schema is still present", dummy.getSchema()); // actually, schema gets downloaded just after purging it assertEquals( "Purged schema information from resource:10000000-0000-0000-0000-000000000305(Dummy Resource Black)\n", output.getConsoleOutput()); }
@Test public void test010TestResourceBroken() throws Exception { TestUtil.displayTestTile(this, "test010TestResourceBroken"); // GIVEN Task task = taskManager.createTaskInstance( TestModelServiceContract.class.getName() + ".test010TestResourceBroken"); OperationResult result = task.getResult(); // WHEN OperationResult testResult = modelService.testResource(RESOURCE_CSVFILE_BROKEN_OID, task); // THEN display("testResource result", testResult); TestUtil.assertSuccess("testResource result", testResult); }
@Test public void test110EmptyPipeline() throws Exception { final String TEST_NAME = "test110EmptyPipeline"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); ExpressionPipelineType pipeline = new ExpressionPipelineType(); ObjectFactory of = new ObjectFactory(); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(pipeline, result); // THEN assertNoOutputData(output); result.computeStatus(); TestUtil.assertSuccess(result); }
@Test public void testCapabilities() throws Exception { TestUtil.displayTestTile("testCapabilities"); // GIVEN OperationResult result = new OperationResult("testCapabilities"); // WHEN Collection<Object> capabilities = cc.fetchCapabilities(result); // THEN result.computeStatus("getCapabilities failed"); TestUtil.assertSuccess("getCapabilities failed (result)", result); assertFalse("Empty capabilities returned", capabilities.isEmpty()); CredentialsCapabilityType capCred = CapabilityUtil.getCapability(capabilities, CredentialsCapabilityType.class); assertNotNull("password capability not present", capCred.getPassword()); }
@Test public void test206SearchForRoles() throws Exception { final String TEST_NAME = "test206SearchForRoles"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<SearchExpressionType> expression = parseAnyData(SEARCH_FOR_ROLES_FILE); // WHEN Data output = scriptingExpressionEvaluator .evaluateExpression(expression.getAnyValue().getValue(), result) .getFinalOutput(); // THEN IntegrationTestTools.display("output", output.getData()); result.computeStatus(); TestUtil.assertSuccess(result); // assertEquals(9, output.getData().size()); }
@Test public void test500ScriptingUsers() throws Exception { final String TEST_NAME = "test500ScriptingUsers"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<ScriptingExpressionType> expression = parseAnyData(SCRIPTING_USERS_FILE); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression( expression.getAnyValue().getValue(), result); // THEN TestUtil.assertSuccess(result); Data data = output.getFinalOutput(); assertEquals("Unexpected # of items in output", 5, data.getData().size()); Set<String> realOids = new HashSet<>(); for (PrismValue value : data.getData()) { PrismObject<UserType> user = ((PrismObjectValue<UserType>) value).asPrismObject(); assertEquals("Description not set", "Test", user.asObjectable().getDescription()); realOids.add(user.getOid()); } assertEquals( "Unexpected OIDs in output", Sets.newHashSet( Arrays.asList( USER_ADMINISTRATOR_OID, USER_JACK_OID, USER_BARBOSSA_OID, USER_GUYBRUSH_OID, USER_ELAINE_OID)), realOids); IntegrationTestTools.display("stdout", output.getConsoleOutput()); IntegrationTestTools.display(result); result.computeStatus(); }
@Test public void test225SearchForUsersAccountsNoFetch() throws Exception { final String TEST_NAME = "test225SearchForUsersAccountsNoFetch"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<SearchExpressionType> expression = parseAnyData(SEARCH_FOR_USERS_ACCOUNTS_NOFETCH_FILE); // WHEN Data output = scriptingExpressionEvaluator .evaluateExpression(expression.getAnyValue().getValue(), result) .getFinalOutput(); // THEN IntegrationTestTools.display("output", output.getData()); result.computeStatus(); TestUtil.assertSuccess(result); assertEquals(4, output.getData().size()); assertAttributesNotFetched(output.getData()); }
@Test public void test200SearchUser() throws Exception { final String TEST_NAME = "test200SearchUser"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<SearchExpressionType> expression = parseAnyData(SEARCH_FOR_USERS_FILE); // WHEN Data output = scriptingExpressionEvaluator .evaluateExpression(expression.getAnyValue().getValue(), result) .getFinalOutput(); // THEN IntegrationTestTools.display("output", output.getData()); result.computeStatus(); TestUtil.assertSuccess(result); assertEquals(2, output.getData().size()); // assertEquals("administrator", ((PrismObject<UserType>) // output.getData().get(0)).asObjectable().getName().getOrig()); }
@Test public void test350RecomputeJack() throws Exception { final String TEST_NAME = "test350RecomputeJack"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<ScriptingExpressionType> expression = parseAnyData(RECOMPUTE_JACK_FILE); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression( expression.getAnyValue().getValue(), result); // THEN assertNoOutputData(output); IntegrationTestTools.display("stdout", output.getConsoleOutput()); IntegrationTestTools.display(result); result.computeStatus(); TestUtil.assertSuccess(result); assertEquals( "Recomputed user:c0c010c0-d34d-b33f-f00d-111111111111(jack)\n", output.getConsoleOutput()); }
@Test public void test120Log() throws Exception { final String TEST_NAME = "test120Log"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<ScriptingExpressionType> logAction = parseAnyData(LOG_FILE); LogfileTestTailer tailer = new LogfileTestTailer(LoggingConfigurationManager.AUDIT_LOGGER_NAME); tailer.tail(); tailer.setExpecteMessage("Custom message:"); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(logAction.getAnyValue().getValue(), result); // THEN assertNoOutputData(output); result.computeStatus(); TestUtil.assertSuccess(result); tailer.tail(); tailer.assertExpectedMessage(); }
@Test public void test320DeleteAndAddJack() throws Exception { final String TEST_NAME = "test320DeleteAndAddJack"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<ScriptingExpressionType> expression = parseAnyData(DELETE_AND_ADD_JACK_FILE); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression( expression.getAnyValue().getValue(), result); // THEN assertNoOutputData(output); IntegrationTestTools.display("stdout", output.getConsoleOutput()); result.computeStatus(); TestUtil.assertSuccess(result); assertEquals( "Deleted user:c0c010c0-d34d-b33f-f00d-111111111111(jack)\nAdded user:c0c010c0-d34d-b33f-f00d-111111111111(jack)\n", output.getConsoleOutput()); assertAdministrativeStatusEnabled(searchObjectByName(UserType.class, "jack")); }
@Test public void test370AssignToJackInBackground() throws Exception { final String TEST_NAME = "test370AssignToJackInBackground"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME); PrismProperty<ScriptingExpressionType> expression = parseAnyData(ASSIGN_TO_JACK_2_FILE); // WHEN Task task = taskManager.createTaskInstance(); task.setOwner(getUser(USER_ADMINISTRATOR_OID)); scriptingExpressionEvaluator.evaluateExpressionInBackground( expression.getAnyValue().getValue(), task, result); waitForTaskFinish(task.getOid(), false); task.refresh(result); // THEN IntegrationTestTools.display(task.getResult()); TestUtil.assertSuccess(task.getResult()); PrismObject<UserType> jack = getUser(USER_JACK_OID); IntegrationTestTools.display("jack after assignment creation", jack); assertAssignedRole(jack, "12345678-d34d-b33f-f00d-555555556677"); }