Skip to content

Commit

Permalink
add test for deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
ePaul committed Jul 28, 2023
1 parent 4e41d31 commit 23b471f
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.zalando.nakadiproducer.eventlog.impl;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.core.Is.is;

import javax.transaction.Transactional;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.zalando.nakadiproducer.BaseMockedExternalCommunicationIT;

import java.util.List;

@Transactional
public class EventLogRepositoryIT extends BaseMockedExternalCommunicationIT {

Expand Down Expand Up @@ -44,14 +48,45 @@ public class EventLogRepositoryIT extends BaseMockedExternalCommunicationIT {
public void setUp() {
eventLogRepository.deleteAll();

persistTestEvent("FLOW_ID");
}

private void persistTestEvent(String flowId) {
final EventLog eventLog = EventLog.builder()
.eventBodyData(WAREHOUSE_EVENT_BODY_DATA)
.eventType(WAREHOUSE_EVENT_TYPE)
.compactionKey(COMPACTION_KEY)
.flowId("FLOW_ID").build();
.flowId(flowId)
.build();
eventLogRepository.persist(eventLog);
}

@Test
public void testDeleteMultipleEvents() {
persistTestEvent("second_Flow-ID");
persistTestEvent("third flow-ID");
persistTestEvent("fourth flow-ID");
persistTestEvent("fifth flow-ID");

List<EventLog> events = findAllEventsInDB();
assertThat(events, hasSize(5));
EventLog notDeleted = events.remove(0);

// now the actual test – delete just 4 of the 5 events from the DB
eventLogRepository.delete(events);

List<EventLog> remaining = findAllEventsInDB();
assertThat(remaining, hasSize(1));
assertThat(remaining.get(0).getId(), is(notDeleted.getId()));
assertThat(remaining.get(0).getFlowId(), is(notDeleted.getFlowId()));
}

private List<EventLog> findAllEventsInDB() {
return jdbcTemplate.query(
"SELECT * FROM nakadi_events.event_log",
new BeanPropertyRowMapper<>(EventLog.class));
}

@Test
public void testFindEventInRepositoryById() {
Integer id = jdbcTemplate.queryForObject(
Expand Down

0 comments on commit 23b471f

Please sign in to comment.