Skip to content

Commit

Permalink
Cleaning up model-impl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 4, 2016
1 parent a7295f4 commit 24b835b
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 237 deletions.
Expand Up @@ -965,19 +965,17 @@ public <T extends ObjectType> T resolveReferenceIfExists(ObjectReferenceType ref
}

@Override
public <T extends ObjectType> T getObject(Class<T> type,
String oid, Collection<SelectorOptions<GetOperationOptions>> options)
public <T extends ObjectType> T getObject(Class<T> type, String oid,
Collection<SelectorOptions<GetOperationOptions>> options)
throws ObjectNotFoundException, SchemaException,
CommunicationException, ConfigurationException,
SecurityViolationException {
return modelService.getObject(type, oid, options, getCurrentTask(), getCurrentResult()).asObjectable();
}

@Override
public <T extends ObjectType> T getObject(Class<T> type,
String oid) throws ObjectNotFoundException, SchemaException,
SecurityViolationException, CommunicationException,
ConfigurationException, SecurityViolationException {
public <T extends ObjectType> T getObject(Class<T> type, String oid) throws ObjectNotFoundException, SchemaException,
CommunicationException, ConfigurationException, SecurityViolationException {
PrismObject<T> prismObject = modelService.getObject(type, oid, null, getCurrentTask(), getCurrentResult());
return prismObject.asObjectable();
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -86,73 +86,68 @@
*/
public class AbstractInternalModelIntegrationTest extends AbstractModelIntegrationTest {

protected static final String CONNECTOR_DUMMY_FILENAME = COMMON_DIR_PATH + "/connector-dummy.xml";

public static final String SYSTEM_CONFIGURATION_FILENAME = COMMON_DIR_PATH + "/system-configuration.xml";
public static final File SYSTEM_CONFIGURATION_FILE = new File(COMMON_DIR, "system-configuration.xml");
public static final String SYSTEM_CONFIGURATION_OID = SystemObjectsType.SYSTEM_CONFIGURATION.value();

public static final File USER_ADMINISTRATOR_FILE = new File(COMMON_DIR, "user-administrator.xml");
protected static final String USER_ADMINISTRATOR_NAME = "administrator";
protected static final String USER_ADMINISTRATOR_OID = "00000000-0000-0000-0000-000000000002";

protected static final String USER_JACK_FILENAME = COMMON_DIR_PATH + "/user-jack.xml";
protected static final File USER_JACK_FILE = new File(COMMON_DIR, "user-jack.xml");
protected static final String USER_JACK_OID = "c0c010c0-d34d-b33f-f00d-111111111111";
protected static final String USER_JACK_USERNAME = "jack";

protected static final String USER_BARBOSSA_FILENAME = COMMON_DIR_PATH + "/user-barbossa.xml";
protected static final File USER_BARBOSSA_FILE = new File(COMMON_DIR, "user-barbossa.xml");
protected static final String USER_BARBOSSA_OID = "c0c010c0-d34d-b33f-f00d-111111111112";

protected static final String USER_GUYBRUSH_FILENAME = COMMON_DIR_PATH + "/user-guybrush.xml";
protected static final File USER_GUYBRUSH_FILE = new File(COMMON_DIR, "user-guybrush.xml");
protected static final String USER_GUYBRUSH_OID = "c0c010c0-d34d-b33f-f00d-111111111116";

static final String USER_ELAINE_FILENAME = COMMON_DIR_PATH + "/user-elaine.xml";
static final File USER_ELAINE_FILE = new File(COMMON_DIR, "user-elaine.xml");
protected static final String USER_ELAINE_OID = "c0c010c0-d34d-b33f-f00d-11111111111e";
protected static final String USER_ELAINE_USERNAME = "elaine";

// Largo does not have a full name set, employeeType=PIRATE
protected static final String USER_LARGO_FILENAME = COMMON_DIR_PATH + "/user-largo.xml";
protected static final File USER_LARGO_FILE = new File(COMMON_DIR, "user-largo.xml");
protected static final String USER_LARGO_OID = "c0c010c0-d34d-b33f-f00d-111111111118";

public static final File ROLE_SUPERUSER_FILE = new File(COMMON_DIR, "role-superuser.xml");
protected static final String ROLE_SUPERUSER_OID = "00000000-0000-0000-0000-000000000004";

protected static final String ACCOUNT_HBARBOSSA_DUMMY_FILENAME = COMMON_DIR_PATH + "/account-hbarbossa-dummy.xml";
protected static final File ACCOUNT_HBARBOSSA_DUMMY_FILE = new File(COMMON_DIR, "account-hbarbossa-dummy.xml");
protected static final String ACCOUNT_HBARBOSSA_DUMMY_OID = "c0c010c0-d34d-b33f-f00d-222211111112";
protected static final String ACCOUNT_HBARBOSSA_DUMMY_USERNAME = "hbarbossa";

public static final File ACCOUNT_SHADOW_JACK_DUMMY_FILE = new File(COMMON_DIR, "account-shadow-jack-dummy.xml");
public static final String ACCOUNT_JACK_DUMMY_USERNAME = "jack";

public static final String ACCOUNT_HERMAN_DUMMY_FILENAME = COMMON_DIR_PATH + "/account-herman-dummy.xml";
public static final File ACCOUNT_HERMAN_DUMMY_FILE = new File(COMMON_DIR, "account-herman-dummy.xml");
public static final String ACCOUNT_HERMAN_DUMMY_OID = "22220000-2200-0000-0000-444400004444";
public static final String ACCOUNT_HERMAN_DUMMY_USERNAME = "ht";

// public static final String ACCOUNT_HERMAN_OPENDJ_FILENAME = COMMON_DIR_NAME + "/account-herman-opendj.xml";
// public static final String ACCOUNT_HERMAN_OPENDJ_OID = "22220000-2200-0000-0000-333300003333";

public static final String ACCOUNT_SHADOW_GUYBRUSH_DUMMY_FILENAME = COMMON_DIR_PATH + "/account-shadow-guybrush-dummy.xml";
public static final File ACCOUNT_SHADOW_GUYBRUSH_DUMMY_FILE = new File(COMMON_DIR, "account-shadow-guybrush-dummy.xml");
public static final String ACCOUNT_SHADOW_GUYBRUSH_OID = "22226666-2200-6666-6666-444400004444";
public static final String ACCOUNT_GUYBRUSH_DUMMY_USERNAME = "guybrush";
public static final String ACCOUNT_GUYBRUSH_DUMMY_FILENAME = COMMON_DIR_PATH + "/account-guybrush-dummy.xml";
public static final File ACCOUNT_GUYBRUSH_DUMMY_FILE = new File(COMMON_DIR, "account-guybrush-dummy.xml");

public static final String ACCOUNT_SHADOW_ELAINE_DUMMY_FILENAME = COMMON_DIR_PATH + "/account-elaine-dummy.xml";
public static final File ACCOUNT_SHADOW_ELAINE_DUMMY_FILE = new File(COMMON_DIR, "account-elaine-dummy.xml");
public static final String ACCOUNT_SHADOW_ELAINE_DUMMY_OID = "c0c010c0-d34d-b33f-f00d-22220004000e";
public static final String ACCOUNT_ELAINE_DUMMY_USERNAME = USER_ELAINE_USERNAME;

public static final File ENTITLEMENT_SHADOW_PIRATE_DUMMY_FILE = new File(COMMON_DIR, "entitlement-shadow-pirate-dummy.xml");
public static final String ENTITLEMENT_PIRATE_DUMMY_NAME = "pirate";

public static final String ACCOUNT_SHADOW_CALYPSO_DUMMY_FILENAME = COMMON_DIR_PATH + "/account-shadow-calypso-dummy.xml";
public static final File ACCOUNT_SHADOW_CALYPSO_DUMMY_FILE = new File(COMMON_DIR, "account-shadow-calypso-dummy.xml");
public static final String ACCOUNT_CALYPSO_DUMMY_USERNAME = "calypso";

public static final String RESOURCE_DUMMY_FILENAME = COMMON_DIR_PATH + "/resource-dummy.xml";
public static final File RESOURCE_DUMMY_FILE = new File(COMMON_DIR, "resource-dummy.xml");
public static final String RESOURCE_DUMMY_OID = "10000000-0000-0000-0000-000000000004";
public static final String RESOURCE_DUMMY_NAMESPACE = "http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004";

public static final String USER_TEMPLATE_FILENAME = COMMON_DIR_PATH + "/user-template.xml";
public static final File USER_TEMPLATE_FILE = new File(COMMON_DIR, "user-template.xml");
public static final String USER_TEMPLATE_OID = "10000000-0000-0000-0000-000000000002";

protected static final String PASSWORD_POLICY_GLOBAL_FILENAME = COMMON_DIR_PATH + "/password-policy-global.xml";
protected static final File PASSWORD_POLICY_GLOBAL_FILE = new File(COMMON_DIR, "password-policy-global.xml");
protected static final String PASSWORD_POLICY_GLOBAL_OID = "12344321-0000-0000-0000-000000000003";

protected static final String MOCK_CLOCKWORK_HOOK_URL = MidPointConstants.NS_MIDPOINT_TEST_PREFIX + "/mockClockworkHook";
Expand Down Expand Up @@ -185,7 +180,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti

// System Configuration
try {
repoAddObjectFromFile(SYSTEM_CONFIGURATION_FILENAME, SystemConfigurationType.class, initResult);
repoAddObjectFromFile(SYSTEM_CONFIGURATION_FILE, SystemConfigurationType.class, initResult);
} catch (ObjectAlreadyExistsException e) {
throw new ObjectAlreadyExistsException("System configuration already exists in repository;" +
"looks like the previous test haven't cleaned it up", e);
Expand All @@ -197,14 +192,14 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
login(userAdministrator);

// User Templates
repoAddObjectFromFile(USER_TEMPLATE_FILENAME, ObjectTemplateType.class, initResult);
repoAddObjectFromFile(USER_TEMPLATE_FILE, ObjectTemplateType.class, initResult);

// Resources

dummyResourceCtl = DummyResourceContoller.create(null, resourceDummy);
dummyResourceCtl.extendSchemaPirate();
dummyResource = dummyResourceCtl.getDummyResource();
resourceDummy = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_FILENAME, RESOURCE_DUMMY_OID, initTask, initResult);
resourceDummy = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_FILE, RESOURCE_DUMMY_OID, initTask, initResult);
resourceDummyType = resourceDummy.asObjectable();
dummyResourceCtl.setResource(resourceDummy);

Expand All @@ -225,15 +220,15 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
dummyResourceCtl.addAccount(ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", "Melee Island");

// Accounts
repoAddObjectFromFile(ACCOUNT_HBARBOSSA_DUMMY_FILENAME, ShadowType.class, initResult);
repoAddObjectFromFile(ACCOUNT_SHADOW_GUYBRUSH_DUMMY_FILENAME, ShadowType.class, initResult);
repoAddObjectFromFile(ACCOUNT_SHADOW_ELAINE_DUMMY_FILENAME, ShadowType.class, initResult);
repoAddObjectFromFile(ACCOUNT_HBARBOSSA_DUMMY_FILE, ShadowType.class, initResult);
repoAddObjectFromFile(ACCOUNT_SHADOW_GUYBRUSH_DUMMY_FILE, ShadowType.class, initResult);
repoAddObjectFromFile(ACCOUNT_SHADOW_ELAINE_DUMMY_FILE, ShadowType.class, initResult);

// Users
userTypeJack = repoAddObjectFromFile(USER_JACK_FILENAME, UserType.class, initResult).asObjectable();
userTypeBarbossa = repoAddObjectFromFile(USER_BARBOSSA_FILENAME, UserType.class, initResult).asObjectable();
userTypeGuybrush = repoAddObjectFromFile(USER_GUYBRUSH_FILENAME, UserType.class, initResult).asObjectable();
userTypeElaine = repoAddObjectFromFile(USER_ELAINE_FILENAME, UserType.class, initResult).asObjectable();
userTypeJack = repoAddObjectFromFile(USER_JACK_FILE, UserType.class, initResult).asObjectable();
userTypeBarbossa = repoAddObjectFromFile(USER_BARBOSSA_FILE, UserType.class, initResult).asObjectable();
userTypeGuybrush = repoAddObjectFromFile(USER_GUYBRUSH_FILE, UserType.class, initResult).asObjectable();
userTypeElaine = repoAddObjectFromFile(USER_ELAINE_FILE, UserType.class, initResult).asObjectable();

}

Expand Down Expand Up @@ -291,9 +286,9 @@ protected LensProjectionContext fillContextWithAccount(LensContext<UserType> con
return fillContextWithAccount(context, account, result);
}

protected LensProjectionContext fillContextWithAccountFromFile(LensContext<UserType> context, String filename, OperationResult result) throws SchemaException,
protected LensProjectionContext fillContextWithAccountFromFile(LensContext<UserType> context, File file, OperationResult result) throws SchemaException,
ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, IOException {
PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(filename));
PrismObject<ShadowType> account = PrismTestUtil.parseObject(file);
provisioningService.applyDefinition(account, result);
return fillContextWithAccount(context, account, result);
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,13 +66,14 @@
*
* @author lazyman
* @author mederly
* @author semancik
*
*/
@ContextConfiguration(locations = { "classpath:ctx-model-test-main.xml" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class TestModelExpressions extends AbstractModelIntegrationTest {
public class TestModelExpressions extends AbstractInternalModelIntegrationTest {

private static final String TEST_DIR = "src/test/resources/expr";
private static final File TEST_DIR = new File("src/test/resources/expr");

private static final QName PROPERTY_NAME = new QName(SchemaConstants.NS_C, "foo");

Expand All @@ -94,7 +95,7 @@ public class TestModelExpressions extends AbstractModelIntegrationTest {
@Autowired(required = true)
private TaskManager taskManager;

private static final String TEST_EXPRESSIONS_OBJECTS = "./src/test/resources/expr/orgstruct.xml";
private static final File TEST_EXPRESSIONS_OBJECTS_FILE = new File(TEST_DIR, "orgstruct.xml");

@BeforeSuite
public void setup() throws SchemaException, SAXException, IOException {
Expand All @@ -106,12 +107,7 @@ public void setup() throws SchemaException, SAXException, IOException {
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);

modelService.postInit(initResult);

// Administrator
PrismObject<UserType> userAdministrator = repoAddObjectFromFile(AbstractInternalModelIntegrationTest.USER_ADMINISTRATOR_FILE, UserType.class, initResult);
repoAddObjectFromFile(AbstractInternalModelIntegrationTest.ROLE_SUPERUSER_FILE, RoleType.class, initResult);
login(userAdministrator);
importObjectFromFile(TEST_EXPRESSIONS_OBJECTS_FILE);
}

@Test
Expand Down Expand Up @@ -144,14 +140,6 @@ private ScriptExpressionEvaluatorType parseScriptType(String fileName) throws Sc
return expressionType;
}

private boolean imported = false;
private void importIfNeeded() throws Exception {
if (!imported) {
importObjectFromFile(TEST_EXPRESSIONS_OBJECTS);
imported = true;
}
}

@Test
public void testGetUserByOid() throws Exception {
final String TEST_NAME = "testGetUserByOid";
Expand All @@ -160,12 +148,11 @@ public void testGetUserByOid() throws Exception {
// GIVEN
OperationResult result = new OperationResult(TestModelExpressions.class.getName() + "." + TEST_NAME);

importIfNeeded();

PrismObject<UserType> chef = repositoryService.getObject(UserType.class, CHEF_OID, null, result);

ScriptExpressionEvaluatorType scriptType = parseScriptType("expression-" + TEST_NAME + ".xml");
ItemDefinition outputDefinition = new PrismPropertyDefinition(PROPERTY_NAME, DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext()); ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptType, outputDefinition, TEST_NAME);
ItemDefinition outputDefinition = new PrismPropertyDefinition(PROPERTY_NAME, DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext());
ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptType, outputDefinition, TEST_NAME);
ExpressionVariables variables = new ExpressionVariables();
variables.addVariableDefinition(new QName(SchemaConstants.NS_C, "user"), chef);

Expand All @@ -187,8 +174,6 @@ public void testGetManagersOids() throws Exception {
// GIVEN
OperationResult result = new OperationResult(TestModelExpressions.class.getName() + "." + TEST_NAME);

importIfNeeded();

PrismObject<UserType> chef = repositoryService.getObject(UserType.class, CHEF_OID, null, result);

ScriptExpressionEvaluatorType scriptType = parseScriptType("expression-" + TEST_NAME + ".xml");
Expand All @@ -202,13 +187,12 @@ public void testGetManagersOids() throws Exception {

// THEN
display("Script output", scriptOutputs);
assertEquals("Unexpected number of script outputs", 4, scriptOutputs.size());
assertEquals("Unexpected number of script outputs", 3, scriptOutputs.size());
Set<String> oids = new HashSet<String>();
oids.add(scriptOutputs.get(0).getValue());
oids.add(scriptOutputs.get(1).getValue());
oids.add(scriptOutputs.get(2).getValue());
oids.add(scriptOutputs.get(3).getValue());
Set<String> expectedOids = new HashSet<String>(Arrays.asList(new String[] { CHEESE_OID, CHEESE_JR_OID, ELAINE_OID, LECHUCK_OID }));
Set<String> expectedOids = new HashSet<String>(Arrays.asList(new String[] { CHEESE_OID, CHEESE_JR_OID, LECHUCK_OID }));
assertEquals("Unexpected script output", expectedOids, oids);
}

Expand All @@ -220,8 +204,6 @@ public void testGetOrgByName() throws Exception {
// GIVEN
OperationResult result = new OperationResult(TestModelExpressions.class.getName() + "." + TEST_NAME);

importIfNeeded();

ScriptExpressionEvaluatorType scriptType = parseScriptType("expression-" + TEST_NAME + ".xml");
ItemDefinition outputDefinition = new PrismPropertyDefinition(PROPERTY_NAME, DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext()); ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptType, outputDefinition, TEST_NAME);
ExpressionVariables variables = new ExpressionVariables();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -475,11 +475,11 @@ public void test032ModifyUserLegalizeAccount() throws Exception {
Task task = taskManager.createTaskInstance(TestAssignmentProcessor.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

repoAddObjectFromFile(USER_LARGO_FILENAME, UserType.class, result);
repoAddObjectFromFile(USER_LARGO_FILE, UserType.class, result);

LensContext<UserType> context = createUserAccountContext();
fillContextWithUser(context, USER_LARGO_OID, result);
fillContextWithAccountFromFile(context, ACCOUNT_SHADOW_ELAINE_DUMMY_FILENAME, result);
fillContextWithAccountFromFile(context, ACCOUNT_SHADOW_ELAINE_DUMMY_FILE, result);
context.recompute();

ProjectionPolicyType accountSynchronizationSettings = new ProjectionPolicyType();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -127,7 +127,7 @@ public void test010SerializeAddUserBarbossa() throws Exception {
OperationResult result = task.getResult();

LensContext<UserType> context = createUserAccountContext();
PrismObject<UserType> bill = prismContext.parseObject(new File(USER_BARBOSSA_FILENAME));
PrismObject<UserType> bill = prismContext.parseObject(USER_BARBOSSA_FILE);
fillContextWithAddUserDelta(context, bill);

// WHEN
Expand Down

0 comments on commit 24b835b

Please sign in to comment.