Skip to content

Commit

Permalink
More progress on conntests
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed May 28, 2015
1 parent f977d8d commit 1eca645
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 48 deletions.
Expand Up @@ -134,45 +134,12 @@ public TaskRunResult run(Task task) {
return runResult;
}


// ResourceType resource = null;
// try {
//
// resource = task.getObject(ResourceType.class, opResult).asObjectable();
//
// } catch (ObjectNotFoundException ex) {
// String resourceOid = null;
// if (task.getObjectRef() != null) {
// resourceOid = task.getObjectRef().getOid();
// }
// LOGGER.error("Import: Resource not found: {}", resourceOid, ex);
// // This is bad. The resource does not exist. Permanent problem.
// opResult.recordFatalError("Resource not found " + resourceOid, ex);
// runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
// return runResult;
// } catch (SchemaException ex) {
// LOGGER.error("Import: Error dealing with schema: {}", ex.getMessage(), ex);
// // Not sure about this. But most likely it is a misconfigured resource or connector
// // It may be worth to retry. Error is fatal, but may not be permanent.
// opResult.recordFatalError("Error dealing with schema: " + ex.getMessage(), ex);
// runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
// return runResult;
// } catch (RuntimeException ex) {
// LOGGER.error("Import: Internal Error: {}", ex.getMessage(), ex);
// // Can be anything ... but we can't recover from that.
// // It is most likely a programming error. Does not make much sense to retry.
// opResult.recordFatalError("Internal Error: " + ex.getMessage(), ex);
// runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
// return runResult;
// }

