Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e1415027d0682a9dd2e1d47c4ddc8b0fe10f470f (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
/*
 * Copyright (c) 2008-2012 Eike Stepper (Berlin, 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:
 *    Victor Roldan Betancort - initial API and implementation
 *    Simon McDuff - maintenance
 *    Eike Stepper - maintenance
 */
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.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOURIUtil;
import org.eclipse.emf.cdo.view.CDOView;

/**
 * CDOView.hasResource() is not aware of deleted resources
 * <p>
 * See bug 248117
 * 
 * @author Victor Roldan Betancort
 */
public class Bugzilla_248124_Test extends AbstractCDOTest
{
  public void testBugzilla_248124_hasResourceWithCommit() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction1 = session.openTransaction();

    String resourcePath = "/test1";
    CDOResource res = transaction1.createResource(getResourcePath(resourcePath));
    res.getContents().add(getModel1Factory().createCompany());
    res.getContents().add(getModel1Factory().createCompany());
    res.getContents().add(getModel1Factory().createCompany());
    transaction1.commit();
    res.delete(null);
    transaction1.commit();
    CDOView view = session.openView();
    assertEquals(false, view.hasResource(getResourcePath(resourcePath)));
  }

  public void testBugzilla_248124_getResourceWithCommit() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction1 = session.openTransaction();

    String resourcePath = "/test1";
    CDOResource res = transaction1.createResource(getResourcePath(resourcePath));
    res.getContents().add(getModel1Factory().createCompany());
    res.getContents().add(getModel1Factory().createCompany());
    res.getContents().add(getModel1Factory().createCompany());
    transaction1.commit();
    res.delete(null);
    transaction1.commit();
    CDOView view = session.openView();

    try
    {
      view.getResourceSet().getResource(CDOURIUtil.createResourceURI(view, getResourcePath(resourcePath)), true);
      fail("Exception expected");
    }
    catch (Exception expected)
    {
    }

    CDOView transaction2 = session.openTransaction();

    try
    {
      transaction2.getResourceSet()
          .getResource(CDOURIUtil.createResourceURI(view, getResourcePath(resourcePath)), true);
      fail("RuntimeException expected");
    }
    catch (RuntimeException expected)
    {
    }
  }

  public void testBugzilla_248124_hasResourceWithoutCommit() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction1 = session.openTransaction();

    String resourcePath = "/test1";
    CDOResource res = transaction1.createResource(getResourcePath(resourcePath));
    res.getContents().add(getModel1Factory().createCompany());
    res.getContents().add(getModel1Factory().createCompany());
    res.getContents().add(getModel1Factory().createCompany());

    res.delete(null);
    assertEquals(false, transaction1.hasResource(getResourcePath(resourcePath)));
  }

  public void testBugzilla_248124_getResourceWithoutCommit() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction1 = session.openTransaction();

    String resourcePath = "/test1";
    CDOResource res = transaction1.createResource(getResourcePath(resourcePath));
    res.getContents().add(getModel1Factory().createCompany());
    res.getContents().add(getModel1Factory().createCompany());
    res.getContents().add(getModel1Factory().createCompany());
    transaction1.commit();
    res.delete(null);

    try
    {
      transaction1.getResourceSet().getResource(
          CDOURIUtil.createResourceURI(transaction1, getResourcePath(resourcePath)), true);
      fail("RuntimeException expected");
    }
    catch (RuntimeException expected)
    {
    }
  }
}

Back to the top