Skip to content

Commit

Permalink
Extending service account tests for recon (MID-4522)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jul 9, 2018
1 parent b5aa165 commit b5abe0b
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 7 deletions.
Expand Up @@ -3003,6 +3003,19 @@ protected void restartTask(String taskOid) throws CommonException {
throw new IllegalStateException("Task " + task + " cannot be restarted, because its state is: " + task.getExecutionStatus());
}
}

protected void suspendTask(String taskOid) throws CommonException {
final OperationResult result = new OperationResult(AbstractIntegrationTest.class+".suspendTask");
Task task = taskManager.getTaskWithResult(taskOid, result);
LOGGER.info("Suspending task {}", taskOid);
taskManager.suspendTask(task, 3000, result);
}

protected void assertTaskExecutionStatus(String taskOid, TaskExecutionStatusType expectedExecutionStatus) throws ObjectNotFoundException, SchemaException {
final OperationResult result = new OperationResult(AbstractIntegrationTest.class+".assertTaskExecutionStatus");
Task task = taskManager.getTask(taskOid, result);
assertEquals("Wrong executionStatus in "+task, expectedExecutionStatus, task.getExecutionStatus());
}

protected void setSecurityContextUser(String userOid) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
Task task = taskManager.createTaskInstance("get administrator");
Expand Down
Expand Up @@ -69,6 +69,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType;
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.TaskExecutionStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;

Expand All @@ -84,10 +85,16 @@ public class TestServiceAccounts extends AbstractStoryTest {

private static final String ACCOUNT_RUM_STORAGE_DUMMY_USERNAME = "rum-storage";
private static final String ACCOUNT_RUM_STORAGE_DUMMY_FULLNAME = "Rum Storage Application";

private static final String ACCOUNT_MAGAZINE_DUMMY_USERNAME = "magazine";
private static final String ACCOUNT_MAGAZINE_DUMMY_FULLNAME = "Gunpowder magazine";

private static final File TASK_LIVE_SYNC_DUMMY_FILE = new File(TEST_DIR, "task-dumy-livesync.xml");
private static final File TASK_LIVE_SYNC_DUMMY_FILE = new File(TEST_DIR, "task-dummy-livesync.xml");
private static final String TASK_LIVE_SYNC_DUMMY_OID = "474eb3ac-837e-11e8-8cf8-6bd4fe328f30";

private static final File TASK_RECONCILE_DUMMY_FILE = new File(TEST_DIR, "task-dummy-reconcile.xml");
private static final String TASK_RECONCILE_DUMMY_OID = "10335c7c-838f-11e8-93a6-4b1dd0ab58e4";

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
Expand All @@ -97,8 +104,8 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
}

