Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: walid-sahnoun <[email protected]>
  • Loading branch information
Walid-Sahnoun committed Sep 20, 2023
1 parent 7563f5e commit 8679427
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void deleteStashedModificationGroup(UUID groupUuid, boolean errorOnGroupN
ModificationGroupEntity groupEntity = getModificationGroup(groupUuid);
if (!groupEntity.getModifications().isEmpty()) {
List<UUID> stashedModifications = groupEntity.getModifications().stream()
.filter(modificationEntity -> modificationEntity.getStashed()).map(modification -> modification.getId()).collect(Collectors.toList());
.filter(ModificationEntity::getStashed).map(ModificationEntity::getId).collect(Collectors.toList());
deleteModifications(groupUuid, stashedModifications);
}
} catch (NetworkModificationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1279,4 +1279,29 @@ public void testCreateVoltageInitModification() throws Exception {
assertEquals(1, modificationsInfos2.size());
assertThat(modificationsInfos2.get(0)).recursivelyEquals(modificationsInfos1);
}

@Test
public void testDeleteStashedNetworkModifications() throws Exception {
MvcResult mvcResult;
EquipmentAttributeModificationInfos loadModificationInfos = EquipmentAttributeModificationInfos.builder()
.equipmentType(IdentifiableType.LOAD)
.equipmentAttributeName("v1load")
.equipmentId("v1load")
.build();
String loadModificationInfosJson = objectWriter.writeValueAsString(loadModificationInfos);

mvcResult = mockMvc.perform(post(URI_NETWORK_MODIF).content(loadModificationInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
assertApplicationStatusOK(mvcResult);

List<ModificationInfos> modifications = modificationRepository.getModifications(TEST_GROUP_ID, false, true);
assertEquals(1, modifications.size());
String uuidString = modifications.get(0).getUuid().toString();
mockMvc.perform(post(URI_NETWORK_MODIF_BASE + "/stash")
.queryParam("groupUuid", TEST_GROUP_ID.toString())
.queryParam("uuids", uuidString))
.andExpect(status().isOk());
assertEquals(1, modificationRepository.getModifications(TEST_GROUP_ID, false, true, true).size());
mockMvc.perform(delete("/v1/groups/" + TEST_GROUP_ID + "/stashed-modifications").queryParam("errorOnGroupNotFound", "false")).andExpect(status().isOk());
assertEquals(0, modificationRepository.getModifications(TEST_GROUP_ID, false, true, true).size());
}
}

0 comments on commit 8679427

Please sign in to comment.