Skip to content

Commit 0d4e441

Browse files
author
Mark
committed
added document test
1 parent a69782e commit 0d4e441

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb;
22+
23+
import static org.hamcrest.Matchers.is;
24+
import static org.hamcrest.Matchers.notNullValue;
25+
import static org.junit.Assert.assertThat;
26+
27+
import java.util.Map;
28+
29+
import org.junit.Before;
30+
import org.junit.Test;
31+
32+
import com.arangodb.entity.BaseDocument;
33+
import com.arangodb.entity.DocumentCreateEntity;
34+
35+
/**
36+
* @author Mark - mark at arangodb.com
37+
*
38+
*/
39+
public class DocumentTest extends BaseTest {
40+
41+
private static final String COLLECTION_NAME = "collection_test";
42+
private ArangoCollection collection;
43+
44+
@Before
45+
public void setup() {
46+
collection = db.collection(COLLECTION_NAME);
47+
try {
48+
collection.drop();
49+
} catch (final ArangoDBException e) {
50+
}
51+
db.createCollection(COLLECTION_NAME);
52+
}
53+
54+
@SuppressWarnings("unchecked")
55+
@Test
56+
public void insertAsJson() {
57+
//@formatter:off
58+
final String json =
59+
"{"
60+
+ "\"article\": {"
61+
+ "\"artist\": \"PREGARDIEN/RHEINISCHE KANTOREI/DAS\","
62+
+ "\"releaseDate\": \"1970-01-01\","
63+
+ "\"composer\": \"BACH\","
64+
+ "\"format\": \"CD\","
65+
+ "\"vat\": \"H\","
66+
+ "\"carriers\": 1,"
67+
+ "\"label\": \"CAPRICCIO\","
68+
+ "\"title\": \"BACH ST MATTHEW PASSION BWV244\","
69+
+ "\"barcode\": ["
70+
+ "\"4006408600466\""
71+
+ "],"
72+
+ "\"conductor\": \"MAX, H.\""
73+
+ "},"
74+
+ "\"stock\": {"
75+
+ "\"status\": \"RMV\","
76+
+ "\"lastUpdate\": \"2016-11-01 00:00\""
77+
+ "}"
78+
+ "}";
79+
//@formatter:on
80+
final DocumentCreateEntity<String> createResult = collection.insertDocument(json);
81+
final BaseDocument doc = collection.getDocument(createResult.getKey(), BaseDocument.class);
82+
assertThat(doc, is(notNullValue()));
83+
final Object article = doc.getAttribute("article");
84+
assertThat(article, is(notNullValue()));
85+
final Object artist = ((Map<String, Object>) article).get("artist");
86+
assertThat(artist, is(notNullValue()));
87+
assertThat(artist.toString(), is("PREGARDIEN/RHEINISCHE KANTOREI/DAS"));
88+
}
89+
90+
@SuppressWarnings("unchecked")
91+
@Test
92+
public void insertAsBaseDocument() {
93+
final BaseDocument document = new BaseDocument();
94+
{
95+
final BaseDocument article = new BaseDocument();
96+
document.addAttribute("article", article);
97+
article.addAttribute("artist", "PREGARDIEN/RHEINISCHE KANTOREI/DAS");
98+
article.addAttribute("releaseDate", "1970-01-01");
99+
article.addAttribute("composer", "BACH");
100+
article.addAttribute("format", "CD");
101+
article.addAttribute("vat", "H");
102+
article.addAttribute("carriers", 1);
103+
article.addAttribute("label", "CAPRICCIO");
104+
article.addAttribute("title", "BACH ST MATTHEW PASSION BWV244");
105+
article.addAttribute("barcode", new String[] { "4006408600466" });
106+
article.addAttribute("conductor", "MAX, H.");
107+
final BaseDocument stock = new BaseDocument();
108+
document.addAttribute("stock", stock);
109+
stock.addAttribute("status", "RMV");
110+
stock.addAttribute("lastUpdate", "2016-11-01 00:00");
111+
}
112+
final DocumentCreateEntity<BaseDocument> createResult = collection.insertDocument(document);
113+
final BaseDocument doc = collection.getDocument(createResult.getKey(), BaseDocument.class);
114+
assertThat(doc, is(notNullValue()));
115+
final Object article = doc.getAttribute("article");
116+
assertThat(article, is(notNullValue()));
117+
final Object artist = ((Map<String, Object>) article).get("artist");
118+
assertThat(artist, is(notNullValue()));
119+
assertThat(artist.toString(), is("PREGARDIEN/RHEINISCHE KANTOREI/DAS"));
120+
}
121+
122+
}

0 commit comments

Comments
 (0)