Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ed858a38050d79136c0a9adfc4770cd8d1896169 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (c) 2011, 2012 Eike Stepper (Loehne, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.model3.ClassWithIDAttribute;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;

import java.io.ByteArrayOutputStream;
import java.util.Map;

/**
 * @author Eike Stepper
 */
public class Bugzilla_339908_Test extends AbstractCDOTest
{
  public void testIDAttribute() throws Exception
  {
    String[] ids = new String[10];

    {
      CDOSession session = openSession();
      CDOTransaction transaction = session.openTransaction();
      CDOResource resource = transaction.createResource(getResourcePath("test"));

      for (int i = 0; i < ids.length; i++)
      {
        String id = java.util.UUID.randomUUID().toString();
        ids[i] = id;

        ClassWithIDAttribute object = getModel3Factory().createClassWithIDAttribute();
        object.setId(id);
        resource.getContents().add(object);
      }

      transaction.commit();

      clearCache(getRepository().getRevisionManager());
    }

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.getResource(getResourcePath("test"));

    int i = 0;
    EList<EObject> contents = resource.getContents();
    for (EObject object : contents)
    {
      assertEquals(ids[i], ((ClassWithIDAttribute)object).getId());
      assertEquals(ids[i], EcoreUtil.getID(object));
      ++i;
    }
  }

  @SuppressWarnings("unused")
  private String createXMI() throws Exception
  {
    ResourceSet resourceSet = new ResourceSetImpl();
    Map<String, Object> map = resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap();
    map.put("xmi", new XMIResourceFactoryImpl());
    Resource xmiResource = resourceSet.createResource(URI.createURI("test.xmi"));

    for (int i = 0; i < 10; i++)
    {
      ClassWithIDAttribute object = getModel3Factory().createClassWithIDAttribute();
      object.setId(java.util.UUID.randomUUID().toString());
      xmiResource.getContents().add(object);
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    xmiResource.save(baos, null);

    String xmi = baos.toString();
    System.out.println(xmi);
    return xmi;
  }
}

Back to the top