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
|
/*
* Copyright (c) 2012, 2015, 2016 Esteban Dugueperoux 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.CDOResourceFactory;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.common.util.URI;
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.util.Collections;
/**
* ResourceSet.getResource(URI,true) fails when called several times. See bug 395999.
*
* @author Esteban Dugueperoux
*/
public class Bugzilla_395999_Test extends AbstractCDOTest
{
public void testTwiceGetCDOResourceOnResourceSetImpl() throws Exception
{
URI uri = URI.createURI(getURIPrefix() + "/" + getRepository().getName() + getResourcePath("/res1") + "?transactional=true");
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(getURIProtocol(), CDOResourceFactory.INSTANCE);
Resource resource = resourceSet.createResource(uri);
resource.save(Collections.emptyMap());
loadTwiceAndSaveResource(uri);
}
public void testTwiceGetXMIResourceOnResourceSetImpl() throws Exception
{
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("model1", new XMIResourceFactoryImpl());
URI uri = URI.createFileURI(createTempFile(getName(), ".model1").getCanonicalPath());
Resource resource = resourceSet.createResource(uri);
resource.save(Collections.emptyMap());
loadTwiceAndSaveResource(uri);
}
private void loadTwiceAndSaveResource(URI resourceURI) throws Exception
{
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(getURIProtocol(), CDOResourceFactory.INSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("model1", new XMIResourceFactoryImpl());
Resource resource = resourceSet.getResource(resourceURI, true);
assertEquals("The ResourceSetImpl should returns the same Resource as in the first call", resource, resourceSet.getResource(resourceURI, true));
resource.save(Collections.emptyMap());
}
}
|