add mapper tests
This commit is contained in:
@@ -12,19 +12,15 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class MetricMapper {
|
||||
private final ExperimentRepository experimentRepository;
|
||||
private final JacksonUtils jacksonUtils;
|
||||
public MetricResponse mapMetricEntityToMetricResponse(MetricEntity metricEntity){
|
||||
long numberOfExperimentsForMetrics = experimentRepository.countByPrimaryMetric(metricEntity.getMetricName());
|
||||
return MetricResponse.builder()
|
||||
.metricId(metricEntity.getMetricId())
|
||||
.createdBy(metricEntity.getCreatedBy())
|
||||
.metricName(metricEntity.getMetricName())
|
||||
.metricType(StringUtils.isNotBlank(metricEntity.getMetricType())
|
||||
? jacksonUtils.stringToObject(metricEntity.getMetricType(), MetricType.class)
|
||||
? MetricType.valueOf(metricEntity.getMetricType())
|
||||
: null)
|
||||
.updatedAt(metricEntity.getUpdatedAt())
|
||||
.numberOfExperiments(numberOfExperimentsForMetrics)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.navi.medici.validator.MetricValidator;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@@ -26,7 +27,9 @@ public record MetricServiceImpl(MetricRepository metricRepository,
|
||||
MetricEntity metric = MetricEntity.builder()
|
||||
.metricId(UUID.randomUUID().toString())
|
||||
.metricName(createMetricRequest.getMetricName())
|
||||
.metricType(jacksonUtils.objectToString(createMetricRequest.getMetricType()))
|
||||
.metricType(Objects.nonNull(createMetricRequest.getMetricType())
|
||||
? createMetricRequest.getMetricType().toString()
|
||||
: null)
|
||||
.createdBy(emailId)
|
||||
.athenaQuery(createMetricRequest.getAthenaQuery())
|
||||
.build();
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.navi.medici.mapper;
|
||||
|
||||
import com.navi.medici.entity.MetricEntity;
|
||||
import com.navi.medici.enums.MetricType;
|
||||
import com.navi.medici.response.MetricResponse;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class MetricMapperTest {
|
||||
@InjectMocks
|
||||
private MetricMapper metricMapper;
|
||||
|
||||
@Test
|
||||
void mapMetricEntityToMetricResponse() {
|
||||
MetricEntity metricEntity = MetricEntity.builder()
|
||||
.metricId("uuid")
|
||||
.metricType("BUSINESS")
|
||||
.createdBy("user")
|
||||
.athenaQuery("athena-query")
|
||||
.metricName("metric-name")
|
||||
.build();
|
||||
MetricResponse response = metricMapper.mapMetricEntityToMetricResponse(metricEntity);
|
||||
Assertions.assertEquals("uuid", response.getMetricId());
|
||||
Assertions.assertEquals("BUSINESS", response.getMetricType().toString());
|
||||
Assertions.assertEquals("user", response.getCreatedBy());
|
||||
Assertions.assertEquals("metric-name", response.getMetricName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user