Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoneNuts committed Dec 27, 2023
1 parent f5c3b51 commit 44d689e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public interface IConfigSRV {
Boolean isSubjectNotAllowed();

Boolean isRemoveEds();

long getRefreshRate();

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
@Service
public class ConfigSRV implements IConfigSRV {

private static final long DELTA_MS = 300_000L;

@Autowired
private IConfigClient client;
@Autowired
Expand All @@ -51,9 +49,9 @@ public void postConstruct() {
@Override
public Boolean isRemoveEds() {
long lastUpdate = props.get(PROPS_NAME_REMOVE_EDS_ENABLE).getKey();
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
if (new Date().getTime() - lastUpdate >= getRefreshRate()) {
synchronized(Locks.REMOVE_EDS_ENABLE) {
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
if (new Date().getTime() - lastUpdate >= getRefreshRate()) {
refresh(PROPS_NAME_REMOVE_EDS_ENABLE);
}
}
Expand All @@ -64,9 +62,9 @@ public Boolean isRemoveEds() {
@Override
public Boolean isAuditEnable() {
long lastUpdate = props.get(PROPS_NAME_AUDIT_ENABLED).getKey();
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
if (new Date().getTime() - lastUpdate >= getRefreshRate()) {
synchronized(Locks.AUDIT_ENABLED) {
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
if (new Date().getTime() - lastUpdate >= getRefreshRate()) {
refresh(PROPS_NAME_AUDIT_ENABLED);
}
}
Expand All @@ -79,9 +77,9 @@ public Boolean isAuditEnable() {
@Override
public Boolean isControlLogPersistenceEnable() {
long lastUpdate = props.get(PROPS_NAME_CONTROL_LOG_ENABLED).getKey();
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
if (new Date().getTime() - lastUpdate >= getRefreshRate()) {
synchronized(Locks.CONTROL_LOG_ENABLED) {
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
if (new Date().getTime() - lastUpdate >= getRefreshRate()) {
refresh(PROPS_NAME_CONTROL_LOG_ENABLED);
}
}
Expand All @@ -94,9 +92,9 @@ public Boolean isControlLogPersistenceEnable() {
@Override
public Boolean isSubjectNotAllowed() {
long lastUpdate = props.get(PROPS_NAME_SUBJECT).getKey();
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
if (new Date().getTime() - lastUpdate >= getRefreshRate()) {
synchronized (Locks.SUBJECT_CLEANING) {
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
if (new Date().getTime() - lastUpdate >= getRefreshRate()) {
refresh(PROPS_NAME_SUBJECT);
}
}
Expand All @@ -109,9 +107,9 @@ public Boolean isSubjectNotAllowed() {
@Override
public Boolean isCfOnIssuerNotAllowed() {
long lastUpdate = props.get(PROPS_NAME_ISSUER_CF).getKey();
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
if (new Date().getTime() - lastUpdate >= getRefreshRate()) {
synchronized(Locks.ISSUER_CF_CLEANING) {
if (new Date().getTime() - lastUpdate >= DELTA_MS) {
if (new Date().getTime() - lastUpdate >= getRefreshRate()) {
refresh(PROPS_NAME_ISSUER_CF);
}
}
Expand Down Expand Up @@ -157,6 +155,11 @@ private void init() {
integrity();
}

@Override
public long getRefreshRate() {
return 300_000L;
}

private static final class Locks {
public static final Object REMOVE_EDS_ENABLE = new Object();
public static final Object CONTROL_LOG_ENABLED = new Object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void givenACorrectCDA_shouldInsertInInvocations(final String filename) {

PublicationUpdateReqDTO requestBody = new PublicationUpdateReqDTO();
requestBody.setIdentificativoDoc(idDocument);
requestBody.setIdentificativoRep("testRep");
requestBody.setIdentificativoRep("2.16.840.1.113883.2.9.2.080.4.5.1234");
requestBody.setIdentificativoSottomissione("testSottomissione");
requestBody.setTipoDocumentoLivAlto(TipoDocAltoLivEnum.WOR);
requestBody.setAssettoOrganizzativo(PracticeSettingCodeEnum.AD_PSC001);
Expand Down Expand Up @@ -208,7 +208,7 @@ void givenInvalidRequest_shouldReturnError(final String filename) {

callValidation(ActivityEnum.VALIDATION, HealthDataFormatEnum.CDA, InjectionModeEnum.ATTACHMENT, pdfAttachment, true, false, true);

rBody.setIdentificativoRep("Identificativo rep");
rBody.setIdentificativoRep("2.16.840.1.113883.2.9.2.080.4.5.1234");
assertThrows(HttpClientErrorException.BadRequest.class,
() -> callReplace(idDocument, pdfAttachment, rBody, true), "Not providing a valid request body should throw a bad request exception");

Expand Down Expand Up @@ -258,7 +258,9 @@ void givenInvalidRequest_shouldReturnError(final String filename) {
private void mockFhirMapping() {
log.info("Mocking fhir-mapping client");
final ValidationInfoDTO info = new ValidationInfoDTO(RawValidationEnum.OK, new ArrayList<>(), "", "");
TransformResDTO transform = new TransformResDTO("", new Document("_id", "idProva"));
Mockito.doReturn(new ResponseEntity<>(info, HttpStatus.OK)).when(restTemplate).exchange(anyString(), eq(HttpMethod.POST), any(HttpEntity.class), eq(ValidationResDTO.class));
Mockito.doReturn(transform).when(restTemplate).postForObject(anyString(), any(HttpEntity.class), eq(TransformResDTO.class));
}

private List<IniEdsInvocationETY> getIniInvocationEntities(final String workflowInstanceId) {
Expand Down Expand Up @@ -306,7 +308,7 @@ PublicationCreationReqDTO buildCreationDTO() {
out.setDataFinePrestazione(""+new Date().getTime());
out.setDataInizioPrestazione(""+new Date().getTime());
out.setHealthDataFormat(HealthDataFormatEnum.CDA);
out.setIdentificativoRep("Identificativo rep");
out.setIdentificativoRep("2.16.840.1.113883.2.9.2.080.4.5.1234");
out.setIdentificativoSottomissione("Identificativo Sottomissione");
out.setMode(InjectionModeEnum.ATTACHMENT);
out.setAttiCliniciRegoleAccesso(java.util.Arrays.asList(EventCodeEnum._94503_0.getCode()));
Expand Down

0 comments on commit 44d689e

Please sign in to comment.