Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 73530d1fc43ab7bf3d948a8d1007b4d96fbdae7b (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
/*
 * 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
 */
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.config.IModelConfig;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
import org.eclipse.emf.cdo.tests.model3.NodeA;
import org.eclipse.emf.cdo.tests.model3.NodeE;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;

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.xmi.impl.XMIResourceFactoryImpl;

import java.io.File;
import java.util.Collections;

/**
 * Bug 414949 - ArrayIndexOutOfBoundsException with CDOLegacyWrapper and CDOIDExternal
 * 
 * @author Esteban Dugueperoux
 */
@Requires(IModelConfig.CAPABILITY_LEGACY)
public class Bugzilla_414949_Test extends AbstractCDOTest
{
  private static final String SHARED_RESOURCE_NAME = "sharedResource.aird";

  private static final String LOCAL_RESOURCE_NAME = "localResource.xmi";

  private Resource localResource;

  private Object oldResourceFactory;

  @Override
  protected void doSetUp() throws Exception
  {
    super.doSetUp();
    NodeE dDiagram = getModel3Factory().createNodeE();

    NodeA diagramDescription = getModel3Factory().createNodeA();
    NodeA concernSet = getModel3Factory().createNodeA();
    NodeA concernDescription = getModel3Factory().createNodeA();
    CDOUtil.getCDOObject(concernDescription);
    NodeA filterDescription1 = getModel3Factory().createNodeA();
    CDOUtil.getCDOObject(filterDescription1);
    concernDescription.getOtherNodes().add(filterDescription1);
    diagramDescription.getChildren().add(filterDescription1);
    concernSet.getChildren().add(concernDescription);
    diagramDescription.getChildren().add(concernSet);

    dDiagram.setMainNode(concernDescription);
    dDiagram.getOtherNodes().add(filterDescription1);

    ResourceSet resourceSet = new ResourceSetImpl();
    oldResourceFactory = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*",
        new XMIResourceFactoryImpl());
    String path = new File("./" + LOCAL_RESOURCE_NAME).getCanonicalPath();
    URI localResourceURI = URI.createFileURI(path);
    localResource = resourceSet.createResource(localResourceURI);
    localResource.getContents().add(diagramDescription);
    localResource.save(Collections.emptyMap());

    CDOSession session = openSession();
    CDOTransaction cdoTransaction = session.openTransaction(resourceSet);
    Resource sharedResource = cdoTransaction.createResource(getResourcePath(SHARED_RESOURCE_NAME));
    sharedResource.getContents().add(dDiagram);
    sharedResource.save(Collections.emptyMap());
  }

  public void testEcoreUtilGetURIWithCDOLegacyWrapperBug() throws Exception
  {

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.getResource(getResourcePath(SHARED_RESOURCE_NAME));
    EList<EObject> contents = resource.getContents();
    contents.get(0);
  }

  @Override
  protected void doTearDown() throws Exception
  {
    localResource.delete(Collections.emptyMap());
    localResource = null;
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", oldResourceFactory);
    oldResourceFactory = null;
    super.doTearDown();
  }
}

Back to the top