Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 不能调用";org.apache.commons.logging.Log.isDebugEnabled();因为";这是“logger”;是空的_Spring Boot_Testcase - Fatal编程技术网

Spring boot 不能调用";org.apache.commons.logging.Log.isDebugEnabled();因为";这是“logger”;是空的

Spring boot 不能调用";org.apache.commons.logging.Log.isDebugEnabled();因为";这是“logger”;是空的,spring-boot,testcase,Spring Boot,Testcase,这里是我用来保存数据的代码,我使用@Transactional我想写测试这个方法,但失败了 @事务性(rollbackFor=BadRequestException.class,传播=propagation.REQUIRES\u NEW) public void saveContent(ContentAbstractEntity内容){ mongoTemplate.setSessionSynchronization(SessionSynchronization.ALWAYS); Transact

这里是我用来保存数据的代码,我使用@Transactional我想写测试这个方法,但失败了

@事务性(rollbackFor=BadRequestException.class,传播=propagation.REQUIRES\u NEW) public void saveContent(ContentAbstractEntity内容){

mongoTemplate.setSessionSynchronization(SessionSynchronization.ALWAYS);
TransactionBody txnBody=
(() -> {
ContentAbstractEntity ContentAbstractEntity=contentRepository.save(内容);
if(学习内容的内容实例){
LearningContent LearningContent=(LearningContent)内容;
Long tutorCountInDB=tutorRepository.countBy_idIn(learningContent.getTutorIds());
如果(!countryRepository.existsbysyll\u成绩\u科目\u id(
learningContent.getSubjectId())
抛出新的BadRequestException(“未找到主题”);
Topic Topic=topicRepository.findBy_id(learningContent.getTopicId());
如果(topic==null)抛出新的BadRequestException(“未找到主题”);
罗列莱索尼德=
topic.getLessons().stream().map(m->m.get_id()).collect(Collectors.toList());
布尔Alllesson性别歧视=
learningContent.getLessonIds().stream().allMatch(a->lessonIds.contains(a));
如果(!allLessonsExists)抛出新的BadRequestException(“课程不匹配”);
if(tutorCountInDB!=learningContent.getTutorIds().size()){
抛出新的BadRequestException(“导师不匹配”);
}
}
返回“插入成功”;
});
MongoClient=MongoClient.create(uri);
ClientSession ClientSession=client.startSession();
试一试{
clientSession.withTransaction(txnBody);
}捕获(BADE异常){
抛出新的BadRequestException(例如getMessage());
}最后{
clientSession.close();
}
}

我试图为上述代码编写测试,但我发现它返回了错误

@试验 void when nsavecontent()引发异常{

ContentAbstractDto contentAbstractDto = new ContentAbstractDto();

ContentAbstractEntity content = learningVideo();

if (contentAbstractDto instanceof LearningDocsDto) {

  LearningDocsDto learninfDocsDto = (LearningDocsDto) contentAbstractDto;

  // ToDo when a Doc Saves and Assessment saves
}

when(contentRepository.save(content)).thenReturn(content);

if (content instanceof LearningContent) {

  LearningContent learningContent = (LearningContent) content;

  Long tutorCountInDB = (long) learningContent.getTutorIds().size();
  when(tutorRepository.countBy_idIn(learningContent.getTutorIds())).thenReturn(tutorCountInDB);

  when(subjectRepository.existsBy_id(learningContent.getSubjectId())).thenReturn(true);

  Topic topic = getTopic();
  when(topicRepository.findBy_id(learningContent.getTopicId())).thenReturn(topic);

  if (topic == null) throw new BadRequestException("Topic is not found");

  List<ObjectId> lessonIds =
      topic.getLessons().stream().map(m -> m.get_id()).collect(Collectors.toList());

  boolean allLessonsExists =
      learningContent.getLessonIds().stream().allMatch(a -> lessonIds.contains(a));

  if (!allLessonsExists) throw new BadRequestException("Lessons are not mismatched");

  if (tutorCountInDB != learningContent.getTutorIds().size()) {
    throw new BadRequestException("Tutors are not matched");
  }
  
  
  


}
ContentAbstractDto ContentAbstractDto=新ContentAbstractDto();
ContentAbstractEntity content=learningVideo();
if(contentAbstractDto到实例learningdocsdo){
LearningDocsDto LearningDocsDto=(LearningDocsDto)contentAbstractDto;
//单据保存和评估保存时的ToDo
}
当(contentRepository.save(content)),然后返回(content);
if(学习内容的内容实例){
LearningContent LearningContent=(LearningContent)内容;
Long tutorCountInDB=(Long)learningContent.gettuorids().size();
当(tutorRepository.countBy_idIn(learningContent.getTutorIds())。然后返回(tutorCountInDB);
当(subjectRepository.existsBy_id(learningContent.getSubjectId())。然后返回(true);
Topic=getTopic();
when(topicRepository.findBy_id(learningContent.getTopicId())。然后返回(topic);
如果(topic==null)抛出新的BadRequestException(“未找到主题”);
罗列莱索尼德=
topic.getLessons().stream().map(m->m.get_id()).collect(Collectors.toList());
布尔Alllesson性别歧视=
learningContent.getLessonIds().stream().allMatch(a->lessonIds.contains(a));
如果(!allLessonsExists)抛出新的BadRequestException(“课程不匹配”);
if(tutorCountInDB!=learningContent.getTutorIds().size()){
抛出新的BadRequestException(“导师不匹配”);
}
}
ContentAbstractDto contentAbstractDto = new ContentAbstractDto();

ContentAbstractEntity content = learningVideo();

if (contentAbstractDto instanceof LearningDocsDto) {

  LearningDocsDto learninfDocsDto = (LearningDocsDto) contentAbstractDto;

  // ToDo when a Doc Saves and Assessment saves
}

when(contentRepository.save(content)).thenReturn(content);

if (content instanceof LearningContent) {

  LearningContent learningContent = (LearningContent) content;

  Long tutorCountInDB = (long) learningContent.getTutorIds().size();
  when(tutorRepository.countBy_idIn(learningContent.getTutorIds())).thenReturn(tutorCountInDB);

  when(subjectRepository.existsBy_id(learningContent.getSubjectId())).thenReturn(true);

  Topic topic = getTopic();
  when(topicRepository.findBy_id(learningContent.getTopicId())).thenReturn(topic);

  if (topic == null) throw new BadRequestException("Topic is not found");

  List<ObjectId> lessonIds =
      topic.getLessons().stream().map(m -> m.get_id()).collect(Collectors.toList());

  boolean allLessonsExists =
      learningContent.getLessonIds().stream().allMatch(a -> lessonIds.contains(a));

  if (!allLessonsExists) throw new BadRequestException("Lessons are not mismatched");

  if (tutorCountInDB != learningContent.getTutorIds().size()) {
    throw new BadRequestException("Tutors are not matched");
  }
  
  
  


}