Skip to content

Commit

Permalink
Prism and schema tests passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Oct 19, 2016
1 parent 89a72c5 commit c5ad8b7
Show file tree
Hide file tree
Showing 26 changed files with 250 additions and 185 deletions.
17 changes: 8 additions & 9 deletions .travis.yml
@@ -1,4 +1,4 @@
sudo: false
sudo: required
dist: trusty
language: java

Expand All @@ -15,20 +15,19 @@ before_install:
- unzip -qq apache-maven-3.3.9-bin.zip
- export M2_HOME=$PWD/apache-maven-3.3.9
- export PATH=$M2_HOME/bin:$PATH
- export MAVEN_OPTS='-Xmx2g -XX:MaxPermSize=256m'
- export MAVEN_OPTS='-Xmx2g'

# custom script is used so build and tests are done in one mvn command, separating it (as Travis does by default) leads to problem with ConnId (notably DummyResource)
script: mvn clean install

addons:
hostname: localhost # workaround for short hostname
apt:
packages:
- oracle-java8-installer # install newest JDK8
#- openjdk-8-jdk
#apt:
#packages:
#- oracle-java8-installer # install newest JDK8

jdk:
- openjdk7
- oraclejdk7
#- openjdk8
#- openjdk7
#- oraclejdk7
- oraclejdk8
- openjdk8
Expand Up @@ -158,11 +158,11 @@ private void assertRefinedSchema(ResourceType resourceType, RefinedResourceSchem
RefinedObjectClassDefinition rAccountDef = rSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String)null);

RefinedObjectClassDefinition accountDefByNullObjectclass = rSchema.findRefinedDefinitionByObjectClassQName(ShadowKindType.ACCOUNT, null);
assertTrue("findAccountDefinitionByObjectClass(null) returned wrong value", rAccountDef.equals(accountDefByNullObjectclass));
assertEquals("findAccountDefinitionByObjectClass(null) returned wrong value", rAccountDef, accountDefByNullObjectclass);

RefinedObjectClassDefinition accountDefByIcfAccountObjectclass = rSchema.findRefinedDefinitionByObjectClassQName(ShadowKindType.ACCOUNT,
new QName(resourceType.getNamespace(), SchemaTestConstants.ICF_ACCOUNT_OBJECT_CLASS_LOCAL_NAME));
assertTrue("findAccountDefinitionByObjectClass(ICF account) returned wrong value", rAccountDef.equals(accountDefByIcfAccountObjectclass));
assertEquals("findAccountDefinitionByObjectClass(ICF account) returned wrong value", rAccountDef, accountDefByIcfAccountObjectclass);

