Skip to content

Commit

Permalink
fix: issue with EqualsAndHashCode
Browse files Browse the repository at this point in the history
float(4) postgresql data type should be mapped to Float, as earlier it was mapped to Double some extra precision values are added and EqualsAndHashCode is always failing as a result.

Now the Integration Test case should also pass

Refer : https://zontroy.com/postgresql-to-java-type-mapping
  • Loading branch information
rajadilipkolli authored Jan 11, 2024
1 parent b8c4485 commit fc217a6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Licensed under Apache-2.0 2021-2023. */
/* Licensed under Apache-2.0 2021-2024. */
package com.learning.mfscreener.entities;

import jakarta.persistence.Column;
Expand Down Expand Up @@ -35,7 +35,7 @@ public class MFSchemeNavEntity extends AuditableEntity<String> implements Serial
@Column(name = "id", nullable = false)
private Long id;

private double nav;
private Float nav;

@Column(name = "nav_date")
private LocalDate navDate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Licensed under Apache-2.0 2021-2022. */
/* Licensed under Apache-2.0 2021-2024. */
package com.learning.mfscreener.mapper;

import com.learning.mfscreener.entities.MFSchemeEntity;
Expand Down Expand Up @@ -34,7 +34,7 @@ public interface MfSchemeDtoToEntityMapper extends Converter<MFSchemeDTO, MFSche
@AfterMapping
default void updateMFScheme(MFSchemeDTO scheme, @MappingTarget MFSchemeEntity mfSchemeEntity) {
MFSchemeNavEntity mfSchemenavEntity = new MFSchemeNavEntity();
mfSchemenavEntity.setNav("N.A.".equals(scheme.nav()) ? 0D : Double.parseDouble(scheme.nav()));
mfSchemenavEntity.setNav("N.A.".equals(scheme.nav()) ? 0F : Float.parseFloat(scheme.nav()));
mfSchemenavEntity.setNavDate(LocalDate.parse(scheme.date(), DATE_FORMATTER));
mfSchemeEntity.addSchemeNav(mfSchemenavEntity);
}
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/learning/mfscreener/models/NAVDataDTO.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* Licensed under Apache-2.0 2021-2022. */
/* Licensed under Apache-2.0 2021-2024. */
package com.learning.mfscreener.models;

import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serializable;
import java.time.LocalDate;
import lombok.With;

public record NAVDataDTO(
@JsonFormat(pattern = "dd-MM-yyyy", shape = JsonFormat.Shape.STRING) LocalDate date, Double nav, Long schemeId)
implements Serializable {
public NAVDataDTO setSchemeId(Long schemeCode) {
return new NAVDataDTO(date(), nav(), schemeCode);
}
}
@JsonFormat(pattern = "dd-MM-yyyy", shape = JsonFormat.Shape.STRING) LocalDate date,
Float nav,
@With Long schemeId)
implements Serializable {}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void mergeList(NavResponse navResponse, MFSchemeEntity mfSchemeEntity, Long sche
if (navResponse.getData().size()
!= mfSchemeEntity.getMfSchemeNavEntities().size()) {
List<MFSchemeNavEntity> navList = navResponse.getData().stream()
.map(navDataDTO -> navDataDTO.setSchemeId(schemeCode))
.map(navDataDTO -> navDataDTO.withSchemeId(schemeCode))
.map(conversionServiceAdapter::mapNAVDataDTOToMFSchemeNavEntity)
.toList();
log.info("No of entries from Server :{}", navList.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.learning.mfscreener.common.AbstractIntegrationTest;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;

Expand Down Expand Up @@ -55,7 +54,6 @@ void shouldLoadDataWhenSchemeFoundAndLoadHistoricalData() throws Exception {
}

@Test
@Disabled
void shouldNotLoadDataWhenSchemeFoundAndLoadHistoricalDataNotFound() throws Exception {
this.mockMvc
.perform(get("/api/nav/{schemeCode}/{date}", 151113, "2022-10-20")
Expand Down

0 comments on commit fc217a6

Please sign in to comment.