/hibernate-ogm-mongodb/src/test/java/org/hibernate/ogm/test/mongodb/loading/LoadSelectedColumnsInEntityTest.java

https://bitbucket.org/cprenzberg/hibernate-ogm · Java · 75 lines · 38 code · 10 blank · 27 comment · 0 complexity · 91c6e1e4dfdf49f8f9560d9ccb18fd46 MD5 · raw file

  1. /*
  2. * Hibernate, Relational Persistence for Idiomatic Java
  3. *
  4. * JBoss, Home of Professional Open Source
  5. * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
  6. * as indicated by the @authors tag. All rights reserved.
  7. * See the copyright.txt in the distribution for a
  8. * full listing of individual contributors.
  9. *
  10. * This copyrighted material is made available to anyone wishing to use,
  11. * modify, copy, or redistribute it subject to the terms and conditions
  12. * of the GNU Lesser General Public License, v. 2.1.
  13. * This program is distributed in the hope that it will be useful, but WITHOUT A
  14. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  15. * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  16. * You should have received a copy of the GNU Lesser General Public License,
  17. * v.2.1 along with this distribution; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. * MA 02110-1301, USA.
  20. */
  21. package org.hibernate.ogm.test.mongodb.loading;
  22. import static org.fest.assertions.Assertions.assertThat;
  23. import java.util.Set;
  24. import org.hibernate.cfg.Configuration;
  25. import org.hibernate.ogm.datastore.mongodb.AssociationStorage;
  26. import org.hibernate.ogm.datastore.mongodb.Environment;
  27. import org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider;
  28. import org.hibernate.ogm.datastore.spi.DatastoreProvider;
  29. import org.hibernate.ogm.dialect.mongodb.MongoDBDialect;
  30. import com.mongodb.BasicDBObject;
  31. import com.mongodb.DB;
  32. import com.mongodb.DBCollection;
  33. import com.mongodb.DBObject;
  34. /**
  35. * @author Guillaume Scheibel <guillaume.scheibel@gmail.com>
  36. */
  37. public class LoadSelectedColumnsInEntityTest extends LoadSelectedColumnsCollectionTest {
  38. @Override
  39. protected void configure(Configuration cfg) {
  40. super.configure( cfg );
  41. cfg.setProperty(
  42. Environment.MONGODB_ASSOCIATIONS_STORE,
  43. AssociationStorage.IN_ENTITY.toString().toLowerCase()
  44. );
  45. }
  46. @Override
  47. protected void addExtraColumn() {
  48. MongoDBDatastoreProvider provider = (MongoDBDatastoreProvider) super.getService( DatastoreProvider.class );
  49. DB database = provider.getDatabase();
  50. DBCollection collection = database.getCollection( "Project" );
  51. BasicDBObject query = new BasicDBObject( 1 );
  52. query.put( "_id", "projectID" );
  53. BasicDBObject updater = new BasicDBObject( 1 );
  54. updater.put( "$push", new BasicDBObject( "extraColumn", 1 ) );
  55. collection.update( query, updater );
  56. }
  57. protected void checkLoading(DBObject associationObject) {
  58. /*
  59. * The only column (except _id) that needs to be retrieved is "modules"
  60. * So we should have 2 columns
  61. */
  62. final Set<?> retrievedColumns = associationObject.keySet();
  63. assertThat( retrievedColumns ).hasSize( 2 ).containsOnly( MongoDBDialect.ID_FIELDNAME, "modules" );
  64. }
  65. }