Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: bd31c6e5cf56478c304ece11a3e1385a51b72be4 (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
/*
 * Copyright (c) 2015 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.eresource.CDOResourceFactory;
import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
import org.eclipse.emf.cdo.server.IRepository.Props;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.config.ISessionConfig;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig;
import org.eclipse.emf.cdo.util.CDOURIData;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Factory.Registry;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;

import org.junit.Assert;

/**
 * Bug 437817: "Only one view per repository..." RuntimeException using connection aware URI
 * 
 * @author Esteban Dugueperoux
 */
@Requires(ISessionConfig.CAPABILITY_NET4J_TCP)
public class Bugzilla_437817_Test extends AbstractCDOTest
{

  public void testConnectionAwareURITwiceCDOResourceCreation() throws Exception
  {
    getRepository();

    Registry registry = Resource.Factory.Registry.INSTANCE;
    registry.getProtocolToFactoryMap().put(CDONet4jUtil.PROTOCOL_TCP, CDOResourceFactory.INSTANCE);

    try
    {
      ResourceSet resourceSet = new ResourceSetImpl();

      URI sharedResource1URI = URI.createURI(
          CDONet4jUtil.PROTOCOL_TCP + "://localhost:2036/" + RepositoryConfig.REPOSITORY_NAME
              + getResourcePath("/sharedResource1")).appendQuery(CDOURIData.TRANSACTIONAL_PARAMETER + "=true");
      URI sharedResource2URI = URI.createURI(
          CDONet4jUtil.PROTOCOL_TCP + "://localhost:2036/" + RepositoryConfig.REPOSITORY_NAME
              + getResourcePath("/sharedResource2")).appendQuery(CDOURIData.TRANSACTIONAL_PARAMETER + "=true");
      Resource sharedResource1 = resourceSet.createResource(sharedResource1URI);
      Resource sharedResource2 = resourceSet.createResource(sharedResource2URI);

      Assert.assertTrue(sharedResource1 instanceof CDOResource);
      Assert.assertTrue(sharedResource2 instanceof CDOResource);
      CDOResource sharedCDOResource1 = (CDOResource)sharedResource1;
      CDOResource sharedCDOResource2 = (CDOResource)sharedResource2;
      assertEquals(
          "Both CDOResources should have the same CDOView as they have the same ResourceSet and use content from the same repository",
          sharedCDOResource1.cdoView(), sharedCDOResource2.cdoView());
    }
    finally
    {
      registry.getProtocolToFactoryMap().remove(CDONet4jUtil.PROTOCOL_TCP);
    }
  }

  public void testConnectionAwareURITwiceCDOResourceCreationWithUUID() throws Exception
  {
    getTestProperties().put(Props.OVERRIDE_UUID, RepositoryConfig.REPOSITORY_NAME + "UUID");
    testConnectionAwareURITwiceCDOResourceCreation();
  }

}

Back to the top