Skip to content

Commit

Permalink
minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
ariannazafarana committed Nov 3, 2023
1 parent 5985292 commit 9aef321
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Getter
@Setter
@Table("SIGNAL")
public class SignalEntity implements Serializable {
public class Signal implements Serializable {
@Id
@Column("id")
private Long id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.pagopa.interop.signalhub.history.cleanup.repository;

import it.pagopa.interop.signalhub.history.cleanup.entities.SignalEntity;
import it.pagopa.interop.signalhub.history.cleanup.entities.Signal;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -9,9 +9,9 @@
import java.time.LocalDate;

@Repository
public interface SignalRepository extends ReactiveCrudRepository<SignalEntity, Long> {
public interface SignalRepository extends ReactiveCrudRepository<Signal, Long> {

@Query("delete from signal s where s.tmst_Insert < :date")
Mono<Void> deleteByDateBefore(LocalDate date );
@Query("delete from Signal s where trunc(s.tmst_Insert) < trunc(:date)")
Mono<Void> deleteByDate(LocalDate date );

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public class SignalServiceImpl implements SignalService {

public void cleanSignal() {
LocalDate pastDate = LocalDate.now().minus(Long.parseLong(appConfig.getDelayDays()), ChronoUnit.DAYS);
signalRepository.deleteByDateBefore(pastDate)
signalRepository.deleteByDate(pastDate)
.doOnSuccess(x -> log.info("clean complete with success"))
.doOnError(x -> log.error("Find an error {}",x.getMessage()))
.doOnError(ex -> log.error("Find an error {}",ex))
.subscribe();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,72 @@
package it.pagopa.interop.signalhub.history.cleanup.entity;

import it.pagopa.interop.signalhub.history.cleanup.entities.SignalEntity;
import it.pagopa.interop.signalhub.history.cleanup.entities.Signal;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

import java.time.Instant;

import static org.junit.jupiter.api.Assertions.assertEquals;


@ExtendWith(MockitoExtension.class)
public class SignalEntityTest {
public class SignalTest {

@InjectMocks
private SignalEntity signalEntity;
private Signal signal;

@BeforeEach
public void setUp() {
signalEntity = new SignalEntity();
signal = new Signal();
}

@Test
public void testId() {
Long id = 1L;
signalEntity.setId(id);
assertEquals(id, signalEntity.getId());
signal.setId(id);
assertEquals(id, signal.getId());
}
@Test
public void testSignalId() {
Long signalId = 123L;
signalEntity.setSignalId(signalId);
assertEquals(signalId, signalEntity.getSignalId());
signal.setSignalId(signalId);
assertEquals(signalId, signal.getSignalId());
}
@Test
public void testObjectId() {
String objectId = "testObject";
signalEntity.setObjectId(objectId);
assertEquals(objectId, signalEntity.getObjectId());
signal.setObjectId(objectId);
assertEquals(objectId, signal.getObjectId());
}

@Test
public void testEserviceId() {
String eserviceId = "testEservice";
signalEntity.setEserviceId(eserviceId);
assertEquals(eserviceId, signalEntity.getEserviceId());
signal.setEserviceId(eserviceId);
assertEquals(eserviceId, signal.getEserviceId());
}
@Test
public void testObjectType() {
String objectType = "testType";
signalEntity.setObjectType(objectType);
assertEquals(objectType, signalEntity.getObjectType());
signal.setObjectType(objectType);
assertEquals(objectType, signal.getObjectType());
}

@Test
public void testSignalType() {
String signalType = "testSignal";
signalEntity.setSignalType(signalType);
assertEquals(signalType, signalEntity.getSignalType());
signal.setSignalType(signalType);
assertEquals(signalType, signal.getSignalType());
}

@Test
public void testTmstInsert() {
Instant tmstInsert = Instant.now();
signalEntity.setTmstInsert(tmstInsert);
assertEquals(tmstInsert, signalEntity.getTmstInsert());
signal.setTmstInsert(tmstInsert);
assertEquals(tmstInsert, signal.getTmstInsert());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
import org.mockito.junit.jupiter.MockitoExtension;
import reactor.core.publisher.Mono;

import java.io.FileNotFoundException;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

@ExtendWith(MockitoExtension.class)
public class SignalServiceImplTest {
class SignalServiceImplTest {
@InjectMocks
private SignalServiceImpl signalService;

Expand All @@ -27,16 +23,10 @@ public class SignalServiceImplTest {
private AppConfig appConfig;

@Test
void testDeleteSignal() throws FileNotFoundException {
LocalDate expectedDate = LocalDate.now().minus(30, ChronoUnit.DAYS);

void testDeleteSignal() {
Mockito.when(appConfig.getDelayDays()).thenReturn("30");

Mockito.when(signalRepository.deleteByDateBefore(Mockito.any())).thenReturn(Mono.empty());
Mockito.when(signalRepository.deleteByDate(Mockito.any())).thenReturn(Mono.empty());
signalService.cleanSignal();
Mockito.verify(signalRepository, Mockito.times(1)).deleteByDateBefore(Mockito.any());



Mockito.verify(signalRepository, Mockito.times(1)).deleteByDate(Mockito.any());
}
}

0 comments on commit 9aef321

Please sign in to comment.