Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3ea4f4a01b6e160b8f60e7630a8b35d9dce65884 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
 * Copyright (c) 2004 - 2010 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:
 *    Stefan Winkler - initial API and implementation
 *    Eike Stepper - maintenance
 */
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.Company;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
import org.eclipse.emf.cdo.tests.model1.PurchaseOrder;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOView;

import java.util.GregorianCalendar;

/**
 * @author Stefan Winkler
 */
public class DBStoreTest extends AbstractCDOTest
{
  // Bug 256462
  public void testInsertNull() throws Exception
  {
    CDOSession s = openModel1Session();
    CDOTransaction t = s.openTransaction();
    CDOResource r = t.createResource("/dbStoreTest");

    Company c = Model1Factory.eINSTANCE.createCompany();
    c.setName(null);
    r.getContents().add(c);

    t.commit();
  }

  public void testStoreStringTrailingBackslash()
  {
    storeRetrieve("foobar\\");
  }

  public void testStoreStringContainingBackslash()
  {
    storeRetrieve("foo\\bar");
  }

  public void testStoreStringTrailingSingleQuote()
  {
    storeRetrieve("foobar'");
  }

  public void testStoreStringContainingSingleQuote()
  {
    storeRetrieve("foo'bar");
  }

  public void testStoreStringTrailingDoubleQuote()
  {
    storeRetrieve("foobar\"");
  }

  public void testStoreStringContainingDoubleQuote()
  {
    storeRetrieve("foo\"bar");
  }

  public void testStoreStringTrailingTwoSingleQuote()
  {
    storeRetrieve("foobar''");
  }

  public void testStoreStringContainingTwoSingleQuote()
  {
    storeRetrieve("foo''bar");
  }

  private void storeRetrieve(String s)
  {
    CDOSession session = openModel1Session();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.getOrCreateResource("/test");

    Company e = Model1Factory.eINSTANCE.createCompany();
    e.setName(s);
    // this escapes only the string!
    // resulting string only contains one backslash

    resource.getContents().add(e);
    transaction.commit();

    transaction.close();
    session.close();
    clearCache(getRepository().getRevisionManager());

    session = openModel1Session();
    CDOView view = session.openView();
    resource = view.getResource("/test");

    assertEquals(1, resource.getContents().size());
    e = (Company)resource.getContents().get(0);
    assertEquals(s, e.getName());
  }

  // Bug 217255
  public void testStoreDate()
  {
    CDOSession session = openModel1Session();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.getOrCreateResource("/test");

    PurchaseOrder o = Model1Factory.eINSTANCE.createPurchaseOrder();
    o.setDate(new GregorianCalendar(2008, 11, 24, 12, 34, 56).getTime());

    resource.getContents().add(o);
    transaction.commit();

    transaction.close();
    session.close();
    clearCache(getRepository().getRevisionManager());

    session = openModel1Session();
    CDOView view = session.openView();
    resource = view.getResource("/test");

    assertEquals(1, resource.getContents().size());
    o = (PurchaseOrder)resource.getContents().get(0);
    assertEquals(new GregorianCalendar(2008, 11, 24, 12, 34, 56).getTime(), o.getDate());
  }
}

Back to the top