Skip to content

Commit

Permalink
Test cleanup: logger usage, all classes should have our superclasses
Browse files Browse the repository at this point in the history
And some IDEA warning fixes, removed unused JAXBUtilTest.java, etc.
  • Loading branch information
virgo47 committed Mar 13, 2020
1 parent 951391e commit 4d91d71
Show file tree
Hide file tree
Showing 57 changed files with 685 additions and 1,004 deletions.
1 change: 0 additions & 1 deletion dist/pom.xml
Expand Up @@ -51,7 +51,6 @@
<dependency>
<groupId>com.evolveum.midpoint.tools</groupId>
<artifactId>test-ng</artifactId>
<version>4.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 0 additions & 1 deletion gui/admin-gui/pom.xml
Expand Up @@ -708,7 +708,6 @@
<dependency>
<groupId>com.evolveum.midpoint.tools</groupId>
<artifactId>test-ng</artifactId>
<version>4.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -81,7 +81,7 @@ public static void main(String[] args) {
" Application mode:" + mode + " context:" + applicationContext);
}

if (applicationContext != null && mode != null && "stop".equals(mode)) {
if (applicationContext != null && "stop".equals(mode)) {
System.exit(SpringApplication.exit(applicationContext, new ExitCodeGenerator() {

@Override
Expand Down
1 change: 0 additions & 1 deletion infra/common/pom.xml
Expand Up @@ -144,7 +144,6 @@
<dependency>
<groupId>com.evolveum.midpoint.tools</groupId>
<artifactId>test-ng</artifactId>
<version>4.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -31,9 +31,6 @@
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;

/**
* @author semancik
*/
public class AbstractPrismTest extends AbstractUnitTest {

protected static final String USER_FOO_OID = "01234567";
Expand Down
Expand Up @@ -9,7 +9,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.fail;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -22,9 +21,6 @@
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.SchemaException;

/**
* @author mederly
*/
@SuppressWarnings("Duplicates")
public abstract class AbstractJsonLexicalProcessorTest extends AbstractLexicalProcessorTest {

Expand Down
Expand Up @@ -6,6 +6,25 @@
*/
package com.evolveum.midpoint.prism.lex;

import static org.testng.AssertJUnit.*;

import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*;
import static com.evolveum.midpoint.prism.util.PrismTestUtil.createDefaultParsingContext;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;

import org.testng.annotations.Test;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.DiffUtil;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
Expand All @@ -20,37 +39,15 @@
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.prism.xnode.*;
import com.evolveum.midpoint.prism.xnode.RootXNode;
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*;
import static com.evolveum.midpoint.prism.util.PrismTestUtil.createDefaultParsingContext;
import static org.testng.AssertJUnit.*;

/**
* @author semancik
*
*/
public abstract class AbstractLexicalProcessorTest {
public abstract class AbstractLexicalProcessorTest extends AbstractPrismTest {

private static final QName XSD_COMPLEX_TYPE_ELEMENT_NAME
= new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "complexType");
Expand All @@ -63,12 +60,6 @@ public abstract class AbstractLexicalProcessorTest {
private static final String OBJECTS_6_SINGLE = "objects-6-single";
private static final String OBJECTS_7_SINGLE = "objects-7-single";

@BeforeSuite
public void setupDebug() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX);
PrismTestUtil.resetPrismContext(new PrismInternalTestUtil());
}

protected abstract String getSubdirName();

protected abstract String getFilenameSuffix();
Expand All @@ -78,7 +69,7 @@ protected File getCommonSubdir() {
}

protected File getFile(String baseName) {
return new File(getCommonSubdir(), baseName+"."+getFilenameSuffix());
return new File(getCommonSubdir(), baseName + "." + getFilenameSuffix());
}

protected abstract LexicalProcessor<String> createParser();
Expand Down Expand Up @@ -171,9 +162,9 @@ public void testParseUserRoundTrip() throws Exception {
System.out.println("\naccountRef object diff:");
System.out.println(accountRefObjDiff.debugDump());

assertTrue("Re-parsed object in accountRef does not match: "+accountRefObjDiff, accountRefObjDiff.isEmpty());
assertTrue("Re-parsed object in accountRef does not match: " + accountRefObjDiff, accountRefObjDiff.isEmpty());

assertTrue("Re-parsed user does not match: "+diff, diff.isEmpty());
assertTrue("Re-parsed user does not match: " + diff, diff.isEmpty());
}

// to check if timestamps are serialized correctly
Expand Down Expand Up @@ -245,10 +236,9 @@ public void testParseResourceRoundTrip() throws Exception {
System.out.println("\nDiff:");
System.out.println(diff.debugDump());

assertTrue("Re-parsed user does not match: "+diff, diff.isEmpty());
assertTrue("Re-parsed user does not match: " + diff, diff.isEmpty());
}


private void assertResourceRum(PrismObject<ResourceType> resource) throws SchemaException {
resource.checkConsistence();
resource.assertDefinitions("test");
Expand Down Expand Up @@ -279,7 +269,7 @@ private void assertResourceRum(PrismObject<ResourceType> resource) throws Schema
}

private PrismObject findObjectFromAccountRef(PrismObject<UserType> user) {
for (PrismReferenceValue rval: user.findReference(UserType.F_ACCOUNT_REF).getValues()) {
for (PrismReferenceValue rval : user.findReference(UserType.F_ACCOUNT_REF).getValues()) {
if (rval.getObject() != null) {
return rval.getObject();
}
Expand All @@ -288,33 +278,33 @@ private PrismObject findObjectFromAccountRef(PrismObject<UserType> user) {
}

protected <X extends XNodeImpl> X getAssertXNode(String message, XNode xnode, Class<X> expectedClass) {
assertNotNull(message+" is null", xnode);
assertTrue(message+", expected "+expectedClass.getSimpleName()+", was "+xnode.getClass().getSimpleName(),
assertNotNull(message + " is null", xnode);
assertTrue(message + ", expected " + expectedClass.getSimpleName() + ", was " + xnode.getClass().getSimpleName(),
expectedClass.isAssignableFrom(xnode.getClass()));
return (X) xnode;
}

protected <X extends XNodeImpl> X getAssertXMapSubnode(String message, MapXNodeImpl xmap, QName key, Class<X> expectedClass) {
XNodeImpl xsubnode = xmap.get(key);
assertNotNull(message+" no key "+key, xsubnode);
return getAssertXNode(message+" key "+key, xsubnode, expectedClass);
assertNotNull(message + " no key " + key, xsubnode);
return getAssertXNode(message + " key " + key, xsubnode, expectedClass);
}

protected void assertUserJackXNodeOrdering(String message, XNode xnode) {
if (xnode instanceof RootXNodeImpl) {
xnode = ((RootXNodeImpl)xnode).getSubnode();
xnode = ((RootXNodeImpl) xnode).getSubnode();
}
MapXNodeImpl xmap = getAssertXNode(message+": top", xnode, MapXNodeImpl.class);
MapXNodeImpl xmap = getAssertXNode(message + ": top", xnode, MapXNodeImpl.class);
Set<Entry<QName, XNodeImpl>> reTopMapEntrySet = xmap.entrySet();
Iterator<Entry<QName, XNodeImpl>> reTopMapEntrySetIter = reTopMapEntrySet.iterator();
Entry<QName, XNodeImpl> reTopMapEntry0 = reTopMapEntrySetIter.next();
assertEquals(message+": Wrong entry 0, the xnodes were shuffled", "oid", reTopMapEntry0.getKey().getLocalPart());
assertEquals(message + ": Wrong entry 0, the xnodes were shuffled", "oid", reTopMapEntry0.getKey().getLocalPart());
Entry<QName, XNodeImpl> reTopMapEntry1 = reTopMapEntrySetIter.next();
assertEquals(message+": Wrong entry 1, the xnodes were shuffled", "version", reTopMapEntry1.getKey().getLocalPart());
assertEquals(message + ": Wrong entry 1, the xnodes were shuffled", "version", reTopMapEntry1.getKey().getLocalPart());
Entry<QName, XNodeImpl> reTopMapEntry2 = reTopMapEntrySetIter.next();
assertEquals(message+": Wrong entry 2, the xnodes were shuffled", UserType.F_NAME, reTopMapEntry2.getKey());
assertEquals(message + ": Wrong entry 2, the xnodes were shuffled", UserType.F_NAME, reTopMapEntry2.getKey());
Entry<QName, XNodeImpl> reTopMapEntry3 = reTopMapEntrySetIter.next();
assertEquals(message+": Wrong entry 3, the xnodes were shuffled", UserType.F_DESCRIPTION, reTopMapEntry3.getKey());
assertEquals(message + ": Wrong entry 3, the xnodes were shuffled", UserType.F_DESCRIPTION, reTopMapEntry3.getKey());

}

Expand Down
Expand Up @@ -6,30 +6,21 @@
*/
package com.evolveum.midpoint.prism.lex;

import static org.testng.AssertJUnit.assertEquals;

import static com.evolveum.midpoint.prism.util.PrismTestUtil.createDefaultParsingContext;

import org.testng.annotations.Test;

import com.evolveum.midpoint.prism.AbstractPrismTest;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.impl.PrismContextImpl;
import com.evolveum.midpoint.prism.PrismInternalTestUtil;
import com.evolveum.midpoint.prism.crypto.Protector;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.prism.impl.PrismContextImpl;
import com.evolveum.midpoint.prism.impl.xnode.MapXNodeImpl;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;

import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import java.io.IOException;

import static com.evolveum.midpoint.prism.PrismInternalTestUtil.DEFAULT_NAMESPACE_PREFIX;
import static com.evolveum.midpoint.prism.util.PrismTestUtil.createDefaultParsingContext;
import static org.testng.AssertJUnit.assertEquals;

/**
* @author mederly
*/
public class TestProtectedString extends AbstractPrismTest {

@Test
Expand Down
Expand Up @@ -7,6 +7,7 @@

package com.evolveum.midpoint.prism.path;

import com.evolveum.midpoint.prism.AbstractPrismTest;
import com.evolveum.midpoint.prism.PrismInternalTestUtil;
import com.evolveum.midpoint.prism.impl.marshaller.ItemPathHolder;
import com.evolveum.midpoint.prism.impl.marshaller.PathHolderSegment;
Expand Down Expand Up @@ -48,7 +49,7 @@
*
* @author semancik
*/
public class ItemPathTest {
public class ItemPathTest extends AbstractPrismTest {

private static final String FILENAME_STRANGECHARS = "src/test/resources/path/strange.txt";
private static final String FILENAME_DATA_XML = "src/test/resources/path/data.xml";
Expand Down
1 change: 0 additions & 1 deletion infra/schema-pure-jaxb/pom.xml
Expand Up @@ -35,7 +35,6 @@
<dependency>
<groupId>com.evolveum.midpoint.tools</groupId>
<artifactId>test-ng</artifactId>
<version>4.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -10,36 +10,23 @@
import static com.evolveum.midpoint.schema.TestConstants.COMMON_DIR_PATH;

import java.io.File;
import java.io.IOException;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.xml.sax.SAXException;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.schema.MidPointPrismContextFactory;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.tools.testng.AbstractUnitTest;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.schema.AbstractSchemaTest;

/**
* @author mederly
*/
public abstract class AbstractParserTest extends AbstractUnitTest {
public abstract class AbstractParserTest extends AbstractSchemaTest {

protected String language;
protected boolean namespaces;

@BeforeSuite
public void setup() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY);
}

@BeforeClass
@Parameters({ "language", "namespaces" })
public void temp(@Optional String language, @Optional Boolean namespaces) {
Expand Down

0 comments on commit 4d91d71

Please sign in to comment.