Search in sources :

Example 1 with ObjectAlreadyExistsFaultType

use of com.evolveum.midpoint.xml.ns._public.common.fault_3.ObjectAlreadyExistsFaultType in project midpoint by Evolveum.

the class TestSanityLegacy method test006reimportResourceDummy.

@Test
public void test006reimportResourceDummy() throws Exception {
    TestUtil.displayTestTile("test006reimportResourceDummy");
    //get object from repo (with version set and try to add it - it should be re-added, without error)
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<ResourceType> resource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, repoResult);
    assertNotNull(resource);
    ModelExecuteOptionsType options = new ModelExecuteOptionsType();
    options.setOverwrite(Boolean.TRUE);
    options.setIsImport(Boolean.TRUE);
    addObjectViaModelWS(resource.asObjectable(), options, new Holder<String>(), new Holder<OperationResultType>());
    //TODO: add some asserts
    //parse object from file again and try to add it - this should fail, becasue the same object already exists)
    resource = PrismTestUtil.parseObject(new File(RESOURCE_DUMMY_FILENAME));
    try {
        Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
        options = new ModelExecuteOptionsType();
        options.setIsImport(Boolean.TRUE);
        addObjectViaModelWS(resource.asObjectable(), options, new Holder<String>(), resultHolder);
        OperationResultType result = resultHolder.value;
        TestUtil.assertFailure(result);
        fail("Expected object already exists exception, but haven't got one.");
    } catch (FaultMessage ex) {
        LOGGER.info("fault {}", ex.getFaultInfo());
        LOGGER.info("fault {}", ex.getCause());
        if (ex.getFaultInfo() instanceof ObjectAlreadyExistsFaultType) {
        // this is OK, we expect this
        } else {
            fail("Expected object already exists exception, but haven't got one.");
        }
    }
//         ResourceType resourceType = uObject.asObjectable();
//         assertNotNull("Reference on the connector must not be null in resource.",resourceType.getConnectorRef());
//         assertNotNull("Missing oid reference on the connector",resourceType.getConnectorRef().getOid());
}
Also used : FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) ModelExecuteOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectAlreadyExistsFaultType(com.evolveum.midpoint.xml.ns._public.common.fault_3.ObjectAlreadyExistsFaultType) File(java.io.File) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 2 with ObjectAlreadyExistsFaultType

use of com.evolveum.midpoint.xml.ns._public.common.fault_3.ObjectAlreadyExistsFaultType in project midpoint by Evolveum.

the class TestSanity method test006reimportResourceDummy.

@Test
public void test006reimportResourceDummy() throws Exception {
    TestUtil.displayTestTile("test006reimportResourceDummy");
    //get object from repo (with version set and try to add it - it should be re-added, without error)
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<ResourceType> resource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, repoResult);
    assertNotNull(resource);
    ModelExecuteOptionsType options = new ModelExecuteOptionsType();
    options.setOverwrite(Boolean.TRUE);
    options.setIsImport(Boolean.TRUE);
    addObjectViaModelWS(resource.asObjectable(), options, new Holder<String>(), new Holder<OperationResultType>());
    //TODO: add some asserts
    //parse object from file again and try to add it - this should fail, becasue the same object already exists)
    resource = PrismTestUtil.parseObject(new File(RESOURCE_DUMMY_FILENAME));
    try {
        Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
        options = new ModelExecuteOptionsType();
        options.setIsImport(Boolean.TRUE);
        addObjectViaModelWS(resource.asObjectable(), options, new Holder<String>(), resultHolder);
        OperationResultType result = resultHolder.value;
        TestUtil.assertFailure(result);
        fail("Expected object already exists exception, but haven't got one.");
    } catch (FaultMessage ex) {
        LOGGER.info("fault {}", ex.getFaultInfo());
        LOGGER.info("fault {}", ex.getCause());
        if (ex.getFaultInfo() instanceof ObjectAlreadyExistsFaultType) {
        // this is OK, we expect this
        } else {
            fail("Expected object already exists exception, but haven't got one.");
        }
    }
//         ResourceType resourceType = uObject.asObjectable();
//         assertNotNull("Reference on the connector must not be null in resource.",resourceType.getConnectorRef());
//         assertNotNull("Missing oid reference on the connector",resourceType.getConnectorRef().getOid());
}
Also used : FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) ModelExecuteOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectAlreadyExistsFaultType(com.evolveum.midpoint.xml.ns._public.common.fault_3.ObjectAlreadyExistsFaultType) File(java.io.File) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Aggregations

AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)2 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 ModelExecuteOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType)2 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)2 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)2 FaultMessage (com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage)2 ObjectAlreadyExistsFaultType (com.evolveum.midpoint.xml.ns._public.common.fault_3.ObjectAlreadyExistsFaultType)2 File (java.io.File)2 Holder (javax.xml.ws.Holder)2 Test (org.testng.annotations.Test)2