SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

89 lines
2.6 KiB

package de.superx.spring.service;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Optional;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import de.superx.BaseDbTest;
import de.superx.TestApplicationConfigPg;
import de.superx.jdbc.entity.MaskStatistic;
import de.superx.jdbc.repository.MaskStatisticRepository;
//@ContextConfiguration(classes = { TestApplicationConfigPg.class })
public class MaskStatisticServiceTest extends BaseDbTest {
private static final Integer TID_1 = Integer.valueOf(3141592);
private static final Integer TID_2 = Integer.valueOf(2718281);
@Autowired
MaskStatisticService maskStatisticService;
@Autowired
MaskStatisticRepository maskStatisticRepository;
@After
public void cleanup() {
setApnr("Nutzungsstatistiken", Integer.valueOf(0));
}
@Test
public void singleUsageTest() {
setApnr("Nutzungsstatistiken", Integer.valueOf(1));
maskStatisticService.logUsage(TID_1);
Optional<MaskStatistic> om = maskStatisticRepository.findByTid(TID_1);
assertTrue(om.isPresent());
}
@Test
public void multipleUsageTest() {
setApnr("Nutzungsstatistiken", Integer.valueOf(1));
maskStatisticService.logUsage(TID_1);
maskStatisticService.logUsage(TID_2);
maskStatisticService.logUsage(TID_1);
Optional<MaskStatistic> om = maskStatisticRepository.findByTid(TID_1);
Optional<MaskStatistic> om1 = maskStatisticRepository.findByTid(TID_2);
assertTrue("Both TIDs logged", om.isPresent() && om1.isPresent());
assertTrue("Both entries have correct values", om.get().counter == 2 && om1.get().counter == 1);
}
@Test
public void logOnDisabledTest() {
setApnr("Nutzungsstatistiken", Integer.valueOf(0));
Optional<MaskStatistic> maskStatistic = maskStatisticRepository.findByTid(TID_1);
if(maskStatistic.isPresent()) {
maskStatisticRepository.deleteById(maskStatistic.get().id);
}
maskStatisticService.logUsage(TID_1);
Optional<MaskStatistic> om = maskStatisticRepository.findByTid(TID_1);
assertFalse(om.isPresent());
}
// @Test
// @Ignore
// public void testDelete() {
// Iterable<Konstante> all = konstanteRepository.findAll();
// for(Konstante k1 : all) {
// if(!k1.tid.equals(Integer.valueOf(206))) {
// if(k1.beschreibung.equals("Nutzungsstatistiken")) {
// konstanteRepository.delete(k1);
// }
// }
// System.out.println(k1.beschreibung+ " / "+k1.tid);
// }
//
// assertFalse("Non left", konstanteRepository.findByBeschreibung("Nutzungsstatistiken").isPresent());
// }
}