Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d264e6f8369507998621d0fa5b845cc220c4b7f3 (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
/*
 * Copyright (c) 2013 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:
 *    Esteban Dugueperoux - initial API and implementation
 *    Christian W. Damus (CEA) - add test case for view closure
 */
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.model1.Company;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.impl.AdapterImpl;

/**
 * Bug 412686: NPE when removing/adding an adapter after CDO view closed.
 *
 * @author Esteban Dugueperoux
 */
public class Bugzilla_381395_Test extends AbstractCDOTest
{
  public void testAdapterRemoveAfterCDOServerShutdown() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/my/resource"));

    Company company = getModel1Factory().createCompany();
    resource.getContents().add(company);
    transaction.commit();

    Adapter adapter = new AdapterImpl();
    company.eAdapters().add(adapter);

    getScenario().tearDown();

    // Used to throw an NPE without the fix.
    company.eAdapters().remove(adapter);
  }

  public void testAdapterRemoveAfterCDOViewClosed() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/my/resource"));

    Company company = getModel1Factory().createCompany();
    resource.getContents().add(company);
    transaction.commit();

    Adapter adapter = new AdapterImpl();
    company.eAdapters().add(adapter);

    transaction.close();

    // Used to throw an NPE without the fix.
    company.eAdapters().remove(adapter);
  }

  public void testAdapterAddAfterCDOServerShutdown() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/my/resource"));

    Company company = getModel1Factory().createCompany();
    resource.getContents().add(company);
    transaction.commit();

    getScenario().tearDown();

    // Used to throw an NPE without the fix.
    company.eAdapters().add(new AdapterImpl());
  }

  public void testAdapterAddAfterCDOViewClosed() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/my/resource"));

    Company company = getModel1Factory().createCompany();
    resource.getContents().add(company);
    transaction.commit();

    transaction.close();

    // Used to throw an NPE without the fix.
    company.eAdapters().add(new AdapterImpl());
  }
}

Back to the top