if (resource == null) {
LOGGER.error("Live Sync: No resource specified");
opResult.recordFatalError("No resource specified");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
// String resourceOid = resource.getOid();

RefinedResourceSchema refinedSchema;
try {
Expand All @@ -188,7 +155,6 @@ public TaskRunResult run(Task task) {
opResult.recordFatalError("No refined schema defined. Probably some configuration problem.");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
LOGGER.error("Live Sync: No refined schema defined. Probably some configuration problem.");
// throw new SchemaException();re
return runResult;
}

Expand Down
Expand Up @@ -115,6 +115,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

/**
Expand Down Expand Up @@ -168,12 +169,12 @@ public abstract class AbstractLdapConnTest extends AbstractModelIntegrationTest
protected static final String ACCOUNT_239_UID = "u00000239";
protected static final String ACCOUNT_240_UID = "u00000240";

private static final int NUMBER_OF_GENERATED_ACCOUNTS = 4000;
protected static final int NUMBER_OF_GENERATED_ACCOUNTS = 4000;

private static final String ACCOUNT_HT_UID = "ht";
private static final String ACCOUNT_HT_CN = "Herman Toothrot";
private static final String ACCOUNT_HT_GIVENNAME = "Herman";
private static final String ACCOUNT_HT_SN = "Toothrot";
protected static final String ACCOUNT_HT_UID = "ht";
protected static final String ACCOUNT_HT_CN = "Herman Toothrot";
protected static final String ACCOUNT_HT_GIVENNAME = "Herman";
protected static final String ACCOUNT_HT_SN = "Toothrot";

@Autowired(required = true)
protected MatchingRuleRegistry matchingRuleRegistry;
Expand All @@ -190,7 +191,7 @@ public abstract class AbstractLdapConnTest extends AbstractModelIntegrationTest
protected String accountBarbossaOid;

@Autowired
private ReconciliationTaskHandler reconciliationTaskHandler;
protected ReconciliationTaskHandler reconciliationTaskHandler;

@Override
protected void startResources() throws Exception {
Expand Down Expand Up @@ -236,6 +237,10 @@ protected File getSyncTaskFile() {
return new File(getBaseDir(), "task-sync.xml");
}

protected File getSyncTaskInetOrgPersonFile() {
return new File(getBaseDir(), "task-sync-inetorgperson.xml");
}

protected abstract String getSyncTaskOid();

protected QName getAccountObjectClass() {
Expand Down Expand Up @@ -757,7 +762,7 @@ public void test200AssignAccountToBarbossa() throws Exception {
ResourceAttribute<Long> createTimestampAttribute = ShadowUtil.getAttribute(shadow, new QName(MidPointConstants.NS_RI, "createTimestamp"));
assertNotNull("No createTimestamp in "+shadow, createTimestampAttribute);
Long createTimestamp = createTimestampAttribute.getRealValue();
TestUtil.assertBetween("Wrong createTimestamp in "+shadow, tsStart, tsEnd, createTimestamp);
TestUtil.assertBetween("Wrong createTimestamp in "+shadow, roundTsDown(tsStart), roundTsUp(tsEnd), createTimestamp);
}

@Test
Expand Down Expand Up @@ -866,7 +871,7 @@ public void test800ImportSyncTask() throws Exception {
result.computeStatus();
TestUtil.assertSuccess(result);

waitForTaskStart(getSyncTaskOid(), true);
waitForTaskNextRun(getSyncTaskOid(), true);

long tsEnd = System.currentTimeMillis();

Expand Down Expand Up @@ -984,8 +989,8 @@ public void test815RenameAccount() throws Exception {
}

@Test
public void test819DeleteAccountHtm() throws Exception {
final String TEST_NAME = "test819DeleteAccountHtm";
public void test818DeleteAccountHtm() throws Exception {
final String TEST_NAME = "test818DeleteAccountHtm";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Expand All @@ -1011,12 +1016,84 @@ public void test819DeleteAccountHtm() throws Exception {
assertNull("User "+ACCOUNT_HT_UID+" still exist", findUserByUsername(ACCOUNT_HT_UID));

assertStepSyncToken(getSyncTaskOid(), 4, tsStart, tsEnd);
}


// TODO: sync with "ALL" object class

@Test
public void test819DeleteSyncTask() throws Exception {
final String TEST_NAME = "test819DeleteSyncTask";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

// WHEN
TestUtil.displayWhen(TEST_NAME);
deleteObject(TaskType.class, getSyncTaskOid(), task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

assertNoObject(TaskType.class, getSyncTaskOid(), task, result);
}

@Test
public void test820ImportSyncTaskInetOrgPerson() throws Exception {
final String TEST_NAME = "test820ImportSyncTaskInetOrgPerson";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

long tsStart = System.currentTimeMillis();

// WHEN
TestUtil.displayWhen(TEST_NAME);
addObject(getSyncTaskInetOrgPersonFile(), task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

waitForTaskNextRun(getSyncTaskOid(), true);

long tsEnd = System.currentTimeMillis();

PrismObject<TaskType> syncTask = getTask(getSyncTaskOid());
display("Sync task after start", syncTask);

assertStepSyncToken(getSyncTaskOid(), 0, tsStart, tsEnd);
}

// TODO: create object of a different object class. See that it is ignored by sync.

// TODO: sync with "ALL" object class
@Test
public void test829DeleteSyncTask() throws Exception {
final String TEST_NAME = "test829DeleteSyncTask";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

// WHEN
TestUtil.displayWhen(TEST_NAME);
deleteObject(TaskType.class, getSyncTaskOid(), task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

assertNoObject(TaskType.class, getSyncTaskOid(), task, result);
}

protected Entry getLdapAccountByUid(String uid) throws LdapException, IOException, CursorException {
LdapNetworkConnection connection = ldapConnect();
Expand Down Expand Up @@ -1125,4 +1202,11 @@ protected void assertAccountShadow(PrismObject<ShadowType> shadow, String dn) {
assertShadowCommon(shadow, null, dn, resourceType, getAccountObjectClass(), ciMatchingRule);
}

protected long roundTsDown(long ts) {
return (((long)(ts/1000))*1000);
}

protected long roundTsUp(long ts) {
return (((long)(ts/1000))*1000)+1;
}
}
Expand Up @@ -16,6 +16,7 @@
package com.evolveum.midpoint.testing.conntest;

import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;

import java.io.File;
import java.text.ParseException;
Expand All @@ -24,6 +25,7 @@
import org.testng.AssertJUnit;
import org.testng.annotations.Test;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand All @@ -35,6 +37,7 @@
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

/**
* @author semancik
Expand Down Expand Up @@ -117,12 +120,36 @@ protected void assertStepSyncToken(String syncTaskOid, int step, long tsStart, l
} catch (ParseException e) {
throw new RuntimeException(e.getMessage(),e);
}
TestUtil.assertBetween("Wrong time in sync token: "+syncToken, roundTs(tsStart), roundTs(tsEnd), syncTokenGt.getCalendar().getTimeInMillis());
TestUtil.assertBetween("Wrong time in sync token: "+syncToken, roundTsDown(tsStart), roundTsUp(tsEnd), syncTokenGt.getCalendar().getTimeInMillis());

}

private Long roundTs(long ts) {
return (((long)(ts/1000))*1000);
@Override
public void test818DeleteAccountHtm() throws Exception {
final String TEST_NAME = "test818DeleteAccountHtm";
TestUtil.displayTestTile(this, TEST_NAME);

// The original test is not applicable for modifyTimestamp sync.
// Therefore just delete the user so we have consistent state

// GIVEN
Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

PrismObject<UserType> user = findUserByUsername("htm");

// WHEN
deleteObject(UserType.class, user.getOid(), task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

assertNull("User "+"htm"+" still exist", findUserByUsername("htm"));
assertNull("User "+ACCOUNT_HT_UID+" still exist", findUserByUsername(ACCOUNT_HT_UID));
}



}
Expand Up @@ -67,6 +67,10 @@
<level>DEBUG</level>
<package>com.evolveum.midpoint.model.impl.lens.Clockwork</package>
</classLogger>
<classLogger>
<level>TRACE</level>
<package>com.evolveum.midpoint.provisioning.impl</package>
</classLogger>
<classLogger>
<c:level>TRACE</c:level>
<c:package>com.evolveum.midpoint.test</c:package>
Expand Down
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2015 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<task oid="cd1e0ff2-0099-11e5-9e22-001e8c717e5b"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:syncext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3">

<name>Synchronization: OpenDJ</name>

<extension>
<syncext:objectclass>ri:inetOrgPerson</syncext:objectclass>
</extension>

<taskIdentifier>cd1e0ff2-0099-11e5-9e22-001e8c717e5b</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<executionStatus>runnable</executionStatus>

<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/live-sync/handler-3</handlerUri>
<objectRef oid="371ffc38-c424-11e4-8467-001e8c717e5b" xsi:type="c:ResourceType"/>
<recurrence>recurring</recurrence>
<binding>tight</binding>
<schedule>
<interval>3</interval>
</schedule>

</task>
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2015 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<task oid="cd1e0ff2-0099-11e5-9e22-001e8c717e5b"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:syncext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3">

<name>Synchronization: OpenLDAP</name>

<extension>
<syncext:objectclass>ri:inetOrgPerson</syncext:objectclass>
</extension>

<taskIdentifier>cd1e0ff2-0099-11e5-9e22-001e8c717e5b</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<executionStatus>runnable</executionStatus>

<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/live-sync/handler-3</handlerUri>
<objectRef oid="2a7c7130-7a34-11e4-bdf6-001e8c717e5b" xsi:type="c:ResourceType"/>
<recurrence>recurring</recurrence>
<binding>tight</binding>
<schedule>
<interval>3</interval>
</schedule>

</task>

0 comments on commit 1eca645

Please sign in to comment.