Skip to content

Commit e5926ea

Browse files
committed
Added more test cases
1 parent 483eb16 commit e5926ea

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

document-store/src/test/java/org/hypertrace/core/documentstore/JSONDocumentTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import java.io.IOException;
56
import java.util.Map;
67
import org.junit.jupiter.api.Assertions;
78
import org.junit.jupiter.api.Test;
@@ -106,4 +107,36 @@ public void testToStringMethod() throws Exception {
106107
// toString should return the same as toJson
107108
Assertions.assertEquals(document.toJson(), document.toString());
108109
}
110+
111+
@Test
112+
public void testJsonNodeConstructors() throws Exception {
113+
JsonNode node = mapper.createObjectNode().put("test", "value");
114+
115+
// Test JsonNode constructor without DocumentType
116+
JSONDocument doc1 = new JSONDocument(node);
117+
Assertions.assertEquals(DocumentType.NESTED, doc1.getDocumentType());
118+
119+
// Test JsonNode constructor with DocumentType
120+
JSONDocument doc2 = new JSONDocument(node, DocumentType.FLAT);
121+
Assertions.assertEquals(DocumentType.FLAT, doc2.getDocumentType());
122+
}
123+
124+
@Test
125+
public void testStringConstructorWithInvalidJson() {
126+
// Test invalid JSON handling
127+
Assertions.assertThrows(
128+
IOException.class,
129+
() -> new JSONDocument("invalid json {"));
130+
131+
Assertions.assertThrows(
132+
IOException.class,
133+
() -> new JSONDocument("invalid json {", DocumentType.FLAT));
134+
}
135+
136+
@Test
137+
public void testNullHandling() throws Exception {
138+
// Test null JsonNode
139+
JSONDocument nullNodeDoc = new JSONDocument((JsonNode) null);
140+
Assertions.assertNotNull(nullNodeDoc.toJson()); // Should handle gracefully
141+
}
109142
}

document-store/src/test/java/org/hypertrace/core/documentstore/postgres/PostgresCollectionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.UUID;
3737
import org.hypertrace.core.documentstore.CloseableIterator;
3838
import org.hypertrace.core.documentstore.Document;
39+
import org.hypertrace.core.documentstore.DocumentType;
3940
import org.hypertrace.core.documentstore.Filter;
4041
import org.hypertrace.core.documentstore.JSONDocument;
4142
import org.hypertrace.core.documentstore.Key;
@@ -186,6 +187,7 @@ void testUpdateAtomicWithFilter() throws IOException, SQLException {
186187

187188
assertTrue(oldDocument.isPresent());
188189
assertEquals(document, oldDocument.get());
190+
assertEquals(DocumentType.NESTED, document.getDocumentType());
189191

190192
verify(mockClient, times(1)).getPooledConnection();
191193
verify(mockConnection, times(1)).prepareStatement(selectQuery);

0 commit comments

Comments
 (0)