Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 30, 2020
2 parents d9f4f4c + 974af46 commit 51200a1
Show file tree
Hide file tree
Showing 152 changed files with 2,142 additions and 2,308 deletions.

Large diffs are not rendered by default.

Expand Up @@ -8,7 +8,6 @@
package com.evolveum.midpoint.web;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.EventListener;
Expand Down Expand Up @@ -83,7 +82,7 @@ public ServletRegistration.Dynamic addJspFile(String s, String s1) {
}

@Override
public <T extends Servlet> T createServlet(Class<T> c) throws ServletException {
public <T extends Servlet> T createServlet(Class<T> c) {
return null;
}

Expand Down Expand Up @@ -113,7 +112,7 @@ public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends F
}

@Override
public <T extends Filter> T createFilter(Class<T> c) throws ServletException {
public <T extends Filter> T createFilter(Class<T> c) {
return null;
}

Expand Down Expand Up @@ -163,7 +162,7 @@ public void addListener(Class<? extends EventListener> listenerClass) {
}

@Override
public <T extends EventListener> T createListener(Class<T> c) throws ServletException {
public <T extends EventListener> T createListener(Class<T> c) {
return null;
}

Expand Down Expand Up @@ -241,12 +240,12 @@ public void log(String msg) {
}

@Override
public Enumeration getServlets() {
public Enumeration<Servlet> getServlets() {
return null;
}

@Override
public Enumeration getServletNames() {
public Enumeration<String> getServletNames() {
return null;
}

Expand All @@ -256,7 +255,7 @@ public String getServletContextName() {
}

@Override
public Servlet getServlet(String arg0) throws ServletException {
public Servlet getServlet(String arg0) {
return null;
}

Expand All @@ -266,7 +265,7 @@ public String getServerInfo() {
}

@Override
public Set getResourcePaths(String arg0) {
public Set<String> getResourcePaths(String arg0) {
return null;
}

Expand All @@ -276,7 +275,7 @@ public InputStream getResourceAsStream(String name) {
}

@Override
public URL getResource(String name) throws MalformedURLException {
public URL getResource(String name) {
return this.getClass().getClassLoader().getResource(name);
}

Expand Down Expand Up @@ -311,7 +310,7 @@ public int getMajorVersion() {
}

@Override
public Enumeration getInitParameterNames() {
public Enumeration<String> getInitParameterNames() {
return null;
}

Expand All @@ -331,7 +330,7 @@ public ServletContext getContext(String arg0) {
}

@Override
public Enumeration getAttributeNames() {
public Enumeration<String> getAttributeNames() {
return null;
}

Expand All @@ -351,6 +350,6 @@ public Object getAttribute(String arg0) {
descriptorLoader.loadData(midPointApplication);

// THEN
display("initialized loader", descriptorLoader);
displayDumpable("initialized loader", descriptorLoader);
}
}
Expand Up @@ -60,7 +60,7 @@ private <O extends ObjectType> void testInitialObject(ObjectValidator validator,
display("Checked "+object+": no warnings");
return;
}
display("Validation warnings for "+object, validationResult);
displayDumpable("Validation warnings for "+object, validationResult);
for (ValidationItem valItem : validationResult.getItems()) {
errorsSb.append(file.getName());
errorsSb.append(" ");
Expand Down
Expand Up @@ -32,7 +32,7 @@
import com.evolveum.midpoint.schema.MidPointPrismContextFactory;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.test.util.OperationResultTestMixin;
import com.evolveum.midpoint.test.util.InfraTestMixin;
import com.evolveum.midpoint.tools.testng.AbstractUnitTest;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
Expand All @@ -44,7 +44,7 @@
* @author Radovan Semancik
*/
public class BasicValidatorTest extends AbstractUnitTest
implements OperationResultTestMixin {
implements InfraTestMixin {

public static final String BASE_PATH = "src/test/resources/validator/";
private static final String OBJECT_RESULT_OPERATION_NAME = BasicValidatorTest.class.getName() + ".validateObject";
Expand Down Expand Up @@ -72,8 +72,7 @@ public EventResult preMarshall(Element objectElement, Node postValidationTree,
@Override
public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement,
OperationResult objectResult) {
System.out.println("Validating resorce:");
System.out.println(object.debugDump());
displayDumpable("Validating resource:", object);
object.checkConsistence();

PrismContainer<?> extensionContainer = object.getExtension();
Expand Down Expand Up @@ -114,23 +113,21 @@ public EventResult preMarshall(Element objectElement, Node postValidationTree, O

@Override
public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult) {
System.out.println("Handler processing " + object + ", result:");
System.out.println(objectResult.debugDump());
displayDumpable("Handler processing " + object + ", result:", objectResult);
postMarshallHandledOids.add(object.getOid());
return EventResult.cont();
}

@Override
public void handleGlobalError(OperationResult currentResult) {
System.out.println("Handler got global error:");
System.out.println(currentResult.debugDump());
displayDumpable("Handler got global error:", currentResult);
}

};

validateFile("three-objects.xml", handler, result);

System.out.println(result.debugDump());
displayDumpable("Result:", result);
AssertJUnit.assertTrue("Result is not success", result.isSuccess());
AssertJUnit.assertTrue(postMarshallHandledOids.contains("c0c010c0-d34d-b33f-f00d-111111111111"));
AssertJUnit.assertTrue(preMarshallHandledOids.contains("c0c010c0-d34d-b33f-f00d-111111111111"));
Expand Down Expand Up @@ -233,19 +230,17 @@ private void validateFile(String filename, EventHandler handler, OperationResult
private void validateFile(String filename, LegacyValidator validator, OperationResult result) throws FileNotFoundException {
String filepath = BASE_PATH + filename;

System.out.println("Validating " + filename);
display("Validating " + filename);

File file = new File(filepath);
FileInputStream fis = new FileInputStream(file);

validator.validate(fis, result, OBJECT_RESULT_OPERATION_NAME);

if (!result.isSuccess()) {
System.out.println("Errors:");
System.out.println(result.debugDump());
displayDumpable("Errors:", result);
} else {
System.out.println("No errors");
System.out.println(result.debugDump());
displayDumpable("No errors:", result);
}
}
}
Expand Up @@ -16,14 +16,14 @@
import com.evolveum.midpoint.schema.MidPointPrismContextFactory;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.test.util.OperationResultTestMixin;
import com.evolveum.midpoint.test.util.InfraTestMixin;
import com.evolveum.midpoint.tools.testng.AbstractUnitTest;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;

// TODO testing: missing from suite, all passing
public class UnknownNodeValidationTest extends AbstractUnitTest
implements OperationResultTestMixin {
implements InfraTestMixin {

public static final String BASE_PATH = "src/test/resources/validator/unknown/";
private static final String OBJECT_RESULT_OPERATION_NAME = BasicValidatorTest.class.getName() + ".validateObject";
Expand Down Expand Up @@ -92,7 +92,7 @@ public void elementInConnector() throws Exception {
protected void validateNodeFailure(String name, String file, String expected) throws Exception {
OperationResult result = createOperationResult();
validateFile(file, result);
System.out.println(result.debugDump());
displayDumpable("result", result);
AssertJUnit.assertFalse("Result should not be successful", result.isSuccess());
String message = result.getMessage();
AssertJUnit.assertTrue(message.contains("undeclared"));
Expand All @@ -114,7 +114,6 @@ protected void validateFile(String filename, EventHandler handler, OperationResu
}

protected void customizeValidator(LegacyValidator validator) {

}

private void validateFile(String filename, LegacyValidator validator, OperationResult result) throws FileNotFoundException {
Expand All @@ -126,12 +125,9 @@ private void validateFile(String filename, LegacyValidator validator, OperationR
fis = new FileInputStream(file);
validator.validate(fis, result, OBJECT_RESULT_OPERATION_NAME);
if (!result.isSuccess()) {
System.out.println("Errors:");
System.out.println(result.debugDump());
displayDumpable("Errors:", result);
} else {
System.out.println("No errors");
System.out.println(result.debugDump());
displayDumpable("No errors", result);
}

}
}
Expand Up @@ -337,7 +337,16 @@ public String debugDump(int indent) {

@Override
public void shortDump(StringBuilder sb) {
sb.append(orig);
sb.append("orig=" + orig);
if (getTranslation() != null) {
sb.append("; translation.key=" + getTranslation().getKey());
}
if (getLang() != null) {
sb.append("; lang:");
getLang().keySet().forEach(langKey -> {
sb.append(" " + langKey + "=" + getLang().get(langKey) + ",");
});
}
}

public static String getOrig(PolyString s) {
Expand Down
Expand Up @@ -213,7 +213,6 @@ public static ObjectFilter getFilterCondition(ObjectFilter filter, int index) {
return ((LogicalFilter) filter).getConditions().get(index);
}

// TODO versions with external logger?
public static void display(String title, DebugDumpable dumpable) {
System.out.println(OBJECT_TITLE_OUT_PREFIX + title);
System.out.println(dumpable == null ? "null" : dumpable.debugDump(1));
Expand Down
Expand Up @@ -587,12 +587,15 @@ public String toHumanReadableString() {
// (displaying the aux information in user-visible context). But for e.g. deltas we need this information.
PolyString ps = (PolyString) this.value;
StringBuilder sb = new StringBuilder();
sb.append(ps.getOrig());
sb.append("orig=" + ps.getOrig());
if (ps.getTranslation() != null) {
sb.append(" (has translation key)");
sb.append(", translation.key=" + ps.getTranslation().getKey());
}
if (ps.getLang() != null) {
sb.append(" (").append(ps.getLang().size()).append(" lang map entry/entries)");
sb.append("; lang:");
ps.getLang().keySet().forEach(langKey -> {
sb.append(" " + langKey + "=" + ps.getLang().get(langKey) + ",");
});
}
return sb.toString();
} else {
Expand Down
Expand Up @@ -2,12 +2,14 @@

import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.tools.testng.MidpointTestMixin;
import com.evolveum.midpoint.util.DebugDumpable;

/**
* Mixin interface adding methods for {@link OperationResult} creation with context in its name.
* Mixin interface adding capabilities from infra test-utils like {@link OperationResult} creation
* (with context in its name), display method for dumpable, etc.
* It is based on {@link MidpointTestMixin} and provides all its operations too.
*/
public interface OperationResultTestMixin extends MidpointTestMixin {
public interface InfraTestMixin extends MidpointTestMixin {

/**
* Creates new {@link OperationResult} with name equal to {@link #contextName()}.
Expand All @@ -22,4 +24,14 @@ default OperationResult createOperationResult() {
default OperationResult createOperationResult(String nameSuffix) {
return new OperationResult(contextName() + "." + nameSuffix);
}

/**
* Displays {@link DebugDumpable} value prefixed with provided title.
*/
// TODO: after cleanup rename to displayValue or displayDumpable
default void displayDumpable(String title, DebugDumpable dumpable) {
displayValue(title, dumpable == null ? "null" : dumpable.debugDump(1));
}

// TODO add displayValue(title, Object) based on PrettyPrinter, finish PrettyPrinter ideas
}
Expand Up @@ -666,7 +666,7 @@ public void test110RecordRevokeJackCeo() throws Exception {
checkAllCasesSanity(caseList);

ceoCase = findCase(caseList, USER_JACK_OID, ROLE_CEO_OID);
display("CEO case", ceoCase.asPrismContainerValue());
displayDumpable("CEO case", ceoCase.asPrismContainerValue());
assertEquals("changed case ID", Long.valueOf(id), ceoCase.asPrismContainerValue().getId());
assertSingleDecision(ceoCase, REVOKE, "no way", 1, 1, USER_ADMINISTRATOR_OID, REVOKE, false);

Expand Down

0 comments on commit 51200a1

Please sign in to comment.