]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/deny/DenyTest1.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / write / deny / DenyTest1.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.write.deny;
13
14 import java.util.UUID;
15
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.VirtualGraph;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.common.request.WriteRequest;
21 import org.simantics.db.common.request.WriteResultRequest;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.service.VirtualGraphSupport;
24 import org.simantics.db.testing.base.WriteReadTest;
25
26 public class DenyTest1 extends WriteReadTest {
27         
28         Resource other;
29         
30         @Override
31         protected void write(WriteGraph graph) throws DatabaseException {
32                 
33                 VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);
34                 VirtualGraph virt = support.getMemoryPersistent(UUID.randomUUID().toString());
35
36                 final Resource other2 = graph.syncRequest(new WriteResultRequest<Resource>(virt) {
37
38                         @Override
39                         public Resource perform(WriteGraph graph) throws DatabaseException {
40                                 Resource other = graph.newResource();
41                                 graph.claim(written, L0.ConsistsOf, L0.PartOf, other);
42                                 return other;
43                         }
44                         
45                 });
46
47                 Resource single = graph.getSingleObject(written, L0.ConsistsOf);
48                 assertNotNull(single);
49                 assertTrue(single.equals(other2));
50                 
51                 other = graph.newResource();
52                 graph.claim(written, L0.ConsistsOf, L0.PartOf, other);
53
54                 graph.syncRequest(new WriteRequest() {
55
56                         @Override
57                         public void perform(WriteGraph graph) throws DatabaseException {
58                                 graph.deny(written, L0.ConsistsOf, L0.PartOf, other2);
59                         }
60                         
61                 });
62                 
63         }
64         
65         @Override
66         protected void read(ReadGraph graph) throws DatabaseException {
67                 
68                 Resource single = graph.getPossibleObject(written, L0.ConsistsOf);
69                 assertNotNull(single);
70                 assertTrue(single.equals(other));
71                 
72         }
73         
74 }