Skip to content

Commit

Permalink
more prism-impl tests extend from AbstractPrismTest (+AbstractUnitTest)
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Mar 2, 2020
1 parent c87d0a0 commit a6bb6ad
Show file tree
Hide file tree
Showing 21 changed files with 280 additions and 629 deletions.
Expand Up @@ -45,7 +45,7 @@ public class AbstractPrismTest extends AbstractUnitTest {
protected static final long ASSIGNMENT_ABRAKADABRA_ID = 222L;

@BeforeSuite
public void setupDebug() throws SchemaException, SAXException, IOException {
public void initPrismContext() throws SchemaException, SAXException, IOException {
PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX);
PrismTestUtil.resetPrismContext(new PrismInternalTestUtil());
}
Expand All @@ -70,7 +70,7 @@ protected PolyString createPolyString(String orig) {
return PrismTestUtil.createPolyString(orig);
}

protected PrismContext getPrismContext() {
protected static PrismContext getPrismContext() {
return PrismTestUtil.getPrismContext();
}

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

import static org.testng.AssertJUnit.assertNull;
import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.*;

import static com.evolveum.midpoint.prism.PrismInternalTestUtil.USER_JACK_OID;

import java.io.IOException;
import java.util.Collection;

import com.evolveum.midpoint.prism.delta.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ItemDeltaCollectionsUtil;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.foo.AssignmentType;
import com.evolveum.midpoint.prism.foo.UserType;
import com.evolveum.midpoint.prism.path.ItemPath;
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.tools.testng.AbstractUnitTest;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;

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

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

@Test
public void testUserSimplePropertyDiffNoChange() throws Exception {
Expand Down
Expand Up @@ -7,44 +7,38 @@

package com.evolveum.midpoint.prism;

import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*;
import static org.testng.AssertJUnit.*;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;
import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.xml.namespace.QName;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator;

import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.impl.schema.SchemaRegistryImpl;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import com.evolveum.midpoint.prism.foo.UserType;
import com.evolveum.midpoint.prism.impl.schema.SchemaRegistryImpl;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.schema.PrismSchema;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.tools.testng.AbstractUnitTest;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;

public class TestExtraSchema extends AbstractUnitTest {
public class TestExtraSchema extends AbstractPrismTest {

public static final String NS_USER_2_EXT = "http://example.com/xml/ns/user-2-extension";

private static final ItemName USER_EXTENSION_TYPE_QNAME = new ItemName(NS_USER_EXT,"UserExtensionType");
private static final ItemName USER_2_EXTENSION_TYPE_QNAME = new ItemName(NS_USER_2_EXT,"User2ExtensionType");
private static final ItemName USER_EXTENSION_TYPE_QNAME = new ItemName(NS_USER_EXT, "UserExtensionType");
private static final ItemName USER_2_EXTENSION_TYPE_QNAME = new ItemName(NS_USER_2_EXT, "User2ExtensionType");

private static final ItemName USER_EXT_2_ELEMENT = new ItemName(NS_USER_2_EXT, "ext2");

Expand All @@ -66,7 +60,7 @@ public void testExtraSchema() throws SAXException, IOException, SchemaException

Validator validator = javaxSchema.newValidator();
DOMResult validationResult = new DOMResult();
validator.validate(new DOMSource(dataDoc),validationResult);
validator.validate(new DOMSource(dataDoc), validationResult);
}

/**
Expand Down Expand Up @@ -121,7 +115,7 @@ public void testUserExtensionSchemaParseUser() throws SAXException, IOException,
assertNotNull(javaxSchema);
Validator validator = javaxSchema.newValidator();
DOMResult validationResult = new DOMResult();
validator.validate(new DOMSource(dataDoc),validationResult);
validator.validate(new DOMSource(dataDoc), validationResult);
}

@Test
Expand Down Expand Up @@ -152,9 +146,9 @@ private void assertUserDefinition(PrismObjectDefinition<UserType> userDef) {
System.out.println(extDef.debugDump());

assertTrue("Extension is not dynamic", extDef.isRuntimeSchema());
assertTrue("Wrong extension type "+extDef.getTypeName(),
assertTrue("Wrong extension type " + extDef.getTypeName(),
USER_EXTENSION_TYPE_QNAME.equals(extDef.getTypeName()) || USER_2_EXTENSION_TYPE_QNAME.equals(extDef.getTypeName()));
assertEquals("Wrong extension displayOrder", (Integer)1000, extDef.getDisplayOrder());
assertEquals("Wrong extension displayOrder", (Integer) 1000, extDef.getDisplayOrder());

PrismPropertyDefinition barPropDef = extDef.findPropertyDefinition(USER_EXT_BAR_ELEMENT);
assertNotNull("No 'bar' definition in user extension", barPropDef);
Expand Down Expand Up @@ -186,8 +180,8 @@ private void assertUserDefinition(PrismObjectDefinition<UserType> userDef) {
}

private void assertDefinitionOrder(List<? extends ItemDefinition> definitions, QName elementName, int i) {
assertEquals("Wrong definition, expected that "+PrettyPrinter.prettyPrint(elementName)+" definition will be at index " +
i + " but there was a "+definitions.get(i).getItemName()+" instead", elementName, definitions.get(i).getItemName());
assertEquals("Wrong definition, expected that " + PrettyPrinter.prettyPrint(elementName) + " definition will be at index " +
i + " but there was a " + definitions.get(i).getItemName() + " instead", elementName, definitions.get(i).getItemName());
}

/**
Expand All @@ -205,7 +199,7 @@ public void testTypeOverride() throws SAXException, IOException, SchemaException
System.out.println("Parsed root schema:");
System.out.println(schema.debugDump());

PrismContainerDefinition rootContDef = schema.findContainerDefinitionByElementName(new QName(NS_ROOT,"root"));
PrismContainerDefinition rootContDef = schema.findContainerDefinitionByElementName(new QName(NS_ROOT, "root"));
assertNotNull("Not <root> definition", rootContDef);
PrismContainerDefinition extensionContDef = rootContDef.findContainerDefinition(new ItemName(NS_FOO, "extension"));
assertNotNull("Not <extension> definition", extensionContDef);
Expand Down
Expand Up @@ -13,33 +13,23 @@

import java.io.IOException;

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

import com.evolveum.midpoint.prism.foo.AccountConstructionType;
import com.evolveum.midpoint.prism.foo.AssignmentType;
import com.evolveum.midpoint.prism.foo.UserType;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.tools.testng.AbstractUnitTest;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;

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

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

@Test
public void testFindString() throws SchemaException, SAXException, IOException {
public void testFindString() throws SchemaException, IOException {
// GIVEN
PrismObject<UserType> user = createUser();
ItemPath path = UserType.F_DESCRIPTION;
Expand All @@ -53,7 +43,7 @@ public void testFindString() throws SchemaException, SAXException, IOException {
}

@Test
public void testFindPolyString() throws SchemaException, SAXException, IOException {
public void testFindPolyString() throws SchemaException, IOException {
// GIVEN
PrismObject<UserType> user = createUser();
ItemPath path = UserType.F_POLY_NAME;
Expand All @@ -67,7 +57,7 @@ public void testFindPolyString() throws SchemaException, SAXException, IOExcepti
}

@Test
public void testFindPolyStringOrig() throws SchemaException, SAXException, IOException {
public void testFindPolyStringOrig() throws SchemaException, IOException {
// GIVEN
ItemPath path = ItemPath.create(UserType.F_POLY_NAME, PolyString.F_ORIG);

Expand All @@ -79,7 +69,7 @@ public void testFindPolyStringOrig() throws SchemaException, SAXException, IOExc
}

@Test
public void testFindPolyStringNorm() throws SchemaException, SAXException, IOException {
public void testFindPolyStringNorm() throws SchemaException, IOException {
// GIVEN
ItemPath path = ItemPath.create(UserType.F_POLY_NAME, PolyString.F_NORM);

Expand All @@ -91,7 +81,7 @@ public void testFindPolyStringNorm() throws SchemaException, SAXException, IOExc
}

@Test
public void testFindExtensionBar() throws SchemaException, SAXException, IOException {
public void testFindExtensionBar() throws SchemaException, IOException {
// GIVEN
ItemPath path = ItemPath.create(UserType.F_EXTENSION, EXTENSION_BAR_ELEMENT);

Expand All @@ -103,7 +93,7 @@ public void testFindExtensionBar() throws SchemaException, SAXException, IOExcep
}

@Test
public void testFindAssignment1Description() throws SchemaException, SAXException, IOException {
public void testFindAssignment1Description() throws SchemaException, IOException {
// GIVEN
ItemPath path = ItemPath.create(UserType.F_ASSIGNMENT, USER_ASSIGNMENT_1_ID, AssignmentType.F_DESCRIPTION);

Expand All @@ -115,7 +105,7 @@ public void testFindAssignment1Description() throws SchemaException, SAXExceptio
}

@Test
public void testFindAssignment2Construction() throws SchemaException, SAXException, IOException {
public void testFindAssignment2Construction() throws SchemaException, IOException {
// GIVEN
ItemPath path = ItemPath.create(UserType.F_ASSIGNMENT, USER_ASSIGNMENT_2_ID, AssignmentType.F_ACCOUNT_CONSTRUCTION);

Expand All @@ -127,7 +117,7 @@ public void testFindAssignment2Construction() throws SchemaException, SAXExcepti
}

@Test
public void testFindAssignment() throws SchemaException, SAXException, IOException {
public void testFindAssignment() throws SchemaException, IOException {
// GIVEN
ItemPath path = UserType.F_ASSIGNMENT;

Expand All @@ -139,7 +129,7 @@ public void testFindAssignment() throws SchemaException, SAXException, IOExcepti
assertEquals("Wrong value2 description (path=" + path + ")", "Assignment 2", value2.findProperty(AssignmentType.F_DESCRIPTION).getRealValue());
}

private <T> T findUser(ItemPath path) throws SchemaException, SAXException, IOException {
private <T> T findUser(ItemPath path) throws SchemaException, IOException {
PrismObject<UserType> user = createUser();
return find(user, path);
}
Expand All @@ -157,7 +147,7 @@ private <T> T find(PrismObject<UserType> user, ItemPath path) {
return (T) found;
}

private <T> PrismProperty<T> findUserProperty(ItemPath path) throws SchemaException, SAXException, IOException {
private <T> PrismProperty<T> findUserProperty(ItemPath path) throws SchemaException, IOException {
PrismObject<UserType> user = createUser();
return findProperty(user, path);
}
Expand All @@ -175,7 +165,7 @@ private <T> PrismProperty<T> findProperty(PrismObject<UserType> user, ItemPath p
return property;
}

private <T extends Containerable> PrismContainer<T> findUserContainer(ItemPath path) throws SchemaException, SAXException, IOException {
private <T extends Containerable> PrismContainer<T> findUserContainer(ItemPath path) throws SchemaException, IOException {
PrismObject<UserType> user = createUser();
return findContainer(user, path);
}
Expand All @@ -193,7 +183,7 @@ private <T extends Containerable> PrismContainer<T> findContainer(PrismObject<Us
return container;
}

public PrismObject<UserType> createUser() throws SchemaException, SAXException, IOException {
public PrismObject<UserType> createUser() throws SchemaException, IOException {
return PrismTestUtil.parseObject(USER_JACK_FILE_XML);
}

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

import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*;
import static org.testng.AssertJUnit.assertEquals;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.impl.PrismPropertyValueImpl;
import com.evolveum.midpoint.prism.impl.xnode.MapXNodeImpl;
import com.evolveum.prism.xml.ns._public.types_3.RawType;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import com.evolveum.midpoint.prism.impl.PrismPropertyValueImpl;
import com.evolveum.midpoint.prism.impl.xnode.MapXNodeImpl;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.exception.SchemaException;

import javax.xml.namespace.QName;
import com.evolveum.prism.xml.ns._public.types_3.RawType;

/**
* @author Radovan Semancik
*
*/
public class TestFundamentals {

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

@Test
public void testPrismValueContainsRealValue() throws Exception {
System.out.println("\n\n===[ testPrismValueContainsRealValue ]===\n");
public void testPrismValueContainsRealValue() {
// GIVEN
PrismPropertyValue<String> valFoo1 = new PrismPropertyValueImpl<>("foo");
PrismPropertyValue<String> valBar1 = new PrismPropertyValueImpl<>("bar");
Expand Down Expand Up @@ -70,8 +55,7 @@ public void testPrismValueContainsRealValue() throws Exception {
}

@Test
public void testRawTypeClone() throws Exception {
System.out.println("\n\n===[ testRawTypeClone ]===\n");
public void testRawTypeClone() {
// GIVEN
QName typeQName = new QName("abcdef");
MapXNodeImpl mapXNode = new MapXNodeImpl();
Expand All @@ -84,5 +68,4 @@ public void testRawTypeClone() throws Exception {
// THEN
assertEquals("Wrong or missing type QName", typeQName, rawTypeClone.getXnode().getTypeQName());
}

}

0 comments on commit a6bb6ad

Please sign in to comment.