rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject svn commit: r1148748 - in /incubator/rave/trunk/rave-shindig/src: main/java/org/apache/shindig/social/opensocial/jpa/spi/ main/resources/META-INF/ test/java/org/apache/shindig/social/opensocial/jpa/spi/ test/resources/META-INF/
Date Wed, 20 Jul 2011 13:02:56 GMT
Author: jasha
Date: Wed Jul 20 13:02:55 2011
New Revision: 1148748

URL: http://svn.apache.org/viewvc?rev=1148748&view=rev
Log:
RAVE-62 add simple test for getPerson

Modified:
    incubator/rave/trunk/rave-shindig/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDb.java
    incubator/rave/trunk/rave-shindig/src/main/resources/META-INF/persistence.xml
    incubator/rave/trunk/rave-shindig/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDbTest.java
    incubator/rave/trunk/rave-shindig/src/test/resources/META-INF/persistence.xml

Modified: incubator/rave/trunk/rave-shindig/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDb.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-shindig/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDb.java?rev=1148748&r1=1148747&r2=1148748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-shindig/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDb.java
(original)
+++ incubator/rave/trunk/rave-shindig/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDb.java
Wed Jul 20 13:02:55 2011
@@ -56,13 +56,17 @@ public class PersonServiceDb implements 
    */
   private EntityManager entityManager;
 
+  private ShindigUtil shindigUtil = new ShindigUtil();
+  private BeanConverter beanConverter = shindigUtil.getBeanConverter();
+
+
   /**
    * Create the PersonServiceDb, injecting an entity manager that is configured with the
social
    * model.
    *
    * @param entityManager the entity manager containing the social model.
    */
-//  @Inject
+  //@Inject
   public PersonServiceDb(EntityManager entityManager) {
     this.entityManager = entityManager;
   }
@@ -160,9 +164,6 @@ public class PersonServiceDb implements 
 
   }
   
-  private ShindigUtil shindigUtil = new ShindigUtil();
-  private BeanConverter beanConverter = shindigUtil.getBeanConverter();
-  
   /**
    * {@inheritDoc}
    */
@@ -182,8 +183,9 @@ public class PersonServiceDb implements 
         String jsonStrRep = beanConverter.convertToString(person);
         JSONObject jsonRep = new JSONObject(jsonStrRep);
         if (!fields.isEmpty()) {
-            if (fields.size() != 1 || !fields.contains("id"))
+            if (fields.size() != 1 || !fields.contains("id")) {
                 jsonRep = new JSONObject(jsonRep, fields.toArray(new String[fields.size()]));
+            }
         }
         person = beanConverter.convertToObject(jsonRep.toString(), Person.class);
         return ImmediateFuture.newInstance(person);
@@ -300,4 +302,16 @@ public class PersonServiceDb implements 
           }
       }
   }
+
+    /**
+     * Persists a {@link PersonDb} in the database
+     *
+     * @param person {@link PersonDb}
+     */
+    public void savePersonDb(PersonDb person) {
+        entityManager.getTransaction().begin();
+        entityManager.persist(person);
+        entityManager.flush();
+        entityManager.getTransaction().commit();
+    }
 }

Modified: incubator/rave/trunk/rave-shindig/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-shindig/src/main/resources/META-INF/persistence.xml?rev=1148748&r1=1148747&r2=1148748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-shindig/src/main/resources/META-INF/persistence.xml (original)
+++ incubator/rave/trunk/rave-shindig/src/main/resources/META-INF/persistence.xml Wed Jul
20 13:02:55 2011
@@ -25,6 +25,7 @@
     <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
     <class>org.apache.shindig.gadgets.oauth.model.OAuthConsumerStoreDb</class>
     <class>org.apache.shindig.gadgets.oauth.model.OAuthTokenInfoDb</class>
+    <class>org.apache.shindig.social.opensocial.jpa.PersonDb</class>
     <properties>
       <property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
       <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />

