Package org.eclipselabs.mongoemf.junit.model

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


  @Test
  public void testFeatureMap() throws IOException
  {
    // Setup : Create a primary object and two target objects for the feature map.

    PrimaryObject primaryObject = ModelFactory.eINSTANCE.createPrimaryObject();
    primaryObject.setName("junit");

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

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

    primaryObject.getFeatureMapReferenceType1().add(targetObject1);
    primaryObject.getFeatureMapReferenceType2().add(targetObject2);

    assertThat(primaryObject.getFeatureMapReferenceCollection().size(), is(2));
    assertThat(primaryObject.getFeatureMapReferenceType1().size(), is(1));
    assertThat(primaryObject.getFeatureMapReferenceType2().size(), is(1));

    // Test : Store the object to MongDB

    saveObject(primaryObject);

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

    HashSet<EStructuralFeature> excludeFeatures = new HashSet<EStructuralFeature>(1);
    excludeFeatures.add(ModelPackage.Literals.PRIMARY_OBJECT__FEATURE_MAP_REFERENCE_COLLECTION);
    PrimaryObject actual = EChecker.checkObject(primaryObject, excludeFeatures, createResourceSet());
    assertThat(actual.getFeatureMapReferenceCollection().size(), is(2));
  }
View Full Code Here


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

    PrimaryObject primaryObject = ModelFactory.eINSTANCE.createPrimaryObject();
    primaryObject.setName("junit");

    {
      TargetObject targetObject = ModelFactory.eINSTANCE.createTargetObject();
      targetObject.setSingleAttribute("one");
      saveObject(resourceSet, targetObject);
      primaryObject.setSingleContainmentReferenceProxies(targetObject);
      targetObject.eResource().unload();
    }
    {
      TargetObject targetObject = ModelFactory.eINSTANCE.createTargetObject();
      targetObject.setSingleAttribute("one");
      saveObject(resourceSet, targetObject);
      primaryObject.setSingleNonContainmentReference(targetObject);
      targetObject.eResource().unload();
    }
    {
      TargetObject targetObject = ModelFactory.eINSTANCE.createTargetObject();
      targetObject.setSingleAttribute("one");
      saveObject(resourceSet, targetObject);
      primaryObject.getMultipleContainmentReferenceProxies().add(targetObject);
      targetObject.eResource().unload();
    }
    {
      TargetObject targetObject = ModelFactory.eINSTANCE.createTargetObject();
      targetObject.setSingleAttribute("one");
      saveObject(resourceSet, targetObject);
      primaryObject.getMultipleNonContainmentReference().add(targetObject);
      targetObject.eResource().unload();
    }
    {
      PrimaryObject targetObject = ModelFactory.eINSTANCE.createPrimaryObject();
      targetObject.setName("target");
      saveObject(targetObject);
      primaryObject.setContainmentReferenceSameCollectioin(targetObject);
      targetObject.eResource().unload();
    }

    saveObject(resourceSet, primaryObject);

    // Verify that proxies aren't resolved as a result of saving to Mongo DB.
    //
    assertTrue(((EObject) primaryObject.eGet(ModelPackage.Literals.PRIMARY_OBJECT__CONTAINMENT_REFERENCE_SAME_COLLECTIOIN, false)).eIsProxy());
    assertTrue(((EObject) primaryObject.eGet(ModelPackage.Literals.PRIMARY_OBJECT__SINGLE_CONTAINMENT_REFERENCE_PROXIES, false)).eIsProxy());
    assertTrue(((EObject) primaryObject.eGet(ModelPackage.Literals.PRIMARY_OBJECT__SINGLE_NON_CONTAINMENT_REFERENCE, false)).eIsProxy());
    assertTrue(((EObject) ((InternalEList<?>) primaryObject.eGet(ModelPackage.Literals.PRIMARY_OBJECT__MULTIPLE_CONTAINMENT_REFERENCE_PROXIES)).basicGet(0)).eIsProxy());
    assertTrue(((EObject) ((InternalEList<?>) primaryObject.eGet(ModelPackage.Literals.PRIMARY_OBJECT__MULTIPLE_NON_CONTAINMENT_REFERENCE)).basicGet(0)).eIsProxy());

    ResourceSet resourceSet2 = createResourceSet();
    resourceSet2.getLoadOptions().put(Options.OPTION_PROXY_ATTRIBUTES, Boolean.TRUE);
    Resource primaryResource2 = resourceSet2.getResource(primaryObject.eResource().getURI(), true);
    PrimaryObject primaryObject2 = (PrimaryObject) primaryResource2.getContents().get(0);

    // Verify that proxies are created when loading from Mongo DB.
    //
    assertTrue(((EObject) primaryObject2.eGet(ModelPackage.Literals.PRIMARY_OBJECT__SINGLE_CONTAINMENT_REFERENCE_PROXIES, false)).eIsProxy());
    assertTrue(((EObject) primaryObject2.eGet(ModelPackage.Literals.PRIMARY_OBJECT__SINGLE_NON_CONTAINMENT_REFERENCE, false)).eIsProxy());
    assertTrue(((EObject) ((InternalEList<?>) primaryObject2.eGet(ModelPackage.Literals.PRIMARY_OBJECT__MULTIPLE_CONTAINMENT_REFERENCE_PROXIES)).basicGet(0)).eIsProxy());
    assertTrue(((EObject) ((InternalEList<?>) primaryObject2.eGet(ModelPackage.Literals.PRIMARY_OBJECT__MULTIPLE_NON_CONTAINMENT_REFERENCE)).basicGet(0)).eIsProxy());

    // Verify that those proxies have attributes populated as expected for OPTION_PROXY_ATTRIBUTES
    //
    assertThat(((TargetObject) ((EObject) primaryObject2.eGet(ModelPackage.Literals.PRIMARY_OBJECT__SINGLE_CONTAINMENT_REFERENCE_PROXIES, false))).getSingleAttribute(), is("one"));
    assertThat(((TargetObject) ((EObject) primaryObject2.eGet(ModelPackage.Literals.PRIMARY_OBJECT__SINGLE_NON_CONTAINMENT_REFERENCE, false))).getSingleAttribute(), is("one"));
    assertThat(((TargetObject) ((EObject) ((InternalEList<?>) primaryObject2.eGet(ModelPackage.Literals.PRIMARY_OBJECT__MULTIPLE_CONTAINMENT_REFERENCE_PROXIES)).basicGet(0))).getSingleAttribute(),
        is("one"));
    assertThat(((TargetObject) ((EObject) ((InternalEList<?>) primaryObject2.eGet(ModelPackage.Literals.PRIMARY_OBJECT__MULTIPLE_NON_CONTAINMENT_REFERENCE)).basicGet(0))).getSingleAttribute(),
        is("one"));

    // Save it to XML, again with proxy attributes.
    //
    Map<Object, Object> options = new HashMap<Object, Object>();
    options.put(XMLResource.OPTION_PROXY_ATTRIBUTES, Boolean.TRUE);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    primaryResource2.save(out, options);

    ResourceSet resourceSet3 = createResourceSet();
    Resource primaryResource3 = resourceSet3.createResource(primaryObject.eResource().getURI());
    primaryResource3.load(new ByteArrayInputStream(out.toByteArray()), null);

    // Verify that proxies are created when loading from XML.
    //
    PrimaryObject primaryObject3 = (PrimaryObject) primaryResource3.getContents().get(0);
    assertTrue(((EObject) primaryObject3.eGet(ModelPackage.Literals.PRIMARY_OBJECT__SINGLE_CONTAINMENT_REFERENCE_PROXIES, false)).eIsProxy());
    assertTrue(((EObject) primaryObject3.eGet(ModelPackage.Literals.PRIMARY_OBJECT__SINGLE_NON_CONTAINMENT_REFERENCE, false)).eIsProxy());
    assertTrue(((EObject) ((InternalEList<?>) primaryObject3.eGet(ModelPackage.Literals.PRIMARY_OBJECT__MULTIPLE_CONTAINMENT_REFERENCE_PROXIES)).basicGet(0)).eIsProxy());
    assertTrue(((EObject) ((InternalEList<?>) primaryObject3.eGet(ModelPackage.Literals.PRIMARY_OBJECT__MULTIPLE_NON_CONTAINMENT_REFERENCE)).basicGet(0)).eIsProxy());

    // Verify that those proxies have attributes populated as expected for OPTION_PROXY_ATTRIBUTES.
    //
    assertThat(((TargetObject) ((EObject) primaryObject3.eGet(ModelPackage.Literals.PRIMARY_OBJECT__SINGLE_CONTAINMENT_REFERENCE_PROXIES, false))).getSingleAttribute(), is("one"));
    assertThat(((TargetObject) ((EObject) primaryObject3.eGet(ModelPackage.Literals.PRIMARY_OBJECT__SINGLE_NON_CONTAINMENT_REFERENCE, false))).getSingleAttribute(), is("one"));
    assertThat(((TargetObject) ((EObject) ((InternalEList<?>) primaryObject3.eGet(ModelPackage.Literals.PRIMARY_OBJECT__MULTIPLE_CONTAINMENT_REFERENCE_PROXIES)).basicGet(0))).getSingleAttribute(),
        is("one"));
    assertThat(((TargetObject) ((EObject) ((InternalEList<?>) primaryObject3.eGet(ModelPackage.Literals.PRIMARY_OBJECT__MULTIPLE_NON_CONTAINMENT_REFERENCE)).basicGet(0))).getSingleAttribute(),
        is("one"));
  }
