Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
  • Loading branch information
TheMaskedTurtle committed Feb 5, 2024
1 parent 6167206 commit 4ffe44f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public List<ModificationInfos> getModificationsMetadata(UUID groupUuid, boolean
.findAllBaseByGroupId(getModificationGroup(groupUuid).getId())
.stream();
if (onlyStashed) {
return modificationEntitySteam.filter(m -> m.getStashed())
return modificationEntitySteam.filter(ModificationEntity::getStashed)
.map(ModificationEntity::toModificationInfos)
.collect(Collectors.toList());
} else {
Expand All @@ -156,29 +156,31 @@ public List<ModificationInfos> getModificationsMetadata(UUID groupUuid, boolean
}

public List<ModificationInfos> getModificationsInfos(List<UUID> groupUuids, boolean onlyStashed) {
Stream<ModificationEntity> modificationEntity = groupUuids.stream().flatMap(this::getModificationEntityStream);
Stream<ModificationEntity> modificationEntities = groupUuids.stream().flatMap(this::getModificationEntityStream);
if (onlyStashed) {
return modificationEntity.filter(m -> m.getStashed() == onlyStashed)
.map(ModificationEntity::toModificationInfos)
.toList();
return modificationEntities.filter(m -> m.getStashed() == onlyStashed)
.map(this::getModificationInfos)
.collect(Collectors.toList());
} else {
return modificationEntity.map(ModificationEntity::toModificationInfos).toList();
return modificationEntities.map(this::getModificationInfos).collect(Collectors.toList());
}
}

@Transactional(readOnly = true)
public ModificationInfos getModificationInfo(UUID modificationUuid) {
return modificationRepository.findById(modificationUuid)
.map(modificationEntity -> {
if (modificationEntity instanceof TabularModificationEntity tabularModificationEntity) {
tabularModificationRepository.fillSubEntities(tabularModificationEntity);
return tabularModificationEntity.toModificationInfos();
}
return modificationEntity.toModificationInfos();
})
.map(this::getModificationInfos)
.orElseThrow(() -> new NetworkModificationException(MODIFICATION_NOT_FOUND, modificationUuid.toString()));
}

private ModificationInfos getModificationInfos(ModificationEntity modificationEntity) {
if (modificationEntity instanceof TabularModificationEntity tabularModificationEntity) {
tabularModificationRepository.fillSubEntities(tabularModificationEntity);
return tabularModificationEntity.toModificationInfos();
}
return modificationEntity.toModificationInfos();
}

@Transactional // To have the 2 delete in the same transaction (atomic)
public void deleteModificationGroup(UUID groupUuid, boolean errorOnGroupNotFound) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testCheckSqlRequestsCount() throws Exception {
mockMvc.perform(get("/v1/network-modifications/{uuid}", modificationUuid)).andExpectAll(
status().isOk(), content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
assertSelectCount(4);
assertSelectCount(3);

modifications = List.of(
GeneratorModificationInfos.builder().equipmentId("idGenerator").maxActivePower(new AttributeModification<>(300., OperationType.SET)).build(),
Expand All @@ -119,7 +119,7 @@ public void testCheckSqlRequestsCount() throws Exception {
status().isOk(), content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
// We check that the request count is not dependent on the number of sub modifications of the tabular modification (the JPA N+1 problem is correctly solved)
assertSelectCount(4);
assertSelectCount(3);
reset();

// We get the modifications of the group (so the 2 tabular modifications)
Expand Down

0 comments on commit 4ffe44f

Please sign in to comment.