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
katkav committed Mar 18, 2020
2 parents 0948644 + 6b82757 commit 54fa7a9
Show file tree
Hide file tree
Showing 12 changed files with 949 additions and 948 deletions.

Large diffs are not rendered by default.

Expand Up @@ -13,7 +13,6 @@
import static com.evolveum.midpoint.web.AdminGuiTestConstants.*;

import java.io.File;
import java.lang.reflect.Method;
import java.util.Locale;
import javax.xml.namespace.QName;

Expand All @@ -25,10 +24,7 @@
import org.apache.wicket.util.tester.WicketTester;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

import com.evolveum.midpoint.common.LocalizationService;
import com.evolveum.midpoint.gui.api.prism.ItemStatus;
Expand Down Expand Up @@ -58,8 +54,6 @@
import com.evolveum.midpoint.security.enforcer.api.SecurityEnforcer;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.web.security.MidPointApplication;
import com.evolveum.midpoint.web.security.util.SecurityUtils;
Expand Down Expand Up @@ -140,39 +134,10 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
tester = new WicketTester(application, true);
}

@BeforeMethod
public void beforeMethodApplication() {
}

@AfterMethod
public void afterMethodApplication() {
}

@BeforeClass
public void beforeClass() {
System.out.println("\n>>>>>>>>>>>>>>>>>>>>>>>> START " + getClass().getName() + "<<<<<<<<<<<<<<<<<<<<<<<<");
logger.info("\n>>>>>>>>>>>>>>>>>>>>>>>> START {} <<<<<<<<<<<<<<<<<<<<<<<<", new Object[] { getClass().getName() });
logger.info("Loalization serivce : {}", localizationService);
String s = localizationService.translate("midpoint.system.build", null, localizationService.getDefaultLocale());
logger.info("SsSSSSSSSSSSSSS {}", s);
}

@AfterClass
public void afterClass() {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> FINISH " + getClass().getName() + "<<<<<<<<<<<<<<<<<<<<<<<<");
logger.info(">>>>>>>>>>>>>>>>>>>>>>>> FINISH {} <<<<<<<<<<<<<<<<<<<<<<<<\n", new Object[] { getClass().getName() });
}

@BeforeMethod
public void beforeMethod(Method method) {
System.out.println("\n>>>>>>>>>>>>>>>>>>>>>>>> START TEST" + getClass().getName() + "." + method.getName() + "<<<<<<<<<<<<<<<<<<<<<<<<");
logger.info("\n>>>>>>>>>>>>>>>>>>>>>>>> START {}.{} <<<<<<<<<<<<<<<<<<<<<<<<", new Object[] { getClass().getName(), method.getName() });
}

