Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Apr 28, 2020
2 parents 8e1dea7 + 36316f4 commit 25b0c35
Show file tree
Hide file tree
Showing 23 changed files with 2,889 additions and 62 deletions.
Expand Up @@ -13,19 +13,13 @@
import java.io.InputStream;
import java.util.Properties;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.ex.ElementNotFound;
import com.codeborne.selenide.testng.BrowserPerClass;

import com.evolveum.midpoint.schrodinger.component.AssignmentsTab;

import com.evolveum.midpoint.schrodinger.component.common.FeedbackBox;
import com.evolveum.midpoint.schrodinger.component.common.table.AbstractTableWithPrismView;
import com.evolveum.midpoint.schrodinger.page.AssignmentHolderDetailsPage;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down Expand Up @@ -70,7 +64,7 @@ public abstract class AbstractSchrodingerTest extends AbstractIntegrationTest {

private static final Logger LOG = LoggerFactory.getLogger(AbstractSchrodingerTest.class);

protected static File csvTargetDir;
protected static File testTargetDir;

protected EnvironmentConfiguration configuration;

Expand Down Expand Up @@ -220,19 +214,19 @@ protected File initTestDirectory(String dir) throws IOException {
String home = fetchMidpointHome();
File parentDir = new File(home, "schrodinger");
parentDir.mkdir();
csvTargetDir = new File(parentDir, dir);
testTargetDir = new File(parentDir, dir);

if (csvTargetDir.mkdir()) {
if (testTargetDir.mkdir()) {

return csvTargetDir;
return testTargetDir;
} else {
if (csvTargetDir.exists()) {
if (testTargetDir.exists()) {

FileUtils.cleanDirectory(csvTargetDir);
return csvTargetDir;
FileUtils.cleanDirectory(testTargetDir);
return testTargetDir;
} else {

throw new IOException("Creation of directory \"" + csvTargetDir.getAbsolutePath() + "\" unsuccessful");
throw new IOException("Creation of directory \"" + testTargetDir.getAbsolutePath() + "\" unsuccessful");
}
}
}
Expand Down
Expand Up @@ -59,6 +59,7 @@ public class AbstractLabTest extends AbstractSchrodingerTest {
protected static final File HR_SOURCE_FILE_10_2_PART1 = new File(LAB_SOURCES_DIRECTORY + "source-10-2-part1.csv");
protected static final File HR_SOURCE_FILE_10_2_PART2 = new File(LAB_SOURCES_DIRECTORY + "source-10-2-part2.csv");
protected static final File HR_SOURCE_FILE_10_2_PART3 = new File(LAB_SOURCES_DIRECTORY + "source-10-2-part3.csv");
protected static final File HR_SOURCE_FILE_11_1 = new File(LAB_SOURCES_DIRECTORY + "source-11-1.csv");


protected static final String DIRECTORY_CURRENT_TEST = "labTests";
Expand All @@ -74,6 +75,7 @@ public class AbstractLabTest extends AbstractSchrodingerTest {
protected static final String CSV_3_RESOURCE_OID = "10000000-9999-9999-0000-a000ff000004";
protected static final String HR_FILE_SOURCE_NAME = "source.csv";
protected static final String HR_RESOURCE_NAME = "ExAmPLE, Inc. HR Source";
protected static final String NOTIFICATION_FILE_NAME = "notification.txt";

protected static final String PASSWORD_ATTRIBUTE_RESOURCE_KEY = "User password attribute name";
protected static final String UNIQUE_ATTRIBUTE_RESOURCE_KEY = "Unique attribute name";
Expand All @@ -89,6 +91,7 @@ public class AbstractLabTest extends AbstractSchrodingerTest {
protected static File csv2TargetFile;
protected static File csv3TargetFile;
protected static File hrTargetFile;
protected static File notificationFile = new File("./target/notification.txt");

@AfterClass
@Override
Expand All @@ -112,8 +115,8 @@ public AssignmentHolderObjectListTable<ListUsersPage, UserPage> showUserInTable(
.search()
.byName()
.inputValue(userName)
.updateSearch()
.and();
.updateSearch()
.and();
}

public AccountPage showShadow(String resourceName, String searchedItem, String itemValue){
Expand Down Expand Up @@ -143,7 +146,7 @@ public ResourceShadowTable getShadowTable(String resourceName, String searchedIt
.search()
.byName()
.inputValue(resourceName)
.updateSearch()
.updateSearch()
.and()
.clickByName(resourceName)
.clickAccountsTab();
Expand All @@ -153,26 +156,26 @@ public ResourceShadowTable getShadowTable(String resourceName, String searchedIt
tab.clickSearchInResource();
}
Selenide.sleep(1000);
if (intent != null && !intent.isBlank()) {
if (intent != null && !intent.isEmpty()) {
tab.setIntent(intent);
Selenide.sleep(MidPoint.TIMEOUT_DEFAULT_2_S);
}
return tab.table()
.search()
.resetBasicSearch()
.byItem(searchedItem)
.inputValueWithEnter(itemValue)
.and()
.and();
.search()
.resetBasicSearch()
.byItem(searchedItem)
.inputValueWithEnter(itemValue)
.and()
.and();
}

protected TaskPage showTask(String name) {
return basicPage.listTasks()
.table()
.search()
.byName()
.inputValue(name)
.updateSearch()
.inputValue(name)
.updateSearch()
.and()
.clickByName(name);
}
Expand Down
Expand Up @@ -18,17 +18,13 @@
import com.evolveum.midpoint.schrodinger.component.configuration.ObjectPolicyTab;
import com.evolveum.midpoint.schrodinger.component.org.OrgRootTab;
import com.evolveum.midpoint.schrodinger.component.resource.ResourceAccountsTab;
import com.evolveum.midpoint.schrodinger.page.configuration.AboutPage;
import com.evolveum.midpoint.schrodinger.page.resource.ViewResourcePage;
import com.evolveum.midpoint.schrodinger.page.task.TaskPage;
import com.evolveum.midpoint.schrodinger.page.user.UserPage;
import com.evolveum.midpoint.testing.schrodinger.scenarios.ScenariosCommons;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

import java.io.File;
Expand All @@ -40,29 +36,12 @@

public class M10ObjectTemplate extends AbstractLabTest{

private static final Logger LOG = LoggerFactory.getLogger(M10ObjectTemplate.class);

private static final File OBJECT_TEMPLATE_USER_SIMPLE_FILE = new File(LAB_OBJECTS_DIRECTORY + "objectTemplate/object-template-example-user-simple.xml");
private static final File OBJECT_TEMPLATE_USER_FILE = new File(LAB_OBJECTS_DIRECTORY + "objectTemplate/object-template-example-user.xml");
private static final File OBJECT_TEMPLATE_USER_FILE_10_3 = new File(LAB_OBJECTS_DIRECTORY + "objectTemplate/object-template-example-user-10-3.xml");
private static final File LOOKUP_EMP_STATUS_FILE = new File(LAB_OBJECTS_DIRECTORY + "lookupTables/lookup-emp-status.xml");
private static final File CSV_3_RESOURCE_FILE_10_4 = new File(LAB_OBJECTS_DIRECTORY + "resources/localhost-csvfile-3-ldap-10-4.xml");

@AfterClass
@Override
public void afterClass() {
super.afterClass();

midPoint.formLogin().loginWithReloadLoginPage(username, password);

LOG.info("After: Login name " + username + " pass " + password);

AboutPage aboutPage = basicPage.aboutPage();
aboutPage
.clickSwitchToFactoryDefaults()
.clickYes();
}

@Test(groups={"M10"}, dependsOnGroups={"M9"})
public void mod10test01SimpleObjectTemplate() throws IOException {
importObject(OBJECT_TEMPLATE_USER_SIMPLE_FILE, true);
Expand Down
@@ -0,0 +1,188 @@
/*
* Copyright (c) 2010-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.schrodinger.labs;

import static com.codeborne.selenide.Selenide.$;

import com.codeborne.selenide.Selenide;

import com.evolveum.midpoint.schrodinger.MidPoint;

import com.evolveum.midpoint.schrodinger.page.configuration.AboutPage;
import com.evolveum.midpoint.schrodinger.page.login.FormLoginPage;
import com.evolveum.midpoint.schrodinger.util.Schrodinger;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
* @author skublik
*/

public class M11SystemConfiguration extends AbstractLabTest {

private static final Logger LOG = LoggerFactory.getLogger(M11SystemConfiguration.class);

private static final File SYSTEM_CONFIGURATION_FILE_11_1 = new File(LAB_OBJECTS_DIRECTORY + "systemConfiguration/system-configuration-11-1.xml");
private static final File SYSTEM_CONFIGURATION_FILE_11_2 = new File(LAB_OBJECTS_DIRECTORY + "systemConfiguration/system-configuration-11-2.xml");
private static final File SYSTEM_CONFIGURATION_FILE_11_3 = new File(LAB_OBJECTS_DIRECTORY + "systemConfiguration/system-configuration-11-3.xml");
private static final File OBJECT_COLLECTION_ACTIVE_EMP_FILE = new File(LAB_OBJECTS_DIRECTORY + "objectCollections/objectCollection-active-employees.xml");
private static final File OBJECT_COLLECTION_INACTIVE_EMP_FILE = new File(LAB_OBJECTS_DIRECTORY + "objectCollections/objectCollection-inactive-employees.xml");
private static final File OBJECT_COLLECTION_FORMER_EMP_FILE = new File(LAB_OBJECTS_DIRECTORY + "objectCollections/objectCollection-former-employees.xml");

@AfterClass
@Override
public void afterClass() {
super.afterClass();

midPoint.formLogin().loginWithReloadLoginPage(username, password);

LOG.info("After: Login name " + username + " pass " + password);

AboutPage aboutPage = basicPage.aboutPage();
aboutPage
.clickSwitchToFactoryDefaults()
.clickYes();
}

@Test(groups={"M11"}, dependsOnGroups={"M10"})
public void mod11test01ConfiguringNotifications() throws IOException {
notificationFile = new File(testTargetDir, NOTIFICATION_FILE_NAME);
notificationFile.createNewFile();

importObject(SYSTEM_CONFIGURATION_FILE_11_1, true);

basicPage.notifications()
.setRedirectToFile(notificationFile.getAbsolutePath())
.and()
.save()
.feedback()
.isSuccess();

FileUtils.copyFile(HR_SOURCE_FILE_11_1, hrTargetFile);
Selenide.sleep(MidPoint.TIMEOUT_MEDIUM_6_S);

String notification = readBodyOfLastNotification();

String startOfNotification = "Notification about user-related operation (status: SUCCESS)\n"
+ "\n"
+ "User: Chuck Norris (X000997, oid ";

String endOfNotification = "The user record was created with the following data:\n"
+ " - Name: X000997\n"
+ " - Full name: Chuck Norris\n"
+ " - Given name: Chuck\n"
+ " - Family name: Norris\n"
+ " - Title: Application Developer\n"
+ " - Email: chuck.norris@example.com\n"
+ " - Employee Number: 000997\n"
+ " - Cost Center: 0211\n"
+ " - Organizational Unit: Java Development\n"
+ " - Extension:\n"
+ " - Organizational Path: 0200:0210:0211\n"
+ " - Is Manager: false\n"
+ " - Employee Status: A\n"
+ " - Credentials:\n"
+ " - Password:\n"
+ " - Value: (protected string)\n"
+ " - Activation:\n"
+ " - Administrative status: ENABLED\n"
+ " - Valid from: Jul 15, 2010, 8:20:00 AM\n"
+ " - Assignment #1:\n"
+ " - Target: Employee (archetype) [default]\n"
+ " - Assignment #2:\n"
+ " - Target: ACTIVE (org) [default]\n"
+ " - Assignment #3:\n"
+ " - Target: 0211 (org) [default]\n"
+ " - Assignment #4:\n"
+ " - Target: Internal Employee (role) [default]\n"
+ "\n"
+ "Requester: midPoint Administrator (administrator)\n"
+ "Channel: http://midpoint.evolveum.com/xml/ns/public/provisioning/channels-3#liveSync\n"
+ "\n";

Assert.assertTrue(notification.startsWith(startOfNotification));
Assert.assertTrue(notification.endsWith(endOfNotification));
}

@Test(dependsOnMethods = {"mod11test01ConfiguringNotifications"},groups={"M11"}, dependsOnGroups={"M10"})
public void mod11test02ConfiguringDeploymentInformation() {
importObject(SYSTEM_CONFIGURATION_FILE_11_2, true);

Assert.assertTrue($(Schrodinger.byDataId("header", "mainHeader"))
.getCssValue("background-color").equals("rgba(48, 174, 48, 1)"));
Assert.assertTrue($(Schrodinger.byDataId("span", "pageTitle")).getText().startsWith("DEV:"));

basicPage.deploymentInformation()
.form()
.addAttributeValue("headerColor", "lightblue")
.and()
.and()
.save()
.feedback()
.isSuccess();

Assert.assertTrue($(Schrodinger.byDataId("header", "mainHeader"))
.getCssValue("background-color").equals("rgba(173, 216, 230, 1)"));

basicPage.deploymentInformation()
.form()
.addAttributeValue("headerColor", "#30ae30")
.and()
.and()
.save()
.feedback()
.isSuccess();
Assert.assertTrue($(Schrodinger.byDataId("header", "mainHeader"))
.getCssValue("background-color").equals("rgba(48, 174, 48, 1)"));
}

@Test(dependsOnMethods = {"mod11test02ConfiguringDeploymentInformation"},groups={"M11"}, dependsOnGroups={"M10"})
public void mod11test03ConfiguringObjectCollectionsAndViews() {
importObject(OBJECT_COLLECTION_ACTIVE_EMP_FILE, true);
importObject(OBJECT_COLLECTION_INACTIVE_EMP_FILE, true);
importObject(OBJECT_COLLECTION_FORMER_EMP_FILE, true);
importObject(SYSTEM_CONFIGURATION_FILE_11_3, true);

basicPage.loggedUser().logoutIfUserIsLogin();
FormLoginPage login = midPoint.formLogin();
login.login(getUsername(), getPassword());

basicPage.listUsers("Employees");
basicPage.listUsers("Externals");
basicPage.listUsers("Inactive Employees");
basicPage.listUsers("Former Employees");
basicPage.listUsers("Active Employees");

}

protected String readBodyOfLastNotification() throws IOException {
String separator = "============================================";
byte[] encoded = Files.readAllBytes(Paths.get(notificationFile.getAbsolutePath()));
String notifications = new String(encoded, Charset.defaultCharset());
if (!notifications.contains(separator)) {
return "";
}
String notification = notifications.substring(notifications.lastIndexOf(separator) + separator.length(), notifications.length()-1);
String bodyTag = "body='";
if (!notifications.contains(bodyTag)) {
return "";
}
String body = notification.substring(notification.indexOf(bodyTag) + bodyTag.length(), notification.lastIndexOf("'"));
return body;
}
}
Expand Up @@ -52,7 +52,7 @@ public void beforeClass() throws IOException {
public void mod03test01ViewingResources() throws Exception {
initTestDirectory(DIRECTORY_CURRENT_TEST);

csv1TargetFile = new File(csvTargetDir, CSV_1_FILE_SOURCE_NAME);
csv1TargetFile = new File(testTargetDir, CSV_1_FILE_SOURCE_NAME);
FileUtils.copyFile(CSV_1_SOURCE_FILE, csv1TargetFile);

importObject(CSV_1_SIMPLE_RESOURCE_FILE,true);
Expand Down Expand Up @@ -127,14 +127,14 @@ public void mod03test01ViewingResources() throws Exception {

importObject(NUMERIC_PIN_FIRST_NONZERO_POLICY_FILE,true);

csv2TargetFile = new File(csvTargetDir, CSV_2_FILE_SOURCE_NAME);
csv2TargetFile = new File(testTargetDir, CSV_2_FILE_SOURCE_NAME);
FileUtils.copyFile(CSV_2_SOURCE_FILE, csv2TargetFile);

importObject(CSV_2_RESOURCE_FILE,true);

changeResourceAttribute(CSV_2_RESOURCE_NAME, ScenariosCommons.CSV_RESOURCE_ATTR_FILE_PATH, csv2TargetFile.getAbsolutePath(), true);

csv3TargetFile = new File(csvTargetDir, CSV_3_FILE_SOURCE_NAME);
csv3TargetFile = new File(testTargetDir, CSV_3_FILE_SOURCE_NAME);
FileUtils.copyFile(CSV_3_SOURCE_FILE, csv3TargetFile);

importObject(CSV_3_RESOURCE_FILE,true);
Expand Down

0 comments on commit 25b0c35

Please sign in to comment.