-
Notifications
You must be signed in to change notification settings - Fork 188
/
AbstractObjTemplateSyncTest.java
226 lines (176 loc) · 9.86 KB
/
AbstractObjTemplateSyncTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
* Copyright (c) 2010-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.
*/
package com.evolveum.midpoint.model.intest.sync;
import com.evolveum.icf.dummy.resource.DummyAccount;
import com.evolveum.icf.dummy.resource.DummyResource;
import com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;
import javax.xml.datatype.XMLGregorianCalendar;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Date;
import static com.evolveum.midpoint.test.IntegrationTestTools.display;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
/**
* @author semancik
*
*/
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public abstract class AbstractObjTemplateSyncTest extends AbstractInitializedModelIntegrationTest {
public static final File TEST_DIR = new File("src/test/resources/sync");
protected static final File RESOURCE_DUMMY_BYZANTINE_FILE = new File(TEST_DIR, "resource-dummy-byzantine.xml");
protected static final String RESOURCE_DUMMY_BYZANTINE_OID = "10000000-0000-0000-0000-00000000f904";
protected static final String RESOURCE_DUMMY_BYZANTINE_NAME = "byzantine";
protected static final File TASK_LIVE_SYNC_DUMMY_BYZANTINE_FILE = new File(TEST_DIR, "task-dummy-byzantine-livesync.xml");
protected static final String TASK_LIVE_SYNC_DUMMY_BYZANTINE_OID = "10000000-0000-0000-5555-55550000f904";
protected static final File TASK_RECON_DUMMY_BYZANTINE_FILE = new File(TEST_DIR, "task-dummy-byzantine-recon.xml");
protected static final String TASK_RECON_DUMMY_BYZANTINE_OID = "10000000-0000-0000-5656-56560000f904";
protected static DummyResource dummyResourceByzantine;
protected static DummyResourceContoller dummyResourceCtlByzantine;
protected ResourceType resourceDummyByzantineType;
protected PrismObject<ResourceType> resourceDummyByzantine;
protected static final String ACCOUNT_MANCOMB_DUMMY_USERNAME = "mancomb";
private static final Date ACCOUNT_MANCOMB_VALID_FROM_DATE = MiscUtil.asDate(2011, 2, 3, 4, 5, 6);
private static final Date ACCOUNT_MANCOMB_VALID_TO_DATE = MiscUtil.asDate(2066, 5, 4, 3, 2, 1);
protected long timeBeforeSync;
public static final File SYSTEM_CONFIGURATION_FILE = new File(TEST_DIR, "system-configuration-byzantine.xml");
protected static final String ORG_F0001_OID = "00000000-8888-6666-0000-100000000001";
public static final File USER_TEMPLATE_FILE = new File(TEST_DIR, "user-template-byzantine.xml");
@Override
protected File getSystemConfigurationFile() {
return SYSTEM_CONFIGURATION_FILE;
}
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
// templates
repoAddObjectFromFile(USER_TEMPLATE_FILE, ObjectTemplateType.class, initResult);
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
dummyResourceCtlByzantine = DummyResourceContoller.create(RESOURCE_DUMMY_BYZANTINE_NAME, resourceDummyByzantine);
dummyResourceCtlByzantine.extendSchemaPirate();
dummyResourceByzantine = dummyResourceCtlByzantine.getDummyResource();
resourceDummyByzantine = importAndGetObjectFromFile(ResourceType.class, getResourceDummyByzantineFile(), RESOURCE_DUMMY_BYZANTINE_OID, initTask, initResult);
resourceDummyByzantineType = resourceDummyByzantine.asObjectable();
dummyResourceCtlByzantine.setResource(resourceDummyByzantine);
}
protected File getResourceDummyByzantineFile() {
return RESOURCE_DUMMY_BYZANTINE_FILE;
}
protected abstract void importSyncTask(PrismObject<ResourceType> resource) throws FileNotFoundException;
protected abstract String getSyncTaskOid(PrismObject<ResourceType> resource);
protected int getWaitTimeout() {
return DEFAULT_TASK_WAIT_TIMEOUT;
}
@Test
public void test100ImportLiveSyncTaskDummyByzantine() throws Exception {
final String TEST_NAME = "test100ImportLiveSyncTaskDummyByzantine";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(AbstractObjTemplateSyncTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
/// WHEN
TestUtil.displayWhen(TEST_NAME);
importSyncTask(resourceDummyByzantine);
// THEN
TestUtil.displayThen(TEST_NAME);
waitForSyncTaskStart(resourceDummyByzantine);
}
@Test
public void test110AddDummyByzantineAccountMancomb() throws Exception {
final String TEST_NAME = "test110AddDummyByzantineAccountMancomb";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(AbstractObjTemplateSyncTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
rememberTimeBeforeSync();
prepareNotifications();
// Preconditions
assertUsers(5);
DummyAccount account = new DummyAccount(ACCOUNT_MANCOMB_DUMMY_USERNAME);
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Mancomb Seepgood");
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Melee Island");
long loot = ACCOUNT_MANCOMB_VALID_FROM_DATE.getTime();
account.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, loot);
String gossip = XmlTypeConverter.createXMLGregorianCalendar(ACCOUNT_MANCOMB_VALID_TO_DATE).toXMLFormat();
account.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, gossip);
/// WHEN
TestUtil.displayWhen(TEST_NAME);
display("Adding dummy account", account.debugDump());
dummyResourceByzantine.addAccount(account);
waitForSyncTaskNextRun(resourceDummyByzantine);
// THEN
TestUtil.displayThen(TEST_NAME);
PrismObject<ShadowType> accountMancomb = findAccountByUsername(ACCOUNT_MANCOMB_DUMMY_USERNAME, resourceDummyByzantine);
display("Account mancomb", accountMancomb);
assertNotNull("No mancomb account shadow", accountMancomb);
assertEquals("Wrong resourceRef in mancomb account", RESOURCE_DUMMY_BYZANTINE_OID,
accountMancomb.asObjectable().getResourceRef().getOid());
assertShadowOperationalData(accountMancomb, SynchronizationSituationType.LINKED);
PrismObject<UserType> userMancomb = findUserByUsername(ACCOUNT_MANCOMB_DUMMY_USERNAME);
display("User mancomb", userMancomb);
assertNotNull("User mancomb was not created", userMancomb);
assertLinks(userMancomb, 1);
assertAdministrativeStatusEnabled(userMancomb);
assertLinked(userMancomb, accountMancomb);
assertEquals("Wrong e-mail address for mancomb", "mancomb.Mr@test.com", userMancomb.asObjectable().getEmailAddress());
assertAssignedOrg(userMancomb, ORG_F0001_OID);
// this fails (see MID-2149)
//assertHasOrg(userMancomb, ORG_F0001_OID);
assertUsers(6);
// notifications
notificationManager.setDisabled(true);
}
protected void waitForSyncTaskStart(PrismObject<ResourceType> resource) throws Exception {
waitForTaskStart(getSyncTaskOid(resource), false, getWaitTimeout());
}
protected void waitForSyncTaskNextRun(PrismObject<ResourceType> resource) throws Exception {
waitForTaskNextRun(getSyncTaskOid(resource), false, getWaitTimeout());
}
protected void rememberTimeBeforeSync() {
timeBeforeSync = System.currentTimeMillis();
}
protected void assertShadowOperationalData(PrismObject<ShadowType> shadow, SynchronizationSituationType expectedSituation) {
ShadowType shadowType = shadow.asObjectable();
SynchronizationSituationType actualSituation = shadowType.getSynchronizationSituation();
assertEquals("Wrong situation in shadow "+shadow, expectedSituation, actualSituation);
XMLGregorianCalendar actualTimestampCal = shadowType.getSynchronizationTimestamp();
assert actualTimestampCal != null : "No synchronization timestamp in shadow "+shadow;
long actualTimestamp = XmlTypeConverter.toMillis(actualTimestampCal);
assert actualTimestamp >= timeBeforeSync : "Synchronization timestamp was not updated in shadow "+shadow;
// TODO: assert sync description
}
}