assertRObjectClassDef(rAccountDef, resourceType, sourceLayer, validationLayer);
System.out.println("Refined account definitionn:");
Expand Down Expand Up @@ -341,7 +341,7 @@ private void assertAccountShadow(PrismObject<ShadowType> accObject, PrismObject<
PrismAsserts.assertPropertyValue(accObject, ShadowType.F_INTENT, SchemaConstants.INTENT_DEFAULT);

PrismContainer<?> attributes = accObject.findOrCreateContainer(SchemaConstants.C_ATTRIBUTES);
assertEquals("Wrong type of <attributes> definition in account", ResourceAttributeContainerDefinition.class, attributes.getDefinition().getClass());
assertEquals("Wrong type of <attributes> definition in account", ResourceAttributeContainerDefinitionImpl.class, attributes.getDefinition().getClass());
ResourceAttributeContainerDefinition attrDef = (ResourceAttributeContainerDefinition)attributes.getDefinition();
assertAttributeDefs(attrDef, resourceType, null, LayerType.MODEL);

Expand Down Expand Up @@ -435,7 +435,7 @@ private void assertAttributeDefs(ResourceAttributeContainerDefinition attrsDef,
assertNotNull("Null account definition", attrsDef);
assertEquals(SchemaConstants.INTENT_DEFAULT, attrsDef.getIntent());
assertEquals("AccountObjectClass", attrsDef.getComplexTypeDefinition().getTypeName().getLocalPart());
assertEquals("Wrong objectclass in the definition of <attributes> definition in account", RefinedObjectClassDefinition.class, attrsDef.getComplexTypeDefinition().getClass());
assertEquals("Wrong objectclass in the definition of <attributes> definition in account", RefinedObjectClassDefinitionImpl.class, attrsDef.getComplexTypeDefinition().getClass());
RefinedObjectClassDefinition rAccount = (RefinedObjectClassDefinition) attrsDef.getComplexTypeDefinition();
assertRObjectClassDef(rAccount, resourceType, sourceLayer, validationLayer);
}
Expand Down
Expand Up @@ -393,6 +393,9 @@ public boolean add(V newValue) throws SchemaException {

public boolean add(V newValue, boolean checkUniqueness) throws SchemaException {
checkMutability();
if (newValue.getPrismContext() == null) {
newValue.setPrismContext(prismContext);
}
newValue.setParent(this);
if (checkUniqueness && containsEquivalentValue(newValue)) {
return false;
Expand Down
Expand Up @@ -95,4 +95,5 @@ public interface ItemDefinition<I extends Item> extends Definition {

@Override
void revive(PrismContext prismContext);

}
Expand Up @@ -61,8 +61,6 @@ public class PrismContainerValue<C extends Containerable> extends PrismValue imp
// It can be lazily evaluated based on containerable value.
private ComplexTypeDefinition complexTypeDefinition = null;

transient private PrismContext prismContext;

public PrismContainerValue() {
}

Expand All @@ -79,15 +77,10 @@ public PrismContainerValue(C containerable, PrismContext prismContext) {
this.prismContext = prismContext;
}

private void setPrismContext(PrismContext prismContext) {
this.prismContext = prismContext;
}

public PrismContainerValue(OriginType type, Objectable source, PrismContainerable container, Long id, ComplexTypeDefinition complexTypeDefinition, PrismContext prismContext) {
super(type, source, container);
super(prismContext, type, source, container);
this.id = id;
this.complexTypeDefinition = complexTypeDefinition;
this.prismContext = prismContext;
}

@Override
Expand Down Expand Up @@ -1447,4 +1440,11 @@ public Class<?> getRealClass() {
}
return resolveClass(null);
}

@SuppressWarnings("unchecked")
@Nullable
@Override
public <T> T getRealValue() {
return (T) asContainerable();
}
}
Expand Up @@ -17,17 +17,13 @@
package com.evolveum.midpoint.prism;

import com.evolveum.midpoint.prism.xnode.RootXNode;
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.util.exception.SchemaException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.Element;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
Expand All @@ -37,17 +33,18 @@
* 1. how to determine the type of data to be retrieved,
* 2. how to determine the name of the item that is to be created (in case of prism items).
*
* For most cases, this data can be determined from the input. E.g. if we are parsing a prism object that is rooted at the
* For most cases, both can be determined from the input. E.g. if we are parsing a prism object that is rooted at the
* "user" XML element, it is clear that the type is c:UserType and the name is c:user. In other cases, the algorithms
* are the following:
*
* Data type determination: We collect all the available data, i.e.
* - source data (xsi:type/@type),
* - itemDefinition,
* - itemName,
* - typeName,
* - typeClass
* and take the most specific of these.
* - explicit type specification in source data (xsi:type/@type),
* - itemDefinition provided by the caller,
* - item name in source data,
* - itemName provided by the caller,
* - typeName provided by the caller,
* - typeClass provided by the caller
* and take the most specific of these. In case of conflict we report an error.
*
* Data name determination: First name that is present takes precedence:
* 1. itemName
Expand Down Expand Up @@ -92,8 +89,8 @@ public interface PrismParser {
PrismParser yaml();

/**
* Provides a parsing context for the parser. The context contains e.g. mode of operations (set by client)
* or a list of warnings (maintained by the parser).
* Provides a parsing context for the parser. The context contains e.g. selection of strict/compat
* mode of operation (set by client) or a list of warnings (maintained by the parser).
* @param context The parsing context.
* @return Updated parser.
*/
Expand Down Expand Up @@ -123,14 +120,6 @@ public interface PrismParser {
@NotNull
PrismParser definition(ItemDefinition<?> itemDefinition);

/**
* Tells parser what name to use for parsed item. Optional.
* @param itemName Item name to use.
* @return Updated parser.
*/
@NotNull
PrismParser name(QName itemName);

/**
* Tells parser what data type to expect. Optional.
* @param typeName Data type to expect.
Expand All @@ -147,6 +136,14 @@ public interface PrismParser {
@NotNull
PrismParser type(Class<?> typeClass);

/**
* Tells parser what name to use for parsed item. Optional.
* @param itemName Item name to use.
* @return Updated parser.
*/
@NotNull
PrismParser name(QName itemName);

/**
* Parses the input as a prism object.
* @return The object.
Expand All @@ -156,26 +153,28 @@ public interface PrismParser {

/**
* Parses the input as a prism item. (Object, container, reference, value.)
* May return raw property values as part of the prism structure, if definitions are not known.
* @return The item.
*/
<IV extends PrismValue, ID extends ItemDefinition> Item<IV,ID> parseItem() throws SchemaException, IOException;

/**
* Parses the input as a prism value. (Container value, reference value, property value.)
* May return raw property values as part of the prism structure, if definitions are not known.
* @return The item.
*/
<IV extends PrismValue> IV parseItemValue() throws SchemaException, IOException;

/**
* Parses a real value - either property or container value.
* @param clazz Expected class of the data (can be Object.class when unknown).
* @return Real value - POJO, Containerable or Objectable.
* @param clazz Expected class of the data. May be null if unknown.
* @return Real value - POJO, Containerable, Objectable or Referencable.
*/
<T> T parseRealValue(Class<T> clazz) throws IOException, SchemaException;
<T> T parseRealValue(@Nullable Class<T> clazz) throws IOException, SchemaException;

/**
* Parses a real value with an unknown class.
* @return Real value - POJO, Containerable or Objectable.
* Parses a real value. The class is not supplied by the caller, so it has to be determined from the data source.
* @return Real value - POJO, Containerable, Objectable or Referencable.
*/
<T> T parseRealValue() throws IOException, SchemaException;

Expand All @@ -185,11 +184,29 @@ public interface PrismParser {
<T> JAXBElement<T> parseRealValueToJaxbElement() throws IOException, SchemaException;

/**
* Parses the input into RootXNode.
* Parses the input into RootXNode. This is a bit unusual approach, skipping the unmarshalling phase altogether.
* But it is useful at some places.
* @return RootXNode corresponding to the input.
*/
RootXNode parseToXNode() throws IOException, SchemaException;

/**
* Parses either an item, or a real value. It depends on the type declaration or item name in the source data.
* 1) If explicit type is present, it is taken into account. If it corresponds to a prism item, the input is parsed
* as a prism item. Otherwise, it is parsed as a real value (containerable or simple POJO), if possible.
* 2) If there is no type, the item name is consulted. If it corresponds to a prism item, the input is parsed
* as a prism item. Otherwise, an exception is thrown.
*
* Pre-set parameters (itemDefinition, typeName, itemName) must NOT be present.
*
* Use with utmost care. If at all possible, avoid it.
*
* @return either prism item (Item) or a real value (Object)
*/
Object parseItemOrRealValue() throws IOException, SchemaException;



// ============= other methods (convenience ones, deprecated ones etc) =============

/**
Expand All @@ -214,18 +231,4 @@ public interface PrismParser {
// <T> T parseAtomicValue(QName typeName) throws IOException, SchemaException;


/**
* Parses (almost) anything: either an item with a definition, or an atomic (i.e. property-like) value.
* Does not care for schemaless items!
*
* CAUTION: EXPERIMENTAL - Avoid using this method if at all possible.
* Its result is not well defined, namely, whether it returns Item or a value.
*
* Used for scripting and wf-related data serialization. To be replaced.
*
* @return either Item or an unmarshalled bean value
*/
@Deprecated
Object parseAnyData() throws IOException, SchemaException;

}
Expand Up @@ -66,11 +66,10 @@ public interface PrismParserNoIO extends PrismParser {
<T> T parseRealValue() throws SchemaException;
<T> JAXBElement<T> parseRealValueToJaxbElement() throws SchemaException;
RootXNode parseToXNode() throws SchemaException;
Object parseItemOrRealValue() throws SchemaException;

// auxiliary and deprecated methods
// auxiliary methods
@NotNull
List<PrismObject<? extends Objectable>> parseObjects() throws SchemaException;

@Deprecated
Object parseAnyData() throws SchemaException;
}
Expand Up @@ -18,6 +18,7 @@

import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.DisplayableValue;
import com.evolveum.midpoint.util.exception.SchemaException;

Expand All @@ -32,10 +33,27 @@ public interface PrismPropertyDefinition<T> extends ItemDefinition<PrismProperty

T defaultValue();

/**
* Returns QName of the property value type.
* <p/>
* The returned type is either XSD simple type or complex type. It may not
* be defined in the same schema (especially if it is standard XSD simple
* type).
*
* @return QName of the property value type
*
* NOTE: This is very strange property. Isn't it the same as typeName().
* It is even not used in midPoint. Marking as deprecated.
*/
@Deprecated
QName getValueType();

Boolean isIndexed();

default boolean isAnyType() {
return DOMUtil.XSD_ANYTYPE.equals(getTypeName());
}

QName getMatchingRuleQName();

@Override
Expand Down
Expand Up @@ -86,25 +86,13 @@ public Collection<? extends DisplayableValue<T>> getAllowedValues() {
public T defaultValue(){
return defaultValue;
}
/**
* Returns QName of the property value type.
* <p/>
* The returned type is either XSD simple type or complex type. It may not
* be defined in the same schema (especially if it is standard XSD simple
* type).
*
* @return QName of the property value type
*/

@Override
public QName getValueType() {
return valueType;
}

void setValueType(QName valueType) {
this.valueType = valueType;
}

/**
/**
* This is XSD annotation that specifies whether a property should
* be indexed in the storage. It can only apply to properties. It
* has following meaning:
Expand Down

0 comments on commit c5ad8b7

Please sign in to comment.