View Full Code Here

  public void testQueryIDAttribute() throws IOException
  {
    // Setup : Create a primary object with the ID attribute set

    String id = "Attribute ID";
    PrimaryObject primaryObject = org.eclipselabs.mongoemf.junit.model.ModelFactory.eINSTANCE.createPrimaryObject();
    primaryObject.setIdAttribute(id);

    // Test : Store the object with the option to use the ID attribute as the MongoDB _id

    HashMap<String, Object> options = new HashMap<String, Object>();
    options.put(Options.OPTION_USE_ID_ATTRIBUTE_AS_PRIMARY_KEY, Boolean.TRUE);

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

    // Verify : Check that the object was stored correctly

    ResourceSet resourceSet = createResourceSet();
    Resource resource = resourceSet.getResource(createQueryURI(org.eclipselabs.mongoemf.junit.model.ModelPackage.Literals.PRIMARY_OBJECT, "idAttribute=='" + id + "'"), true);
View Full Code Here

  }

  @Test
  public void testUnsettableAttributeSetToNULL() throws IOException
  {
    PrimaryObject primaryObject = ModelFactory.eINSTANCE.createPrimaryObject();
    primaryObject.setUnsettableAttribute(null);
    saveObject(primaryObject);

    ResourceSet resourceSet = createResourceSet();
    Resource resource = resourceSet.getResource(primaryObject.eResource().getURI(), true);
    PrimaryObject object = (PrimaryObject) resource.getContents().get(0);
    assertTrue(object.isSetUnsettableAttribute());
    assertThat(object.getUnsettableAttribute(), is(nullValue()));
  }
