Skip to content

Commit 772cbfb

Browse files
committed
chore: fix unit
1 parent 14f22eb commit 772cbfb

1 file changed

Lines changed: 44 additions & 9 deletions

File tree

src/test/java/io/github/thunderz99/cosmos/CosmosDatabaseTest.java

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package io.github.thunderz99.cosmos;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
import java.util.Map;
6-
import java.util.Set;
3+
import java.util.*;
74

85
import com.azure.cosmos.models.SqlParameter;
96
import io.github.thunderz99.cosmos.condition.Aggregate;
@@ -80,18 +77,56 @@ void create_and_read_should_work() throws Exception {
8077
db.delete(conName, user.id, "Users");
8178
}
8279

83-
}
80+
}
8481

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 {
87122
User user = null;
88123
assertThatThrownBy(() -> db.create(conName, user, "Users")).isInstanceOf(IllegalArgumentException.class)
89124
.hasMessageContaining("create data UnitTest Users");
90125

91126
}
92127

93-
@Test
94-
void update_should_work() throws Exception {
128+
@Test
129+
void update_should_work() throws Exception {
95130

96131
var user = new User("unittest_update_01", "first01", "last01");
97132
db.delete(conName, user.id, "Users");

0 commit comments

Comments
 (0)