Skip to content

Commit

Permalink
schrodinger: switching between start/don't start mp
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Feb 23, 2021
1 parent eee105d commit b8754d8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 15 deletions.
Expand Up @@ -34,16 +34,16 @@
import com.evolveum.midpoint.testing.schrodinger.reports.SchrodingerTextReport;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Listeners;
import org.testng.ITestResult;
import org.testng.annotations.*;

import com.evolveum.midpoint.prism.crypto.EncryptionException;
import com.evolveum.midpoint.repo.api.RepoAddOptions;
Expand Down Expand Up @@ -99,6 +99,8 @@ public abstract class AbstractSchrodingerTest extends AbstractIntegrationTest {

protected BasicPage basicPage;

private boolean startMidpoint = true;

public EnvironmentConfiguration getConfiguration() {
return configuration;
}
Expand All @@ -111,6 +113,10 @@ public String getPassword() {
return password;
}

public boolean isStartMidpoint() {
return startMidpoint;
}

@Override
protected void initSystem(Task task, OperationResult initResult) throws Exception {
super.initSystem(task, initResult);
Expand All @@ -122,7 +128,42 @@ protected List<File> getObjectListToImport(){
return new ArrayList<>();
}

@BeforeClass
@BeforeClass(
alwaysRun = true,
dependsOnMethods = {"springTestContextBeforeTestClass"}
)
protected void springTestContextPrepareTestInstance() throws Exception {
String startMidpointStr = System.getProperty("startMidpoint");
if (startMidpointStr == null) {
Properties props = new Properties();
InputStream is = new FileInputStream(new File(SCHRODINGER_PROPERTIES));
props.load(is);
startMidpointStr = props.getProperty("startMidpoint");
}
if (!StringUtils.isEmpty(startMidpointStr) && startMidpointStr.equals("false")) {
startMidpoint = false;
}
if (startMidpoint) {
super.springTestContextPrepareTestInstance();
}
}

@BeforeMethod
public void startTestContext(ITestResult testResult) throws SchemaException {
if (startMidpoint) {
super.startTestContext(testResult);
}
}

@AfterMethod
public void finishTestContext(ITestResult testResult) {
if (startMidpoint) {
super.finishTestContext(testResult);
}
}


@BeforeClass(dependsOnMethods = {"springTestContextPrepareTestInstance"})
public void beforeClass() throws IOException {
LOG.info("Starting tests in class {}", getClass().getName());

Expand Down Expand Up @@ -160,9 +201,11 @@ protected EnvironmentConfiguration buildEnvironmentConfiguration(Properties prop

config.headless(Boolean.parseBoolean(headlessStart));

String baseUrl = System.getProperty("base_url");
String baseUrl;
String urlPropertyName = startMidpoint ? "base_url" : "base_url_mp_already_started";
baseUrl = System.getProperty(urlPropertyName);
if (baseUrl == null) {
baseUrl = props.getProperty("base_url");
baseUrl = props.getProperty(urlPropertyName);
}
config.baseUrl(baseUrl);

Expand Down Expand Up @@ -351,15 +394,15 @@ protected void addObjectFromFile(File file, boolean overwrite) {
}

protected void addObjectFromFile(File file, boolean overwrite, OperationResult result) {
try {
RepoAddOptions options = null;
if (overwrite) {
options = RepoAddOptions.createOverwrite();
}
repoAddObjectsFromFile(file, null, options, result);
} catch (SchemaException | ObjectAlreadyExistsException | EncryptionException | IOException ex) {
LOG.error("Unable to add object, {}", result.getUserFriendlyMessage(), ex);
}
// try {
// RepoAddOptions options = null;
// if (overwrite) {
// options = RepoAddOptions.createOverwrite();
// }
// repoAddObjectsFromFile(file, null, options, result);
// } catch (SchemaException | ObjectAlreadyExistsException | EncryptionException | IOException ex) {
// LOG.error("Unable to add object, {}", result.getUserFriendlyMessage(), ex);
// }
}

public UserPage showUser(String userName){
Expand Down
@@ -1,7 +1,9 @@
username=administrator
password=5ecr3t
base_url=http://localhost:8180/midpoint
base_url_mp_already_started=http://localhost:8080/midpoint
webdriver=CHROME
webdriverLocation=/opt/chromedriver
# By default if no value is specified for headless start then the value is: false
headlessStart=true
startMidpoint=true

0 comments on commit b8754d8

Please sign in to comment.