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

import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.model1.Address;
import org.eclipse.emf.cdo.tests.model2.SpecialPurchaseOrder;
import org.eclipse.emf.cdo.tests.util.TestAdapter;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.view.CDOAdapterPolicy;
import org.eclipse.emf.cdo.view.CDOView;

import org.eclipse.emf.common.notify.Notification;

import java.util.Date;

/**
 *
 */
public class OldValueNotificationTest extends AbstractCDOTest
{
  public void testSameSession() throws Exception
  {
    final CDOSession session = openSession();
    final CDOTransaction transaction = session.openTransaction();
    transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);

    Address address1 = getModel1Factory().createAddress();
    address1.setCity("Basel");
    address1.setStreet("Turnerstrasse 39");
    address1.setName("Michael Szediwy");

    SpecialPurchaseOrder order = getModel2Factory().createSpecialPurchaseOrder();
    order.setDate(new Date());
    order.setShippingAddress(address1);

    final CDOResource resourceA = transaction.createResource(getResourcePath("/test1"));
    resourceA.getContents().add(order);
    transaction.commit();

    final TestAdapter adapter = new TestAdapter()
    {
      @Override
      public void notifyChanged(Notification notification)
      {
        super.notifyChanged(notification);
      }
    };

    final CDOView view = session.openView();
    SpecialPurchaseOrder roOrder = view.getObject(order);
    System.out.println(CDOUtil.getCDOObject(roOrder).cdoState());
    roOrder.eAdapters().add(adapter);

    Address address2 = getModel1Factory().createAddress();
    address2.setCity("Basel2");
    address2.setStreet("Turnerstrasse 392");
    address2.setName("Michael Szediwy2");

    order.setShippingAddress(address2);

    transaction.commit();

    new PollingTimeOuter()
    {
      @Override
      protected boolean successful()
      {
        // Commit notifications from the same session always have full deltas
        Notification[] notifications = adapter.getNotifications();
        return notifications.length == 1;
      }
    }.assertNoTimeOut();

    Notification[] notifications = adapter.getNotifications();
    notifications[0].getOldValue();
  }
}

Back to the top