]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/write/claimLiteral/WriteUntypedL0Literal.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 / claimLiteral / WriteUntypedL0Literal.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.claimLiteral;
13
14 import org.junit.Test;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.Session;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.request.ReadRequest;
20 import org.simantics.db.common.request.WriteResultRequest;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.testing.base.ExistingDatabaseTest;
23 import org.simantics.layer0.Layer0;
24
25
26 public class WriteUntypedL0Literal extends ExistingDatabaseTest {
27         
28         @Test
29         public void test() throws Exception {
30                 
31                 Session session = getSession();
32
33                 final Resource literal = session.syncRequest(new WriteResultRequest<Resource>() {
34
35                         @Override
36                         public Resource perform(WriteGraph graph) throws DatabaseException {
37                                 
38                                 Resource literal = graph.newResource();
39                                 Layer0 b = Layer0.getInstance(graph);
40                                 graph.claimLiteral(literal, b.HasProperty, new String("test"));
41                                 return literal;
42                                 
43                         }
44                         
45                 });
46                 
47                 session.syncRequest(new ReadRequest() {
48                         
49                         @Override
50                         public void run(ReadGraph graph) throws DatabaseException {
51                             Layer0 b = Layer0.getInstance(graph);
52                                 String s = graph.getRelatedValue(literal, b.HasProperty);
53                                 assert(s != null);
54                                 assert(s.equals("test"));
55                                 
56                         }
57                         
58                 });
59                 
60         }
61
62 }