@Test public void testValidIdentification() { CorrelationToken token = new CorrelationToken(); eventListener.onEvent(new AuthorizationRequestedEvent(CHARGING_STATION_ID, IDENTIFYING_TOKEN, identityContext), token); verify(service).validate(IDENTIFYING_TOKEN, CHARGING_STATION_ID); final CommandMessage command = asCommandMessage( new GrantAuthorizationCommand(CHARGING_STATION_ID, IDENTIFYING_TOKEN_ACCEPTED, identityContext)).andMetaData(Collections.singletonMap(CorrelationToken.KEY, token)); verify(gateway).send(argThat(new ArgumentMatcher<CommandMessage>() { @Override public boolean matches(Object o) { if (!(o instanceof GenericCommandMessage)) { return false; } GenericCommandMessage arg = (GenericCommandMessage) o; return command.getMetaData().equals((arg).getMetaData()) && command.getPayload().equals((arg).getPayload()); } })); }
@EventHandler protected void onEvent(AuthorizationRequestedEvent event, @MetaData(value = CorrelationToken.KEY, required = false) CorrelationToken correlationToken) { IdentifyingToken identifyingToken = event.getIdentifyingToken(); identifyingToken = identificationAuthorizationService.validate(identifyingToken, event.getChargingStationId()); CommandMessage commandMessage; IdentityContext identityContext = new IdentityContext(addOnIdentity, new NullUserIdentity()); if (identifyingToken.isValid()) { commandMessage = asCommandMessage(new GrantAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } else { commandMessage = asCommandMessage(new DenyAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } if (correlationToken != null) { commandMessage = commandMessage.andMetaData(Collections.singletonMap(CorrelationToken.KEY, correlationToken)); } commandGateway.send(commandMessage); }
AuthorizationEventListener { @EventHandler protected void onEvent(AuthorizationRequestedEvent event, @MetaData(value = CorrelationToken.KEY, required = false) CorrelationToken correlationToken) { IdentifyingToken identifyingToken = event.getIdentifyingToken(); identifyingToken = identificationAuthorizationService.validate(identifyingToken, event.getChargingStationId()); CommandMessage commandMessage; IdentityContext identityContext = new IdentityContext(addOnIdentity, new NullUserIdentity()); if (identifyingToken.isValid()) { commandMessage = asCommandMessage(new GrantAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } else { commandMessage = asCommandMessage(new DenyAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } if (correlationToken != null) { commandMessage = commandMessage.andMetaData(Collections.singletonMap(CorrelationToken.KEY, correlationToken)); } commandGateway.send(commandMessage); } }
AuthorizationEventListener { @EventHandler protected void onEvent(AuthorizationRequestedEvent event, @MetaData(value = CorrelationToken.KEY, required = false) CorrelationToken correlationToken) { IdentifyingToken identifyingToken = event.getIdentifyingToken(); identifyingToken = identificationAuthorizationService.validate(identifyingToken, event.getChargingStationId()); CommandMessage commandMessage; IdentityContext identityContext = new IdentityContext(addOnIdentity, new NullUserIdentity()); if (identifyingToken.isValid()) { commandMessage = asCommandMessage(new GrantAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } else { commandMessage = asCommandMessage(new DenyAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } if (correlationToken != null) { commandMessage = commandMessage.andMetaData(Collections.singletonMap(CorrelationToken.KEY, correlationToken)); } commandGateway.send(commandMessage); }  }
AuthorizationEventListener { @EventHandler protected void onEvent(AuthorizationRequestedEvent event, @MetaData(value = CorrelationToken.KEY, required = false) CorrelationToken correlationToken) { IdentifyingToken identifyingToken = event.getIdentifyingToken(); identifyingToken = identificationAuthorizationService.validate(identifyingToken, event.getChargingStationId()); CommandMessage commandMessage; IdentityContext identityContext = new IdentityContext(addOnIdentity, new NullUserIdentity()); if (identifyingToken.isValid()) { commandMessage = asCommandMessage(new GrantAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } else { commandMessage = asCommandMessage(new DenyAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } if (correlationToken != null) { commandMessage = commandMessage.andMetaData(Collections.singletonMap(CorrelationToken.KEY, correlationToken)); } commandGateway.send(commandMessage); }  void setIdentificationAuthorizationService(IdentificationAuthorizationService identificationAuthorizationService); void setCommandGateway(AuthorizationCommandGateway commandGateway); void setAddOnIdentity(String addOnIdentity); }
AuthorizationEventListener { @EventHandler protected void onEvent(AuthorizationRequestedEvent event, @MetaData(value = CorrelationToken.KEY, required = false) CorrelationToken correlationToken) { IdentifyingToken identifyingToken = event.getIdentifyingToken(); identifyingToken = identificationAuthorizationService.validate(identifyingToken, event.getChargingStationId()); CommandMessage commandMessage; IdentityContext identityContext = new IdentityContext(addOnIdentity, new NullUserIdentity()); if (identifyingToken.isValid()) { commandMessage = asCommandMessage(new GrantAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } else { commandMessage = asCommandMessage(new DenyAuthorizationCommand(event.getChargingStationId(), identifyingToken, identityContext)); } if (correlationToken != null) { commandMessage = commandMessage.andMetaData(Collections.singletonMap(CorrelationToken.KEY, correlationToken)); } commandGateway.send(commandMessage); }  void setIdentificationAuthorizationService(IdentificationAuthorizationService identificationAuthorizationService); void setCommandGateway(AuthorizationCommandGateway commandGateway); void setAddOnIdentity(String addOnIdentity);  }