|
@@ -0,0 +1,97 @@
|
|
|
+package com.iohao.mmo.person.entity;
|
|
|
+
|
|
|
+import com.hy.corecode.idgen.WFGIdGenerator;
|
|
|
+import com.iohao.mmo.person.service.PersonService;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
+import org.springframework.data.mongodb.core.query.Query;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+import static org.springframework.data.mongodb.core.query.Criteria.where;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author 渔民小镇
|
|
|
+ * @date 2023-07-26
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@SpringBootTest
|
|
|
+public class PersonTest {
|
|
|
+ @Resource
|
|
|
+ MongoTemplate mongoTemplate;
|
|
|
+ @Autowired
|
|
|
+ private WFGIdGenerator idGenerator;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void test0() {
|
|
|
+ for (int i = 0; i < 10; i++) {
|
|
|
+ long next = idGenerator.next();
|
|
|
+ log.info("next : {}", next);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void test1() {
|
|
|
+
|
|
|
+ BasicsProperty person = new BasicsProperty();
|
|
|
+ person.setId("abc");
|
|
|
+ person.setAnger(1);
|
|
|
+
|
|
|
+ mongoTemplate.save(person);
|
|
|
+
|
|
|
+
|
|
|
+ Criteria criteria = where("anger").is(1);
|
|
|
+ Query query = new Query(criteria);
|
|
|
+
|
|
|
+ List<BasicsProperty> entities = mongoTemplate.find(query, BasicsProperty.class);
|
|
|
+
|
|
|
+ log.info("students : {}", entities.size());
|
|
|
+ for (BasicsProperty person1 : entities) {
|
|
|
+ System.out.println(person1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testPerson() {
|
|
|
+ BasicsProperty basicProperty = PersonService.getBasicPropertyTemp();
|
|
|
+
|
|
|
+ Hero hero = getHero(basicProperty);
|
|
|
+
|
|
|
+ String heroId = "hero-1";
|
|
|
+ Hero byId = mongoTemplate.findById(heroId, Hero.class);
|
|
|
+ Objects.requireNonNull(byId);
|
|
|
+ BasicsProperty plus = basicProperty.plus(byId.getBasicsProperty());
|
|
|
+
|
|
|
+ Hero currentHero = new Hero();
|
|
|
+ currentHero.setId(heroId);
|
|
|
+ currentHero.setBasicsProperty(plus);
|
|
|
+
|
|
|
+ Person person = new Person();
|
|
|
+ person.setId("person-1");
|
|
|
+ person.setBasicProperty(basicProperty);
|
|
|
+ person.setHeroes(List.of(hero));
|
|
|
+ person.setCurrentHero(currentHero);
|
|
|
+
|
|
|
+ mongoTemplate.save(person);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Hero getHero(BasicsProperty basicProperty) {
|
|
|
+ Hero hero = new Hero();
|
|
|
+ hero.setId("hero-1");
|
|
|
+ hero.setBasicsProperty(basicProperty);
|
|
|
+ mongoTemplate.save(hero);
|
|
|
+
|
|
|
+ Hero hero2 = new Hero();
|
|
|
+ hero2.setId("hero-2");
|
|
|
+ hero2.setBasicsProperty(basicProperty);
|
|
|
+ mongoTemplate.save(hero2);
|
|
|
+ return hero;
|
|
|
+ }
|
|
|
+}
|