[SYNCOPE-666] Final JPA tests
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/63108c8f Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/63108c8f Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/63108c8f Branch: refs/heads/master Commit: 63108c8f89ba92c5517133545df2350971c703b5 Parents: 419fccf Author: Francesco Chicchiriccò <[email protected]> Authored: Wed May 27 11:41:00 2015 +0200 Committer: Francesco Chicchiriccò <[email protected]> Committed: Wed May 27 11:41:00 2015 +0200 ---------------------------------------------------------------------- .../persistence/jpa/entity/AbstractAttr.java | 130 ++++++++++ .../persistence/jpa/entity/AbstractDerAttr.java | 10 +- .../persistence/jpa/entity/AbstractEntity.java | 3 - .../jpa/entity/AbstractPlainAttr.java | 6 +- .../persistence/jpa/entity/AbstractVirAttr.java | 10 +- .../persistence/jpa/entity/JPAAnyTypeClass.java | 36 +-- .../jpa/entity/conf/JPACPlainAttr.java | 14 ++ .../persistence/jpa/entity/conf/JPAConf.java | 8 +- .../resources/META-INF/spring-orm-oracle.xml | 178 +++++++++----- .../resources/META-INF/spring-orm-sqlserver.xml | 178 +++++++++----- .../core/persistence/jpa/entity/AttrTest.java | 236 ------------------ .../persistence/jpa/entity/DerAttrTest.java | 35 ++- .../persistence/jpa/entity/PlainAttrTest.java | 237 +++++++++++++++++++ .../persistence/jpa/relationship/AttrTest.java | 156 ------------ .../persistence/jpa/relationship/GroupTest.java | 25 +- .../jpa/relationship/PlainAttrTest.java | 179 ++++++++++++++ .../persistence/jpa/relationship/RoleTest.java | 15 +- 17 files changed, 877 insertions(+), 579 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractAttr.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractAttr.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractAttr.java new file mode 100644 index 0000000..4f4a3ec --- /dev/null +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractAttr.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.core.persistence.jpa.entity; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import javax.persistence.Transient; +import org.apache.syncope.core.persistence.api.entity.Any; +import org.apache.syncope.core.persistence.api.entity.AnyTypeClass; +import org.apache.syncope.core.persistence.api.entity.Attr; +import org.apache.syncope.core.persistence.api.entity.DerSchema; +import org.apache.syncope.core.persistence.api.entity.PlainSchema; +import org.apache.syncope.core.persistence.api.entity.Schema; +import org.apache.syncope.core.persistence.api.entity.VirSchema; +import org.apache.syncope.core.persistence.api.entity.anyobject.AMembership; +import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject; +import org.apache.syncope.core.persistence.api.entity.group.TypeExtension; +import org.apache.syncope.core.persistence.api.entity.user.UMembership; +import org.apache.syncope.core.persistence.api.entity.user.User; + +public abstract class AbstractAttr<S extends Schema, O extends Any<?, ?, ?>> + extends AbstractEntity<Long> implements Attr<S, O> { + + private static final long serialVersionUID = -7722134717360731874L; + + @Transient + private Set<PlainSchema> allowedPlainSchemas; + + @Transient + private Set<DerSchema> allowedDerSchemas; + + @Transient + private Set<VirSchema> allowedVirSchemas; + + private void populateClasses(final Collection<? extends AnyTypeClass> anyTypeClasses) { + synchronized (this) { + if (getSchema() instanceof PlainSchema) { + if (allowedPlainSchemas == null) { + allowedPlainSchemas = new HashSet<>(); + } + for (AnyTypeClass anyTypeClass : anyTypeClasses) { + allowedPlainSchemas.addAll(anyTypeClass.getPlainSchemas()); + } + } else if (getSchema() instanceof DerSchema) { + if (allowedDerSchemas == null) { + allowedDerSchemas = new HashSet<>(); + } + for (AnyTypeClass anyTypeClass : anyTypeClasses) { + allowedDerSchemas.addAll(anyTypeClass.getDerSchemas()); + } + } else if (getSchema() instanceof VirSchema) { + if (allowedVirSchemas == null) { + allowedVirSchemas = new HashSet<>(); + } + for (AnyTypeClass anyTypeClass : anyTypeClasses) { + allowedVirSchemas.addAll(anyTypeClass.getVirSchemas()); + } + } + } + } + + @SuppressWarnings("unchecked") + private Set<S> getAllowedSchemas() { + Set<S> result = Collections.emptySet(); + + if (getSchema() instanceof PlainSchema) { + if (allowedPlainSchemas == null) { + allowedPlainSchemas = new HashSet<>(); + } + result = (Set<S>) allowedPlainSchemas; + } else if (getSchema() instanceof DerSchema) { + if (allowedDerSchemas == null) { + allowedDerSchemas = new HashSet<>(); + } + result = (Set<S>) allowedDerSchemas; + } else if (getSchema() instanceof VirSchema) { + if (allowedVirSchemas == null) { + allowedVirSchemas = new HashSet<>(); + } + result = (Set<S>) allowedVirSchemas; + } + + return result; + } + + protected void checkSchema(final S schema) { + if (schema == null || getOwner() == null) { + throw new IllegalStateException("First set owner then schema and finally add values"); + } + + populateClasses(getOwner().getType().getClasses()); + populateClasses(getOwner().getAuxClasses()); + if (getOwner() instanceof User) { + for (UMembership memb : ((User) getOwner()).getMemberships()) { + for (TypeExtension typeExtension : memb.getRightEnd().getTypeExtensions()) { + populateClasses(typeExtension.getAuxClasses()); + } + } + } + if (getOwner() instanceof AnyObject) { + for (AMembership memb : ((AnyObject) getOwner()).getMemberships()) { + for (TypeExtension typeExtension : memb.getRightEnd().getTypeExtensions()) { + populateClasses(typeExtension.getAuxClasses()); + } + } + } + + if (!getAllowedSchemas().contains(schema)) { + throw new IllegalArgumentException(schema + " not allowed for this instance"); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractDerAttr.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractDerAttr.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractDerAttr.java index 60dae3c..fba234d 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractDerAttr.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractDerAttr.java @@ -33,7 +33,8 @@ import org.apache.syncope.core.persistence.api.entity.Any; import org.apache.syncope.core.persistence.api.entity.DerSchema; @MappedSuperclass -public abstract class AbstractDerAttr<O extends Any<?, ?, ?>> extends AbstractEntity<Long> implements DerAttr<O> { +public abstract class AbstractDerAttr<O extends Any<?, ?, ?>> + extends AbstractAttr<DerSchema, O> implements DerAttr<O> { private static final long serialVersionUID = 4740924251090424771L; @@ -56,9 +57,10 @@ public abstract class AbstractDerAttr<O extends Any<?, ?, ?>> extends AbstractEn } @Override - public void setSchema(final DerSchema derSchema) { - checkType(derSchema, JPADerSchema.class); - this.schema = (JPADerSchema) derSchema; + public void setSchema(final DerSchema schema) { + checkType(schema, JPADerSchema.class); + this.schema = (JPADerSchema) schema; + checkSchema(this.schema); } /** http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractEntity.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractEntity.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractEntity.java index dfd706d..1b8ab54 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractEntity.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractEntity.java @@ -34,9 +34,6 @@ public abstract class AbstractEntity<KEY> implements Entity<KEY> { private static final long serialVersionUID = -9017214159540857901L; - /** - * Logger. - */ protected static final Logger LOG = LoggerFactory.getLogger(AbstractEntity.class); protected void checkType(final Object object, final Class<?> clazz) { http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttr.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttr.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttr.java index a93cc45..4bab427 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttr.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractPlainAttr.java @@ -37,13 +37,14 @@ import org.apache.syncope.core.persistence.jpa.validation.entity.PlainAttrCheck; @MappedSuperclass @PlainAttrCheck -public abstract class AbstractPlainAttr<O extends Any<?, ?, ?>> extends AbstractEntity<Long> implements PlainAttr<O> { +public abstract class AbstractPlainAttr<O extends Any<?, ?, ?>> + extends AbstractAttr<PlainSchema, O> implements PlainAttr<O> { private static final long serialVersionUID = -9115431608821806124L; @ManyToOne(fetch = FetchType.EAGER) @Column(name = "schema_name") - private JPAPlainSchema schema; + protected JPAPlainSchema schema; @Override public PlainSchema getSchema() { @@ -54,6 +55,7 @@ public abstract class AbstractPlainAttr<O extends Any<?, ?, ?>> extends Abstract public void setSchema(final PlainSchema schema) { checkType(schema, JPAPlainSchema.class); this.schema = (JPAPlainSchema) schema; + checkSchema(this.schema); } protected abstract boolean addForMultiValue(PlainAttrValue attrValue); http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractVirAttr.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractVirAttr.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractVirAttr.java index 1ed64f3..946b09b 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractVirAttr.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/AbstractVirAttr.java @@ -33,7 +33,8 @@ import org.apache.syncope.core.persistence.api.entity.VirAttr; import org.apache.syncope.core.persistence.api.entity.VirSchema; @MappedSuperclass -public abstract class AbstractVirAttr<O extends Any<?, ?, ?>> extends AbstractEntity<Long> implements VirAttr<O> { +public abstract class AbstractVirAttr<O extends Any<?, ?, ?>> + extends AbstractAttr<VirSchema, O> implements VirAttr<O> { private static final long serialVersionUID = 5023204776925954907L; @@ -74,8 +75,9 @@ public abstract class AbstractVirAttr<O extends Any<?, ?, ?>> extends AbstractEn } @Override - public void setSchema(final VirSchema virSchema) { - checkType(virSchema, JPAVirSchema.class); - this.schema = (JPAVirSchema) virSchema; + public void setSchema(final VirSchema schema) { + checkType(schema, JPAVirSchema.class); + this.schema = (JPAVirSchema) schema; + checkSchema(this.schema); } } http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyTypeClass.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyTypeClass.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyTypeClass.java index e4f0db9..6fba644 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyTypeClass.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyTypeClass.java @@ -63,15 +63,15 @@ public class JPAAnyTypeClass extends AbstractEntity<String> implements AnyTypeCl } @Override - public boolean add(final PlainSchema facet) { - checkType(facet, JPAPlainSchema.class); - return this.plainSchemas.add((JPAPlainSchema) facet); + public boolean add(final PlainSchema schema) { + checkType(schema, JPAPlainSchema.class); + return this.plainSchemas.add((JPAPlainSchema) schema); } @Override - public boolean remove(final PlainSchema facet) { - checkType(facet, JPAPlainSchema.class); - return this.plainSchemas.remove((JPAPlainSchema) facet); + public boolean remove(final PlainSchema schema) { + checkType(schema, JPAPlainSchema.class); + return this.plainSchemas.remove((JPAPlainSchema) schema); } @Override @@ -80,15 +80,15 @@ public class JPAAnyTypeClass extends AbstractEntity<String> implements AnyTypeCl } @Override - public boolean add(final DerSchema facet) { - checkType(facet, JPADerSchema.class); - return this.derSchemas.add((JPADerSchema) facet); + public boolean add(final DerSchema schema) { + checkType(schema, JPADerSchema.class); + return this.derSchemas.add((JPADerSchema) schema); } @Override - public boolean remove(final DerSchema facet) { - checkType(facet, JPADerSchema.class); - return this.derSchemas.remove((JPADerSchema) facet); + public boolean remove(final DerSchema schema) { + checkType(schema, JPADerSchema.class); + return this.derSchemas.remove((JPADerSchema) schema); } @Override @@ -97,15 +97,15 @@ public class JPAAnyTypeClass extends AbstractEntity<String> implements AnyTypeCl } @Override - public boolean add(final VirSchema facet) { - checkType(facet, JPAVirSchema.class); - return this.virSchemas.add((JPAVirSchema) facet); + public boolean add(final VirSchema schema) { + checkType(schema, JPAVirSchema.class); + return this.virSchemas.add((JPAVirSchema) schema); } @Override - public boolean remove(final VirSchema facet) { - checkType(facet, JPAVirSchema.class); - return this.virSchemas.remove((JPAVirSchema) facet); + public boolean remove(final VirSchema schema) { + checkType(schema, JPAVirSchema.class); + return this.virSchemas.remove((JPAVirSchema) schema); } @Override http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPACPlainAttr.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPACPlainAttr.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPACPlainAttr.java index 6fd6c1e..b6b683b 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPACPlainAttr.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPACPlainAttr.java @@ -31,11 +31,13 @@ import javax.persistence.Table; import javax.validation.Valid; import org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue; import org.apache.syncope.core.persistence.api.entity.PlainAttrValue; +import org.apache.syncope.core.persistence.api.entity.PlainSchema; import org.apache.syncope.core.persistence.api.entity.conf.CPlainAttr; import org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrUniqueValue; import org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrValue; import org.apache.syncope.core.persistence.api.entity.conf.Conf; import org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttr; +import org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema; /** * Configuration attribute. @@ -90,6 +92,18 @@ public class JPACPlainAttr extends AbstractPlainAttr<Conf> implements CPlainAttr this.owner = (JPAConf) owner; } + /** + * Explicitly overrides default schema check (used for users, groups and any objects) since Conf does not own any + * type reference. + * + * @param schema schema for this attribute + */ + @Override + public void setSchema(final PlainSchema schema) { + checkType(schema, JPAPlainSchema.class); + this.schema = (JPAPlainSchema) schema; + } + @Override protected boolean addForMultiValue(final PlainAttrValue attrValue) { checkType(attrValue, JPACPlainAttrValue.class); http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPAConf.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPAConf.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPAConf.java index be3fa19..3253f66 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPAConf.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/conf/JPAConf.java @@ -54,13 +54,7 @@ public class JPAConf extends AbstractAnnotatedEntity<Long> implements Conf { @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") @Valid - private List<JPACPlainAttr> plainAttrs; - - public JPAConf() { - super(); - - plainAttrs = new ArrayList<>(); - } + private List<JPACPlainAttr> plainAttrs = new ArrayList<>(); @Override public Long getKey() { http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/main/resources/META-INF/spring-orm-oracle.xml ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/resources/META-INF/spring-orm-oracle.xml b/core/persistence-jpa/src/main/resources/META-INF/spring-orm-oracle.xml index 8c58d33..c592c31 100644 --- a/core/persistence-jpa/src/main/resources/META-INF/spring-orm-oracle.xml +++ b/core/persistence-jpa/src/main/resources/META-INF/spring-orm-oracle.xml @@ -36,8 +36,8 @@ under the License. <table-generator name="SEQ_UPlainAttrValue" pk-column-value="SEQ_UPlainAttrValue" initial-value="100"/> <table-generator name="SEQ_GPlainAttrValue" pk-column-value="SEQ_GPlainAttrValue" initial-value="100"/> - <table-generator name="SEQ_MAttrPlainValue" pk-column-value="SEQ_MAttrPlainValue" initial-value="100"/> - <table-generator name="SEQ_CAttrPlainValue" pk-column-value="SEQ_CAttrPlainValue" initial-value="100"/> + <table-generator name="SEQ_APlainAttrValue" pk-column-value="SEQ_APlainAttrValue" initial-value="100"/> + <table-generator name="SEQ_CPlainAttrValue" pk-column-value="SEQ_CPlainAttrValue" initial-value="100"/> <entity class="org.apache.syncope.core.persistence.jpa.entity.JPARealm"> <attributes> @@ -48,6 +48,33 @@ under the License. </attributes> </entity> + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_AnyObject" strategy="TABLE"/> + <table-generator name="SEQ_AnyObject" pk-column-value="SEQ_AnyObject" initial-value="100"/> + </id> + </attributes> + </entity> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAARelationship"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_ARelationship" strategy="TABLE"/> + <table-generator name="SEQ_ARelationship" pk-column-value="SEQ_ARelationship" initial-value="100"/> + </id> + </attributes> + </entity> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAMembership"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_AMembership" strategy="TABLE"/> + <table-generator name="SEQ_AMembership" pk-column-value="SEQ_AMembership" initial-value="100"/> + </id> + </attributes> + </entity> + <entity class="org.apache.syncope.core.persistence.jpa.entity.JPARole"> <attributes> <id name="id"> @@ -56,8 +83,8 @@ under the License. </id> </attributes> </entity> - - <entity class="org.apache.syncope.core.persistence.jpa.entity.JPADynRoleMembership"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPADynRoleMembership"> <attributes> <id name="id"> <generated-value generator="SEQ_DynRoleMembership" strategy="TABLE"/> @@ -74,63 +101,74 @@ under the License. </id> </attributes> </entity> - - <entity class="org.apache.syncope.core.persistence.jpa.entity.group.JPAGroup"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAURelationship"> <attributes> <id name="id"> - <generated-value generator="SEQ_Group" strategy="TABLE"/> - <table-generator name="SEQ_Group" pk-column-value="SEQ_Group" initial-value="100"/> + <generated-value generator="SEQ_URelationship" strategy="TABLE"/> + <table-generator name="SEQ_URelationship" pk-column-value="SEQ_URelationship" initial-value="100"/> </id> </attributes> </entity> - - <entity class="org.apache.syncope.core.persistence.jpa.entity.JPADynGroupMembership"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUMembership"> <attributes> <id name="id"> - <generated-value generator="SEQ_DynGroupMembership" strategy="TABLE"/> - <table-generator name="SEQ_DynGroupMembership" pk-column-value="SEQ_DynGroupMembership" initial-value="100"/> + <generated-value generator="SEQ_UMembership" strategy="TABLE"/> + <table-generator name="SEQ_UMembership" pk-column-value="SEQ_UMembership" initial-value="100"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.membership.JPAMembership"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.group.JPAGroup"> <attributes> <id name="id"> - <generated-value generator="SEQ_Membership" strategy="TABLE"/> - <table-generator name="SEQ_Membership" pk-column-value="SEQ_Membership" initial-value="100"/> + <generated-value generator="SEQ_Group" strategy="TABLE"/> + <table-generator name="SEQ_Group" pk-column-value="SEQ_Group" initial-value="100"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUMapping"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAADynGroupMembership"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_ADynGroupMembership" strategy="TABLE"/> + <table-generator name="SEQ_ADynGroupMembership" pk-column-value="SEQ_ADynGroupMembership" initial-value="100"/> + </id> + </attributes> + </entity> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUDynGroupMembership"> <attributes> <id name="id"> - <generated-value generator="SEQ_UMapping" strategy="TABLE"/> - <table-generator name="SEQ_UMapping" pk-column-value="SEQ_UMapping" initial-value="100"/> + <generated-value generator="SEQ_UDynGroupMembership" strategy="TABLE"/> + <table-generator name="SEQ_UDynGroupMembership" pk-column-value="SEQ_UDynGroupMembership" initial-value="100"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.group.JPAGMapping"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.resource.JPAProvision"> <attributes> <id name="id"> - <generated-value generator="SEQ_GMapping" strategy="TABLE"/> - <table-generator name="SEQ_GMapping" pk-column-value="SEQ_GMapping" initial-value="100"/> + <generated-value generator="SEQ_Provision" strategy="TABLE"/> + <table-generator name="SEQ_Provision" pk-column-value="SEQ_Provision" initial-value="100"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUMappingItem"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.resource.JPAMapping"> <attributes> <id name="id"> - <generated-value generator="SEQ_UMappingItem" strategy="TABLE"/> - <table-generator name="SEQ_UMappingItem" pk-column-value="SEQ_UMappingItem" initial-value="1000"/> + <generated-value generator="SEQ_Mapping" strategy="TABLE"/> + <table-generator name="SEQ_Mapping" pk-column-value="SEQ_Mapping" initial-value="100"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.group.JPAGMappingItem"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.resource.JPAMappingItem"> <attributes> <id name="id"> - <generated-value generator="SEQ_GMappingItem" strategy="TABLE"/> - <table-generator name="SEQ_GMappingItem" pk-column-value="SEQ_GMappingItem" initial-value="1000"/> + <generated-value generator="SEQ_MappingItem" strategy="TABLE"/> + <table-generator name="SEQ_MappingItem" pk-column-value="SEQ_MappingItem" initial-value="1000"/> </id> </attributes> </entity> @@ -144,6 +182,14 @@ under the License. </attributes> </entity> + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAPlainAttr"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_APlainAttr" strategy="TABLE"/> + <table-generator name="SEQ_APlainAttr" pk-column-value="SEQ_APlainAttr" initial-value="1000"/> + </id> + </attributes> + </entity> <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUPlainAttr"> <attributes> <id name="id"> @@ -160,39 +206,39 @@ under the License. </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.group.JPAGPlainAttrTemplate"> - <attributes> - <id name="id"> - <generated-value generator="SEQ_GPlainAttrTemplate" strategy="TABLE"/> - <table-generator name="SEQ_GPlainAttrTemplate" pk-column-value="SEQ_GPlainAttrTemplate" initial-value="1000"/> - </id> - </attributes> - </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.membership.JPAMPlainAttr"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttr"> <attributes> <id name="id"> - <generated-value generator="SEQ_MPlainAttr" strategy="TABLE"/> - <table-generator name="SEQ_MPlainAttr" pk-column-value="SEQ_MPlainAttr" initial-value="1000"/> + <generated-value generator="SEQ_CAttrPlain" strategy="TABLE"/> + <table-generator name="SEQ_CAttrPlain" pk-column-value="SEQ_CAttrPlain" initial-value="1000"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.membership.JPAMPlainAttrTemplate"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAPlainAttrValue"> <attributes> <id name="id"> - <generated-value generator="SEQ_MPlainAttrTemplate" strategy="TABLE"/> - <table-generator name="SEQ_MPlainAttrTemplate" pk-column-value="SEQ_MPlainAttrTemplate" initial-value="1000"/> + <generated-value generator="SEQ_APlainAttrValue" strategy="TABLE"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttr"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAPlainAttrUniqueValue"> + <table> + <unique-constraint> + <column-name>booleanValue</column-name> + <column-name>dateValue</column-name> + <column-name>stringValue</column-name> + <column-name>doubleValue</column-name> + <column-name>longValue</column-name> + <column-name>schema_name</column-name> + </unique-constraint> + </table> <attributes> <id name="id"> - <generated-value generator="SEQ_CAttrPlain" strategy="TABLE"/> - <table-generator name="SEQ_CAttrPlain" pk-column-value="SEQ_CAttrPlain" initial-value="1000"/> + <generated-value generator="SEQ_APlainAttrValue" strategy="TABLE"/> </id> </attributes> - </entity> - + </entity> <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUPlainAttrValue"> <attributes> <id name="id"> @@ -241,14 +287,14 @@ under the License. </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.membership.JPAMPlainAttrValue"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttrValue"> <attributes> <id name="id"> - <generated-value generator="SEQ_MAttrPlainValue" strategy="TABLE"/> + <generated-value generator="SEQ_CPlainAttrValue" strategy="TABLE"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.membership.JPAMPlainAttrUniqueValue"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttrUniqueValue"> <table> <unique-constraint> <column-name>booleanValue</column-name> @@ -261,31 +307,25 @@ under the License. </table> <attributes> <id name="id"> - <generated-value generator="SEQ_MAttrPlainValue" strategy="TABLE"/> + <generated-value generator="SEQ_CPlainAttrValue" strategy="TABLE"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttrValue"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.task.JPAAnyTemplate"> <attributes> <id name="id"> - <generated-value generator="SEQ_CAttrPlainValue" strategy="TABLE"/> + <generated-value generator="SEQ_AnyTemplate" strategy="TABLE"/> + <table-generator name="SEQ_AnyTemplate" pk-column-value="SEQ_AnyTemplate" initial-value="1000"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttrUniqueValue"> - <table> - <unique-constraint> - <column-name>booleanValue</column-name> - <column-name>dateValue</column-name> - <column-name>stringValue</column-name> - <column-name>doubleValue</column-name> - <column-name>longValue</column-name> - <column-name>schema_name</column-name> - </unique-constraint> - </table> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.task.JPAAnyFilter"> <attributes> <id name="id"> - <generated-value generator="SEQ_CAttrPlainValue" strategy="TABLE"/> + <generated-value generator="SEQ_AnyFilter" strategy="TABLE"/> + <table-generator name="SEQ_AnyFilter" pk-column-value="SEQ_AnyFilter" initial-value="1000"/> </id> </attributes> </entity> @@ -340,6 +380,15 @@ under the License. </id> </attributes> </entity> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.JPAAnyAbout"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_AnyAbout" strategy="TABLE"/> + <table-generator name="SEQ_AnyAbout" pk-column-value="SEQ_AnyAbout" initial-value="100"/> + </id> + </attributes> + </entity> <entity class="org.apache.syncope.core.persistence.jpa.entity.JPANotification"> <attributes> <id name="id"> @@ -348,6 +397,7 @@ under the License. </id> </attributes> </entity> + <entity class="org.apache.syncope.core.persistence.jpa.entity.JPASecurityQuestion"> <attributes> <id name="id"> http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/main/resources/META-INF/spring-orm-sqlserver.xml ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/resources/META-INF/spring-orm-sqlserver.xml b/core/persistence-jpa/src/main/resources/META-INF/spring-orm-sqlserver.xml index bd7f664..c592c31 100644 --- a/core/persistence-jpa/src/main/resources/META-INF/spring-orm-sqlserver.xml +++ b/core/persistence-jpa/src/main/resources/META-INF/spring-orm-sqlserver.xml @@ -36,8 +36,8 @@ under the License. <table-generator name="SEQ_UPlainAttrValue" pk-column-value="SEQ_UPlainAttrValue" initial-value="100"/> <table-generator name="SEQ_GPlainAttrValue" pk-column-value="SEQ_GPlainAttrValue" initial-value="100"/> - <table-generator name="SEQ_MAttrPlainValue" pk-column-value="SEQ_MAttrPlainValue" initial-value="100"/> - <table-generator name="SEQ_CAttrPlainValue" pk-column-value="SEQ_CAttrPlainValue" initial-value="100"/> + <table-generator name="SEQ_APlainAttrValue" pk-column-value="SEQ_APlainAttrValue" initial-value="100"/> + <table-generator name="SEQ_CPlainAttrValue" pk-column-value="SEQ_CPlainAttrValue" initial-value="100"/> <entity class="org.apache.syncope.core.persistence.jpa.entity.JPARealm"> <attributes> @@ -48,6 +48,33 @@ under the License. </attributes> </entity> + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_AnyObject" strategy="TABLE"/> + <table-generator name="SEQ_AnyObject" pk-column-value="SEQ_AnyObject" initial-value="100"/> + </id> + </attributes> + </entity> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAARelationship"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_ARelationship" strategy="TABLE"/> + <table-generator name="SEQ_ARelationship" pk-column-value="SEQ_ARelationship" initial-value="100"/> + </id> + </attributes> + </entity> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAMembership"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_AMembership" strategy="TABLE"/> + <table-generator name="SEQ_AMembership" pk-column-value="SEQ_AMembership" initial-value="100"/> + </id> + </attributes> + </entity> + <entity class="org.apache.syncope.core.persistence.jpa.entity.JPARole"> <attributes> <id name="id"> @@ -57,7 +84,7 @@ under the License. </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.JPADynRoleMembership"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPADynRoleMembership"> <attributes> <id name="id"> <generated-value generator="SEQ_DynRoleMembership" strategy="TABLE"/> @@ -65,7 +92,7 @@ under the License. </id> </attributes> </entity> - + <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUser"> <attributes> <id name="id"> @@ -74,63 +101,74 @@ under the License. </id> </attributes> </entity> - - <entity class="org.apache.syncope.core.persistence.jpa.entity.group.JPAGroup"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAURelationship"> <attributes> <id name="id"> - <generated-value generator="SEQ_Group" strategy="TABLE"/> - <table-generator name="SEQ_Group" pk-column-value="SEQ_Group" initial-value="100"/> + <generated-value generator="SEQ_URelationship" strategy="TABLE"/> + <table-generator name="SEQ_URelationship" pk-column-value="SEQ_URelationship" initial-value="100"/> </id> </attributes> </entity> - - <entity class="org.apache.syncope.core.persistence.jpa.entity.JPADynGroupMembership"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUMembership"> <attributes> <id name="id"> - <generated-value generator="SEQ_DynGroupMembership" strategy="TABLE"/> - <table-generator name="SEQ_DynGroupMembership" pk-column-value="SEQ_DynGroupMembership" initial-value="100"/> + <generated-value generator="SEQ_UMembership" strategy="TABLE"/> + <table-generator name="SEQ_UMembership" pk-column-value="SEQ_UMembership" initial-value="100"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.membership.JPAMembership"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.group.JPAGroup"> <attributes> <id name="id"> - <generated-value generator="SEQ_Membership" strategy="TABLE"/> - <table-generator name="SEQ_Membership" pk-column-value="SEQ_Membership" initial-value="100"/> + <generated-value generator="SEQ_Group" strategy="TABLE"/> + <table-generator name="SEQ_Group" pk-column-value="SEQ_Group" initial-value="100"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUMapping"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAADynGroupMembership"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_ADynGroupMembership" strategy="TABLE"/> + <table-generator name="SEQ_ADynGroupMembership" pk-column-value="SEQ_ADynGroupMembership" initial-value="100"/> + </id> + </attributes> + </entity> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUDynGroupMembership"> <attributes> <id name="id"> - <generated-value generator="SEQ_UMapping" strategy="TABLE"/> - <table-generator name="SEQ_UMapping" pk-column-value="SEQ_UMapping" initial-value="100"/> + <generated-value generator="SEQ_UDynGroupMembership" strategy="TABLE"/> + <table-generator name="SEQ_UDynGroupMembership" pk-column-value="SEQ_UDynGroupMembership" initial-value="100"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.group.JPAGMapping"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.resource.JPAProvision"> <attributes> <id name="id"> - <generated-value generator="SEQ_GMapping" strategy="TABLE"/> - <table-generator name="SEQ_GMapping" pk-column-value="SEQ_GMapping" initial-value="100"/> + <generated-value generator="SEQ_Provision" strategy="TABLE"/> + <table-generator name="SEQ_Provision" pk-column-value="SEQ_Provision" initial-value="100"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUMappingItem"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.resource.JPAMapping"> <attributes> <id name="id"> - <generated-value generator="SEQ_UMappingItem" strategy="TABLE"/> - <table-generator name="SEQ_UMappingItem" pk-column-value="SEQ_UMappingItem" initial-value="1000"/> + <generated-value generator="SEQ_Mapping" strategy="TABLE"/> + <table-generator name="SEQ_Mapping" pk-column-value="SEQ_Mapping" initial-value="100"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.group.JPAGMappingItem"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.resource.JPAMappingItem"> <attributes> <id name="id"> - <generated-value generator="SEQ_GMappingItem" strategy="TABLE"/> - <table-generator name="SEQ_GMappingItem" pk-column-value="SEQ_GMappingItem" initial-value="1000"/> + <generated-value generator="SEQ_MappingItem" strategy="TABLE"/> + <table-generator name="SEQ_MappingItem" pk-column-value="SEQ_MappingItem" initial-value="1000"/> </id> </attributes> </entity> @@ -144,6 +182,14 @@ under the License. </attributes> </entity> + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAPlainAttr"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_APlainAttr" strategy="TABLE"/> + <table-generator name="SEQ_APlainAttr" pk-column-value="SEQ_APlainAttr" initial-value="1000"/> + </id> + </attributes> + </entity> <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUPlainAttr"> <attributes> <id name="id"> @@ -160,39 +206,39 @@ under the License. </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.group.JPAGPlainAttrTemplate"> - <attributes> - <id name="id"> - <generated-value generator="SEQ_GPlainAttrTemplate" strategy="TABLE"/> - <table-generator name="SEQ_GPlainAttrTemplate" pk-column-value="SEQ_GPlainAttrTemplate" initial-value="1000"/> - </id> - </attributes> - </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.membership.JPAMPlainAttr"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttr"> <attributes> <id name="id"> - <generated-value generator="SEQ_MPlainAttr" strategy="TABLE"/> - <table-generator name="SEQ_MPlainAttr" pk-column-value="SEQ_MPlainAttr" initial-value="1000"/> + <generated-value generator="SEQ_CAttrPlain" strategy="TABLE"/> + <table-generator name="SEQ_CAttrPlain" pk-column-value="SEQ_CAttrPlain" initial-value="1000"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.membership.JPAMPlainAttrTemplate"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAPlainAttrValue"> <attributes> <id name="id"> - <generated-value generator="SEQ_MPlainAttrTemplate" strategy="TABLE"/> - <table-generator name="SEQ_MPlainAttrTemplate" pk-column-value="SEQ_MPlainAttrTemplate" initial-value="1000"/> + <generated-value generator="SEQ_APlainAttrValue" strategy="TABLE"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttr"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAPlainAttrUniqueValue"> + <table> + <unique-constraint> + <column-name>booleanValue</column-name> + <column-name>dateValue</column-name> + <column-name>stringValue</column-name> + <column-name>doubleValue</column-name> + <column-name>longValue</column-name> + <column-name>schema_name</column-name> + </unique-constraint> + </table> <attributes> <id name="id"> - <generated-value generator="SEQ_CAttrPlain" strategy="TABLE"/> - <table-generator name="SEQ_CAttrPlain" pk-column-value="SEQ_CAttrPlain" initial-value="1000"/> + <generated-value generator="SEQ_APlainAttrValue" strategy="TABLE"/> </id> </attributes> - </entity> - + </entity> <entity class="org.apache.syncope.core.persistence.jpa.entity.user.JPAUPlainAttrValue"> <attributes> <id name="id"> @@ -241,14 +287,14 @@ under the License. </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.membership.JPAMPlainAttrValue"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttrValue"> <attributes> <id name="id"> - <generated-value generator="SEQ_MAttrPlainValue" strategy="TABLE"/> + <generated-value generator="SEQ_CPlainAttrValue" strategy="TABLE"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.membership.JPAMPlainAttrUniqueValue"> + <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttrUniqueValue"> <table> <unique-constraint> <column-name>booleanValue</column-name> @@ -261,31 +307,25 @@ under the License. </table> <attributes> <id name="id"> - <generated-value generator="SEQ_MAttrPlainValue" strategy="TABLE"/> + <generated-value generator="SEQ_CPlainAttrValue" strategy="TABLE"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttrValue"> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.task.JPAAnyTemplate"> <attributes> <id name="id"> - <generated-value generator="SEQ_CAttrPlainValue" strategy="TABLE"/> + <generated-value generator="SEQ_AnyTemplate" strategy="TABLE"/> + <table-generator name="SEQ_AnyTemplate" pk-column-value="SEQ_AnyTemplate" initial-value="1000"/> </id> </attributes> </entity> - <entity class="org.apache.syncope.core.persistence.jpa.entity.conf.JPACPlainAttrUniqueValue"> - <table> - <unique-constraint> - <column-name>booleanValue</column-name> - <column-name>dateValue</column-name> - <column-name>stringValue</column-name> - <column-name>doubleValue</column-name> - <column-name>longValue</column-name> - <column-name>schema_name</column-name> - </unique-constraint> - </table> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.task.JPAAnyFilter"> <attributes> <id name="id"> - <generated-value generator="SEQ_CAttrPlainValue" strategy="TABLE"/> + <generated-value generator="SEQ_AnyFilter" strategy="TABLE"/> + <table-generator name="SEQ_AnyFilter" pk-column-value="SEQ_AnyFilter" initial-value="1000"/> </id> </attributes> </entity> @@ -340,6 +380,15 @@ under the License. </id> </attributes> </entity> + + <entity class="org.apache.syncope.core.persistence.jpa.entity.JPAAnyAbout"> + <attributes> + <id name="id"> + <generated-value generator="SEQ_AnyAbout" strategy="TABLE"/> + <table-generator name="SEQ_AnyAbout" pk-column-value="SEQ_AnyAbout" initial-value="100"/> + </id> + </attributes> + </entity> <entity class="org.apache.syncope.core.persistence.jpa.entity.JPANotification"> <attributes> <id name="id"> @@ -348,6 +397,7 @@ under the License. </id> </attributes> </entity> + <entity class="org.apache.syncope.core.persistence.jpa.entity.JPASecurityQuestion"> <attributes> <id name="id"> http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttrTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttrTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttrTest.java deleted file mode 100644 index a0d12a6..0000000 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AttrTest.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.persistence.jpa.entity; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.UnsupportedEncodingException; -import java.util.Arrays; -import java.util.Random; -import javax.validation.ValidationException; -import org.apache.syncope.common.lib.SyncopeConstants; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.common.lib.types.EntityViolationType; -import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException; -import org.apache.syncope.core.persistence.api.dao.PlainAttrDAO; -import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO; -import org.apache.syncope.core.persistence.api.dao.UserDAO; -import org.apache.syncope.core.persistence.api.entity.user.UPlainAttr; -import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrUniqueValue; -import org.apache.syncope.core.persistence.api.entity.user.User; -import org.apache.syncope.core.persistence.jpa.AbstractTest; -import org.apache.syncope.core.misc.security.Encryptor; -import org.apache.syncope.core.persistence.api.entity.PlainSchema; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.crypto.codec.Base64; -import org.springframework.transaction.annotation.Transactional; - -@Transactional -public class AttrTest extends AbstractTest { - - @Autowired - private UserDAO userDAO; - - @Autowired - private PlainAttrDAO plainAttrDAO; - - @Autowired - private PlainSchemaDAO plainSchemaDAO; - - @Test - public void findById() { - UPlainAttr attribute = plainAttrDAO.find(100L, UPlainAttr.class); - assertNotNull("did not find expected attribute schema", attribute); - attribute = plainAttrDAO.find(104L, UPlainAttr.class); - assertNotNull("did not find expected attribute schema", attribute); - } - - @Test - public void read() { - UPlainAttr attribute = plainAttrDAO.find(100L, UPlainAttr.class); - assertNotNull(attribute); - assertTrue(attribute.getValues().isEmpty()); - assertNotNull(attribute.getUniqueValue()); - } - - @Test - public void save() throws ClassNotFoundException { - User user = userDAO.find(1L); - - PlainSchema emailSchema = plainSchemaDAO.find("email"); - assertNotNull(emailSchema); - - UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class); - attribute.setSchema(emailSchema); - attribute.setOwner(user); - - Exception thrown = null; - try { - attribute.add("[email protected]", anyUtilsFactory.getInstance(AnyTypeKind.USER)); - attribute.add("[email protected]", anyUtilsFactory.getInstance(AnyTypeKind.USER)); - } catch (ValidationException e) { - thrown = e; - } - assertNull("no validation exception expected here ", thrown); - - try { - attribute.add("http://www.apache.org", anyUtilsFactory.getInstance(AnyTypeKind.USER)); - } catch (ValidationException e) { - thrown = e; - } - assertNotNull("validation exception expected here ", thrown); - } - - @Test - public void saveWithEnum() throws ClassNotFoundException { - User user = userDAO.find(1L); - assertNotNull(user); - - PlainSchema gender = plainSchemaDAO.find("gender"); - assertNotNull(gender); - assertNotNull(gender.getType()); - assertNotNull(gender.getEnumerationValues()); - - UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class); - attribute.setSchema(gender); - attribute.setOwner(user); - user.add(attribute); - - Exception thrown = null; - - try { - attribute.add("A", anyUtilsFactory.getInstance(AnyTypeKind.USER)); - } catch (ValidationException e) { - thrown = e; - } - assertNotNull("validation exception expected here ", thrown); - - attribute.add("M", anyUtilsFactory.getInstance(AnyTypeKind.USER)); - - InvalidEntityException iee = null; - try { - userDAO.save(user); - } catch (InvalidEntityException e) { - iee = e; - } - assertNull(iee); - } - - @Test - public void validateAndSave() { - User user = userDAO.find(1L); - - PlainSchema emailSchema = plainSchemaDAO.find("email"); - assertNotNull(emailSchema); - - PlainSchema fullnameSchema = plainSchemaDAO.find("fullname"); - assertNotNull(fullnameSchema); - - UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class); - attribute.setSchema(emailSchema); - - UPlainAttrUniqueValue uauv = entityFactory.newEntity(UPlainAttrUniqueValue.class); - uauv.setAttr(attribute); - uauv.setSchema(fullnameSchema); - uauv.setStringValue("a value"); - - attribute.setUniqueValue(uauv); - - user.add(attribute); - - InvalidEntityException iee = null; - try { - userDAO.save(user); - fail(); - } catch (InvalidEntityException e) { - iee = e; - } - assertNotNull(iee); - // for attribute - assertTrue(iee.hasViolation(EntityViolationType.InvalidValueList)); - // for uauv - assertTrue(iee.hasViolation(EntityViolationType.InvalidPlainSchema)); - } - - @Test - public void saveWithEncrypted() throws Exception { - User user = userDAO.find(1L); - - PlainSchema obscureSchema = plainSchemaDAO.find("obscure"); - assertNotNull(obscureSchema); - assertNotNull(obscureSchema.getSecretKey()); - assertNotNull(obscureSchema.getCipherAlgorithm()); - - UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class); - attribute.setSchema(obscureSchema); - attribute.add("testvalue", anyUtilsFactory.getInstance(AnyTypeKind.USER)); - attribute.setOwner(user); - user.add(attribute); - - userDAO.save(user); - - UPlainAttr obscure = user.getPlainAttr("obscure"); - assertNotNull(obscure); - assertEquals(1, obscure.getValues().size()); - assertEquals(Encryptor.getInstance(obscureSchema.getSecretKey()). - encode("testvalue", obscureSchema.getCipherAlgorithm()), obscure.getValues().get(0).getStringValue()); - } - - @Test - public void saveWithBinary() throws UnsupportedEncodingException { - User user = userDAO.find(1L); - - PlainSchema photoSchema = plainSchemaDAO.find("photo"); - assertNotNull(photoSchema); - assertNotNull(photoSchema.getMimeType()); - - final byte[] bytes = new byte[20]; - new Random().nextBytes(bytes); - final String photoB64Value = new String(Base64.encode(bytes), SyncopeConstants.DEFAULT_ENCODING); - - UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class); - attribute.setSchema(photoSchema); - attribute.add(photoB64Value, anyUtilsFactory.getInstance(AnyTypeKind.USER)); - attribute.setOwner(user); - user.add(attribute); - - userDAO.save(user); - - UPlainAttr obscure = user.getPlainAttr("photo"); - assertNotNull(obscure); - assertEquals(1, obscure.getValues().size()); - assertTrue(Arrays.equals(bytes, obscure.getValues().get(0).getBinaryValue())); - } - - @Test - public void delete() { - UPlainAttr attribute = plainAttrDAO.find(104L, UPlainAttr.class); - String attrSchemaName = attribute.getSchema().getKey(); - - plainAttrDAO.delete(attribute.getKey(), UPlainAttr.class); - - PlainSchema schema = plainSchemaDAO.find(attrSchemaName); - assertNotNull("user attribute schema deleted when deleting values", schema); - } -} http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerAttrTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerAttrTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerAttrTest.java index 11381e5..f64e314 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerAttrTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/DerAttrTest.java @@ -25,10 +25,12 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.util.List; +import org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO; import org.apache.syncope.core.persistence.api.dao.DerAttrDAO; import org.apache.syncope.core.persistence.api.dao.DerSchemaDAO; import org.apache.syncope.core.persistence.api.dao.GroupDAO; import org.apache.syncope.core.persistence.api.dao.UserDAO; +import org.apache.syncope.core.persistence.api.entity.AnyTypeClass; import org.apache.syncope.core.persistence.api.entity.DerSchema; import org.apache.syncope.core.persistence.api.entity.group.GDerAttr; import org.apache.syncope.core.persistence.api.entity.group.GPlainAttrValue; @@ -56,6 +58,9 @@ public class DerAttrTest extends AbstractTest { @Autowired private DerSchemaDAO derSchemaDAO; + @Autowired + private AnyTypeClassDAO anyTypeClassDAO; + @Test public void findAll() { List<UDerAttr> list = derAttrDAO.findAll(UDerAttr.class); @@ -132,19 +137,28 @@ public class DerAttrTest extends AbstractTest { @Test public void issueSYNCOPE134User() { + AnyTypeClass other = anyTypeClassDAO.find("other"); + DerSchema sderived = entityFactory.newEntity(DerSchema.class); sderived.setKey("sderived"); sderived.setExpression("status + ' - ' + username + ' - ' + creationDate + '[' + failedLogins + ']'"); sderived = derSchemaDAO.save(sderived); + derSchemaDAO.flush(); - DerSchema actual = derSchemaDAO.find("sderived"); - assertNotNull("expected save to work", actual); - assertEquals(sderived, actual); + other.add(sderived); + sderived.setAnyTypeClass(other); + + derSchemaDAO.flush(); + + sderived = derSchemaDAO.find("sderived"); + assertNotNull("expected save to work", sderived); + assertEquals(other, sderived.getAnyTypeClass()); User owner = userDAO.find(3L); assertNotNull("did not get expected user", owner); + owner.add(other); UDerAttr derAttr = entityFactory.newEntity(UDerAttr.class); derAttr.setOwner(owner); @@ -165,19 +179,28 @@ public class DerAttrTest extends AbstractTest { @Test public void issueSYNCOPE134Group() { + AnyTypeClass genericMembership = anyTypeClassDAO.find("generic membership"); + DerSchema sderived = entityFactory.newEntity(DerSchema.class); sderived.setKey("sderived"); sderived.setExpression("name"); sderived = derSchemaDAO.save(sderived); + derSchemaDAO.flush(); - DerSchema actual = derSchemaDAO.find("sderived"); - assertNotNull("expected save to work", actual); - assertEquals(sderived, actual); + genericMembership.add(sderived); + sderived.setAnyTypeClass(genericMembership); + + derSchemaDAO.flush(); + + sderived = derSchemaDAO.find("sderived"); + assertNotNull("expected save to work", sderived); + assertEquals(genericMembership, sderived.getAnyTypeClass()); Group owner = groupDAO.find(7L); assertNotNull("did not get expected group", owner); + owner.add(genericMembership); GDerAttr derAttr = entityFactory.newEntity(GDerAttr.class); derAttr.setOwner(owner); http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainAttrTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainAttrTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainAttrTest.java new file mode 100644 index 0000000..014ee64 --- /dev/null +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainAttrTest.java @@ -0,0 +1,237 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.core.persistence.jpa.entity; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.Random; +import javax.validation.ValidationException; +import org.apache.syncope.common.lib.SyncopeConstants; +import org.apache.syncope.common.lib.types.AnyTypeKind; +import org.apache.syncope.common.lib.types.EntityViolationType; +import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException; +import org.apache.syncope.core.persistence.api.dao.PlainAttrDAO; +import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO; +import org.apache.syncope.core.persistence.api.dao.UserDAO; +import org.apache.syncope.core.persistence.api.entity.user.UPlainAttr; +import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrUniqueValue; +import org.apache.syncope.core.persistence.api.entity.user.User; +import org.apache.syncope.core.persistence.jpa.AbstractTest; +import org.apache.syncope.core.misc.security.Encryptor; +import org.apache.syncope.core.persistence.api.entity.PlainSchema; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.codec.Base64; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +public class PlainAttrTest extends AbstractTest { + + @Autowired + private UserDAO userDAO; + + @Autowired + private PlainAttrDAO plainAttrDAO; + + @Autowired + private PlainSchemaDAO plainSchemaDAO; + + @Test + public void findById() { + UPlainAttr attribute = plainAttrDAO.find(100L, UPlainAttr.class); + assertNotNull("did not find expected attribute schema", attribute); + attribute = plainAttrDAO.find(104L, UPlainAttr.class); + assertNotNull("did not find expected attribute schema", attribute); + } + + @Test + public void read() { + UPlainAttr attribute = plainAttrDAO.find(100L, UPlainAttr.class); + assertNotNull(attribute); + assertTrue(attribute.getValues().isEmpty()); + assertNotNull(attribute.getUniqueValue()); + } + + @Test + public void save() throws ClassNotFoundException { + User user = userDAO.find(1L); + + PlainSchema emailSchema = plainSchemaDAO.find("email"); + assertNotNull(emailSchema); + + UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class); + attr.setOwner(user); + attr.setSchema(emailSchema); + + Exception thrown = null; + try { + attr.add("[email protected]", anyUtilsFactory.getInstance(AnyTypeKind.USER)); + attr.add("[email protected]", anyUtilsFactory.getInstance(AnyTypeKind.USER)); + } catch (ValidationException e) { + thrown = e; + } + assertNull("no validation exception expected here ", thrown); + + try { + attr.add("http://www.apache.org", anyUtilsFactory.getInstance(AnyTypeKind.USER)); + } catch (ValidationException e) { + thrown = e; + } + assertNotNull("validation exception expected here ", thrown); + } + + @Test + public void saveWithEnum() throws ClassNotFoundException { + User user = userDAO.find(1L); + assertNotNull(user); + + PlainSchema gender = plainSchemaDAO.find("gender"); + assertNotNull(gender); + assertNotNull(gender.getType()); + assertNotNull(gender.getEnumerationValues()); + + UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class); + attribute.setOwner(user); + attribute.setSchema(gender); + user.add(attribute); + + Exception thrown = null; + + try { + attribute.add("A", anyUtilsFactory.getInstance(AnyTypeKind.USER)); + } catch (ValidationException e) { + thrown = e; + } + assertNotNull("validation exception expected here ", thrown); + + attribute.add("M", anyUtilsFactory.getInstance(AnyTypeKind.USER)); + + InvalidEntityException iee = null; + try { + userDAO.save(user); + } catch (InvalidEntityException e) { + iee = e; + } + assertNull(iee); + } + + @Test + public void validateAndSave() { + User user = userDAO.find(1L); + + PlainSchema emailSchema = plainSchemaDAO.find("email"); + assertNotNull(emailSchema); + + PlainSchema fullnameSchema = plainSchemaDAO.find("fullname"); + assertNotNull(fullnameSchema); + + UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class); + attr.setOwner(user); + attr.setSchema(emailSchema); + + UPlainAttrUniqueValue uauv = entityFactory.newEntity(UPlainAttrUniqueValue.class); + uauv.setAttr(attr); + uauv.setSchema(fullnameSchema); + uauv.setStringValue("a value"); + + attr.setUniqueValue(uauv); + + user.add(attr); + + InvalidEntityException iee = null; + try { + userDAO.save(user); + fail(); + } catch (InvalidEntityException e) { + iee = e; + } + assertNotNull(iee); + // for attribute + assertTrue(iee.hasViolation(EntityViolationType.InvalidValueList)); + // for uauv + assertTrue(iee.hasViolation(EntityViolationType.InvalidPlainSchema)); + } + + @Test + public void saveWithEncrypted() throws Exception { + User user = userDAO.find(1L); + + PlainSchema obscureSchema = plainSchemaDAO.find("obscure"); + assertNotNull(obscureSchema); + assertNotNull(obscureSchema.getSecretKey()); + assertNotNull(obscureSchema.getCipherAlgorithm()); + + UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class); + attr.setOwner(user); + attr.setSchema(obscureSchema); + attr.add("testvalue", anyUtilsFactory.getInstance(AnyTypeKind.USER)); + user.add(attr); + + userDAO.save(user); + + UPlainAttr obscure = user.getPlainAttr("obscure"); + assertNotNull(obscure); + assertEquals(1, obscure.getValues().size()); + assertEquals(Encryptor.getInstance(obscureSchema.getSecretKey()). + encode("testvalue", obscureSchema.getCipherAlgorithm()), obscure.getValues().get(0).getStringValue()); + } + + @Test + public void saveWithBinary() throws UnsupportedEncodingException { + User user = userDAO.find(1L); + + PlainSchema photoSchema = plainSchemaDAO.find("photo"); + assertNotNull(photoSchema); + assertNotNull(photoSchema.getMimeType()); + + final byte[] bytes = new byte[20]; + new Random().nextBytes(bytes); + final String photoB64Value = new String(Base64.encode(bytes), SyncopeConstants.DEFAULT_ENCODING); + + UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class); + attr.setOwner(user); + attr.setSchema(photoSchema); + attr.add(photoB64Value, anyUtilsFactory.getInstance(AnyTypeKind.USER)); + user.add(attr); + + userDAO.save(user); + + UPlainAttr obscure = user.getPlainAttr("photo"); + assertNotNull(obscure); + assertEquals(1, obscure.getValues().size()); + assertTrue(Arrays.equals(bytes, obscure.getValues().get(0).getBinaryValue())); + } + + @Test + public void delete() { + UPlainAttr attribute = plainAttrDAO.find(104L, UPlainAttr.class); + String attrSchemaName = attribute.getSchema().getKey(); + + plainAttrDAO.delete(attribute.getKey(), UPlainAttr.class); + + PlainSchema schema = plainSchemaDAO.find(attrSchemaName); + assertNotNull("user attribute schema deleted when deleting values", schema); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/AttrTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/AttrTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/AttrTest.java deleted file mode 100644 index ef500fe..0000000 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/AttrTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.core.persistence.jpa.relationship; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.apache.syncope.common.lib.SyncopeConstants; -import org.apache.syncope.common.lib.types.AnyTypeKind; -import org.apache.syncope.common.lib.types.AttrSchemaType; -import org.apache.syncope.common.lib.types.CipherAlgorithm; -import org.apache.syncope.core.persistence.api.dao.DerAttrDAO; -import org.apache.syncope.core.persistence.api.dao.DerSchemaDAO; -import org.apache.syncope.core.persistence.api.dao.PlainAttrDAO; -import org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO; -import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO; -import org.apache.syncope.core.persistence.api.dao.UserDAO; -import org.apache.syncope.core.persistence.api.entity.DerSchema; -import org.apache.syncope.core.persistence.api.entity.PlainSchema; -import org.apache.syncope.core.persistence.api.entity.user.UDerAttr; -import org.apache.syncope.core.persistence.api.entity.user.UPlainAttr; -import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue; -import org.apache.syncope.core.persistence.api.entity.user.User; -import org.apache.syncope.core.persistence.jpa.AbstractTest; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - -@Transactional -public class AttrTest extends AbstractTest { - - @Autowired - private PlainAttrDAO plainAttrDAO; - - @Autowired - private DerAttrDAO derAttrDAO; - - @Autowired - private PlainAttrValueDAO plainAttrValueDAO; - - @Autowired - private PlainSchemaDAO plainSchemaDAO; - - @Autowired - private DerSchemaDAO derSchemaDAO; - - @Autowired - private UserDAO userDAO; - - @Test - public void deleteAttribute() { - plainAttrDAO.delete(117L, UPlainAttr.class); - - plainAttrDAO.flush(); - - assertNull(plainAttrDAO.find(117L, UPlainAttr.class)); - assertNull(plainAttrValueDAO.find(28L, UPlainAttrValue.class)); - } - - @Test - public void deleteAttributeValue() { - UPlainAttrValue value = plainAttrValueDAO.find(14L, UPlainAttrValue.class); - int attributeValueNumber = value.getAttr().getValues().size(); - - plainAttrValueDAO.delete(value.getKey(), UPlainAttrValue.class); - - plainAttrValueDAO.flush(); - - assertNull(plainAttrValueDAO.find(value.getKey(), UPlainAttrValue.class)); - - UPlainAttr attribute = plainAttrDAO.find(104L, UPlainAttr.class); - assertEquals(attribute.getValues().size(), attributeValueNumber - 1); - } - - @Test - public void checkForEnumType() { - User user = userDAO.find(1L); - user.setPassword("password123", CipherAlgorithm.SHA); - assertNotNull(user); - - PlainSchema schema = entityFactory.newEntity(PlainSchema.class); - schema.setType(AttrSchemaType.Enum); - schema.setKey("color"); - schema.setEnumerationValues("red" + SyncopeConstants.ENUM_VALUES_SEPARATOR + "yellow"); - - PlainSchema actualSchema = plainSchemaDAO.save(schema); - assertNotNull(actualSchema); - - UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class); - attr.setSchema(actualSchema); - attr.setOwner(user); - attr.add("yellow", anyUtilsFactory.getInstance(AnyTypeKind.USER)); - user.add(attr); - - userDAO.save(user); - userDAO.flush(); - - user = userDAO.find(1L); - assertNotNull(user); - assertNotNull(user.getPlainAttr(schema.getKey())); - assertNotNull(user.getPlainAttr(schema.getKey()).getValues()); - assertEquals(user.getPlainAttr(schema.getKey()).getValues().size(), 1); - } - - @Test - public void derAttrFromSpecialAttrs() { - DerSchema sderived = entityFactory.newEntity(DerSchema.class); - sderived.setKey("sderived"); - sderived.setExpression("username + ' - ' + creationDate + '[' + failedLogins + ']'"); - - sderived = derSchemaDAO.save(sderived); - derSchemaDAO.flush(); - - DerSchema actual = derSchemaDAO.find("sderived"); - assertNotNull("expected save to work", actual); - assertEquals(sderived, actual); - - User owner = userDAO.find(3L); - assertNotNull("did not get expected user", owner); - - UDerAttr derAttr = entityFactory.newEntity(UDerAttr.class); - derAttr.setOwner(owner); - derAttr.setSchema(sderived); - - derAttr = derAttrDAO.save(derAttr); - derAttrDAO.flush(); - - derAttr = derAttrDAO.find(derAttr.getKey(), UDerAttr.class); - assertNotNull("expected save to work", derAttr); - - String value = derAttr.getValue(owner.getPlainAttrs()); - assertNotNull(value); - assertFalse(value.isEmpty()); - assertTrue(value.startsWith("vivaldi - 2010-10-20")); - assertTrue(value.endsWith("[0]")); - } -} http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/GroupTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/GroupTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/GroupTest.java index c9b551a..b32e970 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/GroupTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/GroupTest.java @@ -35,6 +35,7 @@ import org.apache.commons.collections4.Transformer; import org.apache.syncope.common.lib.types.AnyTypeKind; import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException; import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO; +import org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO; import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO; import org.apache.syncope.core.persistence.api.dao.PlainAttrDAO; import org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO; @@ -88,6 +89,9 @@ public class GroupTest extends AbstractTest { @Autowired private PlainAttrValueDAO plainAttrValueDAO; + @Autowired + private AnyTypeClassDAO anyTypeClassDAO; + @Test(expected = InvalidEntityException.class) public void saveWithTwoOwners() { Group root = groupDAO.find("root"); @@ -154,12 +158,13 @@ public class GroupTest extends AbstractTest { User user = entityFactory.newEntity(User.class); user.setUsername("username"); user.setRealm(realmDAO.find("/even/two")); + user.add(anyTypeClassDAO.find("minimal other")); - UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class); - attribute.setSchema(plainSchemaDAO.find("cool")); - attribute.setOwner(user); - attribute.add("true", anyUtilsFactory.getInstance(AnyTypeKind.USER)); - user.add(attribute); + UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class); + attr.setOwner(user); + attr.setSchema(plainSchemaDAO.find("cool")); + attr.add("true", anyUtilsFactory.getInstance(AnyTypeKind.USER)); + user.add(attr); user = userDAO.save(user); Long newUserKey = user.getKey(); @@ -248,11 +253,11 @@ public class GroupTest extends AbstractTest { anyObject.setType(anyTypeDAO.find("OTHER")); anyObject.setRealm(realmDAO.find("/even/two")); - APlainAttr attribute = entityFactory.newEntity(APlainAttr.class); - attribute.setSchema(plainSchemaDAO.find("cool")); - attribute.setOwner(anyObject); - attribute.add("true", anyUtilsFactory.getInstance(AnyTypeKind.ANY_OBJECT)); - anyObject.add(attribute); + APlainAttr attr = entityFactory.newEntity(APlainAttr.class); + attr.setOwner(anyObject); + attr.setSchema(plainSchemaDAO.find("cool")); + attr.add("true", anyUtilsFactory.getInstance(AnyTypeKind.ANY_OBJECT)); + anyObject.add(attr); anyObject = anyObjectDAO.save(anyObject); Long newAnyObjectKey = anyObject.getKey(); http://git-wip-us.apache.org/repos/asf/syncope/blob/63108c8f/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/PlainAttrTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/PlainAttrTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/PlainAttrTest.java new file mode 100644 index 0000000..ae4220c --- /dev/null +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/PlainAttrTest.java @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.core.persistence.jpa.relationship; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.apache.syncope.common.lib.SyncopeConstants; +import org.apache.syncope.common.lib.types.AnyTypeKind; +import org.apache.syncope.common.lib.types.AttrSchemaType; +import org.apache.syncope.common.lib.types.CipherAlgorithm; +import org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO; +import org.apache.syncope.core.persistence.api.dao.DerAttrDAO; +import org.apache.syncope.core.persistence.api.dao.DerSchemaDAO; +import org.apache.syncope.core.persistence.api.dao.PlainAttrDAO; +import org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO; +import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO; +import org.apache.syncope.core.persistence.api.dao.UserDAO; +import org.apache.syncope.core.persistence.api.entity.AnyTypeClass; +import org.apache.syncope.core.persistence.api.entity.DerSchema; +import org.apache.syncope.core.persistence.api.entity.PlainSchema; +import org.apache.syncope.core.persistence.api.entity.user.UDerAttr; +import org.apache.syncope.core.persistence.api.entity.user.UPlainAttr; +import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue; +import org.apache.syncope.core.persistence.api.entity.user.User; +import org.apache.syncope.core.persistence.jpa.AbstractTest; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +public class PlainAttrTest extends AbstractTest { + + @Autowired + private PlainAttrDAO plainAttrDAO; + + @Autowired + private DerAttrDAO derAttrDAO; + + @Autowired + private PlainAttrValueDAO plainAttrValueDAO; + + @Autowired + private PlainSchemaDAO plainSchemaDAO; + + @Autowired + private DerSchemaDAO derSchemaDAO; + + @Autowired + private UserDAO userDAO; + + @Autowired + private AnyTypeClassDAO anyTypeClassDAO; + + @Test + public void deleteAttribute() { + plainAttrDAO.delete(117L, UPlainAttr.class); + + plainAttrDAO.flush(); + + assertNull(plainAttrDAO.find(117L, UPlainAttr.class)); + assertNull(plainAttrValueDAO.find(28L, UPlainAttrValue.class)); + } + + @Test + public void deleteAttributeValue() { + UPlainAttrValue value = plainAttrValueDAO.find(14L, UPlainAttrValue.class); + int attributeValueNumber = value.getAttr().getValues().size(); + + plainAttrValueDAO.delete(value.getKey(), UPlainAttrValue.class); + + plainAttrValueDAO.flush(); + + assertNull(plainAttrValueDAO.find(value.getKey(), UPlainAttrValue.class)); + + UPlainAttr attribute = plainAttrDAO.find(104L, UPlainAttr.class); + assertEquals(attribute.getValues().size(), attributeValueNumber - 1); + } + + @Test + public void checkForEnumType() { + User user = userDAO.find(1L); + user.setPassword("password123", CipherAlgorithm.SHA); + assertNotNull(user); + + AnyTypeClass other = anyTypeClassDAO.find("other"); + + PlainSchema color = entityFactory.newEntity(PlainSchema.class); + color.setType(AttrSchemaType.Enum); + color.setKey("color"); + color.setEnumerationValues("red" + SyncopeConstants.ENUM_VALUES_SEPARATOR + "yellow"); + + color = plainSchemaDAO.save(color); + + other.add(color); + color.setAnyTypeClass(other); + + plainSchemaDAO.flush(); + + color = plainSchemaDAO.find("color"); + assertNotNull("expected save to work", color); + assertEquals(other, color.getAnyTypeClass()); + + UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class); + attr.setOwner(user); + attr.setSchema(color); + attr.add("yellow", anyUtilsFactory.getInstance(AnyTypeKind.USER)); + user.add(attr); + + userDAO.save(user); + userDAO.flush(); + + user = userDAO.find(1L); + assertNotNull(user); + assertNotNull(user.getPlainAttr(color.getKey())); + assertNotNull(user.getPlainAttr(color.getKey()).getValues()); + assertEquals(user.getPlainAttr(color.getKey()).getValues().size(), 1); + } + + @Test + public void derAttrFromSpecialAttrs() { + AnyTypeClass other = anyTypeClassDAO.find("other"); + + DerSchema sderived = entityFactory.newEntity(DerSchema.class); + sderived.setKey("sderived"); + sderived.setExpression("username + ' - ' + creationDate + '[' + failedLogins + ']'"); + + sderived = derSchemaDAO.save(sderived); + + derSchemaDAO.flush(); + + other.add(sderived); + sderived.setAnyTypeClass(other); + + derSchemaDAO.flush(); + + sderived = derSchemaDAO.find("sderived"); + assertNotNull("expected save to work", sderived); + assertEquals(other, sderived.getAnyTypeClass()); + + User owner = userDAO.find(3L); + assertNotNull("did not get expected user", owner); + + UDerAttr derAttr = entityFactory.newEntity(UDerAttr.class); + derAttr.setOwner(owner); + derAttr.setSchema(sderived); + + derAttr = derAttrDAO.save(derAttr); + derAttrDAO.flush(); + + derAttr = derAttrDAO.find(derAttr.getKey(), UDerAttr.class); + assertNotNull("expected save to work", derAttr); + + String value = derAttr.getValue(owner.getPlainAttrs()); + assertNotNull(value); + assertFalse(value.isEmpty()); + assertTrue(value.startsWith("vivaldi - 2010-10-20")); + assertTrue(value.endsWith("[0]")); + } +}
