Skip to content

Commit

Permalink
Test for property
Browse files Browse the repository at this point in the history
  • Loading branch information
thangqp committed Sep 10, 2024
1 parent f1d4fbc commit 7c53cf1
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public abstract class AbstractByFilterModification extends AbstractModification
public static final String REPORT_KEY_EQUIPMENT_MODIFIED_REPORT = "equipmentModifiedReport";
public static final String REPORT_KEY_EQUIPMENT_MODIFIED_REPORT_EXCEPTION = "equipmentModifiedReportException";
public static final String REPORT_KEY_APPLIED_BY_FILTER_MODIFICATIONS = "appliedByFilterModifications";
public static final String REPORT_KEY_APPLIED_BY_FILTER_MODIFICATIONS_INFO = "appliedByFilterModificationsInfo";
public static final String REPORT_KEY_BY_FILTER_MODIFICATION = "byFilterModification";
public static final String REPORT_KEY_BY_FILTER_MODIFICATION_ALL = "byFilterModificationAll";
public static final String REPORT_KEY_BY_FILTER_MODIFICATION_NONE = "byFilterModificationNone";
Expand Down Expand Up @@ -188,7 +187,7 @@ public void apply(Network network, ReportNode subReportNode) {
}
}

private boolean isEquipmentEditable(Identifiable<?> equipment,
protected boolean isEquipmentEditable(Identifiable<?> equipment,
AbstractModificationByFilterInfos modificationByFilterInfos,
List<ReportNode> equipmentsReport) {
if (modificationByFilterInfos.getEditedField() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public NetworkModificationException.Type getExceptionType() {
return BY_SIMPLE_MODIFICATION_ERROR;
}

@Override
protected boolean isEquipmentEditable(Identifiable<?> equipment, AbstractModificationByFilterInfos modificationByFilterInfos, List<ReportNode> equipmentsReport) {
AbstractSimpleModificationByFilterInfos<?> simpleModificationInfos = (AbstractSimpleModificationByFilterInfos<?>) modificationByFilterInfos;
if (simpleModificationInfos.getDataType() == DataType.PROPERTY) {
return true;
} else {
return super.isEquipmentEditable(equipment, modificationByFilterInfos, equipmentsReport);
}
}

@Override
protected boolean preCheckValue(Identifiable<?> equipment, AbstractModificationByFilterInfos modificationByFilterInfos, List<ReportNode> reports, List<String> notEditableEquipments) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import org.gridsuite.modification.server.dto.BySimpleModificationInfos;
import org.gridsuite.modification.server.dto.FilterInfos;
import org.gridsuite.modification.server.dto.NetworkModificationResult;
import org.gridsuite.modification.server.dto.byfilter.DataType;
import org.gridsuite.modification.server.dto.byfilter.simple.AbstractSimpleModificationByFilterInfos;
import org.gridsuite.modification.server.dto.byfilter.simple.DoubleModificationByFilterInfos;
import org.gridsuite.modification.server.dto.byfilter.simple.PropertyModificationByFilterInfos;
import org.gridsuite.modification.server.impacts.AbstractBaseImpact;
import org.gridsuite.modification.server.modifications.AbstractNetworkModificationTest;
import org.gridsuite.modification.server.service.FilterService;
Expand All @@ -38,6 +40,8 @@
import static org.gridsuite.modification.server.Impacts.TestImpactUtils.createCollectionElementImpact;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand Down Expand Up @@ -254,7 +258,16 @@ String getPath(boolean isRegexPath) {

protected abstract List<AbstractFilter> getTestFilters();

protected abstract List<AbstractSimpleModificationByFilterInfos<?>> getSimpleModificationInfos();
protected List<AbstractSimpleModificationByFilterInfos<?>> getSimpleModificationInfos() {
PropertyModificationByFilterInfos spySimpleInfos = spy(PropertyModificationByFilterInfos.builder()
.editedField(DataType.PROPERTY.name())
.propertyName("propertyName")
.value("propertyValue")
.filters(List.of(filter1))
.build());
doReturn(DataType.PROPERTY).when(spySimpleInfos).getDataType();
return new ArrayList<>(List.of(spySimpleInfos));
}

protected abstract List<AbstractSimpleModificationByFilterInfos<?>> getUpdatedSimpleModificationInfos();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ protected List<AbstractSimpleModificationByFilterInfos<?>> getSimpleModification
.value(2.)
.build();

return List.of(simpleInfos1, simpleInfos2, simpleInfos3, simpleInfos4, simpleInfos5);
List<AbstractSimpleModificationByFilterInfos<?>> infosList = super.getSimpleModificationInfos();
infosList.addAll(List.of(simpleInfos1, simpleInfos2, simpleInfos3, simpleInfos4, simpleInfos5));

return infosList;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Date;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.gridsuite.modification.server.utils.NetworkUtil.createGenerator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -169,6 +170,7 @@ protected List<AbstractFilter> getTestFilters() {

@Override
protected List<AbstractSimpleModificationByFilterInfos<?>> getSimpleModificationInfos() {

DoubleModificationByFilterInfos simpleInfos1 = DoubleModificationByFilterInfos.builder()
.editedField(GeneratorField.REACTIVE_POWER_SET_POINT.name())
.value(50.)
Expand Down Expand Up @@ -253,7 +255,9 @@ protected List<AbstractSimpleModificationByFilterInfos<?>> getSimpleModification
.filters(List.of(filter1))
.build();

return List.of(simpleInfos1,
List<AbstractSimpleModificationByFilterInfos<?>> infosList = super.getSimpleModificationInfos();
infosList.addAll(List.of(
simpleInfos1,
simpleInfos2,
simpleInfos3,
simpleInfos4,
Expand All @@ -267,7 +271,9 @@ protected List<AbstractSimpleModificationByFilterInfos<?>> getSimpleModification
simpleInfos12,
simpleInfos13,
simpleInfos14
);
));

return infosList;
}

@Override
Expand All @@ -292,6 +298,7 @@ protected void assertAfterNetworkModificationCreation() {
Generator generator1 = getNetwork().getGenerator(GENERATOR_ID_1);
GeneratorStartup generatorStartup1 = generator1.getExtension(GeneratorStartup.class);
assertNotNull(generatorStartup1);
assertThat(generator1.getProperty("propertyName")).isEqualTo("propertyValue");
assertEquals(100, generator1.getTargetP(), 0);
assertEquals(2, generatorStartup1.getMarginalCost(), 0);
assertEquals(55, generatorStartup1.getPlannedOutageRate(), 0);
Expand All @@ -304,6 +311,7 @@ protected void assertAfterNetworkModificationCreation() {
Generator generator2 = getNetwork().getGenerator(GENERATOR_ID_2);
GeneratorStartup generatorStartup2 = generator2.getExtension(GeneratorStartup.class);
assertNotNull(generatorStartup2);
assertThat(generator2.getProperty("propertyName")).isEqualTo("propertyValue");
assertEquals(200, generator2.getTargetP(), 0);
assertEquals(2, generatorStartup2.getMarginalCost(), 0);
assertEquals(55, generatorStartup2.getPlannedOutageRate(), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ protected List<AbstractSimpleModificationByFilterInfos<?>> getSimpleModification
.filters(List.of(filter1))
.build();

return List.of(simpleInfos1, simpleInfos2, simpleInfos3);
List<AbstractSimpleModificationByFilterInfos<?>> infosList = super.getSimpleModificationInfos();
infosList.addAll(List.of(simpleInfos1, simpleInfos2, simpleInfos3));

return infosList;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ protected List<AbstractSimpleModificationByFilterInfos<?>> getSimpleModification
.filters(List.of(filter5))
.build();

return List.of(simpleInfos1, simpleInfos2, simpleInfos3, simpleInfos4);
List<AbstractSimpleModificationByFilterInfos<?>> infosList = super.getSimpleModificationInfos();
infosList.addAll(List.of(simpleInfos1, simpleInfos2, simpleInfos3, simpleInfos4));

return infosList;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ protected List<AbstractSimpleModificationByFilterInfos<?>> getSimpleModification
.editedField(TwoWindingsTransformerField.RATED_S.name())
.value(2.)
.build();

return List.of(simpleInfos1,
List<AbstractSimpleModificationByFilterInfos<?>> infosList = super.getSimpleModificationInfos();
infosList.addAll(List.of(simpleInfos1,
simpleInfos2,
simpleInfos3,
simpleInfos4,
Expand All @@ -289,7 +289,9 @@ protected List<AbstractSimpleModificationByFilterInfos<?>> getSimpleModification
simpleInfos12,
simpleInfos13,
simpleInfos14,
simpleInfos15);
simpleInfos15));

return infosList;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ protected List<AbstractSimpleModificationByFilterInfos<?>> getUpdatedSimpleModif
.filters(List.of(filter4))
.build();

return List.of(simpleInfos1, simpleInfos2, simpleInfos3);
List<AbstractSimpleModificationByFilterInfos<?>> infosList = super.getSimpleModificationInfos();
infosList.addAll(List.of(simpleInfos1, simpleInfos2, simpleInfos3));

return infosList;
}

@Override
Expand Down

0 comments on commit 7c53cf1

Please sign in to comment.