|
| 1 | +package ru.javaops.masterjava.persist; |
| 2 | + |
| 3 | +import com.google.common.collect.ImmutableMap; |
| 4 | +import ru.javaops.masterjava.persist.dao.GroupDao; |
| 5 | +import ru.javaops.masterjava.persist.model.Group; |
| 6 | + |
| 7 | +import java.util.Map; |
| 8 | + |
| 9 | +import static ru.javaops.masterjava.persist.ProjectTestData.MASTERJAVA_ID; |
| 10 | +import static ru.javaops.masterjava.persist.ProjectTestData.TOPJAVA_ID; |
| 11 | +import static ru.javaops.masterjava.persist.model.type.GroupType.CURRENT; |
| 12 | +import static ru.javaops.masterjava.persist.model.type.GroupType.FINISHED; |
| 13 | + |
| 14 | +public class GroupTestData { |
| 15 | + public static Group TOPJAVA_06; |
| 16 | + public static Group TOPJAVA_07; |
| 17 | + public static Group TOPJAVA_08; |
| 18 | + public static Group MASTERJAVA_01; |
| 19 | + public static Map<String, Group> GROUPS; |
| 20 | + |
| 21 | + public static int TOPJAVA_06_ID; |
| 22 | + public static int TOPJAVA_07_ID; |
| 23 | + public static int TOPJAVA_08_ID; |
| 24 | + public static int MASTERJAVA_01_ID; |
| 25 | + |
| 26 | + |
| 27 | + public static void init() { |
| 28 | + ProjectTestData.init(); |
| 29 | + ProjectTestData.setUp(); |
| 30 | + |
| 31 | + TOPJAVA_06 = new Group("topjava06", FINISHED, TOPJAVA_ID); |
| 32 | + TOPJAVA_07 = new Group("topjava07", FINISHED, TOPJAVA_ID); |
| 33 | + TOPJAVA_08 = new Group("topjava08", CURRENT, TOPJAVA_ID); |
| 34 | + MASTERJAVA_01 = new Group("masterjava01", CURRENT, MASTERJAVA_ID); |
| 35 | + GROUPS = ImmutableMap.of( |
| 36 | + TOPJAVA_06.getName(), TOPJAVA_06, |
| 37 | + TOPJAVA_07.getName(), TOPJAVA_07, |
| 38 | + TOPJAVA_08.getName(), TOPJAVA_08, |
| 39 | + MASTERJAVA_01.getName(), MASTERJAVA_01); |
| 40 | + } |
| 41 | + |
| 42 | + public static void setUp() { |
| 43 | + GroupDao dao = DBIProvider.getDao(GroupDao.class); |
| 44 | + dao.clean(); |
| 45 | + DBIProvider.getDBI().useTransaction((conn, status) -> { |
| 46 | + GROUPS.values().forEach(dao::insert); |
| 47 | + }); |
| 48 | + TOPJAVA_06_ID = TOPJAVA_06.getId(); |
| 49 | + TOPJAVA_07_ID = TOPJAVA_07.getId(); |
| 50 | + TOPJAVA_08_ID = TOPJAVA_08.getId(); |
| 51 | + MASTERJAVA_01_ID = MASTERJAVA_01.getId(); |
| 52 | + } |
| 53 | +} |
0 commit comments