package de.fred4jupiter.fredbet.imexport;

import de.fred4jupiter.fredbet.common.IntegrationTest;
import de.fred4jupiter.fredbet.data.DatabasePopulator;
import de.fred4jupiter.fredbet.util.TempFileWriterUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import static org.assertj.core.api.Assertions.assertThat;

@IntegrationTest
public class ImportExportServiceIT {

    @Autowired
    private ImportExportService importExportService;

    @Autowired
    private DatabasePopulator databasePopulator;

    @Test
    public void exportAllAsJsonAndImportAgain() {
        databasePopulator.createDemoUsers(10);
        databasePopulator.createRandomMatches();
        databasePopulator.createDemoBetsForAllUsers();
        databasePopulator.createDemoResultsForAllMatches();

        String json = importExportService.exportAllToJson();
        boolean result = TempFileWriterUtil.writeToTempFolder(json.getBytes(), "fredbet_export.json");
        assertThat(result).isTrue();

        importExportService.importAllFromJson(json);

    }
}

@@ -146,16 +146,255 @@
 ulator;%0A
+import de.fred4jupiter.fredbet.repository.AppUserRepository;%0Aimport de.fred4jupiter.fredbet.repository.BetRepository;%0Aimport de.fred4jupiter.fredbet.repository.ExtraBetRepository;%0Aimport de.fred4jupiter.fredbet.repository.MatchRepository;%0A
 import d
@@ -788,16 +788,266 @@
 lator;%0A%0A
+    @Autowired%0A    private AppUserRepository appUserRepository;%0A%0A    @Autowired%0A    private MatchRepository matchRepository;%0A%0A    @Autowired%0A    private BetRepository betRepository;%0A%0A    @Autowired%0A    private ExtraBetRepository extraBetRepository;%0A%0A
     @Tes
@@ -1098,16 +1098,58 @@
 ain() %7B%0A
+        final int numberOfDemoUsers = 10;%0A
         
@@ -1182,18 +1182,33 @@
 moUsers(
-10
+numberOfDemoUsers
 );%0A     
@@ -1619,20 +1619,361 @@
 son(json);%0A%0A
+        assertThat(appUserRepository.count()).isGreaterThanOrEqualTo(numberOfDemoUsers);%0A        assertThat(matchRepository.count()).isGreaterThanOrEqualTo(48);%0A        assertThat(betRepository.count()).isGreaterThanOrEqualTo(numberOfDemoUsers * 48);%0A        assertThat(extraBetRepository.count()).isGreaterThanOrEqualTo(numberOfDemoUsers);%0A
     %7D%0A%7D%0A

update test