Modified: incubator/rave/trunk/rave-shindig/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDbTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-shindig/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDbTest.java?rev=1148748&r1=1148747&r2=1148748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-shindig/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDbTest.java
(original)
+++ incubator/rave/trunk/rave-shindig/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDbTest.java
Wed Jul 20 13:02:55 2011
@@ -19,12 +19,30 @@
 
 package org.apache.shindig.social.opensocial.jpa.spi;
 
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.concurrent.Future;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import org.apache.rave.os.model.RaveNameImpl;
+import org.apache.shindig.auth.SecurityToken;
+import org.apache.shindig.common.testing.FakeGadgetToken;
 import org.apache.shindig.protocol.model.FilterOperation;
 import org.apache.shindig.protocol.model.SortOrder;
+import org.apache.shindig.social.opensocial.jpa.EnumDb;
+import org.apache.shindig.social.opensocial.jpa.PersonDb;
 import org.apache.shindig.social.opensocial.jpa.api.FilterCapability;
 import org.apache.shindig.social.opensocial.jpa.api.FilterSpecification;
+import org.apache.shindig.social.opensocial.jpa.openjpa.OpenJPADbModule;
+import org.apache.shindig.social.opensocial.model.Drinker;
+import org.apache.shindig.social.opensocial.model.Name;
+import org.apache.shindig.social.opensocial.model.NetworkPresence;
+import org.apache.shindig.social.opensocial.model.Person;
+import org.apache.shindig.social.opensocial.model.Smoker;
 import org.apache.shindig.social.opensocial.spi.CollectionOptions;
 import org.apache.shindig.social.opensocial.spi.PersonService;
+import org.apache.shindig.social.opensocial.spi.UserId;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -44,7 +62,22 @@ public class PersonServiceDbTest {
 
     @Before
     public void setUp() throws Exception {
-        service = new PersonServiceDb();
+        Injector injector = Guice.createInjector(new OpenJPADbModule());
+        service = injector.getInstance(PersonServiceDb.class);
+        PersonDb person = createPerson();
+        service.savePersonDb(person);
+    }
+
+
+    @Test
+    public void testGetPerson() throws Exception {
+        UserId userId = new UserId(UserId.Type.userId, "canonical");
+        SecurityToken token = new FakeGadgetToken();
+        final Future<Person> personFuture = service.getPerson(userId, Collections.<String>emptySet(),
token);
+        final Person person = personFuture.get();
+        assertEquals("canonical", person.getId());
+        assertEquals(25, person.getAge().intValue());
+        assertEquals(Smoker.NO, person.getSmoker().getValue());
     }
 
     /**
@@ -151,6 +184,26 @@ public class PersonServiceDbTest {
         sb = new StringBuilder();
         service.addOrderClause(sb, co);
         assertEquals(" order by p.randomProperty", sb.toString());
+    }
 
+    private PersonDb createPerson() {
+        PersonDb person = new PersonDb();
+        person.setId("canonical");
+        Name name = new RaveNameImpl();
+        name.setFamilyName("Anonical");
+        name.setGivenName("Carl");
+        person.setName(name);
+        person.setDrinker(new EnumDb<Drinker>(Drinker.NO));
+        person.setGender(Person.Gender.male);
+        person.setNetworkPresence(new EnumDb<NetworkPresence>(NetworkPresence.ONLINE));
+        person.setAboutMe("About me");
+        person.setAge(25);
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(1997, Calendar.SEPTEMBER, 12);
+        person.setBirthday(calendar.getTime());
+        person.setNickname("hoosier");
+        person.setSmoker(new EnumDb<Smoker>(Smoker.NO));
+        return person;
     }
+
 }

Modified: incubator/rave/trunk/rave-shindig/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-shindig/src/test/resources/META-INF/persistence.xml?rev=1148748&r1=1148747&r2=1148748&view=diff
==============================================================================
--- incubator/rave/trunk/rave-shindig/src/test/resources/META-INF/persistence.xml (original)
+++ incubator/rave/trunk/rave-shindig/src/test/resources/META-INF/persistence.xml Wed Jul
20 13:02:55 2011
@@ -26,6 +26,7 @@
     <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
     <class>org.apache.shindig.gadgets.oauth.model.OAuthConsumerStoreDb</class>
     <class>org.apache.shindig.gadgets.oauth.model.OAuthTokenInfoDb</class>
+    <class>org.apache.shindig.social.opensocial.jpa.PersonDb</class>
     <properties>
       <property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
       <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>



Mime
View raw message