Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 67edc607edce000f863ae6bc7e13b2e51876506c (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/***************************************************************************
 * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
 * 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;

import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.tests.legacy.Hook;
import org.eclipse.emf.cdo.tests.legacy.LegacyFactory;
import org.eclipse.emf.cdo.util.CDOUtil;

import org.eclipse.emf.internal.cdo.CDOLegacyWrapper;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;

/**
 * @author Eike Stepper
 */
public class LegacyTest extends AbstractCDOTest
{
  public void testCommit() throws Exception
  {
    Hook hook = createHook("Mr. Hook");

    CDOSession session = openLegacySession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource("/test1");
    resource.getContents().add(hook);
    transaction.commit();

    CDOObject cdoHook = CDOUtil.getCDOObject(hook);
    assertEquals(false, CDOLegacyWrapper.isLegacyProxy(cdoHook));
    assertEquals(CDOState.CLEAN, cdoHook.cdoState());
    assertEquals(CDOState.CLEAN, resource.cdoState());
    session.close();
  }

  public void testLoad() throws Exception
  {
    {
      CDOSession session = openLegacySession();
      CDOTransaction transaction = session.openTransaction();
      CDOResource resource = transaction.createResource("/test1");
      resource.getContents().add(createHook("Mr. Hook"));
      transaction.commit();
      session.close();
    }

    CDOSession session = openLegacySession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.getResource("/test1");
    EList<EObject> contents = resource.getContents();

    Hook hook = (Hook)contents.get(0);
    CDOObject cdoHook = CDOUtil.getCDOObject(hook);
    assertEquals(false, CDOLegacyWrapper.isLegacyProxy(cdoHook));
    assertEquals(CDOState.CLEAN, cdoHook.cdoState());
    assertEquals(CDOState.CLEAN, resource.cdoState());

    String name = hook.getName();
    assertEquals("Mr. Hook", name);
    assertEquals(CDOState.CLEAN, cdoHook.cdoState());
    session.close();
  }

  public void testReferences() throws Exception
  {
    {
      Hook hook = createHook("Mr. Hook");
      EList<Hook> children = hook.getChildren();
      children.add(createHook("Hook 1"));
      children.add(createHook("Hook 2"));
      children.add(createHook("Hook 3"));

      CDOSession session = openLegacySession();
      CDOTransaction transaction = session.openTransaction();
      CDOResource resource = transaction.createResource("/test1");
      resource.getContents().add(hook);
      transaction.commit();

      CDOObject cdoHook = CDOUtil.getCDOObject(hook);
      assertEquals(false, CDOLegacyWrapper.isLegacyProxy(cdoHook));
      assertEquals(CDOState.CLEAN, cdoHook.cdoState());
      assertEquals(CDOState.CLEAN, resource.cdoState());
      session.close();
    }

    CDOSession session = openLegacySession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.getResource("/test1");
    EList<EObject> contents = resource.getContents();

    Hook hook = (Hook)contents.get(0);
    assertNotProxy(hook);

    CDOObject cdoHook = CDOUtil.getCDOObject(hook);
    assertEquals(false, CDOLegacyWrapper.isLegacyProxy(cdoHook));
    assertEquals(CDOState.CLEAN, cdoHook.cdoState());

    EList<Hook> children = hook.getChildren();
    assertEquals(CDOState.CLEAN, cdoHook.cdoState());
    assertEquals(CDOState.CLEAN, resource.cdoState());

    // TODO Should the proxyURI be null for CLEAN?
    // Hook h = children.get(0);
    // URI proxyURI = ((InternalEObject)h).eProxyURI();
    // assertEquals(null,proxyURI);

    int size = children.size();
    assertEquals(3, size);
    assertEquals(CDOState.CLEAN, cdoHook.cdoState());

    Hook h0 = children.get(0);
    assertNotProxy(h0);
    assertEquals("Hook 1", h0.getName());
    assertEquals(CDOState.CLEAN, CDOUtil.getCDOObject(h0).cdoState());

    Hook h1 = children.get(1);
    assertNotProxy(h1);
    assertEquals("Hook 2", h1.getName());
    assertEquals(CDOState.CLEAN, CDOUtil.getCDOObject(h1).cdoState());

    Hook h2 = children.get(2);
    assertNotProxy(h2);
    assertEquals("Hook 3", h2.getName());
    assertEquals(CDOState.CLEAN, CDOUtil.getCDOObject(h2).cdoState());
    session.close();
  }

  private Hook createHook(String name)
  {
    Hook hook = LegacyFactory.eINSTANCE.createHook();
    hook.setName(name);
    return hook;
  }
}

Back to the top