Skip to content

Commit

Permalink
Improve code coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
  • Loading branch information
FranckLecuyer committed Jan 10, 2025
1 parent f6ea175 commit db53bbe
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void onUpdate(Identifiable<?> identifiable, String attribute, String vari
}

@Override
public void onExtensionCreation(Extension<?> extension) {
public void onExtensionBeforeRemoval(Extension<?> extension) {
// do nothing
}

Expand All @@ -81,12 +81,12 @@ public void onExtensionAfterRemoval(Identifiable<?> identifiable, String extensi
}

@Override
public void onExtensionBeforeRemoval(Extension<?> extension) {
public void onExtensionUpdate(Extension<?> extendable, String attribute, String variantId, Object oldValue, Object newValue) {
// do nothing
}

@Override
public void onExtensionUpdate(Extension<?> extendable, String attribute, String variantId, Object oldValue, Object newValue) {
public void onExtensionCreation(Extension<?> extension) {
// do nothing
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.modification.server.service;

import org.gridsuite.modification.server.elasticsearch.EquipmentInfosService;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.NoSuchIndexException;

import java.util.UUID;


/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
class NetworkVariantsListenerTests {
private static final UUID NETWORK_UUID = UUID.randomUUID();
private static final String VARIANT_ID = "variant_1";

@Autowired
private EquipmentInfosService equipmentInfosService;

@AfterEach
void tearDown() {
try {
equipmentInfosService.deleteAll();
} catch (NoSuchIndexException ex) {
// no need to worry that much
}
}

@Test
void testVariantNotifications() {
NetworkVariantsListener listener = new NetworkVariantsListener(null, NETWORK_UUID, equipmentInfosService);

listener.onVariantRemoved(VARIANT_ID);
listener.onVariantCreated("variant_1", "variant_2");
listener.onVariantOverwritten("variant_2", "variant_3");
listener.onUpdate(null, null, null, null, null);
listener.onExtensionUpdate(null, null, null, null, null);
listener.onPropertyAdded(null, null, null);
listener.onPropertyReplaced(null, null, null, null);
listener.onPropertyRemoved(null, null, null);
}
}

0 comments on commit db53bbe

Please sign in to comment.