Skip to content

Commit

Permalink
Some basic integration test foot work to test LDAP polystrings (not m…
Browse files Browse the repository at this point in the history
…uch). PolyString fixes. LDAP story test cleanup.
  • Loading branch information
semancik committed Apr 2, 2019
1 parent ea5fb67 commit 31e2490
Show file tree
Hide file tree
Showing 49 changed files with 859 additions and 244 deletions.
Expand Up @@ -371,7 +371,7 @@ public boolean matches(String regex) {
* Returns true in case that there are language mutations, translation, etc.
*/
public boolean isSimple() {
return translation == null;
return translation == null && lang == null;
}

@Override
Expand Down
Expand Up @@ -474,16 +474,26 @@ public String debugDump(int indent) {
dump = null;
} else {
T realValue = value.getValue();
if (realValue instanceof ShortDumpable) {
((ShortDumpable)realValue).shortDump(sb);
} else if (realValue instanceof DebugDumpable) {

if (DebugUtil.isDetailedDebugDump() && realValue instanceof DebugDumpable) {
// Override in case that the value is both DebugDumpable and ShortDumpable
// In that case we want to force debugDump as we are in detailedDebugMode here.
// This is important e.g. for PolyString, in detailedDebugMode we want to see
// all the PolyString details.
sb.append(((DebugDumpable)realValue).debugDump(indent + 1));
} else {
if (DebugUtil.isDetailedDebugDump()) {
PrismPrettyPrinter.debugDumpValue(sb, indent + 1, realValue, prismContext, getElementName(), null);
if (realValue instanceof ShortDumpable) {
DebugUtil.indentDebugDump(sb, indent + 1);
((ShortDumpable)realValue).shortDump(sb);
} else if (realValue instanceof DebugDumpable) {
sb.append(((DebugDumpable)realValue).debugDump(indent + 1));
} else {
sb.append("SS{"+realValue+"}");
PrettyPrinter.shortDump(sb, realValue);
if (DebugUtil.isDetailedDebugDump()) {
PrismPrettyPrinter.debugDumpValue(sb, indent + 1, realValue, prismContext, getElementName(), null);
} else {
sb.append("SS{"+realValue+"}");
PrettyPrinter.shortDump(sb, realValue);
}
}
}
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 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 @@ -29,11 +29,13 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -730,6 +732,43 @@ public static void assertNoAttribute(Entry response, String name) {
}
AssertJUnit.fail("Attribute "+name+" exists while not expecting it: "+attribute);
}

public static void assertAttributeLang(Entry entry, String attributeName, String expectedOrigValue, String... params) {
List<Attribute> attrs = entry.getAttribute(attributeName.toLowerCase());
if (attrs == null || attrs.size() == 0) {
AssertJUnit.fail("Attribute "+attributeName+" does not have any value");
}
Map<String,String> expectedLangs = MiscUtil.paramsToMap(params);
List<String> langsSeen = new ArrayList<>();
for (Attribute attr : attrs) {
if (attr.size() == 0) {
throw new IllegalArgumentException("No values in attribute "+attributeName+": "+attr);
}
if (attr.size() > 1) {
throw new IllegalArgumentException("Too many values in attribute "+attributeName+": "+attr);
}
String attrValue = attr.iterator().next().toString();
if (attr.getOptions() == null || attr.getOptions().isEmpty()) {
assertEquals("Wrong orig value in attribute '"+attributeName+" in entry "+entry.getDN(), expectedOrigValue, attrValue);
} else if (attr.getOptions().size() == 1) {
String option = attr.getOptions().iterator().next();
if (!option.startsWith("lang-")) {
throw new IllegalArgumentException("Non-lang option "+option+" in attribute "+attributeName+": "+attr);
}
String lang = option.substring("lang-".length());
String expectedValue = expectedLangs.get(lang);
assertEquals("Wrong "+option+" value in attribute '"+attributeName+" in entry "+entry.getDN(), expectedValue, attrValue);
langsSeen.add(lang);
} else {
throw new IllegalArgumentException("More than one option in attribute "+attributeName+": "+attr);
}
}
for (Map.Entry<String, String> expectedLangEntry : expectedLangs.entrySet()) {
if (!langsSeen.contains(expectedLangEntry.getKey())) {
AssertJUnit.fail("No lang "+expectedLangEntry.getKey()+" in attribute "+attributeName+" in entry "+entry.getDN()+"; expected "+expectedLangEntry.getValue());
}
}
}

public void assertActive(Entry response, boolean active) {
assertEquals("Unexpected activation of entry "+response, active, isAccountEnabled(response));
Expand Down
Expand Up @@ -763,4 +763,11 @@ public static String takeThreadDump(@Nullable Thread thread) {
return dump.toString();
}

public static <K,V> Map<K, V> paramsToMap(Object[] params) {
Map<K, V> map = new HashMap<>();
for (int i=0; i < params.length; i+=2) {
map.put((K)params[i], (V)params[i+1]);
}
return map;
}
}
Expand Up @@ -27,6 +27,7 @@
import com.evolveum.midpoint.prism.crypto.EncryptionException;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.asserter.prism.PolyStringAsserter;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
Expand Down Expand Up @@ -195,6 +196,12 @@ public AssignmentsAsserter<UserType, UserAsserter<RA>, RA> assignments() {
return asserter;
}

public PolyStringAsserter<UserAsserter<RA>> fullName() {
PolyStringAsserter<UserAsserter<RA>> asserter = new PolyStringAsserter<>(getPolyStringPropertyValue(UserType.F_FULL_NAME), this, "fullName in "+desc());
copySetupTo(asserter);
return asserter;
}

public UserAsserter<RA> assertFullName(String expectedOrig) {
assertPolyStringProperty(UserType.F_FULL_NAME, expectedOrig);
return this;
Expand Down
@@ -0,0 +1,117 @@
/**
* Copyright (c) 2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.test.asserter.prism;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertTrue;

import java.util.Map;
import java.util.Map.Entry;

import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ContainerDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.schema.PrismSchema;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.asserter.AbstractAsserter;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;

/**
* @author semancik
*
*/
public class PolyStringAsserter<RA> extends AbstractAsserter<RA> {

private PolyString polystring;

public PolyStringAsserter(PolyString polystring) {
super();
this.polystring = polystring;
}

public PolyStringAsserter(PolyString polystring, String detail) {
super(detail);
this.polystring = polystring;
}

public PolyStringAsserter(PolyString polystring, RA returnAsserter, String detail) {
super(returnAsserter, detail);
this.polystring = polystring;
}

public static <O extends ObjectType> PolyStringAsserter<Void> forPolyString(PolyString polystring) {
return new PolyStringAsserter<>(polystring);
}

public PolyString getPolyString() {
return polystring;
}

public PolyStringAsserter<RA> assertOrig(String expected) {
assertEquals("Wrong orig in "+desc(), expected, polystring.getOrig());
return this;
}

public PolyStringAsserter<RA> assertNorm(String expected) {
assertEquals("Wrong norm in "+desc(), expected, polystring.getNorm());
return this;
}

public PolyStringAsserter<RA> assertLangs(String... expectedParams) {
if (polystring.getLang() == null) {
if (expectedParams.length == 0) {
return this;
} else {
fail("No langs in "+desc());
}
}
Map<String, String> expectedLangs = MiscUtil.paramsToMap(expectedParams);
for (Entry<String, String> expectedLangEntry : expectedLangs.entrySet()) {
String realLangValue = polystring.getLang().get(expectedLangEntry.getKey());
assertEquals("Wrong lang "+expectedLangEntry.getKey()+" in "+desc(), expectedLangEntry.getValue(), realLangValue);
}
for (Entry<String, String> realLangEntry : polystring.getLang().entrySet()) {
String expectedLangValue = expectedLangs.get(realLangEntry.getKey());
assertEquals("Wrong lang "+realLangEntry.getKey()+" in "+desc(), expectedLangValue, realLangEntry.getValue());
}
return this;
}

protected String desc() {
return descWithDetails(polystring);
}

public PolyStringAsserter<RA> display() {
display(desc());
return this;
}

public PolyStringAsserter<RA> display(String message) {
IntegrationTestTools.display(message, polystring);
return this;
}
}
Expand Up @@ -167,6 +167,14 @@ public PrismObjectAsserter<O,RA> displayXml(String message) throws SchemaExcepti
return this;
}

protected PolyString getPolyStringPropertyValue(QName propName) {
PrismProperty<PolyString> prop = getObject().findProperty(ItemName.fromQName(propName));
if (prop == null) {
return null;
}
return prop.getRealValue();
}

protected void assertPolyStringProperty(QName propName, String expectedOrig) {
PrismProperty<PolyString> prop = getObject().findProperty(ItemName.fromQName(propName));
assertNotNull("No "+propName.getLocalPart()+" in "+desc(), prop);
Expand Down

0 comments on commit 31e2490

Please sign in to comment.