Package org.eclipselabs.mongoemf.junit.model

Examples of org.eclipselabs.mongoemf.junit.model.TargetObject


  @Test
  public void testSingleIteration() throws IOException
  {
    // Setup : Store a single target object to the database.

    TargetObject targetObject = ModelFactory.eINSTANCE.createTargetObject();
    targetObject.setSingleAttribute("junit");
    saveObject(targetObject);

    // Test: Query the database to return a cursor

    ResourceSet resourceSet = createResourceSet();
    resourceSet.getLoadOptions().put(Options.OPTION_QUERY_CURSOR, Boolean.TRUE);
    Resource resource = resourceSet.getResource(queryURI, true);

    // Verify: Make sure we got a cursor back with only one element that matches the target object

    assertThat(resource, is(notNullValue()));
    assertThat(resource.getContents().size(), is(1));
    assertThat(resource.getContents().get(0), is(instanceOf(MongoCursor.class)));

    MongoCursor cursor = (MongoCursor) resource.getContents().get(0);
    Iterator<EObject> iterator = cursor.iterator();
    assertThat(iterator, is(notNullValue()));

    assertTrue(iterator.hasNext());
    TargetObject actualObject = (TargetObject) iterator.next();
    assertThat(actualObject.getSingleAttribute(), is("junit"));
    assertThat(actualObject.eResource(), is(notNullValue()));
    assertThat(actualObject.eResource().getURI(), is(targetObject.eResource().getURI()));
    assertFalse(iterator.hasNext());
  }
View Full Code Here


  @Test
  public void testMultipleIteration() throws IOException
  {
    // Setup : Store multiple target objects to the database.

    TargetObject targetObject1 = ModelFactory.eINSTANCE.createTargetObject();
    targetObject1.setSingleAttribute("junit1");
    saveObject(targetObject1);

    TargetObject targetObject2 = ModelFactory.eINSTANCE.createTargetObject();
    targetObject2.setSingleAttribute("junit2");
    saveObject(targetObject2);

    TargetObject targetObject3 = ModelFactory.eINSTANCE.createTargetObject();
    targetObject3.setSingleAttribute("junit3");
    saveObject(targetObject3);

    // Test: Query the database to return a cursor

    ResourceSet resourceSet = createResourceSet();
    resourceSet.getLoadOptions().put(Options.OPTION_QUERY_CURSOR, Boolean.TRUE);
    Resource resource = resourceSet.getResource(queryURI, true);

    // Verify: Make sure we got a cursor back with three elements that match the target objects

    HashSet<String> pendingTargets = new HashSet<String>(3);
    pendingTargets.add(targetObject1.getSingleAttribute());
    pendingTargets.add(targetObject2.getSingleAttribute());
    pendingTargets.add(targetObject3.getSingleAttribute());

    assertThat(resource, is(notNullValue()));
    assertThat(resource.getContents().size(), is(1));
    assertThat(resource.getContents().get(0), is(instanceOf(MongoCursor.class)));

    MongoCursor cursor = (MongoCursor) resource.getContents().get(0);
    Iterator<EObject> iterator = cursor.iterator();
    assertThat(iterator, is(notNullValue()));

    assertTrue(iterator.hasNext());
    TargetObject actualObject = (TargetObject) iterator.next();
    pendingTargets.remove(actualObject.getSingleAttribute());

    assertTrue(iterator.hasNext());
    actualObject = (TargetObject) iterator.next();
    pendingTargets.remove(actualObject.getSingleAttribute());

    assertTrue(iterator.hasNext());
    actualObject = (TargetObject) iterator.next();
    pendingTargets.remove(actualObject.getSingleAttribute());

    assertFalse(iterator.hasNext());
    assertTrue(pendingTargets.isEmpty());
  }
View Full Code Here

  {
    // Setup : Create a target object and ObjectId for the ID

    ObjectId id = new ObjectId();

    TargetObject targetObject = ModelFactory.eINSTANCE.createTargetObject();
    targetObject.setSingleAttribute("junit");

    // Test : Store the object to MongoDB

    saveObject(targetObject, createObjectURI(targetObject.eClass(), id), null);

    // Verify : Check that the object was stored correctly, and that is has the ID we specified.

    TargetObject actual = EChecker.checkObject(targetObject, createResourceSet());
    assertThat(EChecker.getID(actual), is(id.toString()));
  }
View Full Code Here

  {
    // Setup : Create a target object and arbitrary string for the ID

    String id = "ID";

    TargetObject targetObject = ModelFactory.eINSTANCE.createTargetObject();
    targetObject.setSingleAttribute("junit");

    // Test : Store the object to MongoDB

    saveObject(targetObject, createObjectURI(targetObject.eClass(), id), null);

    // Verify : Check that the object was stored correctly, and that is has the ID we specified.

    TargetObject actual = EChecker.checkObject(targetObject, createResourceSet());
    assertThat(EChecker.getID(actual), is(id));
  }
