Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ems/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ dependencies {
api "org.jboss.resteasy:resteasy-client-api:$resteasyVersion"
implementation "org.lfenergy.shapeshifter:shapeshifter-core:$shapeshifterVersion"
testImplementation "io.openremote:openremote-test:$openremoteVersion"
// Standalone (shaded) WireMock so its embedded Jetty/Jackson don't clash with the manager's web stack;
// used to mock the GOPACS broker / OAuth2 / address-book HTTP endpoints (the broker send goes through
// java.net.http.HttpClient, which a JAX-RS ClientRequestFilter cannot intercept).
testImplementation "org.wiremock:wiremock-standalone:$wiremockVersion"
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,52 @@ protected GOPACSHandler(String contractedEAN, String realm, String electricitySu
deploy(container);
}

/**
* Test-support constructor. Wires the message-processing collaborators directly and skips
* remote configuration (OAuth client, private-key file) and JAX-RS deployment, so the
* day-ahead UFTP message flow can be exercised in isolation. Not used in production wiring.
*/
protected GOPACSHandler(String contractedEAN,
String realm,
String electricitySupplierAssetId,
AssetProcessingService assetProcessingService,
AssetPredictedDatapointService assetPredictedDatapointService,
TimerService timerService,
ScheduledExecutorService scheduledExecutorService,
String privateKey) {
this.devMode = false;
this.contractedEAN = contractedEAN;
this.realm = realm;
this.electricitySupplierAssetId = electricitySupplierAssetId;
this.participants = new HashMap<>();

this.assetProcessingService = assetProcessingService;
this.assetPredictedDatapointService = assetPredictedDatapointService;
this.timerService = timerService;
this.scheduledExecutorService = scheduledExecutorService;
this.webService = null;

this.gopacsBrokerUrl = "";
this.responseDelaySeconds = 0;
this.flexOfferDelaySeconds = 0;
this.clientId = null;
this.clientSecret = null;
this.privateKey = privateKey;

this.client = null;
this.gopacsAddressBookResource = null;
this.gopacsAuthResource = null;
this.gopacsServerResource = null;

Comment on lines +246 to +250

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path already degrades gracefully — no NPE is thrown.

  1. fetchBearerToken() wraps the gopacsAuthResource call in try/catch (Exception e). A null gopacsAuthResource raises an NPE, which is caught and the method returns "".

  2. getParticipantInformation() checks the blank token before touching the address book:

String authorization = fetchBearerToken();
if (authorization.isBlank()) {
    LOG.warning("Skipping participant lookup for " + domain + ": no OAuth2 bearer token available");
    return Optional.empty();
}
try (Response response = gopacsAddressBookResource.fetchParticipantByDomain(authorization, domain)) {

So even with participants unseeded: caught NPE → blank token → Optional.empty(), and gopacsAddressBookResource is never dereferenced. Additionally, the covered flows pre-seed participants, so the participants.containsKey(domain) cache returns first and fetchBearerToken() is not called at all.

Leaving the constructor as-is; no-op resource implementations would be unused plumbing.

this.participantResolutionService = new ParticipantResolutionService(this);
this.cryptoService = new UftpCryptoService(participantResolutionService, new LazySodiumFactory(), new LazySodiumBase64Pool());
this.uftpValidationService = new UftpValidationService(new ArrayList<>());
this.uftpReceivedMessageService = new UftpReceivedMessageService(uftpValidationService, this);
this.uftpSendMessageService = new UftpSendMessageService(serializer, cryptoService, participantResolutionService, this, uftpValidationService);

this.objectMapper = new ObjectMapper();
}

protected static String getDeploymentName(String contractedEAN) {
return "GOPACS: " + contractedEAN;
}
Expand Down
Loading
Loading