@AfterMethod
public void afterMethod(Method method) {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> END TEST" + getClass().getName() + "." + method.getName() + "<<<<<<<<<<<<<<<<<<<<<<<<");
logger.info(">>>>>>>>>>>>>>>>>>>>>>>> END {}.{} <<<<<<<<<<<<<<<<<<<<<<<<", new Object[] { getClass().getName(), method.getName() });
public void displayLocalizationAndSystemBuildInfo() {
display("Localization service: " + localizationService);
display("System build: " + localizationService.translate("midpoint.system.build", null, localizationService.getDefaultLocale()));
}

protected ModelServiceLocator getServiceLocator(final Task pageTask) {
Expand Down
Expand Up @@ -35,11 +35,6 @@ public class TestQueryBuilder extends AbstractPrismTest {
public static final QName USER_TYPE_QNAME = new QName(NS_FOO, "UserType");
public static final QName ASSIGNMENT_TYPE_QNAME = new QName(NS_FOO, "AssignmentType");

@BeforeMethod
public void beforeMethod(Method method) {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> START TEST" + getClass().getName() + "." + method.getName() + "<<<<<<<<<<<<<<<<<<<<<<<<");
}

@Test
public void test100EmptyFilter() {
ObjectQuery actual = getPrismContext().queryFor(UserType.class).build();
Expand Down
Expand Up @@ -14,6 +14,7 @@
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

import com.evolveum.midpoint.tools.testng.MidpointTestContext;
Expand All @@ -35,6 +36,16 @@ public abstract class AbstractSpringTest extends AbstractTestNGSpringContextTest
*/
protected final Trace logger = TraceManager.getTrace(getClass());

@BeforeClass
public void displayTestClassTitle() {
displayTestTitle("Initializing TEST CLASS: " + getClass().getName());
}

@AfterClass
public void displayTestClassFooter() {
displayTestFooter("Finishing with TEST CLASS: " + getClass().getName());
}

@BeforeMethod
public void startTestContext(ITestResult testResult) throws Exception {
SimpleMidpointTestContext context = SimpleMidpointTestContext.create(testResult);
Expand Down
Expand Up @@ -204,7 +204,6 @@ public void initSystem() throws Exception {
return;
}
initSystemExecuted = true;
logger.trace("initSystem: initializing class {}", getClass().getName());

// Check whether we are already initialized
assertNotNull("Repository is not wired properly", repositoryService);
Expand Down
Expand Up @@ -7,18 +7,14 @@

package com.evolveum.midpoint.testing.schrodinger;

import java.io.*;
import java.lang.reflect.Method;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.codeborne.selenide.Selenide;

import com.codeborne.selenide.testng.BrowserPerClass;

import com.evolveum.midpoint.test.AbstractIntegrationTest;

import com.evolveum.midpoint.web.boot.MidPointSpringApplication;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,7 +23,9 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.testng.Assert;
import org.testng.annotations.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Listeners;

import com.evolveum.midpoint.schrodinger.EnvironmentConfiguration;
import com.evolveum.midpoint.schrodinger.MidPoint;
Expand All @@ -39,16 +37,16 @@
import com.evolveum.midpoint.schrodinger.page.login.FormLoginPage;
import com.evolveum.midpoint.schrodinger.page.resource.ListResourcesPage;
import com.evolveum.midpoint.schrodinger.page.resource.ViewResourcePage;

import static com.codeborne.selenide.Selenide.open;
import com.evolveum.midpoint.test.AbstractIntegrationTest;
import com.evolveum.midpoint.web.boot.MidPointSpringApplication;

/**
* Created by Viliam Repan (lazyman).
*/
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@ActiveProfiles("default")
@SpringBootTest(classes = MidPointSpringApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestPropertySource(properties = {"server.port=8180", "midpoint.schrodinger=true"})
@TestPropertySource(properties = { "server.port=8180", "midpoint.schrodinger=true" })
@Listeners({ BrowserPerClass.class })
public abstract class AbstractSchrodingerTest extends AbstractIntegrationTest {

Expand Down Expand Up @@ -137,16 +135,6 @@ public void afterClass() {
.clickYes();
}

@BeforeMethod
public void beforeMethod(Method method) {
LOG.info("Starting test {}.{}", method.getDeclaringClass().getName(), method.getName());
}

@AfterMethod
public void afterMethod(Method method) {
LOG.info("Finished test {}.{}", method.getDeclaringClass().getName(), method.getName());
}

protected void importObject(File source, Boolean overrideExistingObject) {
ImportObjectPage importPage = basicPage.importObject();

Expand Down
53 changes: 15 additions & 38 deletions tools/ninja/src/test/java/com/evolveum/midpoint/ninja/BaseTest.java
Expand Up @@ -6,28 +6,27 @@
*/
package com.evolveum.midpoint.ninja;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import com.beust.jcommander.JCommander;
import com.evolveum.midpoint.ninja.impl.NinjaContext;
import com.evolveum.midpoint.ninja.opts.ConnectionOptions;
import com.evolveum.midpoint.ninja.util.NinjaUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import java.io.*;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import com.evolveum.midpoint.ninja.impl.NinjaContext;
import com.evolveum.midpoint.ninja.opts.ConnectionOptions;
import com.evolveum.midpoint.ninja.util.NinjaUtils;
import com.evolveum.midpoint.tools.testng.AbstractUnitTest;

/**
* Created by Viliam Repan (lazyman).
*/
public class BaseTest {
public class BaseTest extends AbstractUnitTest {

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

Expand All @@ -38,29 +37,7 @@ public class BaseTest {
private List<String> systemOut;
private List<String> systemErr;

@BeforeMethod
public final void beforeMethod(Method method) throws Exception {
LOG.info(">>>>>>>>>>>>>>>> Start " + method.getDeclaringClass().getSimpleName() + "."
+ method.getName() + "<<<<<<<<<<<<<<<<<<<");

beforeMethodInternal(method);
}

@AfterMethod
public final void afterMethod(Method method) throws Exception {
afterMethodInternal(method);
LOG.info(">>>>>>>>>>>>>>>> Finished " + method.getDeclaringClass().getSimpleName() + "."
+ method.getName() + "<<<<<<<<<<<<<<<<<<<");
}

protected void beforeMethodInternal(Method method) throws Exception {

}

protected void afterMethodInternal(Method method) throws Exception {

}

// add @BeforeMethod calling this into test classes that need this
protected void setupMidpointHome() throws IOException {
FileUtils.deleteDirectory(TARGET_HOME);

Expand Down Expand Up @@ -90,14 +67,14 @@ protected void executeTest(String... args) {
}

protected void executeTest(ExecutionValidator preExecutionValidator,
ExecutionValidator postExecutionValidator, String... args) {
ExecutionValidator postExecutionValidator, String... args) {
executeTest(null, preExecutionValidator, postExecutionValidator, false, false, args);
}

protected void executeTest(ExecutionValidator preInit,
ExecutionValidator preExecution,
ExecutionValidator postExecution,
boolean saveOut, boolean saveErr, String... args) {
ExecutionValidator preExecution,
ExecutionValidator postExecution,
boolean saveOut, boolean saveErr, String... args) {

systemOut = new ArrayList<>();
systemErr = new ArrayList<>();
Expand Down
Expand Up @@ -6,34 +6,34 @@
*/
package com.evolveum.midpoint.ninja;

import org.testng.AssertJUnit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;

import java.lang.reflect.Method;

/**
* Created by Viliam Repan (lazyman).
*/
public class DeleteRepositoryTest extends BaseTest {

@Override
protected void beforeMethodInternal(Method method) throws Exception {
@BeforeMethod
public void initMidpointHome() throws Exception {
setupMidpointHome();
}

@Test
public void deleteByOid() throws Exception {
public void deleteByOid() {
String type = ObjectTypes.ROLE.name();
String oid = SystemObjectsType.ROLE_DELEGATOR.value();

String[] input = new String[]{"-m", getMidpointHome(), "delete", "-o", oid, "-t", type};
String[] input = new String[] { "-m", getMidpointHome(), "delete", "-o", oid, "-t", type };

OperationResult result = new OperationResult("delete by oid");

Expand Down
Expand Up @@ -6,10 +6,10 @@
*/
package com.evolveum.midpoint.ninja;

import java.lang.reflect.Method;
import java.util.List;

import org.testng.AssertJUnit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.evolveum.midpoint.repo.api.RepositoryService;
Expand All @@ -22,14 +22,14 @@
*/
public class ImportInvalidRepositoryTest extends BaseTest {

@Override
protected void beforeMethodInternal(Method method) throws Exception {
@BeforeMethod
public void initMidpointHome() throws Exception {
setupMidpointHome();
}

@Test
public void test100Import() {
String[] input = new String[]{"-m", getMidpointHome(), "import", "-i", RESOURCES_FOLDER + "/unknown-nodes.zip", "-z"};
String[] input = new String[] { "-m", getMidpointHome(), "import", "-i", RESOURCES_FOLDER + "/unknown-nodes.zip", "-z" };
executeTest(null,
context -> {
RepositoryService repo = context.getRepository();
Expand Down
Expand Up @@ -7,10 +7,10 @@
package com.evolveum.midpoint.ninja;

import java.io.ByteArrayOutputStream;
import java.lang.reflect.Method;
import java.util.List;

import org.testng.AssertJUnit;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.evolveum.midpoint.repo.api.RepositoryService;
Expand All @@ -23,8 +23,8 @@
*/
public class ImportRepositoryTest extends BaseTest {

@Override
protected void beforeMethodInternal(Method method) throws Exception {
@BeforeMethod
public void initMidpointHome() throws Exception {
setupMidpointHome();
}

Expand Down
Expand Up @@ -10,7 +10,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

/**
Expand All @@ -21,6 +23,16 @@ public abstract class AbstractUnitTest implements MidpointTestMixin {

protected final Logger logger = LoggerFactory.getLogger(getClass());

@BeforeClass
public void displayTestClassTitle() {
displayTestTitle("Initializing TEST CLASS: " + getClass().getName());
}

@AfterClass
public void displayTestClassFooter() {
displayTestFooter("Finishing with TEST CLASS: " + getClass().getName());
}

@BeforeMethod
public void startTestContext(ITestResult testResult) {
SimpleMidpointTestContext context = SimpleMidpointTestContext.create(testResult);
Expand Down

0 comments on commit 54fa7a9

Please sign in to comment.