Skip to content

Commit

Permalink
Merge pull request #70 from eupakhomov/Add_UUID_parameter_to_server_f…
Browse files Browse the repository at this point in the history
…irmware_management_handler

Add UUID parameter to server firmware management handler
  • Loading branch information
TVolden authored Jun 29, 2018
2 parents 30e6948 + 6df35bd commit 700d51e
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionInde
public ServerFirmwareManagementEventHandler createServerFirmwareManagementEventHandler() {
return new ServerFirmwareManagementEventHandler() {
@Override
public DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotificationRequest(DiagnosticsStatusNotificationRequest request) {
public DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotificationRequest(UUID sessionId, DiagnosticsStatusNotificationRequest request) {
receivedRequest = request;
DiagnosticsStatusNotificationConfirmation confirmation = new DiagnosticsStatusNotificationConfirmation();
return failurePoint(confirmation);
}

@Override
public FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRequest(FirmwareStatusNotificationRequest request) {
public FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRequest(UUID sessionId, FirmwareStatusNotificationRequest request) {
receivedRequest = request;
FirmwareStatusNotificationConfirmation confirmation = new FirmwareStatusNotificationConfirmation();
return failurePoint(confirmation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@ public void clientLost() {
}

public void started() throws Exception {
final String host = "127.0.0.1";

if (!isStarted) {
int port = 8890;
if (server instanceof JSONTestServer) {
port = 8887;
}

server.open("127.0.0.1", port, dummyHandlers.generateServerEventsHandler());
logger.info("Server started on port: {}", port);
server.open(host, port, dummyHandlers.generateServerEventsHandler());
logger.info("Server started on host: {}, port: {}", host, port);
isStarted = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class JSONBaseSpec extends Specification {
FakeChargePoint chargePoint = new FakeChargePoint()

def setupSpec() {
def conditions = new PollingConditions(timeout: 10)
def conditions = new PollingConditions(timeout: 11)

// When a Central System is running
centralSystem.started()
Expand All @@ -36,7 +36,7 @@ abstract class JSONBaseSpec extends Specification {
}

def cleanupSpec() {
def conditions = new PollingConditions(timeout: 10)
def conditions = new PollingConditions(timeout: 11)

centralSystem.stopped()

Expand Down
10 changes: 8 additions & 2 deletions ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.wss.WssFactoryBuilder;
import org.java_websocket.drafts.Draft;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.protocols.IProtocol;
import org.java_websocket.protocols.Protocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.CompletionStage;
Expand All @@ -63,8 +65,12 @@ public class JSONServer implements IServerAPI {
public JSONServer(ServerCoreProfile coreProfile, JSONConfiguration configuration) {
featureRepository = new FeatureRepository();
SessionFactory sessionFactory = new SessionFactory(featureRepository);
draftOcppOnly = new Draft_6455(Collections.emptyList(),
Collections.singletonList(new Protocol("ocpp1.6")));

ArrayList<IProtocol> protocols = new ArrayList<>();
protocols.add(new Protocol("ocpp1.6"));
protocols.add(new Protocol(""));
draftOcppOnly = new Draft_6455(Collections.emptyList(), protocols);

this.listener = new WebSocketListener(sessionFactory, configuration, draftOcppOnly);
server = new Server(this.listener, featureRepository, new PromiseRepository());
featureRepository.addFeatureProfile(coreProfile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ public void relay(String message) {
public void onClose(WebSocket webSocket, int code, String reason, boolean remote) {
logger.debug("On connection close (resource descriptor: {}, code: {}, reason: {}, remote: {})", webSocket.getResourceDescriptor(), code, reason, remote);

sockets.get(webSocket).disconnect();
sockets.remove(webSocket);
WebSocketReceiver receiver = sockets.get(webSocket);
if(receiver != null) {
receiver.disconnect();
sockets.remove(webSocket);
} else {
logger.debug("Receiver for socket not found: {}", webSocket);
}
}

@Override
Expand Down Expand Up @@ -167,8 +172,8 @@ public void close() {
}

try {
sockets.clear();
server.stop(TIMEOUT_IN_MILLIS);
sockets.clear();
} catch (InterruptedException e) {
// Do second try
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public void onError(Exception ex) {
}

configure();

logger.debug("Trying to connect to: {}", resource);

try {
client.connectBlocking();
closed = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationRequest;

import java.util.UUID;

public interface ServerFirmwareManagementEventHandler {
DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotificationRequest(DiagnosticsStatusNotificationRequest request);
DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotificationRequest(UUID sessionIndex, DiagnosticsStatusNotificationRequest request);

FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRequest(FirmwareStatusNotificationRequest request);
FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRequest(UUID sessionIndex, FirmwareStatusNotificationRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public Confirmation handleRequest(UUID sessionIndex, Request request) {
Confirmation result = null;

if (request instanceof DiagnosticsStatusNotificationRequest) {
result = eventHandler.handleDiagnosticsStatusNotificationRequest((DiagnosticsStatusNotificationRequest) request);
result = eventHandler.handleDiagnosticsStatusNotificationRequest(sessionIndex, (DiagnosticsStatusNotificationRequest) request);
} else if (request instanceof FirmwareStatusNotificationRequest) {
result = eventHandler.handleFirmwareStatusNotificationRequest((FirmwareStatusNotificationRequest) request);
result = eventHandler.handleFirmwareStatusNotificationRequest(sessionIndex, (FirmwareStatusNotificationRequest) request);
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ of this software and associated documentation files (the "Software"), to deal

@RunWith(MockitoJUnitRunner.class)
public class ServerFirmwareManagementProfileTest extends ProfileTest {
private static final UUID SESSION_NULL = null;

ServerFirmwareManagementProfile profile;

@Mock
Expand Down Expand Up @@ -99,24 +97,26 @@ public void getFeatureList_containsUpdateFirmwareFeature() {
public void handleRequest_aDiagnosticsStatusNotificationRequest_callsHandleDiagnosticsStatusNotificationRequest() {
// Given
DiagnosticsStatusNotificationRequest request = new DiagnosticsStatusNotificationRequest();
UUID sessionId = UUID.randomUUID();

// When
profile.handleRequest(SESSION_NULL, request);
profile.handleRequest(sessionId, request);

// Then
verify(handler, times(1)).handleDiagnosticsStatusNotificationRequest(eq(request));
verify(handler, times(1)).handleDiagnosticsStatusNotificationRequest(eq(sessionId), eq(request));
}

@Test
public void handleRequest_aFirmwareStatusNotificationRequest_callsHandleFirmwareStatusNotificationRequest() {
// Given
FirmwareStatusNotificationRequest request = new FirmwareStatusNotificationRequest();
UUID sessionId = UUID.randomUUID();

// When
profile.handleRequest(SESSION_NULL, request);
profile.handleRequest(sessionId, request);

// Then
verify(handler, times(1)).handleFirmwareStatusNotificationRequest(eq(request));
verify(handler, times(1)).handleFirmwareStatusNotificationRequest(eq(sessionId), eq(request));
}

}
}

0 comments on commit 700d51e

Please sign in to comment.