View Full Code Here

  }

  @Test
  public void testUnsettableAttributeUnset() throws IOException
  {
    PrimaryObject primaryObject = ModelFactory.eINSTANCE.createPrimaryObject();
    saveObject(primaryObject);

    ResourceSet resourceSet = createResourceSet();
    Resource resource = resourceSet.getResource(primaryObject.eResource().getURI(), true);
    PrimaryObject object = (PrimaryObject) resource.getContents().get(0);
    assertFalse(object.isSetUnsettableAttribute());
  }
View Full Code Here

  }

  @Test
  public void testUnsettableAttributeWithNonNullDefaultSetToNULL() throws IOException
  {
    PrimaryObject primaryObject = ModelFactory.eINSTANCE.createPrimaryObject();
    primaryObject.setUnsettableAttributeWithNonNullDefault(null);
    saveObject(primaryObject);

    ResourceSet resourceSet = createResourceSet();
    Resource resource = resourceSet.getResource(primaryObject.eResource().getURI(), true);
    PrimaryObject object = (PrimaryObject) resource.getContents().get(0);
    assertFalse(object.isSetUnsettableAttribute());
    assertThat(object.getUnsettableAttribute(), is(nullValue()));
  }
View Full Code Here

  }

  @Test
  public void testUnsettableAttributeWithNonNullDefaultUnset() throws IOException
  {
    PrimaryObject primaryObject = ModelFactory.eINSTANCE.createPrimaryObject();
    saveObject(primaryObject);

    ResourceSet resourceSet = createResourceSet();
    Resource resource = resourceSet.getResource(primaryObject.eResource().getURI(), true);
    PrimaryObject object = (PrimaryObject) resource.getContents().get(0);
    assertFalse(object.isSetUnsettableAttribute());
  }
View Full Code Here

  @Test
  public void testFeatureMap() throws IOException
  {
    // Setup : Create a primary object and two attributes for the feature map.

    PrimaryObject primaryObject = ModelFactory.eINSTANCE.createPrimaryObject();
    primaryObject.setName("junit");

    primaryObject.getFeatureMapAttributeType1().add("Hello");
    primaryObject.getFeatureMapAttributeType2().add("World");

    assertThat(primaryObject.getFeatureMapAttributeCollection().size(), is(2));
    assertThat(primaryObject.getFeatureMapAttributeType1().size(), is(1));
    assertThat(primaryObject.getFeatureMapAttributeType2().size(), is(1));

    // Test : Store the object to MongDB

    saveObject(primaryObject);

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

    HashSet<EStructuralFeature> excludeFeatures = new HashSet<EStructuralFeature>(1);
    excludeFeatures.add(ModelPackage.Literals.PRIMARY_OBJECT__FEATURE_MAP_ATTRIBUTE_COLLECTION);
    PrimaryObject actual = EChecker.checkObject(primaryObject, excludeFeatures, createResourceSet());
    assertThat(actual.getFeatureMapAttributeCollection().size(), is(2));
  }
View Full Code Here

  @Test
  public void testPrimaryObject() throws IOException
  {
    // Setup : Create a primary object with only the name attribute set

    PrimaryObject primaryObject = ModelFactory.eINSTANCE.createPrimaryObject();
    primaryObject.setName("junit");

    // Test : Store the object to MongoDB

    saveObject(primaryObject);
View Full Code Here

  }

  @Test
  public void testUnsettableReferenceSetToNULL() throws IOException
  {
    PrimaryObject primaryObject = ModelFactory.eINSTANCE.createPrimaryObject();
    primaryObject.setUnsettableReference(null);
    saveObject(primaryObject);

    ResourceSet resourceSet = createResourceSet();
    Resource resource = resourceSet.getResource(primaryObject.eResource().getURI(), true);
    PrimaryObject object = (PrimaryObject) resource.getContents().get(0);
    assertTrue(object.isSetUnsettableReference());
    assertThat(object.getUnsettableReference(), is(nullValue()));
  }
View Full Code Here

TOP

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

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.