-
Notifications
You must be signed in to change notification settings - Fork 188
/
TestConnectorDiscovery.java
148 lines (120 loc) · 5.75 KB
/
TestConnectorDiscovery.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
/*
* Copyright (c) 2010-2017 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.provisioning.impl;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotNull;
import java.util.List;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.provisioning.api.ProvisioningService;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.AbstractIntegrationTest;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType;
/**
* @author Radovan Semancik
* @author Katka Valalikova
*/
@ContextConfiguration(locations = "classpath:ctx-provisioning-test-main.xml")
@DirtiesContext
public class TestConnectorDiscovery extends AbstractIntegrationTest {
@Autowired
private ProvisioningService provisioningService;
private static Trace LOGGER = TraceManager.getTrace(TestConnectorDiscovery.class);
@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
provisioningService.postInit(initResult);
}
/**
* Check whether the connectors were discovered correctly and were added to the repository.
* @throws SchemaException
*
*/
@Test
public void test001Connectors() throws Exception {
final String TEST_NAME = "test001Connectors";
TestUtil.displayTestTitle(TEST_NAME);
OperationResult result = new OperationResult(TestConnectorDiscovery.class.getName() + "." + TEST_NAME);
// WHEN
TestUtil.displayWhen(TEST_NAME);
List<PrismObject<ConnectorType>> connectors = repositoryService.searchObjects(ConnectorType.class, null, null, result);
// THEN
TestUtil.displayThen(TEST_NAME);
assertFalse("No connector found",connectors.isEmpty());
display("Found "+connectors.size()+" discovered connector");
result.computeStatus();
TestUtil.assertSuccess(result);
for (PrismObject<ConnectorType> connector : connectors) {
ConnectorType conn = connector.asObjectable();
display("Found connector " +conn, conn);
IntegrationTestTools.assertConnectorSchemaSanity(conn, prismContext);
}
assertEquals("Unexpected number of connectors found", 7, connectors.size());
}
@Test
public void testListConnectors() throws Exception{
TestUtil.displayTestTitle("testListConnectors");
OperationResult result = new OperationResult(TestConnectorDiscovery.class.getName()
+ ".listConnectorsTest");
List<PrismObject<ConnectorType>> connectors = provisioningService.searchObjects(ConnectorType.class, null, null, null, result);
assertNotNull(connectors);
for (PrismObject<ConnectorType> connector : connectors){
ConnectorType conn = connector.asObjectable();
System.out.println(conn.toString());
System.out.println("connector name: "+ conn.getName());
System.out.println("connector type: "+ conn.getConnectorType());
System.out.println("-----\n");
}
assertEquals("Unexpected number of connectors found", 7, connectors.size());
}
@Test
public void testSearchConnectorSimple() throws SchemaException{
final String TEST_NAME = "testSearchConnectorSimple";
TestUtil.displayTestTitle(TEST_NAME);
OperationResult result = new OperationResult(TestConnectorDiscovery.class.getName()
+ "." + TEST_NAME);
PrismObject<ConnectorType> ldapConnector = findConnectorByType(IntegrationTestTools.LDAP_CONNECTOR_TYPE, result);
assertEquals("Type does not match", IntegrationTestTools.LDAP_CONNECTOR_TYPE, ldapConnector.asObjectable().getConnectorType());
}
@Test
public void testSearchConnectorAnd() throws SchemaException{
TestUtil.displayTestTitle("testSearchConnectorAnd");
OperationResult result = new OperationResult(TestConnectorDiscovery.class.getName()
+ ".testSearchConnector");
ObjectQuery query = QueryBuilder.queryFor(ConnectorType.class, prismContext)
.item(SchemaConstants.C_CONNECTOR_FRAMEWORK).eq(SchemaConstants.ICF_FRAMEWORK_URI)
.and().item(SchemaConstants.C_CONNECTOR_CONNECTOR_TYPE).eq(IntegrationTestTools.LDAP_CONNECTOR_TYPE)
.build();
System.out.println("Query:\n"+query.debugDump());
List<PrismObject<ConnectorType>> connectors = repositoryService.searchObjects(ConnectorType.class, query, null, result);
assertEquals("Unexpected number of results", 1, connectors.size());
PrismObject<ConnectorType> ldapConnector = connectors.get(0);
assertEquals("Type does not match", IntegrationTestTools.LDAP_CONNECTOR_TYPE, ldapConnector.asObjectable().getConnectorType());
assertEquals("Framework does not match", SchemaConstants.ICF_FRAMEWORK_URI, ldapConnector.asObjectable().getFramework());
}
}