|
1 | 1 | package io.github.thunderz99.cosmos; |
2 | 2 |
|
3 | | -import java.util.ArrayList; |
4 | | -import java.util.List; |
5 | | -import java.util.Map; |
6 | | -import java.util.Set; |
| 3 | +import java.util.*; |
7 | 4 |
|
8 | 5 | import com.azure.cosmos.models.SqlParameter; |
9 | 6 | import io.github.thunderz99.cosmos.condition.Aggregate; |
@@ -80,18 +77,56 @@ void create_and_read_should_work() throws Exception { |
80 | 77 | db.delete(conName, user.id, "Users"); |
81 | 78 | } |
82 | 79 |
|
83 | | - } |
| 80 | + } |
84 | 81 |
|
85 | | - @Test |
86 | | - void create_should_throw_when_data_is_null() throws Exception { |
| 82 | + public static class SheetContent { |
| 83 | + public String id; |
| 84 | + public LinkedHashMap<String, Object> contents; |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + void upsert_and_read_integer_should_work() throws Exception { |
| 89 | + |
| 90 | + var sheet = new LinkedHashMap<String, Object>(); |
| 91 | + var id = "upsert_and_read_integer_should_work001"; |
| 92 | + sheet.put("id", id); |
| 93 | + var contents = new LinkedHashMap<String, Object>(); |
| 94 | + contents.put("name", "Tom"); |
| 95 | + contents.put("age", 20); |
| 96 | + sheet.put("contents", contents); |
| 97 | + |
| 98 | + try { |
| 99 | + var upserted = db.upsert(conName, sheet, "Sheets"); |
| 100 | + var map = upserted.toObject(LinkedHashMap.class); |
| 101 | + |
| 102 | + var upsertedContents = (Map<String, Object>) map.get("contents"); |
| 103 | + |
| 104 | + assertThat(map).containsEntry("id", id); |
| 105 | + assertThat(upsertedContents).containsEntry("name", "Tom"); |
| 106 | + assertThat(upsertedContents).containsEntry("age", 20); |
| 107 | + |
| 108 | + var read = db.read(conName, id, "Sheets").toObject(SheetContent.class); |
| 109 | + assertThat(read.contents).containsEntry("name", "Tom"); |
| 110 | + assertThat(read.contents).containsEntry("age", 20); |
| 111 | + |
| 112 | + |
| 113 | + } finally { |
| 114 | + db.delete(conName, id, "Sheets"); |
| 115 | + } |
| 116 | + |
| 117 | + } |
| 118 | + |
| 119 | + |
| 120 | + @Test |
| 121 | + void create_should_throw_when_data_is_null() throws Exception { |
87 | 122 | User user = null; |
88 | 123 | assertThatThrownBy(() -> db.create(conName, user, "Users")).isInstanceOf(IllegalArgumentException.class) |
89 | 124 | .hasMessageContaining("create data UnitTest Users"); |
90 | 125 |
|
91 | 126 | } |
92 | 127 |
|
93 | | - @Test |
94 | | - void update_should_work() throws Exception { |
| 128 | + @Test |
| 129 | + void update_should_work() throws Exception { |
95 | 130 |
|
96 | 131 | var user = new User("unittest_update_01", "first01", "last01"); |
97 | 132 | db.delete(conName, user.id, "Users"); |
|
0 commit comments