View Full Code Here

  @Test
  public void testTargetObjectWithWriteConcern() throws IOException
  {
    // Setup : Create a target object

    TargetObject targetObject = ModelFactory.eINSTANCE.createTargetObject();
    targetObject.setSingleAttribute("junit");

    // Test : Store the object to MongoDB

    HashMap<String, Object> options = new HashMap<String, Object>(1);
    options.put(Options.OPTION_WRITE_CONCERN, WriteConcern.SAFE);

    saveObject(targetObject, createCollectionURI(targetObject.eClass()), options);

    // Verify : Check that the object was stored correctly.

    EChecker.checkObject(targetObject, createResourceSet());
  }
View Full Code Here

  {
    // Setup : Create a target object and arbitrary string for the ID

    String id = "ID";

    TargetObject targetObject = ModelFactory.eINSTANCE.createTargetObject();
    targetObject.setSingleAttribute("junit");

    saveObject(targetObject, createObjectURI(targetObject.eClass(), id), null);

    // Test : Update the object and store it back to MongoDB

    targetObject.setSingleAttribute("updated");
    targetObject.eResource().save(null);

    // Verify : Check that the object was stored correctly, and that is has the ID we specified.

    TargetObject actual = EChecker.checkObject(targetObject, createResourceSet());
    assertThat(EChecker.getID(actual), is(id));
  }
View Full Code Here

  @Test
  public void testDeleteTargetObject() throws IOException
  {
    // Setup : Create and store the target object

    TargetObject targetObject = ModelFactory.eINSTANCE.createTargetObject();
    targetObject.setSingleAttribute("junit");
    saveObject(targetObject);

    // Test : Delete the target object

    targetObject.eResource().delete(null);

    // Verify : The target object was deleted

    assertThat(getCollection(targetObject.eClass()).getCount(), is(0L));
  }
View Full Code Here

    Resource resource = resourceSet.createResource(createCollectionURI(ModelPackage.Literals.TARGET_OBJECT));
    int numberTargets = 10;

    for (int i = 0; i < numberTargets; i++)
    {
      TargetObject targetObject = ModelFactory.eINSTANCE.createTargetObject();
      targetObject.setSingleAttribute("junit " + i);
      resource.getContents().add(targetObject);
    }

    // Test : Store the objects in the database

    resource.save(null);

    // Verify : The resouce should contain a Result with proxies to all of the stored objects

    assertThat(resource.getContents().size(), is(1));
    assertThat(resource.getContents().get(0), is(instanceOf(ECollection.class)));

    ECollection eCollection = (ECollection) resource.getContents().get(0);
    assertThat(eCollection.getValues().size(), is(numberTargets));

    for (int i = 0; i < numberTargets; i++)
    {
      assertThat(eCollection.getValues().get(i), is(instanceOf(TargetObject.class)));
      TargetObject targetObject = (TargetObject) eCollection.getValues().get(i);
      assertThat(targetObject.getSingleAttribute(), is("junit " + i));
    }
  }
View Full Code Here

  @Test
  public void testXMIRepresentation() throws IOException
  {
    ResourceSet resourceSet = createResourceSet();

    TargetObject targetObject1 = ModelFactory.eINSTANCE.createTargetObject();
    targetObject1.setSingleAttribute("one");
    saveObject(resourceSet, targetObject1);

    TargetObject targetObject2 = ModelFactory.eINSTANCE.createTargetObject();
    targetObject2.setSingleAttribute("two");
    saveObject(resourceSet, targetObject2);

    PrimaryObject primaryObject = ModelFactory.eINSTANCE.createPrimaryObject();
    primaryObject.setName("junit");
    primaryObject.getMultipleContainmentReferenceProxies().add(targetObject1);
View Full Code Here

  @Test
  public void testBinaryRepresentation() throws IOException
  {
    ResourceSet resourceSet = createResourceSet();

    TargetObject targetObject1 = ModelFactory.eINSTANCE.createTargetObject();
    targetObject1.setSingleAttribute("one");
    saveObject(resourceSet, targetObject1);

    TargetObject targetObject2 = ModelFactory.eINSTANCE.createTargetObject();
    targetObject2.setSingleAttribute("two");
    saveObject(resourceSet, targetObject2);

    PrimaryObject primaryObject = ModelFactory.eINSTANCE.createPrimaryObject();
    primaryObject.setName("junit");
    primaryObject.getMultipleContainmentReferenceProxies().add(targetObject1);
View Full Code Here

TOP

Related Classes of org.eclipselabs.mongoemf.junit.model.TargetObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.