CalendarTaskRefresher is skippable via system property.

master
Markus Kreth 7 years ago
parent a8f095db06
commit 80298b48a6
  1. 15
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/CalendarTaskRefresher.java
  2. 46
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/CalendarTaskRefresherTest.java

@ -17,17 +17,24 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
@Component @Component
public class CalendarTaskRefresher { public class CalendarTaskRefresher {
public static final String SKIP_EVENT_UPDATE = "skipEventUpdate";
private static final long RATE = 1000L * 60 * 10; private static final long RATE = 1000L * 60 * 10;
private final Logger log = LoggerFactory.getLogger(getClass()); private final Logger log = LoggerFactory.getLogger(getClass());
private final boolean skip = Boolean.parseBoolean(System.getProperty(SKIP_EVENT_UPDATE, "false"));
@Autowired @Autowired
ClubEventDao dao; ClubEventDao dao;
EventBusiness business = new EventBusiness(); @Autowired
EventBusiness eventBusiness;
@Scheduled(fixedDelay = RATE) @Scheduled(fixedDelay = RATE)
public void synchronizeCalendarTasks() { public void synchronizeCalendarTasks() {
List<ClubEvent> events = business.loadEvents(null, true); if (skip) {
return;
}
List<ClubEvent> events = eventBusiness.loadEvents(null, true);
for (ClubEvent e : events) { for (ClubEvent e : events) {
if (dao.get(e.getId()) == null) { if (dao.get(e.getId()) == null) {
try { try {
@ -48,4 +55,8 @@ public class CalendarTaskRefresher {
public void setDao(ClubEventDao dao) { public void setDao(ClubEventDao dao) {
this.dao = dao; this.dao = dao;
} }
public void setEventBusiness(EventBusiness eventBusiness) {
this.eventBusiness = eventBusiness;
}
} }

@ -0,0 +1,46 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.business;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Collections;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.ClubEventDao;
class CalendarTaskRefresherTest {
@Mock
private ClubEventDao dao;
@Mock
private EventBusiness eventBusiness;
@BeforeEach
void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(eventBusiness.loadEvents(any(), anyBoolean())).thenReturn(Collections.emptyList());
}
@Test
void testSkip() {
CalendarTaskRefresher r = new CalendarTaskRefresher();
r.setDao(dao);
r.setEventBusiness(eventBusiness);
r.synchronizeCalendarTasks();
verify(eventBusiness).loadEvents(any(), anyBoolean());
System.setProperty(CalendarTaskRefresher.SKIP_EVENT_UPDATE, Boolean.TRUE.toString());
r = new CalendarTaskRefresher();
r.setDao(dao);
r.setEventBusiness(eventBusiness);
r.synchronizeCalendarTasks();
verify(eventBusiness).loadEvents(any(), anyBoolean());
}
}
Loading…
Cancel
Save