-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestWriter.java
103 lines (80 loc) · 3.77 KB
/
TestWriter.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
/*
* Copyright (c) 2019 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.testing.story;
import java.io.File;
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 com.evolveum.midpoint.prism.PrismObject;
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.MidPointTestConstants;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
/**
* Test with a resource that can only write. It cannot read the accounts. It has to cache the values.
*
* @author semancik
*/
@ContextConfiguration(locations = { "classpath:ctx-story-test-main.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestWriter extends AbstractStoryTest {
public static final File TEST_DIR = new File(MidPointTestConstants.TEST_RESOURCES_DIR, "writer");
protected static final File RESOURCE_WRITER_FILE = new File(TEST_DIR, "resource-writer.xml");
protected static final String RESOURCE_WRITER_OID = "607c4616-1a66-11ea-b513-ef360fa00fe1";
protected static final String RESOURCE_WRITER_DUMMY_NAME = "writer";
private static final String USER_JACK_FULL_NAME_CAPTAIN = "Captain Jack Sparrow";
private static final String USER_JACK_LOCALITY = "Seven seas";
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
DummyResourceContoller writerDummyController = DummyResourceContoller.create(RESOURCE_WRITER_DUMMY_NAME);
writerDummyController.extendSchemaPirate();
dummyResourceCollection.initDummyResource(RESOURCE_WRITER_DUMMY_NAME, writerDummyController);
PrismObject<ResourceType> resourceWriter = importAndGetObjectFromFile(ResourceType.class, RESOURCE_WRITER_FILE, RESOURCE_WRITER_OID, initTask, initResult);
writerDummyController.setResource(resourceWriter);
}
@Test
public void test000Sanity() throws Exception {
Task task = getTestTask();
OperationResult testResultWriter = modelService.testResource(RESOURCE_WRITER_OID, task);
TestUtil.assertSuccess(testResultWriter);
}
@Test
public void test100AssignJackDummyAccount() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
modifyUserReplace(USER_JACK_OID, UserType.F_LOCALITY, task, result, createPolyString(USER_JACK_LOCALITY));
// WHEN
when();
assignAccountToUser(USER_JACK_OID, RESOURCE_WRITER_OID, null, task, result);
// THEN
then();
assertSuccess(result);
assertDummyAccountByUsername(RESOURCE_WRITER_DUMMY_NAME, USER_JACK_USERNAME)
.assertFullName(USER_JACK_FULL_NAME);
}
/**
* MID-5944
*/
@Test
public void test110ModifyCaptainJack() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
// WHEN
when();
modifyUserReplace(USER_JACK_OID, UserType.F_FULL_NAME, task, result, createPolyString(USER_JACK_FULL_NAME_CAPTAIN));
// THEN
then();
assertSuccess(result);
assertDummyAccountByUsername(RESOURCE_WRITER_DUMMY_NAME, USER_JACK_USERNAME)
.assertFullName(USER_JACK_FULL_NAME_CAPTAIN);
}
}