mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-05-30 10:50:42 +00:00
mongo-db-example updated
This commit is contained in:
-38
@@ -1,7 +1,6 @@
|
||||
package ru.otus.example.mongodbdemo.repositories.withlisteners;
|
||||
|
||||
import lombok.val;
|
||||
import org.bson.Document;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -11,7 +10,6 @@ import ru.otus.example.mongodbdemo.model.Knowledge;
|
||||
import ru.otus.example.mongodbdemo.model.Student;
|
||||
import ru.otus.example.mongodbdemo.repositories.AbstractRepositoryTest;
|
||||
import ru.otus.example.mongodbdemo.repositories.StudentRepository;
|
||||
import ru.otus.example.mongodbdemo.utils.RawResultPrinter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -24,9 +22,6 @@ class StudentRepositoryWithListenersTest extends AbstractRepositoryTest {
|
||||
@Autowired
|
||||
private StudentRepository studentRepository;
|
||||
|
||||
@Autowired
|
||||
private RawResultPrinter rawResultPrinter;
|
||||
|
||||
@DisplayName("должен корректно сохранять студента с отсутствующими в БД знаниями")
|
||||
@Test
|
||||
void shouldCorrectSaveStudentWithNewKnowledge() {
|
||||
@@ -43,37 +38,4 @@ class StudentRepositoryWithListenersTest extends AbstractRepositoryTest {
|
||||
List<Knowledge> knowledgeList = studentRepository.getStudentExperienceById(student.getId());
|
||||
assertThat(knowledgeList).containsExactlyInAnyOrderElementsOf(student.getExperience());
|
||||
}
|
||||
|
||||
@DisplayName("напечатать все стадии агрегации для getStudentExperienceById")
|
||||
@Test
|
||||
void shouldPrintAggregationStagesForHetStudentExperienceByIdMethod() {
|
||||
val student = studentRepository.findAll().get(0);
|
||||
for (int i = 0; i <= 7; i++) {
|
||||
val rawResults = studentRepository.getStudentExperienceByIdAggregationRawResultForStage(
|
||||
student.getId(), i);
|
||||
printStageDesc(i, rawResults);
|
||||
}
|
||||
}
|
||||
|
||||
private void printStageDesc(int stageNum, Document stageRawResults) {
|
||||
String[] operationsAsStr = new String[]{
|
||||
"match(Criteria.where(\"id\").is(studentId)",
|
||||
"unwind(\"experience\")"
|
||||
, "project().andExclude(\"_id\").and(valueOfToArray(\"experience\")).as(\"experience_map\")"
|
||||
, "project().and(\"experience_map\").arrayElementAt(1).as(\"experience_id_map\")"
|
||||
, "project().and(\"experience_id_map.v\").as(\"experience_id\")"
|
||||
, "lookup(\"knowledge\", \"experience_id\", \"_id\", \"experience\")"
|
||||
, "unwind(\"experience\")"
|
||||
, "project().and(\"experience._id\").as(\"_id\").and(\"experience.name\").as(\"name\")"
|
||||
};
|
||||
|
||||
System.out.printf("Stage: %d\n\n", stageNum);
|
||||
for (int j = 0; j <= stageNum; j++) {
|
||||
System.out.println(operationsAsStr[j]);
|
||||
}
|
||||
System.out.println();
|
||||
rawResultPrinter.prettyPrintRawResult(stageRawResults);
|
||||
System.out.println("\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ spring:
|
||||
mongodb:
|
||||
port: 0
|
||||
database: test
|
||||
#host: localhost
|
||||
host: localhost
|
||||
#port: 27017
|
||||
#database: awesomeMongo
|
||||
|
||||
|
||||
Reference in New Issue
Block a user