Author: bdaw
Date: 2008-09-11 03:50:56 -0400 (Thu, 11 Sep 2008)
New Revision: 73
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObject.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationship.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationshipType.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectType.java
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/JPAModelTestCase.java
trunk/identity-impl/src/test/resources/META-INF/
trunk/identity-impl/src/test/resources/META-INF/persistence.xml
Modified:
trunk/identity-impl/pom.xml
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FileBasedIdentityStore.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleIdentity.java
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/PortalIdentityUnitTestCase.java
trunk/identity-model/src/main/java/org/jboss/identity/model/core/IdentityObject.java
Log:
- very simple JPA impl of core model (not complete) with test cases
Modified: trunk/identity-impl/pom.xml
===================================================================
--- trunk/identity-impl/pom.xml 2008-09-10 19:22:59 UTC (rev 72)
+++ trunk/identity-impl/pom.xml 2008-09-11 07:50:56 UTC (rev 73)
@@ -56,5 +56,17 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>3.3.1.ga</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.7</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObject.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObject.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObject.java 2008-09-11
07:50:56 UTC (rev 73)
@@ -0,0 +1,153 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.impl.model;
+
+import org.jboss.identity.model.core.IdentityObject;
+import org.jboss.identity.model.core.IdentityObjectAttribute;
+import org.jboss.identity.exception.PolicyValidationException;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Column;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+@Entity
+@Table(name = "identity_objects")
+public class JPAIdentityObject implements IdentityObject
+{
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(nullable = false)
+ private String name;
+
+ @ManyToOne
+ private JPAIdentityObjectType identityType;
+
+ @OneToMany(mappedBy = "fromIdentityObject")
+ private Set<JPAIdentityObjectRelationship> fromRelationships = new
HashSet<JPAIdentityObjectRelationship>();
+
+ @OneToMany(mappedBy = "toIdentityObject")
+ private Set<JPAIdentityObjectRelationship> toRelationships = new
HashSet<JPAIdentityObjectRelationship>();
+
+
+ public JPAIdentityObject()
+ {
+ }
+
+ public JPAIdentityObject(String name, JPAIdentityObjectType identityType)
+ {
+ this.name = name;
+ this.identityType = identityType;
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public JPAIdentityObjectType getIdentityType()
+ {
+ return identityType;
+ }
+
+ public void setIdentityType(JPAIdentityObjectType identityType)
+ {
+ this.identityType = identityType;
+ }
+
+ public String getFQDN()
+ {
+ return null;
+ }
+
+ public Map<String, Set<String>> getAttributes()
+ {
+ return null;
+ }
+
+ public Set<JPAIdentityObjectRelationship> getFromRelationships()
+ {
+ return fromRelationships;
+ }
+
+ public void setFromRelationships(Set<JPAIdentityObjectRelationship>
fromRelationships)
+ {
+ this.fromRelationships = fromRelationships;
+ }
+
+ public void addFromRelationship(JPAIdentityObjectRelationship fromRelationship)
+ {
+ fromRelationship.setFromIdentityObject(this);
+ fromRelationships.add(fromRelationship);
+ }
+
+ public Set<JPAIdentityObjectRelationship> getToRelationships()
+ {
+ return toRelationships;
+ }
+
+ public void setToRelationships(Set<JPAIdentityObjectRelationship>
toRelationships)
+ {
+ this.toRelationships = toRelationships;
+ }
+
+ public void addToRelationship(JPAIdentityObjectRelationship toRelationship)
+ {
+ toRelationship.setToIdentityObject(this);
+ fromRelationships.add(toRelationship);
+ }
+
+ public void validatePolicy() throws PolicyValidationException
+ {
+
+ }
+}
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationship.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationship.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationship.java 2008-09-11
07:50:56 UTC (rev 73)
@@ -0,0 +1,108 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.impl.model;
+
+import org.jboss.identity.model.core.IdentityObjectRelationship;
+import org.jboss.identity.model.core.IdentityObjectRelationshipType;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.ManyToOne;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+@Entity
+@Table(name="identity_relationships")
+public class JPAIdentityObjectRelationship implements IdentityObjectRelationship
+{
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @ManyToOne
+ private JPAIdentityObjectRelationshipType type;
+
+ @ManyToOne
+ private JPAIdentityObject fromIdentityObject;
+
+ @ManyToOne
+ private JPAIdentityObject toIdentityObject;
+
+ public JPAIdentityObjectRelationship()
+ {
+ }
+
+ public JPAIdentityObjectRelationship(JPAIdentityObjectRelationshipType type,
JPAIdentityObject fromIdentityObject, JPAIdentityObject toIdentityObject)
+ {
+ this.type = type;
+ this.fromIdentityObject = fromIdentityObject;
+ fromIdentityObject.getFromRelationships().add(this);
+ this.toIdentityObject = toIdentityObject;
+ toIdentityObject.getToRelationships().add(this);
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public IdentityObjectRelationshipType getType()
+ {
+ return type;
+ }
+
+ public void setType(JPAIdentityObjectRelationshipType type)
+ {
+ this.type = type;
+ }
+
+ public JPAIdentityObject getFromIdentityObject()
+ {
+ return fromIdentityObject;
+ }
+
+ public void setFromIdentityObject(JPAIdentityObject fromIdentityObject)
+ {
+ this.fromIdentityObject = fromIdentityObject;
+ }
+
+ public JPAIdentityObject getToIdentityObject()
+ {
+ return toIdentityObject;
+ }
+
+ public void setToIdentityObject(JPAIdentityObject toIdentityObject)
+ {
+ this.toIdentityObject = toIdentityObject;
+ }
+}
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationshipType.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationshipType.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectRelationshipType.java 2008-09-11
07:50:56 UTC (rev 73)
@@ -0,0 +1,77 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.impl.model;
+
+import org.jboss.identity.model.core.IdentityObjectRelationshipType;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Column;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+@Entity
+@Table(name = "identity_relationship_types")
+public class JPAIdentityObjectRelationshipType implements IdentityObjectRelationshipType
+{
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(nullable = false, unique = true)
+ private String name;
+
+ public JPAIdentityObjectRelationshipType()
+ {
+ }
+
+ public JPAIdentityObjectRelationshipType(String name)
+ {
+ this.name = name;
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+}
Added:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectType.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectType.java
(rev 0)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/JPAIdentityObjectType.java 2008-09-11
07:50:56 UTC (rev 73)
@@ -0,0 +1,77 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.impl.model;
+
+import org.jboss.identity.model.core.IdentityObjectType;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Column;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+@Entity
+@Table(name = "identity_objects_types")
+public class JPAIdentityObjectType implements IdentityObjectType
+{
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column(nullable = false)
+ private String name;
+
+
+ public JPAIdentityObjectType()
+ {
+ }
+
+ public JPAIdentityObjectType(String name)
+ {
+ this.name = name;
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FileBasedIdentityStore.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FileBasedIdentityStore.java 2008-09-10
19:22:59 UTC (rev 72)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/FileBasedIdentityStore.java 2008-09-11
07:50:56 UTC (rev 73)
@@ -37,6 +37,7 @@
import org.jboss.identity.exception.IdentityException;
import org.jboss.identity.spi.store.IdentityStore;
import org.jboss.identity.spi.store.FeaturesDescription;
+import org.jboss.identity.spi.store.AttributeStore;
/**
* File Based Identity Store
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleIdentity.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleIdentity.java 2008-09-10
19:22:59 UTC (rev 72)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/types/SimpleIdentity.java 2008-09-11
07:50:56 UTC (rev 73)
@@ -23,6 +23,8 @@
import java.util.Collections;
import java.util.List;
+import java.util.Set;
+import java.util.Map;
import org.jboss.identity.model.core.IdentityObjectAttribute;
import org.jboss.identity.api.Role;
@@ -67,9 +69,14 @@
return null;
}
- public List<IdentityObjectAttribute> getAttributes()
+// public List<IdentityObjectAttribute> getAttributes()
+// {
+// return Collections.unmodifiableList(attributes);
+// }
+
+ public Map<String, Set<String>> getAttributes()
{
- return Collections.unmodifiableList(attributes);
+ return null;
}
public List<Group> getGroups()
Added:
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/JPAModelTestCase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/JPAModelTestCase.java
(rev 0)
+++
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/JPAModelTestCase.java 2008-09-11
07:50:56 UTC (rev 73)
@@ -0,0 +1,235 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.test.identity.impl.test.portal;
+
+import junit.framework.TestCase;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
+import javax.persistence.Persistence;
+import javax.persistence.Query;
+import java.util.logging.Logger;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import org.jboss.identity.impl.model.JPAIdentityObject;
+import org.jboss.identity.impl.model.JPAIdentityObjectType;
+import org.jboss.identity.impl.model.JPAIdentityObjectRelationshipType;
+import org.jboss.identity.impl.model.JPAIdentityObjectRelationship;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class JPAModelTestCase extends TestCase
+{
+ private static Logger logger = Logger.getLogger(JPAModelTestCase.class.getName());
+
+ private EntityManagerFactory emFactory;
+
+ private EntityManager em;
+
+ private Connection connection;
+
+ public JPAModelTestCase(String testName) {
+ super(testName);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ try {
+ logger.info("Starting in-memory HSQL database for unit tests");
+ Class.forName("org.hsqldb.jdbcDriver");
+ connection =
DriverManager.getConnection("jdbc:hsqldb:mem:unit-testing-jpa", "sa",
"");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("Exception during HSQL database startup.");
+ }
+ try
+ {
+ logger.info("Building JPA EntityManager for unit tests");
+ emFactory =
Persistence.createEntityManagerFactory("jboss-identity-model");
+ em = emFactory.createEntityManager();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("Exception during JPA EntityManager instanciation.");
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ logger.info("Shuting down Hibernate JPA layer.");
+ if (em != null)
+ {
+ em.close();
+ }
+ if (emFactory != null)
+ {
+ emFactory.close();
+ }
+ logger.info("Stopping in-memory HSQL database.");
+ try
+ {
+ connection.createStatement().execute("SHUTDOWN");
+ }
+ catch (Exception ex) {}
+ }
+
+ public void testPersistence() {
+ try
+ {
+
+ em.getTransaction().begin();
+
+ //
+
+ JPAIdentityObject io = new JPAIdentityObject();
+ io.setName("John Kowalski");
+
+ em.persist(io);
+ assertTrue(em.contains(io));
+
+ em.remove(io);
+ assertFalse(em.contains(io));
+
+ //
+
+ JPAIdentityObjectType iot = new JPAIdentityObjectType();
+ iot.setName("User");
+
+ em.persist(iot);
+ assertTrue(em.contains(iot));
+
+ em.remove(iot);
+ assertFalse(em.contains(iot));
+
+ //
+
+ JPAIdentityObjectRelationshipType iort = new
JPAIdentityObjectRelationshipType();
+ iort.setName("Member");
+
+ em.persist(iort);
+ assertTrue(em.contains(iort));
+
+ //
+
+ JPAIdentityObjectRelationship ior = new JPAIdentityObjectRelationship();
+ ior.setType(iort);
+
+ em.persist(ior);
+ assertTrue(em.contains(ior));
+
+ em.remove(ior);
+ assertFalse(em.contains(ior));
+
+ //
+
+ assertTrue(em.contains(iort));
+
+ em.remove(iort);
+ assertFalse(em.contains(iort));
+
+ em.getTransaction().commit();
+
+ }
+ catch (Exception ex)
+ {
+ em.getTransaction().rollback();
+ ex.printStackTrace();
+ fail("Exception during testPersistence");
+ }
+ }
+
+ public void testRelationships()
+ {
+ try
+ {
+ em.getTransaction().begin();
+
+ JPAIdentityObjectType groupType = new JPAIdentityObjectType("Group");
+ em.persist(groupType);
+ JPAIdentityObjectType userType = new JPAIdentityObjectType("User");
+ em.persist(userType);
+
+ JPAIdentityObject user1 = new JPAIdentityObject("user1", userType);
+ em.persist(user1);
+ JPAIdentityObject user2 = new JPAIdentityObject("user2", userType);
+ em.persist(user2);
+ JPAIdentityObject user3 = new JPAIdentityObject("user3", userType);
+ em.persist(user3);
+
+ JPAIdentityObject group1 = new JPAIdentityObject("group1",
groupType);
+ em.persist(group1);
+ JPAIdentityObject group2 = new JPAIdentityObject("group2",
groupType);
+ em.persist(group2);
+ JPAIdentityObject group3 = new JPAIdentityObject("group3",
groupType);
+ em.persist(group3);
+
+ JPAIdentityObjectRelationshipType memberType = new
JPAIdentityObjectRelationshipType("member");
+ em.persist(memberType);
+
+ JPAIdentityObjectRelationship relationship = new
JPAIdentityObjectRelationship(memberType, group1, user1);
+ em.persist(relationship);
+ relationship = new JPAIdentityObjectRelationship(memberType, group1, user2);
+ em.persist(relationship);
+ relationship = new JPAIdentityObjectRelationship(memberType, group2, user3);
+ em.persist(relationship);
+ relationship = new JPAIdentityObjectRelationship(memberType, group2, group1);
+ em.persist(relationship);
+
+ em.getTransaction().commit();
+
+ //
+
+ em.getTransaction().begin();
+
+ Query ioQuery = em.createQuery("select o from JPAIdentityObject o where
o.name like :name");
+
+ group1 = (JPAIdentityObject)ioQuery.setParameter("name",
"group1").getSingleResult();
+ assertEquals(2, group1.getFromRelationships().size());
+ assertEquals(1, group1.getToRelationships().size());
+ group2 = (JPAIdentityObject)ioQuery.setParameter("name",
"group2").getSingleResult();
+ assertEquals(2, group2.getFromRelationships().size());
+ assertEquals(0, group2.getToRelationships().size());
+
+ user3 = (JPAIdentityObject)ioQuery.setParameter("name",
"user3").getSingleResult();
+ assertEquals(1, user3.getToRelationships().size());
+ assertEquals(0, user3.getFromRelationships().size());
+ assertEquals("group2",
user3.getToRelationships().iterator().next().getFromIdentityObject().getName());
+ em.getTransaction().commit();
+ }
+ catch (Exception ex)
+ {
+ em.getTransaction().rollback();
+ ex.printStackTrace();
+ fail("Exception during testPersistence");
+ }
+ }
+
+}
Modified:
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/PortalIdentityUnitTestCase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/PortalIdentityUnitTestCase.java 2008-09-10
19:22:59 UTC (rev 72)
+++
trunk/identity-impl/src/test/java/org/jboss/test/identity/impl/test/portal/PortalIdentityUnitTestCase.java 2008-09-11
07:50:56 UTC (rev 73)
@@ -1,211 +1,211 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.test.identity.impl.test.portal;
-
-import junit.framework.TestCase;
-
-//import org.jboss.identity.api.managers.IdentityManager;
-//import org.jboss.identity.api.managers.RelationshipManager;
-//import org.jboss.identity.api.store.IdentityStore;
-//import org.jboss.identity.api.store.IdentityStoreRepository;
-//import org.jboss.identity.impl.store.FileBasedIdentityStore;
-//import org.jboss.identity.model.Identity;
-//import org.jboss.identity.model.IdentityType;
-//import org.jboss.identity.model.groups.Group;
-//import org.jboss.identity.model.groups.GroupType;
-//import org.jboss.identity.model.groups.SimpleGroupType;
-//import org.jboss.identity.model.relation.HierarchicalRelationshipType;
-//import org.jboss.identity.model.relation.RelationshipType;
-////import org.jboss.test.identity.impl.portal.PortalIdentityManager;
-//import org.jboss.test.identity.impl.portal.PortalIdentityStoreRepository;
-//import org.jboss.test.identity.impl.portal.PortalRealm;
-//import org.jboss.test.identity.impl.portal.PortalRelationshipManager;
-
-/**
- * Portal identity unit test
- * @author Anil.Saldhana(a)redhat.com
- * @since Jul 22, 2008
- */
-public class PortalIdentityUnitTestCase extends TestCase
-{
-// private IdentityType IDENTITY = IdentityTypeEnum.IDENTITY;
-// private IdentityType GROUP = IdentityTypeEnum.GROUP;
-
-// private RelationshipType hierarchy = new HierarchicalRelationshipType();
-// private RelationshipManager relationshipManager = new PortalRelationshipManager();
-// private IdentityManager identityManager = new PortalIdentityManager();
-// private PortalRealm portalRealm ;
-// private PortalIdentityStoreRepository portalRepository;
-// private IdentityStore portalIdentityStore;
+///*
+// * JBoss, Home of Professional Open Source.
+// * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+// * as indicated by the @author tags. See the copyright.txt file in the
+// * distribution for a full listing of individual contributors.
+// *
+// * This is free software; you can redistribute it and/or modify it
+// * under the terms of the GNU Lesser General Public License as
+// * published by the Free Software Foundation; either version 2.1 of
+// * the License, or (at your option) any later version.
+// *
+// * This software is distributed in the hope that it will be useful,
+// * but WITHOUT ANY WARRANTY; without even the implied warranty of
+// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// * Lesser General Public License for more details.
+// *
+// * You should have received a copy of the GNU Lesser General Public
+// * License along with this software; if not, write to the Free
+// * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+// * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+// */
+//package org.jboss.test.identity.impl.test.portal;
//
-// protected void setUp() throws Exception
-// {
-// portalRealm = (PortalRealm) identityManager.bootstrap("portal");
-// portalRealm.createModelRoots();
-// portalRepository = new PortalIdentityStoreRepository();
-// identityManager.setRepository(portalRealm, portalRepository);
-// portalIdentityStore = new FileBasedIdentityStore();
-//// portalRepository.register(IDENTITY, portalIdentityStore);
-// }
-
- public void testPortalIdentityOrganizationType() throws Exception
- {
- bootstrapOrganizationType();
- searchOrganizationType();
- }
-
- public void testPortalIdentityBusinessType() throws Exception
- {
- bootstrapBusinessType();
- }
-
- /**
- * Bootstrap the organization type system
- */
- private void bootstrapOrganizationType() throws Exception
- {
- //***************************************************
- // Create the Group Model
- //***************************************************
-// GroupType organizationGroupType = new SimpleGroupType("Organization");
-// Group redhatGroup = identityManager.createGroup(portalRealm, "RedHat",
-// organizationGroupType);
+//import junit.framework.TestCase;
//
-// Group jbossGroup = identityManager.createGroup(portalRealm, "JBoss",
-// organizationGroupType);
-// Group rhelGroup = identityManager.createGroup(portalRealm, "RHEL",
-// organizationGroupType);
+////import org.jboss.identity.api.managers.IdentityManager;
+////import org.jboss.identity.api.managers.RelationshipManager;
+////import org.jboss.identity.api.store.IdentityStore;
+////import org.jboss.identity.api.store.IdentityStoreRepository;
+////import org.jboss.identity.impl.store.FileBasedIdentityStore;
+////import org.jboss.identity.model.Identity;
+////import org.jboss.identity.model.IdentityType;
+////import org.jboss.identity.model.groups.Group;
+////import org.jboss.identity.model.groups.GroupType;
+////import org.jboss.identity.model.groups.SimpleGroupType;
+////import org.jboss.identity.model.relation.HierarchicalRelationshipType;
+////import org.jboss.identity.model.relation.RelationshipType;
+//////import org.jboss.test.identity.impl.portal.PortalIdentityManager;
+////import org.jboss.test.identity.impl.portal.PortalIdentityStoreRepository;
+////import org.jboss.test.identity.impl.portal.PortalRealm;
+////import org.jboss.test.identity.impl.portal.PortalRelationshipManager;
//
-// relationshipManager.associate(redhatGroup, jbossGroup, hierarchy);
-// relationshipManager.associate(redhatGroup, rhelGroup, hierarchy);
+///**
+// * Portal identity unit test
+// * @author Anil.Saldhana(a)redhat.com
+// * @since Jul 22, 2008
+// */
+//public class PortalIdentityUnitTestCase extends TestCase
+//{
+//// private IdentityType IDENTITY = IdentityTypeEnum.IDENTITY;
+//// private IdentityType GROUP = IdentityTypeEnum.GROUP;
//
-// Group itGroup = identityManager.createGroup(portalRealm, "IT",
-// organizationGroupType);
-// Group hrGroup = identityManager.createGroup(portalRealm, "HR",
-// organizationGroupType);
+//// private RelationshipType hierarchy = new HierarchicalRelationshipType();
+//// private RelationshipManager relationshipManager = new
PortalRelationshipManager();
+//// private IdentityManager identityManager = new PortalIdentityManager();
+//// private PortalRealm portalRealm ;
+//// private PortalIdentityStoreRepository portalRepository;
+//// private IdentityStore portalIdentityStore;
+////
+//// protected void setUp() throws Exception
+//// {
+//// portalRealm = (PortalRealm) identityManager.bootstrap("portal");
+//// portalRealm.createModelRoots();
+//// portalRepository = new PortalIdentityStoreRepository();
+//// identityManager.setRepository(portalRealm, portalRepository);
+//// portalIdentityStore = new FileBasedIdentityStore();
+////// portalRepository.register(IDENTITY, portalIdentityStore);
+//// }
//
-// relationshipManager.associate(jbossGroup, itGroup, hierarchy);
-// relationshipManager.associate(jbossGroup, hrGroup, hierarchy);
+// public void testPortalIdentityOrganizationType() throws Exception
+// {
+// bootstrapOrganizationType();
+// searchOrganizationType();
+// }
//
-// Group projectsGroup = identityManager.createGroup(portalRealm,
"Projects",
-// organizationGroupType);
-// Group supportGroup = identityManager.createGroup(portalRealm,
"Support",
-// organizationGroupType);
+// public void testPortalIdentityBusinessType() throws Exception
+// {
+// bootstrapBusinessType();
+// }
//
-// relationshipManager.associate(itGroup, projectsGroup, hierarchy);
-// relationshipManager.associate(itGroup, supportGroup, hierarchy);
+// /**
+// * Bootstrap the organization type system
+// */
+// private void bootstrapOrganizationType() throws Exception
+// {
+// //***************************************************
+// // Create the Group Model
+// //***************************************************
+//// GroupType organizationGroupType = new
SimpleGroupType("Organization");
+//// Group redhatGroup = identityManager.createGroup(portalRealm,
"RedHat",
+//// organizationGroupType);
+////
+//// Group jbossGroup = identityManager.createGroup(portalRealm, "JBoss",
+//// organizationGroupType);
+//// Group rhelGroup = identityManager.createGroup(portalRealm, "RHEL",
+//// organizationGroupType);
+////
+//// relationshipManager.associate(redhatGroup, jbossGroup, hierarchy);
+//// relationshipManager.associate(redhatGroup, rhelGroup, hierarchy);
+////
+//// Group itGroup = identityManager.createGroup(portalRealm, "IT",
+//// organizationGroupType);
+//// Group hrGroup = identityManager.createGroup(portalRealm, "HR",
+//// organizationGroupType);
+////
+//// relationshipManager.associate(jbossGroup, itGroup, hierarchy);
+//// relationshipManager.associate(jbossGroup, hrGroup, hierarchy);
+////
+//// Group projectsGroup = identityManager.createGroup(portalRealm,
"Projects",
+//// organizationGroupType);
+//// Group supportGroup = identityManager.createGroup(portalRealm,
"Support",
+//// organizationGroupType);
+////
+//// relationshipManager.associate(itGroup, projectsGroup, hierarchy);
+//// relationshipManager.associate(itGroup, supportGroup, hierarchy);
+////
+//// Group portalGroup = identityManager.createGroup(portalRealm,
"Portal",
+//// organizationGroupType);
+//// Group jbpmGroup = identityManager.createGroup(portalRealm, "jBPM",
+//// organizationGroupType);
+//// Group soaGroup = identityManager.createGroup(portalRealm, "SOA",
+//// organizationGroupType);
+////
+//// relationshipManager.associate(projectsGroup, portalGroup, hierarchy);
+//// relationshipManager.associate(projectsGroup, jbpmGroup, hierarchy);
+//// relationshipManager.associate(projectsGroup, soaGroup, hierarchy);
//
-// Group portalGroup = identityManager.createGroup(portalRealm, "Portal",
-// organizationGroupType);
-// Group jbpmGroup = identityManager.createGroup(portalRealm, "jBPM",
-// organizationGroupType);
-// Group soaGroup = identityManager.createGroup(portalRealm, "SOA",
-// organizationGroupType);
//
-// relationshipManager.associate(projectsGroup, portalGroup, hierarchy);
-// relationshipManager.associate(projectsGroup, jbpmGroup, hierarchy);
-// relationshipManager.associate(projectsGroup, soaGroup, hierarchy);
-
-
- //***************************************************
- // Create the Identity Model
- //***************************************************
- //Create Identities - julien, theute and associate with portal group
-// Identity julien = identityManager.createIdentity(portalRealm,
"julien");
-// Identity theute = identityManager.createIdentity(portalRealm,
"theute");
-//
-// relationshipManager.associate(portalRealm, julien, portalGroup);
-// relationshipManager.associate(portalRealm, theute, portalGroup);
- }
-
-
- /**
- * Bootstrap the business type system
- */
- private void bootstrapBusinessType() throws Exception
- {
- //***************************************************
- // Create the Group Model
- //***************************************************
-// GroupType businessGroupType = new SimpleGroupType("Business");
-// Group rolesGroup = identityManager.createGroup(portalRealm, "Roles",
-// businessGroupType);
-//
-// Group developersGroup = identityManager.createGroup(portalRealm,
-// "Developers",
-// businessGroupType);
-// Group managementGroup = identityManager.createGroup(portalRealm,
-// "Management",
-// businessGroupType);
-//
-// relationshipManager.associate(rolesGroup, developersGroup, hierarchy);
-// relationshipManager.associate(rolesGroup, managementGroup, hierarchy);
-//
-// Group portalProjectLeadGroup = identityManager.createGroup(portalRealm,
-// "Portal Project Lead",
-// businessGroupType);
-// Group portalProductLeadGroup = identityManager.createGroup(portalRealm,
-// "Portal Product Lead",
-// businessGroupType);
-//
-// relationshipManager.associate(developersGroup, portalProjectLeadGroup,
hierarchy);
-// relationshipManager.associate(developersGroup, portalProductLeadGroup,
hierarchy);
-//
-// Group commonFrameworkManagerGroup = identityManager.createGroup(portalRealm,
-// "Common Framework Manager",
-// businessGroupType);
-//
-// relationshipManager.associate(managementGroup,
-// commonFrameworkManagerGroup, hierarchy);
-//
// //***************************************************
// // Create the Identity Model
// //***************************************************
// //Create Identities - julien, theute and associate with portal group
-// Identity julien = identityManager.createIdentity(portalRealm,
"julien");
-// Identity theute = identityManager.createIdentity(portalRealm,
"theute");
-// //bgeorges for common framework manager group
-// Identity bgeorges = identityManager.createIdentity(portalRealm,
"bgeorges");
+//// Identity julien = identityManager.createIdentity(portalRealm,
"julien");
+//// Identity theute = identityManager.createIdentity(portalRealm,
"theute");
+////
+//// relationshipManager.associate(portalRealm, julien, portalGroup);
+//// relationshipManager.associate(portalRealm, theute, portalGroup);
+// }
//
-// relationshipManager.associate(portalRealm, julien, portalProjectLeadGroup);
-// relationshipManager.associate(portalRealm, theute, portalProductLeadGroup);
-// relationshipManager.associate(portalRealm, bgeorges,
commonFrameworkManagerGroup);
//
-// portalIdentityStore.findIdentities(commonFrameworkManagerGroup, hierarchy, true,
0, 0, "", true);
- }
-
- private void searchOrganizationType() throws Exception
- {
-// IdentityStoreRepository repo = identityManager.getRepository(portalRealm);
-// assertEquals(repo, portalRepository);
-// //Get the IdentityStore for identities
-// IdentityStore identityStore = repo.getIdentityStore(IdentityTypeEnum.IDENTITY);
-// assertNotNull("IdentityStore is not null", identityStore);
-// assertEquals("Portal Identity Store",portalIdentityStore,
-// repo.getIdentityStore(IDENTITY));
+// /**
+// * Bootstrap the business type system
+// */
+// private void bootstrapBusinessType() throws Exception
+// {
+// //***************************************************
+// // Create the Group Model
+// //***************************************************
+//// GroupType businessGroupType = new SimpleGroupType("Business");
+//// Group rolesGroup = identityManager.createGroup(portalRealm, "Roles",
+//// businessGroupType);
+////
+//// Group developersGroup = identityManager.createGroup(portalRealm,
+//// "Developers",
+//// businessGroupType);
+//// Group managementGroup = identityManager.createGroup(portalRealm,
+//// "Management",
+//// businessGroupType);
+////
+//// relationshipManager.associate(rolesGroup, developersGroup, hierarchy);
+//// relationshipManager.associate(rolesGroup, managementGroup, hierarchy);
+////
+//// Group portalProjectLeadGroup = identityManager.createGroup(portalRealm,
+//// "Portal Project Lead",
+//// businessGroupType);
+//// Group portalProductLeadGroup = identityManager.createGroup(portalRealm,
+//// "Portal Product Lead",
+//// businessGroupType);
+////
+//// relationshipManager.associate(developersGroup, portalProjectLeadGroup,
hierarchy);
+//// relationshipManager.associate(developersGroup, portalProductLeadGroup,
hierarchy);
+////
+//// Group commonFrameworkManagerGroup = identityManager.createGroup(portalRealm,
+//// "Common Framework Manager",
+//// businessGroupType);
+////
+//// relationshipManager.associate(managementGroup,
+//// commonFrameworkManagerGroup, hierarchy);
+////
+//// //***************************************************
+//// // Create the Identity Model
+//// //***************************************************
+//// //Create Identities - julien, theute and associate with portal group
+//// Identity julien = identityManager.createIdentity(portalRealm,
"julien");
+//// Identity theute = identityManager.createIdentity(portalRealm,
"theute");
+//// //bgeorges for common framework manager group
+//// Identity bgeorges = identityManager.createIdentity(portalRealm,
"bgeorges");
+////
+//// relationshipManager.associate(portalRealm, julien, portalProjectLeadGroup);
+//// relationshipManager.associate(portalRealm, theute, portalProductLeadGroup);
+//// relationshipManager.associate(portalRealm, bgeorges,
commonFrameworkManagerGroup);
+////
+//// portalIdentityStore.findIdentities(commonFrameworkManagerGroup, hierarchy,
true, 0, 0, "", true);
+// }
//
-//
-//
-// Identity julien = portalIdentityStore.findIdentity("julien");
-// assertNotNull(julien);
- }
-}
\ No newline at end of file
+// private void searchOrganizationType() throws Exception
+// {
+//// IdentityStoreRepository repo = identityManager.getRepository(portalRealm);
+//// assertEquals(repo, portalRepository);
+//// //Get the IdentityStore for identities
+//// IdentityStore identityStore =
repo.getIdentityStore(IdentityTypeEnum.IDENTITY);
+//// assertNotNull("IdentityStore is not null", identityStore);
+//// assertEquals("Portal Identity Store",portalIdentityStore,
+//// repo.getIdentityStore(IDENTITY));
+////
+////
+////
+//// Identity julien = portalIdentityStore.findIdentity("julien");
+//// assertNotNull(julien);
+// }
+//}
\ No newline at end of file
Added: trunk/identity-impl/src/test/resources/META-INF/persistence.xml
===================================================================
--- trunk/identity-impl/src/test/resources/META-INF/persistence.xml
(rev 0)
+++ trunk/identity-impl/src/test/resources/META-INF/persistence.xml 2008-09-11 07:50:56
UTC (rev 73)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
+
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
+ version="1.0">
+
+ <persistence-unit name="jboss-identity-model"
transaction-type="RESOURCE_LOCAL">
+
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+
+ <class>org.jboss.identity.impl.model.JPAIdentityObject</class>
+ <class>org.jboss.identity.impl.model.JPAIdentityObjectType</class>
+
<class>org.jboss.identity.impl.model.JPAIdentityObjectRelationship</class>
+
<class>org.jboss.identity.impl.model.JPAIdentityObjectRelationshipType</class>
+
+
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+ <properties>
+ <property name="hibernate.connection.url"
value="jdbc:hsqldb:mem:unit-testing-jpa"/>
+ <property name="hibernate.connection.driver_class"
value="org.hsqldb.jdbcDriver"/>
+ <property name="hibernate.dialect"
value="org.hibernate.dialect.HSQLDialect"/>
+ <property name="hibernate.hbm2ddl.auto"
value="create-drop"/>
+ <property name="hibernate.connection.username"
value="sa"/>
+ <property name="hibernate.connection.password"
value=""/>
+ </properties>
+
+
+ </persistence-unit>
+</persistence>
\ No newline at end of file
Modified:
trunk/identity-model/src/main/java/org/jboss/identity/model/core/IdentityObject.java
===================================================================
---
trunk/identity-model/src/main/java/org/jboss/identity/model/core/IdentityObject.java 2008-09-10
19:22:59 UTC (rev 72)
+++
trunk/identity-model/src/main/java/org/jboss/identity/model/core/IdentityObject.java 2008-09-11
07:50:56 UTC (rev 73)
@@ -25,6 +25,8 @@
import org.jboss.identity.exception.PolicyValidationException;
import java.util.List;
+import java.util.Set;
+import java.util.Map;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot
com">Boleslaw Dawidowicz</a>
@@ -59,10 +61,10 @@
IdentityObjectType getIdentityType();
/**
- * <p>Return a list of attributes</p>
+ * <p>Return a map of attribute values</p>
* @return
*/
- List<IdentityObjectAttribute> getAttributes();
+ public Map<String, Set<String>> getAttributes();
/**
* Validate configured Policies