Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5e311f39767b4f4d6b1dad87630d305b843c562f (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
/***************************************************************************
 * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
 * 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:
 *    Eike Stepper - initial API and implementation
 **************************************************************************/
package org.eclipse.emf.cdo.tests.defs;

import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.cdodefs.CDOSessionDef;
import org.eclipse.emf.cdo.cdodefs.CDOTransactionDef;
import org.eclipse.emf.cdo.cdodefs.util.CDODefsUtil;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
import org.eclipse.emf.cdo.tests.config.impl.SessionConfig;
import org.eclipse.emf.cdo.tests.model1.Customer;

import org.eclipse.net4j.net4jdefs.util.Net4jDefsUtil;

/**
 * @author Eike Stepper
 */
public class CDOTransactionDefImplTest extends AbstractCDOTest
{
  private static final String TEST_RESOURCE = "/test1";

  public void testTransactionIsReused()
  {

    CDOTransactionDef transactionDef = CDODefsUtil.createCDOTransactionDef( //
        CDODefsUtil.createSessionDef( //
            IRepositoryConfig.REPOSITORY_NAME, //
            CDODefsUtil.createEagerPackageRegistryDef(), //
            Net4jDefsUtil.createTCPConnectorDef(SessionConfig.TCP.CONNECTOR_HOST)));

    CDOTransaction thisCdoTransactionReference = (CDOTransaction)transactionDef.getInstance();
    CDOTransaction thatCdoTransactionReference = (CDOTransaction)transactionDef.getInstance();

    assertTrue(thisCdoTransactionReference == thatCdoTransactionReference);

    thisCdoTransactionReference.getSession().close();
  }

  public void testClosedTransactionIsRecreated()
  {
    CDOTransactionDef cdoTransactionDef = CDODefsUtil.createCDOTransactionDef( //
        CDODefsUtil.createSessionDef( //
            IRepositoryConfig.REPOSITORY_NAME, //
            CDODefsUtil.createEagerPackageRegistryDef(), //
            Net4jDefsUtil.createTCPConnectorDef(SessionConfig.TCP.CONNECTOR_HOST)));
    CDOTransaction transactionInstance = (CDOTransaction)cdoTransactionDef.getInstance();
    transactionInstance.close();
    CDOTransaction newTransactionInstance = (CDOTransaction)cdoTransactionDef.getInstance();

    assertTrue(newTransactionInstance != transactionInstance);

    newTransactionInstance.getSession().close();
  }

  public void testCreateAndReadModel()
  {
    CDOSessionDef cdoSessionDef = //
    CDODefsUtil.createSessionDef( //
        IRepositoryConfig.REPOSITORY_NAME, //
        CDODefsUtil.createEagerPackageRegistryDef(), //
        Net4jDefsUtil.createTCPConnectorDef(SessionConfig.TCP.CONNECTOR_HOST));

    CDOTransactionDef transactionDef = CDODefsUtil.createCDOTransactionDef(cdoSessionDef);
    CDOTransaction transaction = (CDOTransaction)transactionDef.getInstance();

    transaction.getSession().getPackageRegistry().putEPackage(getModel1Package());
    CDOResource resource = transaction.createResource(TEST_RESOURCE);
    Customer customer = getModel1Factory().createCustomer();
    resource.getContents().add(customer);
    transaction.commit();

    CDOResource resourceFetched = transaction.getResource(TEST_RESOURCE);
    assertTrue(resourceFetched.eContents().contains(customer));

    transaction.getSession().close();
  }
}

Back to the top