Skip to content

Commit e5647c5

Browse files
committed
refactor: parameterize websocket url in tests
1 parent b5b6066 commit e5647c5

4 files changed

Lines changed: 19 additions & 13 deletions

File tree

src/test/java/de/rwth/idsg/steve/certification/ocpp16/AbstractOcpp16JsonCsms.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package de.rwth.idsg.steve.certification.ocpp16;
2020

2121
import de.rwth.idsg.steve.ocpp.OcppVersion;
22+
import de.rwth.idsg.steve.utils.Helpers;
2223
import de.rwth.idsg.steve.utils.OcppJsonChargePoint;
2324
import de.rwth.idsg.steve.utils.__DatabasePreparer__;
2425
import de.rwth.idsg.steve.web.dto.RestCallback;
@@ -38,6 +39,8 @@
3839
import ocpp.cs._2015._10.StopTransactionRequest;
3940
import org.jetbrains.annotations.Nullable;
4041
import org.joda.time.DateTime;
42+
import org.springframework.beans.factory.annotation.Autowired;
43+
import org.springframework.boot.web.server.autoconfigure.ServerProperties;
4144

4245
import java.util.List;
4346
import java.util.concurrent.CompletableFuture;
@@ -51,13 +54,14 @@
5154
@Slf4j
5255
public abstract class AbstractOcpp16JsonCsms {
5356

54-
static final String PATH = "ws://localhost:8080/steve/websocket/CentralSystemService/";
55-
5657
static final String REGISTERED_CHARGE_BOX_ID = __DatabasePreparer__.getRegisteredChargeBoxId();
5758
static final String REGISTERED_OCPP_TAG = __DatabasePreparer__.getRegisteredOcppTag();
5859

5960
static final String CPO_NAME = "SteVe-CPO";
6061

62+
@Autowired
63+
ServerProperties serverProperties;
64+
6165
static BootNotificationRequest bootNotification() {
6266
return new BootNotificationRequest()
6367
.withChargePointVendor(getRandomString())
@@ -183,8 +187,8 @@ static StartTransactionResponse enterChargingState(OcppJsonChargePoint chargePoi
183187
return startTransactionResponse;
184188
}
185189

186-
static OcppJsonChargePoint defaultStation() {
187-
return new OcppJsonChargePoint(OcppVersion.V_16, REGISTERED_CHARGE_BOX_ID, PATH);
190+
OcppJsonChargePoint defaultStation() {
191+
return new OcppJsonChargePoint(OcppVersion.V_16, REGISTERED_CHARGE_BOX_ID, Helpers.getJsonPath(serverProperties));
188192
}
189193

190194
@FunctionalInterface

src/test/java/de/rwth/idsg/steve/certification/ocpp16/Ocpp16JsonCsmsCertificationIT.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import de.rwth.idsg.steve.repository.ChargingProfileRepository;
2323
import de.rwth.idsg.steve.repository.ReservationStatus;
2424
import de.rwth.idsg.steve.service.OcppOperationsService;
25+
import de.rwth.idsg.steve.utils.Helpers;
2526
import de.rwth.idsg.steve.utils.OcppJsonChargePoint;
2627
import de.rwth.idsg.steve.utils.__DatabasePreparer__;
2728
import de.rwth.idsg.steve.utils.mapper.ChargingProfileDetailsMapper;
@@ -2911,12 +2912,14 @@ public void test_TC_085_CSMS_BasicAuthenticationValidCredentials() {
29112912

29122913
@Test
29132914
public void test_TC_088_CSMS_WebSocketSubprotocolNegotiation() {
2915+
String path = Helpers.getJsonPath(serverProperties);
2916+
29142917
assertThrows(
29152918
RuntimeException.class,
2916-
() -> new OcppJsonChargePoint(List.of("ocpp0.1"), REGISTERED_CHARGE_BOX_ID, PATH).start()
2919+
() -> new OcppJsonChargePoint(List.of("ocpp0.1"), REGISTERED_CHARGE_BOX_ID, path).start()
29172920
);
29182921

2919-
var chargePoint = new OcppJsonChargePoint(List.of("ocpp0.1", "ocpp1.6"), REGISTERED_CHARGE_BOX_ID, PATH).start();
2922+
var chargePoint = new OcppJsonChargePoint(List.of("ocpp0.1", "ocpp1.6"), REGISTERED_CHARGE_BOX_ID, path).start();
29202923

29212924
List<String> responseHeaders = chargePoint.getResponseHeader("Sec-WebSocket-Protocol");
29222925
assertNotNull(responseHeaders);

src/test/java/de/rwth/idsg/steve/certification/ocpp16/Ocpp16JsonCsmsCertification_TLS_IT.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
*/
1919
package de.rwth.idsg.steve.certification.ocpp16;
2020

21+
import de.rwth.idsg.steve.config.WebSocketConfiguration;
2122
import de.rwth.idsg.steve.ocpp.OcppVersion;
2223
import de.rwth.idsg.steve.ocpp.task.CertificateSignedTask;
2324
import de.rwth.idsg.steve.repository.TaskStore;
2425
import de.rwth.idsg.steve.service.OcppOperationsService;
26+
import de.rwth.idsg.steve.utils.Helpers;
2527
import de.rwth.idsg.steve.utils.OcppJsonChargePoint;
2628
import de.rwth.idsg.steve.utils.__DatabasePreparer__;
2729
import de.rwth.idsg.steve.web.dto.ocpp.ExtendedTriggerMessageParams;
@@ -89,17 +91,13 @@ public class Ocpp16JsonCsmsCertification_TLS_IT extends AbstractOcpp16JsonCsms {
8991
Security.addProvider(new BouncyCastleProvider());
9092
}
9193

92-
private static final String SECURE_PATH = "wss://localhost:8443/steve/websocket/CentralSystemService/";
93-
9494
@Autowired
9595
private DSLContext dslContext;
9696
@Autowired
9797
private PasswordEncoder passwordEncoder;
9898
@Autowired
9999
private OcppOperationsService operationsService;
100100
@Autowired
101-
private ServerProperties serverProperties;
102-
@Autowired
103101
private TaskStore taskStore;
104102

105103
private __DatabasePreparer__ databasePreparer;
@@ -407,7 +405,7 @@ private static Path saveCertsToTempFile(List<X509Certificate> certs, CsrMaterial
407405
return p12Path;
408406
}
409407

410-
private static OcppJsonChargePoint defaultSecureStation() {
411-
return new OcppJsonChargePoint(OcppVersion.V_16, REGISTERED_CHARGE_BOX_ID, SECURE_PATH);
408+
private OcppJsonChargePoint defaultSecureStation() {
409+
return new OcppJsonChargePoint(OcppVersion.V_16, REGISTERED_CHARGE_BOX_ID, Helpers.getJsonPath(serverProperties));
412410
}
413411
}

src/test/java/de/rwth/idsg/steve/utils/Helpers.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package de.rwth.idsg.steve.utils;
2020

2121
import de.rwth.idsg.steve.config.SteveProperties;
22+
import de.rwth.idsg.steve.config.WebSocketConfiguration;
2223
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
2324
import org.apache.cxf.ws.addressing.WSAddressingFeature;
2425
import org.springframework.boot.web.server.autoconfigure.ServerProperties;
@@ -81,7 +82,7 @@ public static String getJsonPath(ServerProperties serverProperties) {
8182
+ ":"
8283
+ serverProperties.getPort()
8384
+ serverProperties.getServlet().getContextPath()
84-
+ "/websocket/CentralSystemService/";
85+
+ WebSocketConfiguration.PATH_INFIX;
8586
}
8687

8788
public static ocpp.cs._2015._10.CentralSystemService getForOcpp16(String path) {

0 commit comments

Comments
 (0)