]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/listening/QueryResultCompareTest1.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / request / listening / QueryResultCompareTest1.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.api.request.listening;
13
14 import java.util.Collection;
15
16 import org.junit.Test;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.Session;
20 import org.simantics.db.WriteGraph;
21 import org.simantics.db.common.procedure.adapter.ListenerAdapter;
22 import org.simantics.db.common.request.WriteRequest;
23 import org.simantics.db.common.request.WriteResultRequest;
24 import org.simantics.db.exception.DatabaseException;
25 import org.simantics.db.request.Read;
26 import org.simantics.db.testing.base.ExistingDatabaseTest;
27 import org.simantics.layer0.Layer0;
28
29 public class QueryResultCompareTest1 extends ExistingDatabaseTest {
30
31         @Test
32     public void testNullArrayCompare() throws Exception {
33
34         final Session session = getSession();
35
36                 final Resource newResource = getSession().syncRequest(new WriteResultRequest<Resource>() {
37                         @Override
38                         public Resource perform(WriteGraph graph) throws DatabaseException {
39                                 return graph.newResource();
40                         }
41                 });
42         
43         session.syncRequest(new Read<Resource[]>() {
44             @Override
45             public Resource[] perform(ReadGraph graph) throws DatabaseException {
46                 Layer0 b = Layer0.getInstance(graph);
47                 Collection<Resource> coll = graph.getObjects(newResource, b.ConsistsOf);
48                 if(coll.isEmpty()) return null;
49                 else return coll.toArray(Resource.NONE); 
50             }
51         }, new ListenerAdapter<Resource[]>() {
52             @Override
53             public boolean isDisposed() {
54                 return false;
55             }
56         });
57
58                 getSession().syncRequest(new WriteRequest() {
59                         @Override
60                         public void perform(WriteGraph graph) throws DatabaseException {
61                             Layer0 b = Layer0.getInstance(graph);
62                             graph.claim(newResource, b.ConsistsOf, graph.newResource());
63                         }
64                 });
65         
66     }
67 }