Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2d8a5cce71b361f7e5e85c2d1ff94f2f7480dafd (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
/*
 * 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:
 *    Simon McDuff - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOQuery;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * CDOEList::toArray not implemented
 * <p>
 * See bug 260756
 * 
 * @author Simon McDuff
 */
public class Bugzilla_260756_Test extends AbstractCDOTest
{
  private static final String LANGUAGE = "TEST";

  @Requires("MEM")
  public void testBugzilla_260756() throws Exception
  {
    Set<Object> objects = new HashSet<Object>();
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();

    CDOResource resource1 = transaction.createResource(getResourcePath("/test1"));
    objects.add(resource1);
    Company company1 = getModel1Factory().createCompany();
    Category category1 = getModel1Factory().createCategory();
    Category category2 = getModel1Factory().createCategory();

    resource1.getContents().add(company1);
    company1.getCategories().add(category1);
    company1.getCategories().add(category2);

    objects.add(category1);
    objects.add(category2);

    company1.setName("TEST");

    transaction.commit();
    System.out.println(category1.eClass().getEPackage().getNsURI());

    CDOQuery cdoQuery = transaction.createQuery(LANGUAGE, "QUERYSTRING");
    cdoQuery.setParameter("context", getModel1Package().getCategory());

    List<Category> queryResult = cdoQuery.getResult(Category.class);
    assertEquals(2, queryResult.size());
    assertEquals(true, objects.contains(queryResult.get(0)));
    assertEquals(true, objects.contains(queryResult.get(1)));

    Object[] array1 = queryResult.toArray();
    Category[] arrayOfCategory = queryResult.toArray(new Category[queryResult.size()]);
    assertEquals(2, array1.length);
    assertEquals(queryResult.get(0), array1[0]);
    assertEquals(queryResult.get(1), array1[1]);

    assertEquals(2, arrayOfCategory.length);
    assertEquals(queryResult.get(0), arrayOfCategory[0]);
    assertEquals(queryResult.get(1), arrayOfCategory[1]);

    transaction.close();
    session.close();
  }
}

Back to the top