Skip to content

Commit

Permalink
JUnit Test Framework: unify Dummy components (#2421)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeilmeier authored Nov 2, 2023
1 parent fb6d1dd commit 18bfe03
Show file tree
Hide file tree
Showing 65 changed files with 1,252 additions and 1,726 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface UiWebsocket {
* Response.
*
* @param websocketId the id of the UI websocket connection
* @param request the JsonrpcRequest
* @param request the JsonrpcRequest
* @return the JSON-RPC Success Response Future
* @throws OpenemsNamedException on error
*/
Expand All @@ -29,7 +29,7 @@ public CompletableFuture<JsonrpcResponseSuccess> send(UUID websocketId, JsonrpcR
/**
* Send a JSON-RPC Notification to a UI session.
*
* @param websocketId the id of the UI websocket connection
* @param websocketId the id of the UI websocket connection
* @param notification the JsonrpcNotification
* @throws OpenemsNamedException on error
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class MyUser extends User {

private final int odooId;

public MyUser(int odooId, String login, String name, String token, Language language, Role globalRole,
NavigableMap<String, Role> roles, boolean hasMultipleEdges) {
super(login, name, token, language, globalRole, roles, hasMultipleEdges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ private Map<String, Object> updateCompany(MyUser user, JsonObject companyJson) t
* @throws OpenemsNamedException on error
*/
public byte[] getOdooSetupProtocolReport(int setupProtocolId) throws OpenemsNamedException {
return OdooUtils.getOdooReport(this.credentials, "openems.report_openems_setup_protocol_template", setupProtocolId);
return OdooUtils.getOdooReport(this.credentials, "openems.report_openems_setup_protocol_template",
setupProtocolId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private CollectorUtils() {
* {@link TreeBasedTable}.
*
* @param <KEY> the type of the first map key
* @param <KEY2> the type of the second map key
* @param <KEY2> the type of the second map key
* @param <VALUE> the type of the value
* @return the {@link Collector}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public abstract class AbstractWorker {
/**
* Initializes the worker and starts the worker thread.
*
* @param name the name of the worker thread
* @param initiallyTriggerNextRun true if the {@link AbstractWorker#forever()} method
* should get called immediately; if not false
* @param name the name of the worker thread
* @param initiallyTriggerNextRun true if the {@link AbstractWorker#forever()}
* method should get called immediately; if not
* false
*/
public void activate(String name, boolean initiallyTriggerNextRun) {
this.startWorker(name, initiallyTriggerNextRun);
Expand All @@ -58,9 +59,10 @@ public void activate(String name) {
/**
* Modifies the worker thread.
*
* @param name the name of the worker thread
* @param initiallyTriggerNextRun true if the {@link AbstractWorker#forever()} method
* should get called immediately; if not false
* @param name the name of the worker thread
* @param initiallyTriggerNextRun true if the {@link AbstractWorker#forever()}
* method should get called immediately; if not
* false
*/
public void modified(String name, boolean initiallyTriggerNextRun) {
if (!this.thread.isAlive() && !this.thread.isInterrupted() && !this.isStopped.get()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package io.openems.edge.battery.test;

import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.edge.battery.api.Battery;
import io.openems.edge.common.startstop.StartStop;
import io.openems.edge.common.startstop.StartStoppable;
import io.openems.edge.common.test.AbstractDummyOpenemsComponent;
import io.openems.edge.common.test.TestUtils;

public abstract class AbstractDummyBattery<SELF extends AbstractDummyBattery<?>>
extends AbstractDummyOpenemsComponent<SELF> implements Battery, StartStoppable {

protected AbstractDummyBattery(String id, io.openems.edge.common.channel.ChannelId[] firstInitialChannelIds,
io.openems.edge.common.channel.ChannelId[]... furtherInitialChannelIds) {
super(id, firstInitialChannelIds, furtherInitialChannelIds);
}

@Override
public final void setStartStop(StartStop value) throws OpenemsNamedException {
this.withStartStop(value);
}

/**
* Set {@link StartStoppable.ChannelId#START_STOP}.
*
* @param value the value
* @return myself
*/
public final SELF withStartStop(StartStop value) {
TestUtils.withValue(this, StartStoppable.ChannelId.START_STOP, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#SOC}.
*
* @param value the value
* @return myself
*/
public final SELF withSoc(int value) {
TestUtils.withValue(this, Battery.ChannelId.SOC, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#SOH}.
*
* @param value the value
* @return myself
*/
public final SELF withSoh(int value) {
TestUtils.withValue(this, Battery.ChannelId.SOH, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#CAPACITY}.
*
* @param value the value
* @return myself
*/
public final SELF withCapacity(int value) {
TestUtils.withValue(this, Battery.ChannelId.CAPACITY, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#VOLTAGE}.
*
* @param value the value
* @return myself
*/
public final SELF withVoltage(int value) {
TestUtils.withValue(this, Battery.ChannelId.VOLTAGE, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#CURRENT}.
*
* @param value the value
* @return myself
*/
public final SELF withCurrent(int value) {
TestUtils.withValue(this, Battery.ChannelId.CURRENT, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#DISCHARGE_MAX_CURRENT}.
*
* @param value the value
* @return myself
*/
public final SELF withDischargeMaxCurrent(int value) {
TestUtils.withValue(this, Battery.ChannelId.DISCHARGE_MAX_CURRENT, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#CHARGE_MAX_CURRENT}.
*
* @param value the value
* @return myself
*/
public final SELF withChargeMaxCurrent(int value) {
TestUtils.withValue(this, Battery.ChannelId.CHARGE_MAX_CURRENT, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#DISCHARGE_MIN_VOLTAGE}.
*
* @param value the value
* @return myself
*/
public final SELF withDischargeMinVoltage(int value) {
TestUtils.withValue(this, Battery.ChannelId.DISCHARGE_MIN_VOLTAGE, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#CHARGE_MAX_VOLTAGE}.
*
* @param value the value
* @return myself
*/
public final SELF withChargeMaxVoltage(int value) {
TestUtils.withValue(this, Battery.ChannelId.CHARGE_MAX_VOLTAGE, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#MIN_CELL_VOLTAGE}.
*
* @param value the value
* @return myself
*/
public final SELF withMinCellVoltage(int value) {
TestUtils.withValue(this, Battery.ChannelId.MIN_CELL_VOLTAGE, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#MAX_CELL_VOLTAGE}.
*
* @param value the value
* @return myself
*/
public final SELF withMaxCellVoltage(int value) {
TestUtils.withValue(this, Battery.ChannelId.MAX_CELL_VOLTAGE, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#MIN_CELL_TEMPERATURE}.
*
* @param value the value
* @return myself
*/
public final SELF withMinCellTemperature(int value) {
TestUtils.withValue(this, Battery.ChannelId.MIN_CELL_TEMPERATURE, value);
return this.self();
}

/**
* Set {@link Battery.ChannelId#MAX_CELL_TEMPERATURE}.
*
* @param value the value
* @return myself
*/
public final SELF withMaxCellTemperature(int value) {
TestUtils.withValue(this, Battery.ChannelId.MAX_CELL_TEMPERATURE, value);
return this.self();
}

}
Loading

0 comments on commit 18bfe03

Please sign in to comment.