@Test
public void test050StartSyncTask() throws Exception {
final String TEST_NAME = "test050StartSyncTask";
public void test100StartSyncTask() throws Exception {
final String TEST_NAME = "test100StartSyncTask";
displayTestTitle(TEST_NAME);

assertUsers(getNumberOfUsers());
Expand All @@ -119,8 +126,8 @@ public void test050StartSyncTask() throws Exception {
}

@Test
public void test100AddServiceAccountSync() throws Exception {
final String TEST_NAME = "test100AddServiceAccountSync";
public void test101AddServiceAccountSync() throws Exception {
final String TEST_NAME = "test101AddServiceAccountSync";
displayTestTitle(TEST_NAME);

// Preconditions
Expand Down Expand Up @@ -155,8 +162,8 @@ public void test100AddServiceAccountSync() throws Exception {
* MID-4522
*/
@Test
public void test109DeleteServiceAccountSync() throws Exception {
final String TEST_NAME = "test109DeleteServiceAccountSync";
public void test108DeleteServiceAccountSync() throws Exception {
final String TEST_NAME = "test108DeleteServiceAccountSync";
displayTestTitle(TEST_NAME);

// Preconditions
Expand All @@ -178,4 +185,118 @@ public void test109DeleteServiceAccountSync() throws Exception {
assertNull("Unexpected rum service", serviceRumAfter);
}

public void test109StopLivesyncTask() throws Exception {
final String TEST_NAME = "test109StopLivesyncTask";
displayTestTitle(TEST_NAME);

// Preconditions
assertServices(1);

// WHEN
displayWhen(TEST_NAME);

suspendTask(TASK_LIVE_SYNC_DUMMY_OID);

// THEN
displayThen(TEST_NAME);
assertTaskExecutionStatus(TASK_LIVE_SYNC_DUMMY_OID, TaskExecutionStatusType.SUSPENDED);
}

@Test
public void test120StartReconTask() throws Exception {
final String TEST_NAME = "test120StartReconTask";
displayTestTitle(TEST_NAME);

assertUsers(getNumberOfUsers());
assertServices(0);

// WHEN
displayWhen(TEST_NAME);

importObjectFromFile(TASK_RECONCILE_DUMMY_FILE);

// THEN
displayThen(TEST_NAME);

waitForTaskStart(TASK_RECONCILE_DUMMY_OID, true);

assertServices(0);
assertUsers(getNumberOfUsers());
}

@Test
public void test121AddServiceAccountRecon() throws Exception {
final String TEST_NAME = "test121AddServiceAccountRecon";
displayTestTitle(TEST_NAME);

// Preconditions
assertServices(0);

DummyAccount account = new DummyAccount(ACCOUNT_MAGAZINE_DUMMY_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME,
ACCOUNT_MAGAZINE_DUMMY_FULLNAME);

// WHEN
displayWhen(TEST_NAME);

getDummyResource().addAccount(account);

waitForTaskNextRunAssertSuccess(TASK_RECONCILE_DUMMY_OID, true);

// THEN
displayThen(TEST_NAME);

assertServices(1);
PrismObject<ServiceType> serviceRumAfter = findServiceByUsername(ACCOUNT_MAGAZINE_DUMMY_USERNAME);
display("Service magazine after", serviceRumAfter);
assertNotNull("No magazine service", serviceRumAfter);
PrismAsserts.assertPropertyValue(serviceRumAfter, ServiceType.F_NAME, createPolyString(ACCOUNT_MAGAZINE_DUMMY_USERNAME));
PrismAsserts.assertPropertyValue(serviceRumAfter, ServiceType.F_DESCRIPTION, ACCOUNT_MAGAZINE_DUMMY_FULLNAME);
}

/**
* MID-4522
*/
@Test
public void test128DeleteServiceAccountRecon() throws Exception {
final String TEST_NAME = "test128DeleteServiceAccountRecon";
displayTestTitle(TEST_NAME);

// Preconditions
assertServices(1);

// WHEN
displayWhen(TEST_NAME);

getDummyResource().deleteAccountByName(ACCOUNT_MAGAZINE_DUMMY_USERNAME);

waitForTaskNextRunAssertSuccess(TASK_RECONCILE_DUMMY_OID, true);

// THEN
displayThen(TEST_NAME);

assertServices(0);
PrismObject<ServiceType> serviceRumAfter = findServiceByUsername(ACCOUNT_MAGAZINE_DUMMY_USERNAME);
display("Service rum after", serviceRumAfter);
assertNull("Unexpected rum service", serviceRumAfter);
}

public void test129StopReconTask() throws Exception {
final String TEST_NAME = "test129StopReconTask";
displayTestTitle(TEST_NAME);

// Preconditions
assertServices(1);

// WHEN
displayWhen(TEST_NAME);

suspendTask(TASK_RECONCILE_DUMMY_OID);

// THEN
displayThen(TEST_NAME);
assertTaskExecutionStatus(TASK_RECONCILE_DUMMY_OID, TaskExecutionStatusType.SUSPENDED);
}

}
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2018 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.
-->

<!--Reconciliation task definition for dummy resource -->

<task oid="10335c7c-838f-11e8-93a6-4b1dd0ab58e4"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:syncext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<!-- Resource printable name -->
<name>Reconciliation: Dummy</name>

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

<taskIdentifier>10335c7c-838f-11e8-93a6-4b1dd0ab58e4</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<executionStatus>runnable</executionStatus>

<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/reconciliation/handler-3</handlerUri>
<objectRef oid="0069ac14-8377-11e8-b404-5b5a1a8af0db" type="ResourceType"/>
<recurrence>recurring</recurrence>
<schedule>
<interval>3</interval>
</schedule>

</task>

0 comments on commit b5abe0b

Please sign in to comment.