Search in sources :

Example 1 with ObjectTypeNameMatcher

use of com.evolveum.midpoint.model.impl.util.ObjectTypeNameMatcher in project midpoint by Evolveum.

the class ControllerAddObjectTest method addResourceCorrect.

//	@Test
@SuppressWarnings("unchecked")
public void addResourceCorrect() throws JAXBException, FaultMessage, ObjectAlreadyExistsException, SchemaException, CommunicationException, ObjectNotFoundException, ExpressionEvaluationException, IOException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    TestUtil.displayTestTile("addResourceCorrect");
    Task task = taskManager.createTaskInstance();
    final PrismObject<ResourceType> expectedResource = PrismTestUtil.parseObject(new File(TEST_FOLDER, "add-resource-correct.xml"));
    final ResourceType expectedResourceType = expectedResource.asObjectable();
    AssertJUnit.assertNotNull("resource to add must not be null", expectedResource);
    final String oid = "abababab-abab-abab-abab-000000000002";
    when(provisioning.addObject(argThat(new ObjectTypeNameMatcher(expectedResourceType.getName())), any(OperationProvisioningScriptsType.class), any(ProvisioningOperationOptions.class), any(Task.class), any(OperationResult.class))).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            PrismObject<ResourceType> resource = (PrismObject<ResourceType>) invocation.getArguments()[0];
            PrismAsserts.assertEquivalent("Wrong argument to addObject", expectedResource, resource);
            return oid;
        }
    });
    OperationResult result = new OperationResult("Test Operation");
    try {
        String resourceOid = controller.addObject(expectedResource, null, task, result);
        assertEquals(oid, resourceOid);
    } finally {
        LOGGER.debug(result.debugDump());
        verify(provisioning, times(1)).addObject(argThat(new ObjectTypeNameMatcher(expectedResourceType.getName())), any(OperationProvisioningScriptsType.class), any(ProvisioningOperationOptions.class), any(Task.class), any(OperationResult.class));
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) OperationProvisioningScriptsType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationProvisioningScriptsType) ObjectTypeNameMatcher(com.evolveum.midpoint.model.impl.util.ObjectTypeNameMatcher) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File)

Example 2 with ObjectTypeNameMatcher

use of com.evolveum.midpoint.model.impl.util.ObjectTypeNameMatcher in project midpoint by Evolveum.

the class ControllerAddObjectTest method addUserCorrect.

/**
	 * Testing add user with undefined user template
	 */
//	@Test
@SuppressWarnings("unchecked")
public void addUserCorrect() throws Exception {
    TestUtil.displayTestTile("addUserCorrect");
    // GIVEN
    Task task = taskManager.createTaskInstance();
    ModelTUtil.mockGetSystemConfiguration(repository, new File(TEST_FOLDER_COMMON, "system-configuration.xml"));
    final PrismObject<UserType> expectedUser = PrismTestUtil.parseObject(new File(TEST_FOLDER, "add-user-correct.xml"));
    final UserType expectedUserType = expectedUser.asObjectable();
    final String oid = "abababab-abab-abab-abab-000000000001";
    when(repository.addObject(argThat(new ObjectTypeNameMatcher(expectedUserType.getName())), any(RepoAddOptions.class), any(OperationResult.class))).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            PrismObject<UserType> user = (PrismObject<UserType>) invocation.getArguments()[0];
            IntegrationTestTools.display("Got user", user);
            PrismAsserts.assertEquivalent("Unexpected argument to addObject", expectedUser, user);
            return oid;
        }
    });
    OperationResult result = new OperationResult("Test Operation");
    // WHEN
    String userOid = controller.addObject(expectedUser, null, task, result);
    // THEN
    display("addObject result", result.debugDump());
    verify(repository, times(1)).addObject(argThat(new ObjectTypeNameMatcher(expectedUserType.getName())), any(RepoAddOptions.class), any(OperationResult.class));
    assertEquals(oid, userOid);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectTypeNameMatcher(com.evolveum.midpoint.model.impl.util.ObjectTypeNameMatcher) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RepoAddOptions(com.evolveum.midpoint.repo.api.RepoAddOptions) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

ObjectTypeNameMatcher (com.evolveum.midpoint.model.impl.util.ObjectTypeNameMatcher)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 File (java.io.File)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ProvisioningOperationOptions (com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions)1 RepoAddOptions (com.evolveum.midpoint.repo.api.RepoAddOptions)1 OperationProvisioningScriptsType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationProvisioningScriptsType)1 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1