@Test public void findRootCategoriesTest() throws Exception { Language language = languageRepository.findByCode("en"); List<CategoryDescription> all = categoryDescriptionRepositoryDao.findRootCategories(language); logger.info("------------------------------------------------------"); for (CategoryDescription p : all) { Assert.assertEquals(0L, p.getCategory().getParentId()); } logger.info("------------------------------------------------------"); }
private UUID createChallengeTemplate( CodingContestGameDto dto, UUID organizationId, Map<String, ByteArrayOutputStream> files) throws IOException { ChallengeTemplate challengeTemplate = challengeTemplateRepository.findOneByCanonicalName(dto.getCanonicalName()); if (challengeTemplate != null) { return challengeTemplate.getId(); } Organization organization = organizationRepository.findOne(organizationId); if (organization == null) { throw new CodunoIllegalArgumentException("organization.invalid"); } if (dto.getPuzzles() .stream() .findAny() .filter(puzzleDto -> puzzleDto.getValidationClass() != null) .isPresent()) { throw new CodunoIllegalArgumentException("ccc.game.structure.unsuported"); } Runner runner = getRunner("/io"); Endpoint taskEndpoint = getEndpoint("CCC general task", "ccc-io-task"); Set<Language> languages = new HashSet<>(languageRepository.findAll()); Duration gameDuration = parseGameDuration(dto.getTimeframe()); challengeTemplate = mapChallengeTemplate(dto, organization, gameDuration); for (PuzzleDto puzzle : dto.getPuzzles()) { Task task = mapTask( puzzle, challengeTemplate, organization, files, gameDuration, runner, taskEndpoint, languages); Map<String, ByteArrayOutputStream> testFiles = null; if (puzzle.getInputFilePath() != null) { testFiles = unzip(files.get(puzzle.getInputFilePath()).toByteArray()); } for (PuzzleTestDto puzzleTest : puzzle.getTests()) { Test test = mapTest(puzzleTest, runner, testFiles); task.addTest(test); } task = taskRepository.save(task); challengeTemplate.addTask(task); } return challengeTemplateRepository.save(challengeTemplate).getId(); }
@Test public void findCategoriesByParentIdTest() throws Exception { Language language = languageRepository.findByCode("en"); logger.info("------------------------------------------------------"); for (CategoryDescription p : categoryDescriptionRepositoryDao.findRootCategories(language)) { for (CategoryDescription p2 : categoryDescriptionRepositoryDao.findCategoriesByParentId( p.getCategory().getId(), language)) { Assert.assertEquals(p.getCategory().getId().longValue(), p2.getCategory().getParentId()); } } logger.info("------------------------------------------------------"); }