diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/AbstractPrismTest.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/AbstractPrismTest.java index f827e59b2ba..7ddcaf24f5a 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/AbstractPrismTest.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/AbstractPrismTest.java @@ -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()); } @@ -70,7 +70,7 @@ protected PolyString createPolyString(String orig) { return PrismTestUtil.createPolyString(orig); } - protected PrismContext getPrismContext() { + protected static PrismContext getPrismContext() { return PrismTestUtil.getPrismContext(); } diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestDiff.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestDiff.java index 96fd23d3838..15832e98ca6 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestDiff.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestDiff.java @@ -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 { diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestExtraSchema.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestExtraSchema.java index 4162831196c..495dada9c76 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestExtraSchema.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestExtraSchema.java @@ -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"); @@ -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); } /** @@ -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 @@ -152,9 +146,9 @@ private void assertUserDefinition(PrismObjectDefinition 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); @@ -186,8 +180,8 @@ private void assertUserDefinition(PrismObjectDefinition userDef) { } private void assertDefinitionOrder(List 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()); } /** @@ -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 definition", rootContDef); PrismContainerDefinition extensionContDef = rootContDef.findContainerDefinition(new ItemName(NS_FOO, "extension")); assertNotNull("Not definition", extensionContDef); diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFind.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFind.java index 40e4d330273..a9001b4fe5e 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFind.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFind.java @@ -13,9 +13,7 @@ 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; @@ -23,23 +21,15 @@ 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 user = createUser(); ItemPath path = UserType.F_DESCRIPTION; @@ -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 user = createUser(); ItemPath path = UserType.F_POLY_NAME; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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; @@ -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 findUser(ItemPath path) throws SchemaException, SAXException, IOException { + private T findUser(ItemPath path) throws SchemaException, IOException { PrismObject user = createUser(); return find(user, path); } @@ -157,7 +147,7 @@ private T find(PrismObject user, ItemPath path) { return (T) found; } - private PrismProperty findUserProperty(ItemPath path) throws SchemaException, SAXException, IOException { + private PrismProperty findUserProperty(ItemPath path) throws SchemaException, IOException { PrismObject user = createUser(); return findProperty(user, path); } @@ -175,7 +165,7 @@ private PrismProperty findProperty(PrismObject user, ItemPath p return property; } - private PrismContainer findUserContainer(ItemPath path) throws SchemaException, SAXException, IOException { + private PrismContainer findUserContainer(ItemPath path) throws SchemaException, IOException { PrismObject user = createUser(); return findContainer(user, path); } @@ -193,7 +183,7 @@ private PrismContainer findContainer(PrismObject createUser() throws SchemaException, SAXException, IOException { + public PrismObject createUser() throws SchemaException, IOException { return PrismTestUtil.parseObject(USER_JACK_FILE_XML); } diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFundamentals.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFundamentals.java index 54b5e605bfe..fecaf227235 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFundamentals.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestFundamentals.java @@ -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 valFoo1 = new PrismPropertyValueImpl<>("foo"); PrismPropertyValue valBar1 = new PrismPropertyValueImpl<>("bar"); @@ -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(); @@ -84,5 +68,4 @@ public void testRawTypeClone() throws Exception { // THEN assertEquals("Wrong or missing type QName", typeQName, rawTypeClone.getXnode().getTypeQName()); } - } diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPath.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPath.java index dcee348b8f3..27e8abb6530 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPath.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPath.java @@ -6,39 +6,28 @@ */ package com.evolveum.midpoint.prism; -import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*; -import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertTrue; +import static org.testng.AssertJUnit.*; -import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; - import javax.xml.namespace.QName; -import com.evolveum.midpoint.prism.path.*; -import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; -import org.xml.sax.SAXException; -import com.evolveum.midpoint.prism.util.PrismTestUtil; -import com.evolveum.midpoint.util.PrettyPrinter; -import com.evolveum.midpoint.util.exception.SchemaException; +import com.evolveum.midpoint.prism.path.*; /** * @author semancik - * */ -public class TestPath { +public class TestPath extends AbstractPrismTest { private static final String NS = "http://example.com/"; private static Map> creators = new HashMap<>(); + static { creators.put('C', seq -> getPrismContext().path(seq)); creators.put('S', ItemPath::create); @@ -46,16 +35,8 @@ public class TestPath { creators.put('R', seq -> creators.get("CSN".charAt((int) (Math.random() * 3))).apply(seq)); } - @BeforeSuite - public void setupDebug() throws SchemaException, SAXException, IOException { - PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); - PrismTestUtil.resetPrismContext(new PrismInternalTestUtil()); - } - @Test public void testPathNormalize() { - System.out.println("\n\n===[ testPathNormalize ]===\n"); - PrismContext prismContext = getPrismContext(); // GIVEN @@ -131,8 +112,6 @@ public void testPathCompareHalf2() { } private void testPathCompare(String source) { - System.out.println("\n\n===[ testPathCompare (" + source + ") ]===\n"); - // GIVEN // /foo @@ -239,9 +218,7 @@ private ItemPath create(String source, int index, Object... components) { } @Test - public void testPathRemainder() throws Exception { - System.out.println("\n\n===[ testPathRemainder ]===\n"); - + public void testPathRemainder() { PrismContext prismContext = getPrismContext(); // GIVEN @@ -251,7 +228,7 @@ public void testPathRemainder() throws Exception { UniformItemPath pathFoo123 = prismContext.path(new QName(NS, "foo"), 123L); UniformItemPath pathFooBar = prismContext.path(new QName(NS, "foo"), new QName(NS, "bar")); UniformItemPath pathFooNullBar = prismContext.path(new QName(NS, "foo"), null, - new QName(NS, "bar")); + new QName(NS, "bar")); // WHEN UniformItemPath remainder1 = pathFooBar.remainder(pathFooNull); @@ -261,20 +238,20 @@ public void testPathRemainder() throws Exception { } private void assertNormalizedPath(UniformItemPath normalized, Object... expected) { - assertEquals("wrong path length",normalized.size(), expected.length); - for(int i=0; i> map, Class clazz, QName typeName) { - assertEquals("Wrong xsdType->class mapping for "+typeName, clazz, map.get(typeName)); - } - @Test public void testBasicSchemas() throws SchemaException, SAXException, IOException { - System.out.println("===[ testBasicSchemas ]==="); - // WHEN PrismContext prismContext = constructInitializedPrismContext(); @@ -100,7 +84,7 @@ public void testBasicSchemas() throws SchemaException, SAXException, IOException System.out.println(fooSchema.debugDump()); // Assert USER definition - PrismObjectDefinition userDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO,"user")); + PrismObjectDefinition userDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO, "user")); assertNotNull("No user definition", userDefinition); System.out.println("User definition:"); System.out.println(userDefinition.debugDump()); @@ -111,7 +95,7 @@ public void testBasicSchemas() throws SchemaException, SAXException, IOException assertUserDefinition(userDefinition); // Assert ACCOUNT definition - PrismObjectDefinition accountDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO,"account")); + PrismObjectDefinition accountDefinition = fooSchema.findObjectDefinitionByElementName(new QName(NS_FOO, "account")); assertNotNull("No account definition", accountDefinition); System.out.println("Account definition:"); System.out.println(accountDefinition.debugDump()); @@ -186,8 +170,6 @@ private void assertAccountDefinition(PrismObjectDefinition accountD @Test public void testExtensionSchema() throws SchemaException, SAXException, IOException { - System.out.println("===[ testExtensionSchema ]==="); - // GIVEN PrismContext prismContext = constructInitializedPrismContext(); assertNotNull("No prism context", prismContext); @@ -196,19 +178,19 @@ public void testExtensionSchema() throws SchemaException, SAXException, IOExcept PrismPropertyDefinition ignoredTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_IGNORED_TYPE_ELEMENT); PrismAsserts.assertDefinition(ignoredTypeDef, EXTENSION_IGNORED_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1); - assertTrue("Element "+EXTENSION_IGNORED_TYPE_ELEMENT+" is NOT ignored", ignoredTypeDef.isIgnored()); + assertTrue("Element " + EXTENSION_IGNORED_TYPE_ELEMENT + " is NOT ignored", ignoredTypeDef.isIgnored()); PrismPropertyDefinition stringTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_STRING_TYPE_ELEMENT); PrismAsserts.assertDefinition(stringTypeDef, EXTENSION_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1); - assertFalse("Element "+EXTENSION_STRING_TYPE_ELEMENT+" is ignored", stringTypeDef.isIgnored()); + assertFalse("Element " + EXTENSION_STRING_TYPE_ELEMENT + " is ignored", stringTypeDef.isIgnored()); PrismPropertyDefinition singleStringTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_SINGLE_STRING_TYPE_ELEMENT); PrismAsserts.assertDefinition(singleStringTypeDef, EXTENSION_SINGLE_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, 1); - assertFalse("Element "+EXTENSION_SINGLE_STRING_TYPE_ELEMENT+" is ignored", singleStringTypeDef.isIgnored()); + assertFalse("Element " + EXTENSION_SINGLE_STRING_TYPE_ELEMENT + " is ignored", singleStringTypeDef.isIgnored()); PrismPropertyDefinition intTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_INT_TYPE_ELEMENT); PrismAsserts.assertDefinition(intTypeDef, EXTENSION_INT_TYPE_ELEMENT, DOMUtil.XSD_INT, 0, -1); - assertFalse("Element "+EXTENSION_INT_TYPE_ELEMENT+" is ignored", intTypeDef.isIgnored()); + assertFalse("Element " + EXTENSION_INT_TYPE_ELEMENT + " is ignored", intTypeDef.isIgnored()); PrismContainerDefinition meleeContextDefinition = schemaRegistry.findContainerDefinitionByElementName(EXTENSION_MELEE_CONTEXT_ELEMENT); PrismAsserts.assertDefinition(meleeContextDefinition, EXTENSION_MELEE_CONTEXT_ELEMENT, EXTENSION_MELEE_CONTEXT_TYPE_QNAME, 0, 1); @@ -219,8 +201,6 @@ public void testExtensionSchema() throws SchemaException, SAXException, IOExcept @Test public void testSchemaToDom() throws SchemaException, SAXException, IOException { - System.out.println("===[ testSchemaToDom ]==="); - // GIVEN PrismContext prismContext = constructInitializedPrismContext(); PrismSchema fooSchema = prismContext.getSchemaRegistry().findSchemaByNamespace(NS_FOO); @@ -231,48 +211,4 @@ public void testSchemaToDom() throws SchemaException, SAXException, IOException // THEN assertNotNull("No foo XSD DOM", fooXsd); } - - // This is not supposed to work with foo schema. It container ObjectReferenceType which does - // not survive roundtrip -// @Test -// public void testSchemaParsingRoundTrip() throws SchemaException, SAXException, IOException { -// System.out.println("===[ testSchemaParsingRoundTrip ]==="); -// -// // GIVEN -// PrismContext prismContext = constructInitializedPrismContext(); -// PrismSchema fooSchema = prismContext.getSchemaRegistry().findSchemaByNamespace(NS_FOO); -// -// // WHEN -// Document fooXsd = fooSchema.serializeToXsd(); -// -// // THEN -// assertNotNull("No foo XSD DOM", fooXsd); -// System.out.println("Serialized schema"); -// System.out.println(DOMUtil.serializeDOMToString(fooXsd)); -// -// // WHEN -// PrismSchema parsedSchema = PrismSchema.parse(DOMUtil.getFirstChildElement(fooXsd), prismContext); -// -// // THEN -// assertNotNull("No parsed schema", parsedSchema); -// System.out.println("Parsed schema"); -// System.out.println(parsedSchema.dump()); -// -// // Assert USER definition -// PrismObjectDefinition userDefinition = parsedSchema.findObjectDefinitionByElementName(new QName(NS_FOO,"user")); -// assertNotNull("No user definition", userDefinition); -// System.out.println("User definition:"); -// System.out.println(userDefinition.dump()); -// -// assertUserDefinition(userDefinition); -// -// // Assert ACCOUNT definition -// PrismObjectDefinition accountDefinition = parsedSchema.findObjectDefinitionByElementName(new QName(NS_FOO,"account")); -// assertNotNull("No account definition", accountDefinition); -// System.out.println("Account definition:"); -// System.out.println(accountDefinition.dump()); -// -// assertAccountDefinition(accountDefinition); -// } - } diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismObjectConstruction.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismObjectConstruction.java index f681b3c29c8..8e518c8cae4 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismObjectConstruction.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismObjectConstruction.java @@ -6,23 +6,18 @@ */ package com.evolveum.midpoint.prism; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertTrue; + import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*; -import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext; -import static org.testng.AssertJUnit.assertTrue; -import static org.testng.AssertJUnit.assertEquals; import java.io.IOException; import java.util.List; - import javax.xml.namespace.QName; import javax.xml.transform.dom.DOMSource; import javax.xml.validation.Schema; import javax.xml.validation.Validator; -import com.evolveum.midpoint.prism.impl.PrismContainerImpl; -import com.evolveum.midpoint.prism.impl.PrismObjectImpl; -import com.evolveum.midpoint.prism.impl.PrismReferenceValueImpl; -import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -30,27 +25,21 @@ import com.evolveum.midpoint.prism.foo.ActivationType; import com.evolveum.midpoint.prism.foo.AssignmentType; import com.evolveum.midpoint.prism.foo.UserType; +import com.evolveum.midpoint.prism.impl.PrismContainerImpl; +import com.evolveum.midpoint.prism.impl.PrismReferenceValueImpl; import com.evolveum.midpoint.prism.util.PrismAsserts; import com.evolveum.midpoint.util.DOMUtil; -import com.evolveum.midpoint.util.PrettyPrinter; import com.evolveum.midpoint.util.exception.SchemaException; /** * @author semancik - * */ -public class TestPrismObjectConstruction { +public class TestPrismObjectConstruction extends AbstractPrismTest { private static final String USER_OID = "1234567890"; private static final String ACCOUNT1_OID = "11100000111"; private static final String ACCOUNT2_OID = "11100000222"; - - @BeforeSuite - public void setupDebug() { - PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); - } - /** * Construct object with schema. Starts by instantiating a definition and working downwards. * All the items in the object should have proper definition. @@ -58,8 +47,8 @@ public void setupDebug() { @Test public void testConstructionWithSchema() throws Exception { // GIVEN - PrismContext ctx = constructInitializedPrismContext(); - PrismObjectDefinition userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO,"user")); + PrismContext ctx = getPrismContext(); + PrismObjectDefinition userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO, "user")); // WHEN PrismObject user = userDefinition.instantiate(); @@ -73,64 +62,11 @@ public void testConstructionWithSchema() throws Exception { assertUserDrake(user, true, ctx); } - /** - * Construct object without schema. Starts by creating object "out of the blue" and - * the working downwards. - */ - @Test(enabled = false) // definition-less containers are no longer supported - public void testDefinitionlessConstruction() throws Exception { - // GIVEN - // No context needed - - // WHEN - PrismObject user = new PrismObjectImpl<>(USER_QNAME, UserType.class); - // Fill-in object values, no schema checking - fillInUserDrake(user, false); - - // THEN - System.out.println("User:"); - System.out.println(user.debugDump()); - // Check if the values are correct, no schema checking - PrismContext ctx = constructInitializedPrismContext(); - assertUserDrake(user, false, ctx); - } - - /** - * Construct object without schema. Starts by creating object "out of the blue" and - * the working downwards. Then apply the schema. Check definitions. - */ -// @Test - public void testDefinitionlessConstructionAndSchemaApplication() throws Exception { - // GIVEN - // No context needed (yet) - PrismObject user = new PrismObjectImpl<>(USER_QNAME, UserType.class); - // Fill-in object values, no schema checking - fillInUserDrake(user, false); - // Make sure the object is OK - PrismContext ctx = constructInitializedPrismContext(); - assertUserDrake(user, false, ctx); - - - PrismObjectDefinition userDefinition = - getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO,"user")); - - // WHEN - user.applyDefinition(userDefinition); - - // THEN - System.out.println("User:"); - System.out.println(user.debugDump()); - - // Check schema now - assertUserDrake(user, true, ctx); - - } - @Test public void testClone() throws Exception { // GIVEN - PrismContext ctx = constructInitializedPrismContext(); - PrismObjectDefinition userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO,"user")); + PrismContext ctx = getPrismContext(); + PrismObjectDefinition userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO, "user")); PrismObject user = userDefinition.instantiate(); fillInUserDrake(user, true); // precondition @@ -149,8 +85,8 @@ public void testClone() throws Exception { @Test public void testCloneEquals() throws Exception { // GIVEN - PrismContext ctx = constructInitializedPrismContext(); - PrismObjectDefinition userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO,"user")); + PrismContext ctx = getPrismContext(); + PrismObjectDefinition userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO, "user")); PrismObject user = userDefinition.instantiate(); fillInUserDrake(user, true); PrismObject clone = user.clone(); @@ -160,7 +96,6 @@ public void testCloneEquals() throws Exception { assertTrue("Clone not equivalent", clone.equivalent(user)); } - private void fillInUserDrake(PrismObject user, boolean assertDefinitions) throws SchemaException { user.setOid(USER_OID); @@ -168,7 +103,7 @@ private void fillInUserDrake(PrismObject user, boolean assertDefinitio PrismProperty fullNameProperty = user.findOrCreateProperty(USER_FULLNAME_QNAME); assertEquals(USER_FULLNAME_QNAME, fullNameProperty.getElementName()); PrismAsserts.assertParentConsistency(user); - if (assertDefinitions) PrismAsserts.assertDefinition(fullNameProperty, DOMUtil.XSD_STRING, 1, 1); + if (assertDefinitions) { PrismAsserts.assertDefinition(fullNameProperty, DOMUtil.XSD_STRING, 1, 1); } fullNameProperty.setRealValue("Sir Fancis Drake"); PrismProperty fullNamePropertyAgain = user.findOrCreateProperty(USER_FULLNAME_QNAME); // The "==" is there by purpose. We really want to make sure that is the same *instance*, that is was not created again @@ -178,7 +113,7 @@ private void fillInUserDrake(PrismObject user, boolean assertDefinitio PrismContainer activationContainer = user.findOrCreateContainer(USER_ACTIVATION_QNAME); assertEquals(USER_ACTIVATION_QNAME, activationContainer.getElementName()); PrismAsserts.assertParentConsistency(user); - if (assertDefinitions) PrismAsserts.assertDefinition(activationContainer, ACTIVATION_TYPE_QNAME, 0, 1); + if (assertDefinitions) { PrismAsserts.assertDefinition(activationContainer, ACTIVATION_TYPE_QNAME, 0, 1); } PrismContainer activationContainerAgain = user.findOrCreateContainer(USER_ACTIVATION_QNAME); // The "==" is there by purpose. We really want to make sure that is the same *instance*, that is was not created again assertTrue("Property not the same", activationContainer == activationContainerAgain); @@ -187,7 +122,7 @@ private void fillInUserDrake(PrismObject user, boolean assertDefinitio PrismProperty enabledProperty = user.findOrCreateProperty(USER_ENABLED_PATH); assertEquals(USER_ENABLED_QNAME, enabledProperty.getElementName()); PrismAsserts.assertParentConsistency(user); - if (assertDefinitions) PrismAsserts.assertDefinition(enabledProperty, DOMUtil.XSD_BOOLEAN, 0, 1); + if (assertDefinitions) { PrismAsserts.assertDefinition(enabledProperty, DOMUtil.XSD_BOOLEAN, 0, 1); } enabledProperty.setRealValue(true); PrismProperty enabledPropertyAgain = activationContainer.findOrCreateProperty(USER_ENABLED_QNAME); // The "==" is there by purpose. We really want to make sure that is the same *instance*, that is was not created again @@ -198,7 +133,7 @@ private void fillInUserDrake(PrismObject user, boolean assertDefinitio PrismContainer assignmentContainer = user.getValue().findOrCreateContainer(USER_ASSIGNMENT_QNAME); assertEquals(USER_ASSIGNMENT_QNAME, assignmentContainer.getElementName()); PrismAsserts.assertParentConsistency(user); - if (assertDefinitions) PrismAsserts.assertDefinition(assignmentContainer, ASSIGNMENT_TYPE_QNAME, 0, -1); + if (assertDefinitions) { PrismAsserts.assertDefinition(assignmentContainer, ASSIGNMENT_TYPE_QNAME, 0, -1); } PrismContainer assignmentContainerAgain = user.findOrCreateContainer(USER_ASSIGNMENT_QNAME); // The "==" is there by purpose. We really want to make sure that is the same *instance*, that is was not created again assertTrue("Property not the same", assignmentContainer == assignmentContainerAgain); @@ -231,7 +166,7 @@ private void fillInUserDrake(PrismObject user, boolean assertDefinitio // accountRef PrismReference accountRef = user.findOrCreateReference(USER_ACCOUNTREF_QNAME); assertEquals(USER_ACCOUNTREF_QNAME, accountRef.getElementName()); - if (assertDefinitions) PrismAsserts.assertDefinition(accountRef, OBJECT_REFERENCE_TYPE_QNAME, 0, -1); + if (assertDefinitions) { PrismAsserts.assertDefinition(accountRef, OBJECT_REFERENCE_TYPE_QNAME, 0, -1); } accountRef.add(new PrismReferenceValueImpl(ACCOUNT1_OID)); accountRef.add(new PrismReferenceValueImpl(ACCOUNT2_OID)); PrismReference accountRefAgain = user.findOrCreateReference(USER_ACCOUNTREF_QNAME); @@ -244,7 +179,7 @@ private void fillInUserDrake(PrismObject user, boolean assertDefinitio PrismContainer extensionContainer = user.findOrCreateContainer(USER_EXTENSION_QNAME); assertEquals(USER_EXTENSION_QNAME, extensionContainer.getElementName()); PrismAsserts.assertParentConsistency(user); - if (assertDefinitions) PrismAsserts.assertDefinition(extensionContainer, DOMUtil.XSD_ANY, 0, 1); + if (assertDefinitions) { PrismAsserts.assertDefinition(extensionContainer, DOMUtil.XSD_ANY, 0, 1); } PrismContainer extensionContainerAgain = user.findOrCreateContainer(USER_EXTENSION_QNAME); // The "==" is there by purpose. We really want to make sure that is the same *instance*, that is was not created again assertTrue("Extension not the same", extensionContainer == extensionContainerAgain); @@ -254,7 +189,7 @@ private void fillInUserDrake(PrismObject user, boolean assertDefinitio PrismProperty stringTypeProperty = extensionContainer.findOrCreateProperty(EXTENSION_STRING_TYPE_ELEMENT); assertEquals(EXTENSION_STRING_TYPE_ELEMENT, stringTypeProperty.getElementName()); PrismAsserts.assertParentConsistency(user); - if (assertDefinitions) PrismAsserts.assertDefinition(stringTypeProperty, DOMUtil.XSD_STRING, 0, -1); + if (assertDefinitions) { PrismAsserts.assertDefinition(stringTypeProperty, DOMUtil.XSD_STRING, 0, -1); } // TODO @@ -274,42 +209,42 @@ private void assertUserDrake(PrismObject user, boolean assertDefinitio private void assertUserDrakeContent(PrismObject user, boolean assertDefinitions) { // fullName PrismProperty fullNameProperty = user.findProperty(USER_FULLNAME_QNAME); - if (assertDefinitions) PrismAsserts.assertDefinition(fullNameProperty, DOMUtil.XSD_STRING, 1, 1); + if (assertDefinitions) { PrismAsserts.assertDefinition(fullNameProperty, DOMUtil.XSD_STRING, 1, 1); } assertEquals("Wrong fullname", "Sir Fancis Drake", fullNameProperty.getValue().getValue()); // activation PrismContainer activationContainer = user.findContainer(USER_ACTIVATION_QNAME); assertEquals(USER_ACTIVATION_QNAME, activationContainer.getElementName()); - if (assertDefinitions) PrismAsserts.assertDefinition(activationContainer, ACTIVATION_TYPE_QNAME, 0, 1); + if (assertDefinitions) { PrismAsserts.assertDefinition(activationContainer, ACTIVATION_TYPE_QNAME, 0, 1); } // activation/enabled PrismProperty enabledProperty = user.findProperty(USER_ENABLED_PATH); assertEquals(USER_ENABLED_QNAME, enabledProperty.getElementName()); - if (assertDefinitions) PrismAsserts.assertDefinition(enabledProperty, DOMUtil.XSD_BOOLEAN, 0, 1); + if (assertDefinitions) { PrismAsserts.assertDefinition(enabledProperty, DOMUtil.XSD_BOOLEAN, 0, 1); } assertEquals("Wrong enabled", true, enabledProperty.getValue().getValue()); // assignment PrismContainer assignmentContainer = user.findContainer(USER_ASSIGNMENT_QNAME); assertEquals(USER_ASSIGNMENT_QNAME, assignmentContainer.getElementName()); - if (assertDefinitions) PrismAsserts.assertDefinition(assignmentContainer, ASSIGNMENT_TYPE_QNAME, 0, -1); + if (assertDefinitions) { PrismAsserts.assertDefinition(assignmentContainer, ASSIGNMENT_TYPE_QNAME, 0, -1); } // assignment values List assValues = assignmentContainer.getValues(); assertEquals("Wrong number of assignment values", 3, assValues.size()); // assignment values: blue PrismContainerValue assBlueValue = assValues.get(0); PrismProperty assBlueDescriptionProperty = assBlueValue.findProperty(USER_DESCRIPTION_QNAME); - if (assertDefinitions) PrismAsserts.assertDefinition(assBlueDescriptionProperty, DOMUtil.XSD_STRING, 0, 1); + if (assertDefinitions) { PrismAsserts.assertDefinition(assBlueDescriptionProperty, DOMUtil.XSD_STRING, 0, 1); } assertEquals("Wrong blue assignment description", "Assignment created out of the blue", assBlueDescriptionProperty.getValue().getValue()); // assignment values: cyan PrismContainerValue assCyanValue = assValues.get(1); PrismProperty assCyanDescriptionProperty = assCyanValue.findProperty(USER_DESCRIPTION_QNAME); - if (assertDefinitions) PrismAsserts.assertDefinition(assCyanDescriptionProperty, DOMUtil.XSD_STRING, 0, 1); + if (assertDefinitions) { PrismAsserts.assertDefinition(assCyanDescriptionProperty, DOMUtil.XSD_STRING, 0, 1); } assertEquals("Wrong cyan assignment description", "Assignment created out of the cyan", assCyanDescriptionProperty.getValue().getValue()); // assignment values: red PrismContainerValue assRedValue = assValues.get(2); PrismProperty assRedDescriptionProperty = assRedValue.findProperty(USER_DESCRIPTION_QNAME); - if (assertDefinitions) PrismAsserts.assertDefinition(assRedDescriptionProperty, DOMUtil.XSD_STRING, 0, 1); + if (assertDefinitions) { PrismAsserts.assertDefinition(assRedDescriptionProperty, DOMUtil.XSD_STRING, 0, 1); } assertEquals("Wrong red assignment description", "Assignment created out of the red", assRedDescriptionProperty.getValue().getValue()); // accountRef PrismReference accountRef = user.findReference(USER_ACCOUNTREF_QNAME); - if (assertDefinitions) PrismAsserts.assertDefinition(accountRef, OBJECT_REFERENCE_TYPE_QNAME, 0, -1); + if (assertDefinitions) { PrismAsserts.assertDefinition(accountRef, OBJECT_REFERENCE_TYPE_QNAME, 0, -1); } PrismAsserts.assertReferenceValue(accountRef, ACCOUNT1_OID); PrismAsserts.assertReferenceValue(accountRef, ACCOUNT2_OID); assertEquals("accountRef size", 2, accountRef.getValues().size()); diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsing.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsing.java index a1abf46fbec..b94e3878088 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsing.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsing.java @@ -6,11 +6,9 @@ */ package com.evolveum.midpoint.prism; +import static org.testng.AssertJUnit.*; + import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertNotNull; -import static org.testng.AssertJUnit.assertNull; -import static org.testng.AssertJUnit.assertTrue; import java.io.File; import java.io.IOException; @@ -20,33 +18,29 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; - import javax.xml.datatype.Duration; import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; -import com.evolveum.midpoint.prism.foo.AccountType; -import com.evolveum.midpoint.prism.impl.PrismReferenceValueImpl; -import com.evolveum.midpoint.prism.path.ItemName; -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.DiffUtil; import com.evolveum.midpoint.prism.delta.ObjectDelta; +import com.evolveum.midpoint.prism.foo.AccountType; import com.evolveum.midpoint.prism.foo.UserType; +import com.evolveum.midpoint.prism.impl.PrismReferenceValueImpl; +import com.evolveum.midpoint.prism.path.ItemName; +import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.prism.util.PrismAsserts; import com.evolveum.midpoint.prism.xml.XmlTypeConverter; import com.evolveum.midpoint.util.DOMUtil; -import com.evolveum.midpoint.util.PrettyPrinter; import com.evolveum.midpoint.util.exception.SchemaException; /** * @author semancik - * */ -public abstract class TestPrismParsing { +public abstract class TestPrismParsing extends AbstractPrismTest { protected abstract String getSubdirName(); @@ -57,12 +51,7 @@ protected File getCommonSubdir() { } protected File getFile(String baseName) { - return new File(getCommonSubdir(), baseName+"."+getFilenameSuffix()); - } - - @BeforeSuite - public void setupDebug() { - PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); + return new File(getCommonSubdir(), baseName + "." + getFilenameSuffix()); } protected abstract String getOutputFormat(); @@ -70,7 +59,7 @@ public void setupDebug() { @Test public void test100PrismParseFile() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN PrismObject user = prismContext.parseObject(getFile(USER_JACK_FILE_BASENAME)); @@ -86,7 +75,7 @@ public void test100PrismParseFile() throws Exception { @Test public void test110PrismParseFileNoNs() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN PrismObject user = prismContext.parseObject(getFile(USER_JACK_NO_NS_BASENAME)); @@ -102,7 +91,7 @@ public void test110PrismParseFileNoNs() throws Exception { @Test public void test120PrismParseFileObject() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN PrismObject user = prismContext.parseObject(getFile(USER_JACK_OBJECT_BASENAME)); @@ -118,7 +107,7 @@ public void test120PrismParseFileObject() throws Exception { @Test public void test130PrismParseFileAdhoc() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN PrismObject user = prismContext.parseObject(getFile(USER_JACK_ADHOC_BASENAME)); @@ -149,7 +138,7 @@ public void test220RoundTripObject() throws Exception { private void roundTrip(File file, boolean expectFullPolyName, boolean withIncomplete) throws SchemaException, SAXException, IOException { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); PrismObject originalUser = prismContext.parseObject(file); System.out.println("Input parsed user:"); @@ -168,8 +157,6 @@ private void roundTrip(File file, boolean expectFullPolyName, boolean withIncomp System.out.println(userXml); assertNotNull(userXml); - validateXml(userXml, prismContext); - // WHEN PrismObject parsedUser = prismContext.parseObject(userXml); System.out.println("Re-parsed user:"); @@ -182,20 +169,19 @@ private void roundTrip(File file, boolean expectFullPolyName, boolean withIncomp System.out.println("Diff:"); System.out.println(diff.debugDump()); - assertTrue("Diff: "+diff, diff.isEmpty()); + assertTrue("Diff: " + diff, diff.isEmpty()); - assertTrue("Users not equal", originalUser.equals(parsedUser)); + assertEquals("Users not equal", parsedUser, originalUser); } - @Test public void test230RoundTripAdhoc() throws Exception { roundTripAdhoc(getFile(USER_JACK_ADHOC_BASENAME)); } - private void roundTripAdhoc(File file) throws SchemaException, SAXException, IOException { + private void roundTripAdhoc(File file) throws SchemaException, IOException { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); PrismObject originalUser = prismContext.parseObject(file); System.out.println("Input parsed user:"); @@ -214,8 +200,6 @@ private void roundTripAdhoc(File file) throws SchemaException, SAXException, IOE System.out.println(userXml); assertNotNull(userXml); - validateXml(userXml, prismContext); - // WHEN PrismObject parsedUser = prismContext.parseObject(userXml); System.out.println("Re-parsed user:"); @@ -227,11 +211,10 @@ private void roundTripAdhoc(File file) throws SchemaException, SAXException, IOE assertTrue("Users not equal", originalUser.equals(parsedUser)); } - @Test public void test300MeleeContext() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); PrismObject userJack = prismContext.parseObject(getFile(USER_JACK_FILE_BASENAME)); PrismContainer meleeContextContainer = userJack.findOrCreateContainer(ItemPath.create(UserType.F_EXTENSION, EXTENSION_MELEE_CONTEXT_ELEMENT)); @@ -274,7 +257,7 @@ public void test300MeleeContext() throws Exception { // Make the original user jack suitable for comparison. // Some of the accountRef information is (intentionally) lost in re-parsing therefore erase it before comparing PrismReference jackAccountRef = userJack.findReference(UserType.F_ACCOUNT_REF); - for (PrismReferenceValue accRefVal: jackAccountRef.getValues()) { + for (PrismReferenceValue accRefVal : jackAccountRef.getValues()) { String oid = accRefVal.getOid(); QName targetType = accRefVal.getTargetType(); accRefVal.setObject(null); @@ -289,7 +272,7 @@ public void test300MeleeContext() throws Exception { @Test public void test400UserWill() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN PrismObject user = prismContext.parseObject(getFile(USER_WILL_FILE_BASENAME)); @@ -305,7 +288,7 @@ public void test400UserWill() throws Exception { @Test public void test410UserWillRoundTrip() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN PrismObject user = prismContext.parseObject(getFile(USER_WILL_FILE_BASENAME)); @@ -340,7 +323,7 @@ public void test410UserWillRoundTrip() throws Exception { @Test public void test500UserElisabethRoundTrip() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN PrismObject user = prismContext.parseObject(getFile(USER_ELISABETH_FILE_BASENAME)); @@ -376,7 +359,7 @@ public void test500UserElisabethRoundTrip() throws Exception { @Test public void test600AccountBarbossa() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN PrismObject account = prismContext.parseObject(getFile(ACCOUNT_BARBOSSA_FILE_BASENAME)); @@ -399,7 +382,6 @@ public void test600AccountBarbossa() throws Exception { )), names); } - protected void assertUserAdhoc(PrismObject user, boolean expectRawInConstructions, boolean withIncomplete) throws SchemaException { user.checkConsistence(); assertUserJackContent(user, expectRawInConstructions, true, withIncomplete); @@ -407,7 +389,6 @@ protected void assertUserAdhoc(PrismObject user, boolean expectRawInCo assertVisitor(user, 58); } - private void assertUserExtensionAdhoc(PrismObject user) { PrismContainer extension = user.getExtension(); @@ -417,9 +398,9 @@ private void assertUserExtensionAdhoc(PrismObject user) { assertNull("Extension ID", extensionValue.getId()); PrismAsserts.assertPropertyValue(extension, USER_ADHOC_BOTTLES_ELEMENT, 20); - ItemPath bottlesPath = ItemPath.create(new QName(NS_FOO,"extension"), USER_ADHOC_BOTTLES_ELEMENT); + ItemPath bottlesPath = ItemPath.create(new QName(NS_FOO, "extension"), USER_ADHOC_BOTTLES_ELEMENT); PrismProperty bottlesProperty = user.findProperty(bottlesPath); - assertNotNull("Property "+bottlesPath+" not found", bottlesProperty); + assertNotNull("Property " + bottlesPath + " not found", bottlesProperty); PrismAsserts.assertPropertyValue(bottlesProperty, 20); PrismPropertyDefinition bottlesPropertyDef = bottlesProperty.getDefinition(); assertNotNull("No definition for bottles", bottlesPropertyDef); @@ -511,9 +492,9 @@ private void assertUserWillExtension(PrismObject user) { PrismAsserts.assertDefinition(indexedStringPropertyDef, EXTENSION_SINGLE_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1); assertEquals("'Indexed' attribute on 'singleStringType' property is wrong", Boolean.FALSE, indexedStringPropertyDef.isIndexed()); - ItemPath barPath = ItemPath.create(new QName(NS_FOO,"extension"), EXTENSION_BAR_ELEMENT); + ItemPath barPath = ItemPath.create(new QName(NS_FOO, "extension"), EXTENSION_BAR_ELEMENT); PrismProperty barProperty = user.findProperty(barPath); - assertNotNull("Property "+barPath+" not found", barProperty); + assertNotNull("Property " + barPath + " not found", barProperty); PrismAsserts.assertPropertyValue(barProperty, "BAR"); PrismPropertyDefinition barPropertyDef = barProperty.getDefinition(); assertNotNull("No definition for bar", barPropertyDef); @@ -525,11 +506,10 @@ private void assertUserWillExtension(PrismObject user) { PrismAsserts.assertDefinition(multiPropertyDef, EXTENSION_MULTI_ELEMENT, DOMUtil.XSD_STRING, 1, -1); assertNull("'Indexed' attribute on 'multi' property is not null", multiPropertyDef.isIndexed()); - PrismAsserts.assertPropertyValue(extension, EXTENSION_BAR_ELEMENT, "BAR"); PrismAsserts.assertPropertyValue(extension, EXTENSION_NUM_ELEMENT, 42); Collection> multiPVals = extension.findProperty(EXTENSION_MULTI_ELEMENT).getValues(); - assertEquals("Multi",3,multiPVals.size()); + assertEquals("Multi", 3, multiPVals.size()); } @@ -537,7 +517,6 @@ private void assertUserElisabeth(PrismObject user) throws SchemaExcept user.checkConsistence(); user.assertDefinitions("test"); assertUserElisabethExtension(user); - //assertVisitor(user,55); } private void assertUserElisabethExtension(PrismObject user) { @@ -548,23 +527,10 @@ private void assertUserElisabethExtension(PrismObject user) { assertTrue("Extension parent", extensionValue.getParent() == extension); assertNull("Extension ID", extensionValue.getId()); -// PrismProperty stringType = extension.findProperty(EXTENSION_STRING_TYPE_ELEMENT); -// PrismAsserts.assertPropertyValue(stringType, "BARbar", "FOObar"); -// PrismPropertyDefinition stringTypePropertyDef = stringType.getDefinition(); -// PrismAsserts.assertDefinition(stringTypePropertyDef, EXTENSION_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1); -// assertNull("'Indexed' attribute on 'stringType' property is not null", stringTypePropertyDef.isIndexed()); - PrismProperty secondaryStringType = extension.findProperty(EXTENSION_SECONDARY_SECONDARY_STRING_TYPE_ELEMENT); PrismAsserts.assertPropertyValue(secondaryStringType, "string1"); PrismPropertyDefinition secondaryStringTypePropertyDef = secondaryStringType.getDefinition(); PrismAsserts.assertDefinition(secondaryStringTypePropertyDef, EXTENSION_SINGLE_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1); assertNull("'Indexed' attribute on 'secondaryStringType' property is not null", secondaryStringTypePropertyDef.isIndexed()); } - - protected void validateXml(String xmlString, PrismContext prismContext) throws SAXException, IOException { - } - - protected void displayTestTitle(final String TEST_NAME) { - getSubdirName(); - } } diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsingXml.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsingXml.java index c37bc01a3c4..e6079a44141 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsingXml.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismParsingXml.java @@ -95,7 +95,7 @@ public void testPrismParseXxe() throws Exception { } @Test - public void testPrismParseDomXxe() throws Exception { + public void testPrismParseDomXxe() { try { // WHEN DOMUtil.parseFile(getFile(USER_JACK_XXE_BASENAME)); @@ -108,13 +108,4 @@ public void testPrismParseDomXxe() throws Exception { } } - - @Override - protected void validateXml(String xmlString, PrismContext prismContext) throws SAXException, IOException { -// Document xmlDocument = DOMUtil.parseDocument(xmlString); -// Schema javaxSchema = prismContext.getSchemaRegistry().getJavaxSchema(); -// Validator validator = javaxSchema.newValidator(); -// validator.setResourceResolver(prismContext.getEntityResolver()); -// validator.validate(new DOMSource(xmlDocument)); - } } diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismSchemaConstruction.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismSchemaConstruction.java index faacb8c154e..9ee7119f5b4 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismSchemaConstruction.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPrismSchemaConstruction.java @@ -6,26 +6,24 @@ */ package com.evolveum.midpoint.prism; -import static org.testng.AssertJUnit.assertFalse; -import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*; +import static org.testng.AssertJUnit.*; + +import static com.evolveum.midpoint.prism.PrismInternalTestUtil.DEFAULT_NAMESPACE_PREFIX; +import static com.evolveum.midpoint.prism.PrismInternalTestUtil.constructInitializedPrismContext; -import static org.testng.AssertJUnit.assertNotNull; -import static org.testng.AssertJUnit.assertTrue; -import static org.testng.AssertJUnit.assertEquals; import java.io.IOException; import java.util.Collection; import java.util.Iterator; - import javax.xml.namespace.QName; -import com.evolveum.midpoint.prism.path.ItemName; -import com.evolveum.midpoint.prism.impl.schema.PrismSchemaImpl; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; +import com.evolveum.midpoint.prism.impl.schema.PrismSchemaImpl; +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.util.DOMUtil; @@ -34,9 +32,8 @@ /** * @author semancik - * */ -public class TestPrismSchemaConstruction { +public class TestPrismSchemaConstruction extends AbstractPrismTest { private static final String NS_MY_SCHEMA = "http://midpoint.evolveum.com/xml/ns/test/my-1"; private static final String WEAPON_TYPE_LOCAL_NAME = "WeaponType"; @@ -49,7 +46,6 @@ public class TestPrismSchemaConstruction { private static final String WEAPON_PASSWORD_LOCAL_NAME = "password"; private static final String WEAPON_BLADE_LOCAL_NAME = "blade"; - @BeforeSuite public void setupDebug() { PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); @@ -57,8 +53,6 @@ public void setupDebug() { @Test public void testConstructSchema() throws SchemaException, SAXException, IOException { - System.out.println("===[ testConstructSchema ]==="); - // GIVEN PrismContext ctx = constructInitializedPrismContext(); @@ -73,8 +67,6 @@ public void testConstructSchema() throws SchemaException, SAXException, IOExcept @Test public void testSchemaRoundtrip() throws Exception { - System.out.println("===[ testSchemaRoundtrip ]==="); - // GIVEN PrismContext ctx = constructInitializedPrismContext(); @@ -83,29 +75,23 @@ public void testSchemaRoundtrip() throws Exception { @Test public void testSchemaRoundtripLoopShareContext() throws Exception { - System.out.println("===[ testSchemaRoundtripLoopShareContext ]==="); - PrismContext ctx = constructInitializedPrismContext(); - for(int i=0; i < SCHEMA_ROUNDTRIP_LOOP_ATTEMPTS; i++) { - System.out.println("\n--- attempt "+i+"---"); + for (int i = 0; i < SCHEMA_ROUNDTRIP_LOOP_ATTEMPTS; i++) { + System.out.println("\n--- attempt " + i + "---"); schemaRoundtrip(ctx); } } @Test public void testSchemaRoundtripLoopNewContext() throws Exception { - System.out.println("===[ testSchemaRoundtripLoopNewContext ]==="); - - for(int i=0; i < SCHEMA_ROUNDTRIP_LOOP_ATTEMPTS; i++) { - System.out.println("\n--- attempt "+i+"---"); + for (int i = 0; i < SCHEMA_ROUNDTRIP_LOOP_ATTEMPTS; i++) { + System.out.println("\n--- attempt " + i + "---"); PrismContext ctx = constructInitializedPrismContext(); schemaRoundtrip(ctx); } } - - private void schemaRoundtrip(PrismContext ctx) throws SchemaException, SAXException, IOException { - + private void schemaRoundtrip(PrismContext ctx) throws SchemaException { PrismSchema schema = constructSchema(ctx); assertSchema(schema); @@ -155,7 +141,7 @@ private void assertSchema(PrismSchema schema) { assertEquals("Unexpected number of definitions in schema", 2, definitions.size()); Iterator schemaDefIter = definitions.iterator(); - ComplexTypeDefinition weaponTypeDef = (ComplexTypeDefinition)schemaDefIter.next(); + ComplexTypeDefinition weaponTypeDef = (ComplexTypeDefinition) schemaDefIter.next(); assertEquals("Unexpected number of definitions in weaponTypeDef", 5, weaponTypeDef.getDefinitions().size()); Iterator weaponTypeDefIter = weaponTypeDef.getDefinitions().iterator(); PrismPropertyDefinition kindPropertyDef = (PrismPropertyDefinition) weaponTypeDefIter.next(); @@ -180,12 +166,12 @@ private void assertSchema(PrismSchema schema) { assertEquals("Wrong createTimestampPropertyDef displayName", "Create timestamp", createTimestampPropertyDef.getDisplayName()); assertTrue("createTimestampPropertyDef not operational", createTimestampPropertyDef.isOperational()); - PrismContainerDefinition weaponContDef = (PrismContainerDefinition)schemaDefIter.next(); + PrismContainerDefinition weaponContDef = (PrismContainerDefinition) schemaDefIter.next(); assertEquals("Wrong complex type def in weaponContDef", weaponTypeDef, weaponContDef.getComplexTypeDefinition()); } private void assertPrefix(String expectedPrefix, Element element) { - assertEquals("Wrong prefix on element "+DOMUtil.getQName(element), expectedPrefix, element.getPrefix()); + assertEquals("Wrong prefix on element " + DOMUtil.getQName(element), expectedPrefix, element.getPrefix()); } } diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPropertyArrayList.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPropertyArrayList.java index 58a6f9ba185..caef2815478 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPropertyArrayList.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestPropertyArrayList.java @@ -6,24 +6,21 @@ */ package com.evolveum.midpoint.prism; -import com.evolveum.midpoint.prism.foo.UserType; -import com.evolveum.midpoint.prism.impl.xjc.PropertyArrayList; -import com.evolveum.midpoint.util.DOMUtil; -import org.testng.AssertJUnit; -import org.testng.annotations.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; +import static org.testng.AssertJUnit.assertEquals; + +import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*; import java.io.File; -import java.io.IOException; -import static com.evolveum.midpoint.prism.PrismInternalTestUtil.*; -import static org.testng.AssertJUnit.*; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; -public class TestPropertyArrayList { +import com.evolveum.midpoint.prism.foo.UserType; +import com.evolveum.midpoint.prism.impl.xjc.PropertyArrayList; +import com.evolveum.midpoint.util.DOMUtil; - public static final String USER_JACK_XXE_BASENAME = "user-jack-xxe"; +public class TestPropertyArrayList extends AbstractPrismTest { private String getSubdirName() { return "xml"; @@ -38,7 +35,7 @@ private File getCommonSubdir() { } private File getFile(String baseName) { - return new File(getCommonSubdir(), baseName+"."+getFilenameSuffix()); + return new File(getCommonSubdir(), baseName + "." + getFilenameSuffix()); } @Test @@ -51,16 +48,16 @@ public void testPrismParseDom() throws Exception { PrismObject user = prismContext.parserFor(userElement).parse(); PrismProperty property = user.findProperty(UserType.F_ADDITIONAL_NAMES); - PropertyArrayList propertyArrayList = new PropertyArrayList(property, user.getValue()); + PropertyArrayList propertyArrayList = new PropertyArrayList<>(property, user.getValue()); // WHEN - System.out.println("Additional names before test: " ); + System.out.println("Additional names before test: "); System.out.println(property.debugDump()); String testName = "test-name"; propertyArrayList.set(1, "test-name"); // THEN - System.out.println("Additional names after test: " ); + System.out.println("Additional names after test: "); System.out.println(property.debugDump()); assertEquals(testName, propertyArrayList.get(1)); } diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestTypeConversion.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestTypeConversion.java index 0aa24a14f30..9ca2a6f0a85 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestTypeConversion.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestTypeConversion.java @@ -17,6 +17,7 @@ import com.evolveum.midpoint.prism.impl.xml.XmlTypeConverterInternal; import com.evolveum.midpoint.prism.util.CloneUtil; import org.testng.AssertJUnit; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import org.w3c.dom.Document; @@ -26,6 +27,7 @@ import com.evolveum.midpoint.prism.util.PrismAsserts; import com.evolveum.midpoint.prism.xml.XmlTypeConverter; import com.evolveum.midpoint.prism.xml.XsdTypeMapper; +import com.evolveum.midpoint.tools.testng.AbstractUnitTest; import com.evolveum.midpoint.util.DOMUtil; import com.evolveum.midpoint.util.PrettyPrinter; @@ -33,19 +35,14 @@ * @author semancik * */ -public class TestTypeConversion { +public class TestTypeConversion extends AbstractPrismTest { private static final String MY_NS = "http://midpoint.evolveum.com/xml/ns/testing/xmlconversion"; private static final String MY_ELEMENT_NAME = "foo"; private static final QName MY_ELEMENT_QNAME = new QName(MY_NS, MY_ELEMENT_NAME); - @BeforeSuite - public void setupDebug() { - PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); - } - @Test - public void testXmlDateTimeType() throws Exception { + public void testXmlDateTimeType() { assertEquals("Wrong datetime class", XMLGregorianCalendar.class, XsdTypeMapper.toJavaType(DOMUtil.XSD_DATETIME)); assertEquals("Wrong datetime class", DOMUtil.XSD_DATETIME, XsdTypeMapper.toXsdType(XMLGregorianCalendar.class)); } @@ -62,7 +59,7 @@ public void testXmlDateTimeValue() throws Exception { } @Test - public void testJavaStringToXMLGregorianCalendar() throws Exception { + public void testJavaStringToXMLGregorianCalendar() { String stringDate = "1975-05-30T21:30:00.000Z"; // WHEN @@ -74,12 +71,12 @@ public void testJavaStringToXMLGregorianCalendar() throws Exception { } @Test - public void testJavaStringToXMLGregorianCalendarWrongFormat() throws Exception { + public void testJavaStringToXMLGregorianCalendarWrongFormat() { String stringDate = "blah blah blah"; try { // WHEN - XMLGregorianCalendar xmlGregorianCalendar = JavaTypeConverter.convert(XMLGregorianCalendar.class, stringDate); + JavaTypeConverter.convert(XMLGregorianCalendar.class, stringDate); AssertJUnit.fail("Unexpected success"); } catch (IllegalArgumentException e) { @@ -90,7 +87,7 @@ public void testJavaStringToXMLGregorianCalendarWrongFormat() throws Exception { } @Test - public void testJavaXMLGregorianCalendarToString() throws Exception { + public void testJavaXMLGregorianCalendarToString() { XMLGregorianCalendar cal = XmlTypeConverter.createXMLGregorianCalendar(1975, 5, 30, 21, 30, 0); // WHEN @@ -101,7 +98,7 @@ public void testJavaXMLGregorianCalendarToString() throws Exception { } @Test - public void testJavaXMLGregorianCalendarToLong() throws Exception { + public void testJavaXMLGregorianCalendarToLong() { XMLGregorianCalendar cal = XmlTypeConverter.createXMLGregorianCalendar(1975, 5, 30, 21, 30, 0); // WHEN diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestUnknownItems.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestUnknownItems.java index 6669fbc0d1e..cd9dee52bdd 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestUnknownItems.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestUnknownItems.java @@ -6,39 +6,33 @@ */ package com.evolveum.midpoint.prism; -import com.evolveum.midpoint.prism.foo.UserType; -import com.evolveum.midpoint.util.PrettyPrinter; -import com.evolveum.midpoint.util.exception.SchemaException; -import org.testng.annotations.BeforeSuite; -import org.testng.annotations.Test; +import static org.testng.AssertJUnit.assertNotNull; + +import static com.evolveum.midpoint.prism.PrismInternalTestUtil.constructInitializedPrismContext; import java.io.File; -import static com.evolveum.midpoint.prism.PrismInternalTestUtil.DEFAULT_NAMESPACE_PREFIX; -import static com.evolveum.midpoint.prism.PrismInternalTestUtil.constructInitializedPrismContext; -import static org.testng.AssertJUnit.assertNotNull; +import org.testng.annotations.Test; + +import com.evolveum.midpoint.prism.foo.UserType; +import com.evolveum.midpoint.util.exception.SchemaException; /** * See MID-3249. * * @author mederly */ -public class TestUnknownItems { +public class TestUnknownItems extends AbstractPrismTest { public static final String TEST_DIR = "src/test/resources/common/xml"; public static final File WRONG_ITEM_FILE = new File(TEST_DIR + "/user-wrong-item.xml"); public static final File WRONG_NAMESPACE_FILE = new File(TEST_DIR + "/user-wrong-namespace.xml"); - @BeforeSuite - public void setupDebug() { - PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); - } - @Test(expectedExceptions = SchemaException.class) public void test010ParseWrongItemStrict() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN+THEN try { @@ -52,7 +46,7 @@ public void test010ParseWrongItemStrict() throws Exception { @Test public void test020ParseWrongItemCompat() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN PrismObject user = prismContext.parserFor(WRONG_ITEM_FILE).compat().parse(); @@ -70,7 +64,7 @@ public void test020ParseWrongItemCompat() throws Exception { @Test(enabled = false, expectedExceptions = SchemaException.class) public void test110ParseWrongNamespaceStrict() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN+THEN PrismObject user = prismContext.parseObject(WRONG_NAMESPACE_FILE); @@ -82,7 +76,7 @@ public void test110ParseWrongNamespaceStrict() throws Exception { @Test public void test120ParseWrongNamespaceCompat() throws Exception { // GIVEN - PrismContext prismContext = constructInitializedPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN PrismObject user = prismContext.parserFor(WRONG_NAMESPACE_FILE).compat().parse(); @@ -93,5 +87,4 @@ public void test120ParseWrongNamespaceCompat() throws Exception { assertNotNull(user); } - } diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestXmlSerialization.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestXmlSerialization.java index 785f7d94158..907918d6078 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestXmlSerialization.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/TestXmlSerialization.java @@ -29,19 +29,12 @@ * @author mederly * */ -public class TestXmlSerialization { - - @BeforeSuite - public void setupDebug() throws SchemaException, SAXException, IOException { - PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); - PrismTestUtil.resetPrismContext(new PrismInternalTestUtil()); - } +public class TestXmlSerialization extends AbstractPrismTest { @Test public void testHandlingInvalidChars() throws Exception { // GIVEN - - PrismContext prismContext = PrismTestUtil.getPrismContext(); + PrismContext prismContext = getPrismContext(); // WHEN diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/lex/TestProtectedString.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/lex/TestProtectedString.java index 949d09e696d..ae8f976ee9b 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/lex/TestProtectedString.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/lex/TestProtectedString.java @@ -6,6 +6,7 @@ */ package com.evolveum.midpoint.prism.lex; +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; @@ -28,15 +29,8 @@ /** * @author mederly - * */ -public class TestProtectedString { - - @BeforeSuite - public void setupDebug() throws SchemaException, SAXException, IOException { - PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); - PrismTestUtil.resetPrismContext(new PrismInternalTestUtil()); - } +public class TestProtectedString extends AbstractPrismTest { @Test public void testParseProtectedStringEncrypted() throws Exception { diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/match/TestMatchingRule.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/match/TestMatchingRule.java index 48f9bf3ea77..edc80b4acbe 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/match/TestMatchingRule.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/match/TestMatchingRule.java @@ -6,42 +6,25 @@ */ package com.evolveum.midpoint.prism.match; -import static org.testng.AssertJUnit.assertEquals; -import static com.evolveum.midpoint.prism.PrismInternalTestUtil.DEFAULT_NAMESPACE_PREFIX; -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertTrue; +import static org.testng.AssertJUnit.*; -import java.io.IOException; +import org.testng.annotations.Test; +import com.evolveum.midpoint.prism.AbstractPrismTest; import com.evolveum.midpoint.prism.PrismConstants; import com.evolveum.midpoint.prism.impl.match.MatchingRuleRegistryFactory; -import org.testng.annotations.BeforeSuite; -import org.testng.annotations.Test; -import org.xml.sax.SAXException; - -import com.evolveum.midpoint.prism.PrismInternalTestUtil; import com.evolveum.midpoint.prism.polystring.PolyString; -import com.evolveum.midpoint.prism.util.PrismTestUtil; import com.evolveum.midpoint.util.DOMUtil; -import com.evolveum.midpoint.util.PrettyPrinter; import com.evolveum.midpoint.util.exception.SchemaException; import com.evolveum.prism.xml.ns._public.types_3.PolyStringType; /** * @author semancik - * */ -public class TestMatchingRule { +public class TestMatchingRule extends AbstractPrismTest { - private static MatchingRuleRegistry matchingRuleRegistry; - - @BeforeSuite - public void setup() throws SchemaException, SAXException, IOException { - PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); - PrismTestUtil.resetPrismContext(new PrismInternalTestUtil()); - - matchingRuleRegistry = MatchingRuleRegistryFactory.createRegistry(); - } + private static MatchingRuleRegistry matchingRuleRegistry = + MatchingRuleRegistryFactory.createRegistry(); @Test public void testStringDefault() throws Exception { @@ -149,13 +132,12 @@ public void testXml() throws Exception { assertNormalized(rule, "FOO BAR ", "FOO BAR "); } - private void assertMatch(MatchingRule rule, T a, T b) throws SchemaException { - assertTrue("Values '"+a+"' and '"+b+"' does not match; rule: "+rule, rule.match(a, b)); + assertTrue("Values '" + a + "' and '" + b + "' does not match; rule: " + rule, rule.match(a, b)); } private void assertNoMatch(MatchingRule rule, T a, T b) throws SchemaException { - assertFalse("Values '"+a+"' and '"+b+"' DOES match but they should not; rule: "+rule, rule.match(a, b)); + assertFalse("Values '" + a + "' and '" + b + "' DOES match but they should not; rule: " + rule, rule.match(a, b)); } private void assertNormalized(MatchingRule rule, String expected, String original) throws SchemaException { diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestObjectQuery.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestObjectQuery.java index 2038b521098..416314100f6 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestObjectQuery.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestObjectQuery.java @@ -7,41 +7,28 @@ package com.evolveum.midpoint.prism.query; +import javax.xml.namespace.QName; + +import org.testng.AssertJUnit; +import org.testng.annotations.Test; + +import com.evolveum.midpoint.prism.AbstractPrismTest; import com.evolveum.midpoint.prism.MutablePrismPropertyDefinition; import com.evolveum.midpoint.prism.PrismInternalTestUtil; import com.evolveum.midpoint.prism.PrismObject; import com.evolveum.midpoint.prism.foo.AssignmentType; import com.evolveum.midpoint.prism.foo.UserType; -import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; import com.evolveum.midpoint.prism.impl.match.MatchingRuleRegistryFactory; +import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; 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.util.DOMUtil; -import com.evolveum.midpoint.util.PrettyPrinter; -import com.evolveum.midpoint.util.exception.SchemaException; -import org.testng.AssertJUnit; -import org.testng.annotations.BeforeSuite; -import org.testng.annotations.Test; -import org.xml.sax.SAXException; -import javax.xml.namespace.QName; -import java.io.IOException; - -import static com.evolveum.midpoint.prism.PrismInternalTestUtil.DEFAULT_NAMESPACE_PREFIX; -import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext; - -public class TestObjectQuery { +public class TestObjectQuery extends AbstractPrismTest { - private static MatchingRuleRegistry matchingRuleRegistry; - - @BeforeSuite - public void setupDebug() throws SchemaException, SAXException, IOException { - PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); - PrismTestUtil.resetPrismContext(new PrismInternalTestUtil()); - - matchingRuleRegistry = MatchingRuleRegistryFactory.createRegistry(); - } + private static MatchingRuleRegistry matchingRuleRegistry = + MatchingRuleRegistryFactory.createRegistry(); @Test public void testMatchAndFilter() throws Exception { @@ -50,12 +37,11 @@ public void testMatchAndFilter() throws Exception { getPrismContext().queryFor(UserType.class) .item(UserType.F_GIVEN_NAME).eq("Jack").matchingCaseIgnore() .and().item(UserType.F_FULL_NAME).contains("arr") - .buildFilter(); + .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertTrue("filter does not match object", match); } - @Test public void testMatchOrFilter() throws Exception { PrismObject user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); @@ -125,17 +111,17 @@ public void testMatchEqualEmptyAgainstNonEmptyItem() throws Exception { public void testComplexMatch() throws Exception { PrismObject user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); // System.out.println("user given name" + user.asObjectable().getGivenName()); - System.out.println("definition: " +user.findItem(UserType.F_FAMILY_NAME).getDefinition().debugDump()); + System.out.println("definition: " + user.findItem(UserType.F_FAMILY_NAME).getDefinition().debugDump()); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .item(UserType.F_FAMILY_NAME).eq("Sparrow") .and().item(UserType.F_FULL_NAME).contains("arr") .and() - .block() - .item(UserType.F_GIVEN_NAME).eq("Jack") - .or().item(UserType.F_GIVEN_NAME).eq("Jackie") - .endBlock() - .buildFilter(); + .block() + .item(UserType.F_GIVEN_NAME).eq("Jack") + .or().item(UserType.F_GIVEN_NAME).eq("Jackie") + .endBlock() + .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertTrue("filter does not match object", match); } @@ -167,7 +153,7 @@ public void testExistsNegative() throws Exception { PrismObject user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .exists(UserType.F_ASSIGNMENT) - .item(AssignmentType.F_DESCRIPTION).eq("Assignment NONE") + .item(AssignmentType.F_DESCRIPTION).eq("Assignment NONE") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertFalse("filter matches object, but it should not", match); @@ -178,7 +164,7 @@ public void testExistsPositive() throws Exception { PrismObject user = PrismTestUtil.parseObject(PrismInternalTestUtil.USER_JACK_FILE_XML); ObjectFilter filter = getPrismContext().queryFor(UserType.class) .exists(UserType.F_ASSIGNMENT) - .item(AssignmentType.F_DESCRIPTION).eq("Assignment 2") + .item(AssignmentType.F_DESCRIPTION).eq("Assignment 2") .buildFilter(); boolean match = ObjectQuery.match(user, filter, matchingRuleRegistry); AssertJUnit.assertTrue("filter does not match object, but it should", match); diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestQueryBuilder.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestQueryBuilder.java index 632c0c2d2e6..19852abbfd1 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestQueryBuilder.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestQueryBuilder.java @@ -7,79 +7,61 @@ package com.evolveum.midpoint.prism.query; +import static com.evolveum.midpoint.prism.PrismInternalTestUtil.NS_FOO; +import static com.evolveum.midpoint.prism.util.PrismTestUtil.getSchemaRegistry; + +import java.lang.reflect.Method; +import javax.xml.namespace.QName; + +import org.testng.AssertJUnit; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + import com.evolveum.midpoint.prism.*; import com.evolveum.midpoint.prism.foo.AssignmentType; import com.evolveum.midpoint.prism.foo.UserType; import com.evolveum.midpoint.prism.impl.query.*; -import com.evolveum.midpoint.prism.match.MatchingRuleRegistry; -import com.evolveum.midpoint.prism.impl.match.MatchingRuleRegistryFactory; import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.prism.util.PrismTestUtil; -import com.evolveum.midpoint.util.PrettyPrinter; -import com.evolveum.midpoint.util.exception.SchemaException; -import org.testng.AssertJUnit; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeSuite; -import org.testng.annotations.Test; -import org.xml.sax.SAXException; - -import javax.xml.namespace.QName; -import java.io.IOException; -import java.lang.reflect.Method; - -import static com.evolveum.midpoint.prism.PrismInternalTestUtil.DEFAULT_NAMESPACE_PREFIX; -import static com.evolveum.midpoint.prism.PrismInternalTestUtil.NS_FOO; -import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext; -import static com.evolveum.midpoint.prism.util.PrismTestUtil.getSchemaRegistry; /** * Here are the most simple tests for Query Builder. * More advanced tests are part of QueryInterpreterTest in repo-sql-impl-test. - * + *

* These tests are strict in the sense they check the exact structure of created queries. * Repo tests check just the HQL outcome. */ -public class TestQueryBuilder { +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"); - private static MatchingRuleRegistry matchingRuleRegistry; - - @BeforeSuite - public void setupDebug() throws SchemaException, SAXException, IOException { - PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); - PrismTestUtil.resetPrismContext(new PrismInternalTestUtil()); - - matchingRuleRegistry = MatchingRuleRegistryFactory.createRegistry(); - } @BeforeMethod - public void beforeMethod(Method method) throws Exception { + public void beforeMethod(Method method) { System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> START TEST" + getClass().getName() + "." + method.getName() + "<<<<<<<<<<<<<<<<<<<<<<<<"); } @Test - public void test100EmptyFilter() throws Exception{ + public void test100EmptyFilter() { ObjectQuery actual = getPrismContext().queryFor(UserType.class).build(); ObjectQuery expected = ObjectQueryImpl.createObjectQuery((ObjectFilter) null); compare(actual, expected); } @Test - public void test110EmptyBlock() throws Exception{ + public void test110EmptyBlock() { ObjectQuery actual = getPrismContext().queryFor(UserType.class).block().endBlock().build(); ObjectQuery expected = ObjectQueryImpl.createObjectQuery((ObjectFilter) null); compare(actual, expected); } @Test - public void test112EmptyBlocks() throws Exception{ + public void test112EmptyBlocks() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .block() - .block() - .block() - .endBlock() - .endBlock() + .block() + .block() + .endBlock() + .endBlock() .endBlock() .build(); ObjectQuery expected = ObjectQueryImpl.createObjectQuery((ObjectFilter) null); @@ -87,7 +69,7 @@ public void test112EmptyBlocks() throws Exception{ } @Test(expectedExceptions = IllegalStateException.class) - public void test113BlocksLeftOpen() throws Exception{ + public void test113BlocksLeftOpen() { getPrismContext().queryFor(UserType.class) .block() .block() @@ -98,7 +80,7 @@ public void test113BlocksLeftOpen() throws Exception{ } @Test(expectedExceptions = IllegalStateException.class) - public void test114NoOpenBlocks() throws Exception{ + public void test114NoOpenBlocks() { getPrismContext().queryFor(UserType.class) .block() .block() @@ -109,28 +91,28 @@ public void test114NoOpenBlocks() throws Exception{ } @Test - public void test120All() throws Exception{ + public void test120All() { ObjectQuery actual = getPrismContext().queryFor(UserType.class).all().build(); ObjectQuery expected = ObjectQueryImpl.createObjectQuery(AllFilterImpl.createAll()); compare(actual, expected); } @Test - public void test122AllInBlock() throws Exception{ + public void test122AllInBlock() { ObjectQuery actual = getPrismContext().queryFor(UserType.class).block().all().endBlock().build(); ObjectQuery expected = ObjectQueryImpl.createObjectQuery(AllFilterImpl.createAll()); compare(actual, expected); } @Test - public void test130SingleEquals() throws Exception{ + public void test130SingleEquals() { ObjectQuery actual = getPrismContext().queryFor(UserType.class).item(UserType.F_LOCALITY).eq("Caribbean").build(); ObjectQuery expected = ObjectQueryImpl.createObjectQuery(createEqual(UserType.F_LOCALITY, UserType.class, null, "Caribbean")); compare(actual, expected); } @Test - public void test132SingleAnd() throws Exception{ + public void test132SingleAnd() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .item(UserType.F_LOCALITY).eq("Caribbean") .and().item(UserType.F_DESCRIPTION).eq("desc") @@ -145,7 +127,7 @@ public void test132SingleAnd() throws Exception{ } @Test - public void test134SingleOrWithNot() throws Exception{ + public void test134SingleOrWithNot() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .item(UserType.F_LOCALITY).eq("Caribbean") .or().not().item(UserType.F_DESCRIPTION).eq("desc") @@ -162,16 +144,16 @@ public void test134SingleOrWithNot() throws Exception{ } @Test - public void test136AndOrNotSequence() throws Exception{ + public void test136AndOrNotSequence() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .item(UserType.F_LOCALITY).eq("Caribbean") .or() - .not().item(UserType.F_DESCRIPTION).eq("desc") - .and().all() - .and().none() + .not().item(UserType.F_DESCRIPTION).eq("desc") + .and().all() + .and().none() .or() - .undefined() - .and().not().none() + .undefined() + .and().not().none() .build(); ObjectQuery expected = ObjectQueryImpl.createObjectQuery( OrFilterImpl.createOr( @@ -195,7 +177,7 @@ public void test136AndOrNotSequence() throws Exception{ } @Test - public void test140TypeWithEquals() throws Exception{ + public void test140TypeWithEquals() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .type(UserType.class) .item(UserType.F_LOCALITY).eq("Caribbean") @@ -210,7 +192,7 @@ public void test140TypeWithEquals() throws Exception{ } @Test - public void test142TypeWithEqualsInBlock() throws Exception{ + public void test142TypeWithEqualsInBlock() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .type(UserType.class) .block() @@ -227,7 +209,7 @@ public void test142TypeWithEqualsInBlock() throws Exception{ } @Test - public void test144TypeWithEqualsAndAllInBlock() throws Exception{ + public void test144TypeWithEqualsAndAllInBlock() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .type(UserType.class) .block() @@ -248,7 +230,7 @@ public void test144TypeWithEqualsAndAllInBlock() throws Exception{ } @Test - public void test144TypeInTypeInType() throws Exception{ + public void test144TypeInTypeInType() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .type(UserType.class) .type(AssignmentType.class) @@ -271,7 +253,7 @@ public void test144TypeInTypeInType() throws Exception{ } @Test - public void test146TypeAndSomething() throws Exception{ + public void test146TypeAndSomething() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .type(UserType.class) .none() @@ -290,7 +272,7 @@ public void test146TypeAndSomething() throws Exception{ } @Test - public void test148TypeEmpty() throws Exception{ + public void test148TypeEmpty() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .type(UserType.class) .block().endBlock() @@ -305,7 +287,7 @@ public void test148TypeEmpty() throws Exception{ } @Test - public void test149TypeEmptyAndAll() throws Exception{ + public void test149TypeEmptyAndAll() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .type(UserType.class) .block().endBlock() @@ -324,7 +306,7 @@ public void test149TypeEmptyAndAll() throws Exception{ } @Test - public void test150ExistsWithEquals() throws Exception{ + public void test150ExistsWithEquals() throws Exception { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .exists(UserType.F_ASSIGNMENT) .item(AssignmentType.F_DESCRIPTION).startsWith("desc1") @@ -341,12 +323,12 @@ public void test150ExistsWithEquals() throws Exception{ getPrismContext(), null, "desc1", true, false) ) - ); + ); compare(actual, expected); } @Test - public void test151ExistsWithEquals2() throws Exception{ + public void test151ExistsWithEquals2() throws Exception { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .exists(UserType.F_ASSIGNMENT) .item(AssignmentType.F_NOTE).endsWith("DONE.") @@ -368,11 +350,11 @@ public void test151ExistsWithEquals2() throws Exception{ } @Test - public void test152ExistsWithEqualsInBlock() throws Exception{ + public void test152ExistsWithEqualsInBlock() throws Exception { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .exists(UserType.F_ASSIGNMENT) .block() - .item(AssignmentType.F_NOTE).endsWith("DONE.") + .item(AssignmentType.F_NOTE).endsWith("DONE.") .endBlock() .build(); ComplexTypeDefinition assCtd = getPrismContext().getSchemaRegistry().findComplexTypeDefinitionByCompileTimeClass(AssignmentType.class); @@ -392,12 +374,12 @@ public void test152ExistsWithEqualsInBlock() throws Exception{ } @Test - public void test154ExistsWithEqualsAndAllInBlock() throws Exception{ + public void test154ExistsWithEqualsAndAllInBlock() throws Exception { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .exists(UserType.F_ASSIGNMENT) .block() .item(AssignmentType.F_NOTE).endsWith("DONE.") - .and().all() + .and().all() .endBlock() .build(); ComplexTypeDefinition assCtd = getPrismContext().getSchemaRegistry().findComplexTypeDefinitionByCompileTimeClass(AssignmentType.class); @@ -421,10 +403,10 @@ public void test154ExistsWithEqualsAndAllInBlock() throws Exception{ } @Test - public void test156ExistsAndSomething() throws Exception{ + public void test156ExistsAndSomething() throws Exception { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .exists(UserType.F_ASSIGNMENT) - .none() + .none() .and().all() .build(); @@ -444,7 +426,7 @@ public void test156ExistsAndSomething() throws Exception{ } @Test - public void test200OrderByName() throws Exception{ + public void test200OrderByName() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .asc(UserType.F_NAME) .build(); @@ -471,7 +453,7 @@ public void test210OrderByNameAndId() { } @Test - public void test300EqualItem() throws Exception { + public void test300EqualItem() { ObjectQuery actual = getPrismContext().queryFor(UserType.class) .item(UserType.F_LOCALITY).eq().item(UserType.F_NAME) .build(); @@ -489,14 +471,14 @@ public void test300EqualItem() throws Exception { } @Test - public void test310LessThanItem() throws Exception { + public void test310LessThanItem() { PrismObjectDefinition userDef = getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class); PrismPropertyDefinition nameDef = userDef.findPropertyDefinition(UserType.F_NAME); PrismPropertyDefinition localityDef = userDef.findPropertyDefinition(UserType.F_LOCALITY); ObjectQuery actual = getPrismContext().queryFor(UserType.class) .item(UserType.F_LOCALITY, localityDef) - .le() - .item(UserType.F_NAME, nameDef) + .le() + .item(UserType.F_NAME, nameDef) .build(); ObjectQuery expected = ObjectQueryImpl.createObjectQuery( LessFilterImpl.createLess(UserType.F_LOCALITY, localityDef, null, diff --git a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestQueryConverters.java b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestQueryConverters.java index b703d1e6d22..3b3e3b42dc0 100644 --- a/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestQueryConverters.java +++ b/infra/prism-impl/src/test/java/com/evolveum/midpoint/prism/query/TestQueryConverters.java @@ -7,48 +7,40 @@ package com.evolveum.midpoint.prism.query; +import static org.testng.AssertJUnit.*; + import static com.evolveum.midpoint.prism.PrismInternalTestUtil.DEFAULT_NAMESPACE_PREFIX; -import static com.evolveum.midpoint.prism.util.PrismTestUtil.createPolyString; import static com.evolveum.midpoint.prism.util.PrismTestUtil.displayQuery; import static com.evolveum.midpoint.prism.util.PrismTestUtil.getFilterCondition; -import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertNotNull; -import static org.testng.AssertJUnit.assertTrue; import java.io.File; import java.io.IOException; - import javax.xml.namespace.QName; -import com.evolveum.midpoint.prism.path.ItemPath; -import com.evolveum.midpoint.prism.xnode.MapXNode; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import org.w3c.dom.Element; import org.xml.sax.SAXException; +import com.evolveum.midpoint.prism.AbstractPrismTest; import com.evolveum.midpoint.prism.PrismConstants; import com.evolveum.midpoint.prism.PrismInternalTestUtil; import com.evolveum.midpoint.prism.foo.UserType; -import com.evolveum.midpoint.prism.util.PrismAsserts; -import com.evolveum.midpoint.prism.util.PrismTestUtil; import com.evolveum.midpoint.prism.impl.xnode.ListXNodeImpl; import com.evolveum.midpoint.prism.impl.xnode.MapXNodeImpl; -import com.evolveum.midpoint.tools.testng.AbstractUnitTest; +import com.evolveum.midpoint.prism.path.ItemPath; +import com.evolveum.midpoint.prism.util.PrismAsserts; +import com.evolveum.midpoint.prism.util.PrismTestUtil; +import com.evolveum.midpoint.prism.xnode.MapXNode; import com.evolveum.midpoint.util.DOMUtil; import com.evolveum.midpoint.util.DomAsserts; import com.evolveum.midpoint.util.PrettyPrinter; import com.evolveum.midpoint.util.exception.SchemaException; -import com.evolveum.midpoint.util.logging.Trace; -import com.evolveum.midpoint.util.logging.TraceManager; import com.evolveum.prism.xml.ns._public.query_3.QueryType; import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType; import com.evolveum.prism.xml.ns._public.types_3.PolyStringType; -public class TestQueryConverters extends AbstractUnitTest { - - private static final Trace LOGGER = TraceManager.getTrace(TestQueryConverters.class); +public class TestQueryConverters extends AbstractPrismTest { private static final File TEST_DIR = new File("src/test/resources/query"); @@ -108,12 +100,12 @@ public void testFilterUserAndJaxb() throws Exception { ObjectFilter first = getFilterCondition(filter, 0); PrismAsserts.assertEqualsFilter(first, UserType.F_GIVEN_NAME, DOMUtil.XSD_STRING, - ItemPath.create(new QName(null,UserType.F_GIVEN_NAME.getLocalPart()))); + ItemPath.create(new QName(null, UserType.F_GIVEN_NAME.getLocalPart()))); PrismAsserts.assertEqualsFilterValue((EqualFilter) first, "Jack"); ObjectFilter second = getFilterCondition(filter, 1); PrismAsserts.assertEqualsFilter(second, UserType.F_LOCALITY, DOMUtil.XSD_STRING, - ItemPath.create(new QName(null,UserType.F_LOCALITY.getLocalPart()))); + ItemPath.create(new QName(null, UserType.F_LOCALITY.getLocalPart()))); PrismAsserts.assertEqualsFilterValue((EqualFilter) second, "Caribbean"); QueryType convertedQueryType = toQueryType(query); @@ -168,13 +160,12 @@ public void testFilterTypeUserNone() throws Exception { System.out.println(convertedQueryType.debugDump()); Element filterClauseElement = convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext()); - LOGGER.info(convertedQueryType.getFilter().getFilterClauseXNode().debugDump()); - + logger.info(convertedQueryType.getFilter().getFilterClauseXNode().debugDump()); System.out.println("Serialized filter (JAXB->DOM)"); String filterAsString = DOMUtil.serializeDOMToString(filterClauseElement); System.out.println(filterAsString); - LOGGER.info(filterAsString); + logger.info(filterAsString); DomAsserts.assertElementQName(filterClauseElement, new QName(PrismConstants.NS_QUERY, "type")); } @@ -199,12 +190,12 @@ public void testFilterNotInOid() throws Exception { System.out.println(convertedQueryType.debugDump()); Element filterClauseElement = convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext()); - LOGGER.info(convertedQueryType.getFilter().getFilterClauseXNode().debugDump()); + logger.info(convertedQueryType.getFilter().getFilterClauseXNode().debugDump()); System.out.println("Serialized filter (JAXB->DOM)"); String filterAsString = DOMUtil.serializeDOMToString(filterClauseElement); System.out.println(filterAsString); - LOGGER.info(filterAsString); + logger.info(filterAsString); DomAsserts.assertElementQName(filterClauseElement, new QName(PrismConstants.NS_QUERY, "not")); assertEquals("wrong # of inOid subfilters", 1, filterClauseElement.getElementsByTagNameNS(PrismConstants.NS_QUERY, "inOid").getLength()); @@ -231,32 +222,23 @@ public void testFilterNotFullText() throws Exception { System.out.println(convertedQueryType.debugDump()); Element filterClauseElement = convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext()); - LOGGER.info(convertedQueryType.getFilter().getFilterClauseXNode().debugDump()); + logger.info(convertedQueryType.getFilter().getFilterClauseXNode().debugDump()); System.out.println("Serialized filter (JAXB->DOM)"); String filterAsString = DOMUtil.serializeDOMToString(filterClauseElement); System.out.println(filterAsString); - LOGGER.info(filterAsString); + logger.info(filterAsString); DomAsserts.assertElementQName(filterClauseElement, new QName(PrismConstants.NS_QUERY, "not")); assertEquals("wrong # of fullText subfilters", 1, filterClauseElement.getElementsByTagNameNS(PrismConstants.NS_QUERY, "fullText").getLength()); assertEquals("wrong # of value subfilters", 2, filterClauseElement.getElementsByTagNameNS(PrismConstants.NS_QUERY, "value").getLength()); } - private ObjectQuery toObjectQuery(Class type, QueryType queryType) throws Exception { - ObjectQuery query = getPrismContext().getQueryConverter().createObjectQuery(type, queryType - ); - return query; - } - private ObjectQuery toObjectQuery(Class type, SearchFilterType filterType) throws Exception { - ObjectQuery query = getPrismContext().getQueryConverter().createObjectQuery(type, filterType - ); - return query; + return getPrismContext().getQueryConverter().createObjectQuery(type, filterType); } private QueryType toQueryType(ObjectQuery query) throws Exception { return getPrismContext().getQueryConverter().createQueryType(query); } - }