Search in sources :

Example 11 with KvDocument

use of com.torodb.kvdocument.values.KvDocument in project torodb by torodb.

the class R2DTranslatorTest method readMultipleDocument.

/*
   * Document 1 { "name" : "jero" } Document 2 { "name" : "john" }
   */
@Test
public void readMultipleDocument() {
    MetaDocPartBuilder builder = new MetaDocPartBuilder(rootRef);
    builder.addMetaField("name", "name_s", FieldType.STRING);
    builder.addRow(1, null, 1, null, "jero");
    builder.addRow(2, null, 2, null, "john");
    MockedDocPartResult root = builder.getResultSet();
    List<DocPartResult> lst = Collections.singletonList(root);
    R2DTranslator r2dTranslator = new R2DTranslatorImpl();
    ToroDocument[] readedDocuments = r2dTranslator.translate(lst.iterator()).toArray(new ToroDocument[0]);
    assertEquals(2, readedDocuments.length);
    KvDocument doc1 = readedDocuments[0].getRoot();
    assertEquals("jero", doc1.get("name").getValue());
    KvDocument doc2 = readedDocuments[1].getRoot();
    assertEquals("john", doc2.get("name").getValue());
}
Also used : KvDocument(com.torodb.kvdocument.values.KvDocument) R2DTranslator(com.torodb.core.d2r.R2DTranslator) ToroDocument(com.torodb.core.document.ToroDocument) DocPartResult(com.torodb.core.d2r.DocPartResult) Test(org.junit.Test)

Example 12 with KvDocument

use of com.torodb.kvdocument.values.KvDocument in project torodb by torodb.

the class TestConvertJson method parseMultipleFields.

@Test
public void parseMultipleFields() {
    KvDocument doc = parser.createFromResource("MultipleFields.json");
    assertEquals(2, doc.size());
    assertTrue(doc.containsKey("name"));
    assertEquals("John", doc.get("name").getValue());
    assertTrue(doc.containsKey("surename"));
    assertEquals("Snow", doc.get("surename").getValue());
}
Also used : KvDocument(com.torodb.kvdocument.values.KvDocument) Test(org.junit.Test)

Example 13 with KvDocument

use of com.torodb.kvdocument.values.KvDocument in project torodb by torodb.

the class TestConvertJson method parseArrayWithScalar.

@Test
public void parseArrayWithScalar() {
    KvDocument doc = parser.createFromResource("ArrayWithScalar.json");
    KvArray array = (KvArray) doc.get("day");
    assertEquals(1, array.size());
    KvValue<?> kvValue = array.get(0);
    assertEquals("monday", kvValue.getValue());
}
Also used : KvDocument(com.torodb.kvdocument.values.KvDocument) KvArray(com.torodb.kvdocument.values.KvArray) Test(org.junit.Test)

Example 14 with KvDocument

use of com.torodb.kvdocument.values.KvDocument in project torodb by torodb.

the class TestConvertJson method parseArrayWithDocument.

@Test
public void parseArrayWithDocument() {
    KvDocument doc = parser.createFromResource("ArrayWithDocument.json");
    KvArray array = (KvArray) doc.get("department");
    assertEquals(1, array.size());
    assertTrue(array.get(0) instanceof KvDocument);
}
Also used : KvDocument(com.torodb.kvdocument.values.KvDocument) KvArray(com.torodb.kvdocument.values.KvArray) Test(org.junit.Test)

Example 15 with KvDocument

use of com.torodb.kvdocument.values.KvDocument in project torodb by torodb.

the class TestConvertJson method parseDate.

@Test
public void parseDate() {
    KvDocument doc = parser.createFromResource("DateField.json");
    assertTrue(doc.containsKey("creation"));
    KvValue<?> creation = doc.get("creation");
    assertTrue(creation instanceof KvInstant);
}
Also used : KvDocument(com.torodb.kvdocument.values.KvDocument) KvInstant(com.torodb.kvdocument.values.KvInstant) Test(org.junit.Test)

Aggregations

KvDocument (com.torodb.kvdocument.values.KvDocument)30 Test (org.junit.Test)23 ToroDocument (com.torodb.core.document.ToroDocument)10 DocPartResult (com.torodb.core.d2r.DocPartResult)9 R2DTranslator (com.torodb.core.d2r.R2DTranslator)9 KvArray (com.torodb.kvdocument.values.KvArray)8 TableRef (com.torodb.core.TableRef)4 UserException (com.torodb.core.exceptions.user.UserException)3 Status (com.eightkdata.mongowp.Status)2 BsonDocument (com.eightkdata.mongowp.bson.BsonDocument)2 CollectionData (com.torodb.core.d2r.CollectionData)2 D2RTranslator (com.torodb.core.d2r.D2RTranslator)2 AttributeReference (com.torodb.core.language.AttributeReference)2 ObjectKey (com.torodb.core.language.AttributeReference.ObjectKey)2 MongoWpConverter (com.torodb.kvdocument.conversion.mongowp.MongoWpConverter)2 KvValue (com.torodb.kvdocument.values.KvValue)2 MapKvDocument (com.torodb.kvdocument.values.heap.MapKvDocument)2 UpdatedToroDocumentBuilder (com.torodb.mongodb.language.update.UpdatedToroDocumentBuilder)2 IndexFieldInfo (com.torodb.torod.IndexFieldInfo)2 ErrorCode (com.eightkdata.mongowp.ErrorCode)1