// Path: OCPP-J/src/main/java/eu/chargetime/ocpp/JSONConfiguration.java
// public class JSONConfiguration {
// 
//   public static final String TCP_NO_DELAY_PARAMETER = "TCP_NO_DELAY";
//   public static final String REUSE_ADDR_PARAMETER = "REUSE_ADDR";
//   public static final String PROXY_PARAMETER = "PROXY";
//   public static final String PING_INTERVAL_PARAMETER = "PING_INTERVAL";
//   public static final String USERNAME_PARAMETER = "USERNAME";
//   public static final String PASSWORD_PARAMETER = "PASSWORD";
//   public static final String CONNECT_TIMEOUT_IN_MS_PARAMETER = "CONNECT_TIMEOUT_IN_MS";
//   public static final String WEBSOCKET_WORKER_COUNT = "WEBSOCKET_WORKER_COUNT";
// 
//   private final HashMap<String, Object> parameters = new HashMap<>();
// 
//   private JSONConfiguration() {}
// 
//   public static JSONConfiguration get() {
//     return new JSONConfiguration();
//   }
// 
//   public <T> JSONConfiguration setParameter(String name, T value) {
//     parameters.put(name, value);
//     return this;
//   }
// 
//   public <T> T getParameter(String name) {
//     //noinspection unchecked
//     return (T) parameters.get(name);
//   }
// 
//   public <T> T getParameter(String name, T defaultValue) {
//     //noinspection unchecked
//     T value = (T) parameters.get(name);
//     return value != null ? value : defaultValue;
//   }
// }
// 
// Path: ocpp-common/src/main/java/eu/chargetime/ocpp/ServerEvents.java
// public interface ServerEvents {
//   default void authenticateSession(SessionInformation information, String username, byte[] password)
//       throws AuthenticationException {}
// 
//   void newSession(UUID sessionIndex, SessionInformation information);
// 
//   void lostSession(UUID sessionIndex);
// }
// 
// Path: ocpp-common/src/main/java/eu/chargetime/ocpp/model/SessionInformation.java
// public class SessionInformation {
// 
//   private String identifier;
//   private InetSocketAddress address;
//   private String SOAPtoURL;
//   private String proxiedAddress;
// 
//   public String getIdentifier() {
//     return identifier;
//   }
// 
//   public InetSocketAddress getAddress() {
//     return address;
//   }
// 
//   public String getSOAPtoURL() {
//     return SOAPtoURL;
//   }
// 
//   public String getProxiedAddress() {
//     return proxiedAddress;
//   }
// 
//   public static class Builder {
// 
//     private String identifier;
//     private InetSocketAddress address;
//     private String SOAPtoURL;
//     private String proxiedAddress;
// 
//     public Builder Identifier(String identifier) {
//       this.identifier = identifier;
//       return this;
//     }
// 
//     public Builder InternetAddress(InetSocketAddress address) {
//       this.address = address;
//       return this;
//     }
// 
//     public Builder ProxiedAddress(String proxiedAddress) {
//       this.proxiedAddress = proxiedAddress;
//       return this;
//     }
// 
//     public SessionInformation build() {
//       SessionInformation sessionInformation = new SessionInformation();
//       sessionInformation.identifier = this.identifier;
//       sessionInformation.address = this.address;
//       sessionInformation.SOAPtoURL = this.SOAPtoURL;
//       sessionInformation.proxiedAddress = this.proxiedAddress;
//       return sessionInformation;
//     }
// 
//     public Builder SOAPtoURL(String toUrl) {
//       this.SOAPtoURL = toUrl;
//       return this;
//     }
//   }
// }


import eu.chargetime.ocpp.ServerEvents;
import eu.chargetime.ocpp.UnsupportedFeatureException;
import eu.chargetime.ocpp.feature.Feature;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.SessionInformation;
import java.util.UUID;
import java.util.concurrent.CompletionStage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import eu.chargetime.ocpp.IServerAPI;
import eu.chargetime.ocpp.JSONConfiguration;
import eu.chargetime.ocpp.JSONServer;
import eu.chargetime.ocpp.NotConnectedException;
import eu.chargetime.ocpp.OccurenceConstraintException;
package eu.chargetime.ocpp.test;
/*
   ChargeTime.eu - Java-OCA-OCPP

   MIT License

   Copyright (C) 2018 Thomas Volden <tv@chargetime.eu>

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in all
   copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   SOFTWARE.
*/


public class FakeCentralSystem {
  private static final Logger logger = LoggerFactory.getLogger(FakeCentralSystem.class);
  private final int port = 8887;
  private final String host = "127.0.0.1";

  private IServerAPI server;
  private boolean isStarted;
  private UUID currentSession;
  private Request handlerRequest = null;
  private Confirmation receivedConfirmation;

  public FakeCentralSystem() {
    JSONConfiguration configuration =
        JSONConfiguration.get().setParameter(JSONConfiguration.REUSE_ADDR_PARAMETER, true);
    server = new JSONServer(configuration);
    isStarted = false;
  }

  public void addFeature(Feature feature) {
    FeatureTestDecorator monitoredFeature =
        new FeatureTestDecorator(feature, request -> handlerRequest = request);
    server.addFeature(monitoredFeature);
  }

  public void started() throws Exception {
    if (!isStarted) {
      server.open(
          host,
          port,
// Path: OCPP-J/src/main/java/eu/chargetime/ocpp/JSONConfiguration.java
// public class JSONConfiguration {
// 
//   public static final String TCP_NO_DELAY_PARAMETER = "TCP_NO_DELAY";
//   public static final String REUSE_ADDR_PARAMETER = "REUSE_ADDR";
//   public static final String PROXY_PARAMETER = "PROXY";
//   public static final String PING_INTERVAL_PARAMETER = "PING_INTERVAL";
//   public static final String USERNAME_PARAMETER = "USERNAME";
//   public static final String PASSWORD_PARAMETER = "PASSWORD";
//   public static final String CONNECT_TIMEOUT_IN_MS_PARAMETER = "CONNECT_TIMEOUT_IN_MS";
//   public static final String WEBSOCKET_WORKER_COUNT = "WEBSOCKET_WORKER_COUNT";
// 
//   private final HashMap<String, Object> parameters = new HashMap<>();
// 
//   private JSONConfiguration() {}
// 
//   public static JSONConfiguration get() {
//     return new JSONConfiguration();
//   }
// 
//   public <T> JSONConfiguration setParameter(String name, T value) {
//     parameters.put(name, value);
//     return this;
//   }
// 
//   public <T> T getParameter(String name) {
//     //noinspection unchecked
//     return (T) parameters.get(name);
//   }
// 
//   public <T> T getParameter(String name, T defaultValue) {
//     //noinspection unchecked
//     T value = (T) parameters.get(name);
//     return value != null ? value : defaultValue;
//   }
// }
// 
// Path: ocpp-common/src/main/java/eu/chargetime/ocpp/ServerEvents.java
// public interface ServerEvents {
//   default void authenticateSession(SessionInformation information, String username, byte[] password)
//       throws AuthenticationException {}
// 
//   void newSession(UUID sessionIndex, SessionInformation information);
// 
//   void lostSession(UUID sessionIndex);
// }
// 
// Path: ocpp-common/src/main/java/eu/chargetime/ocpp/model/SessionInformation.java
// public class SessionInformation {
// 
//   private String identifier;
//   private InetSocketAddress address;
//   private String SOAPtoURL;
//   private String proxiedAddress;
// 
//   public String getIdentifier() {
//     return identifier;
//   }
// 
//   public InetSocketAddress getAddress() {
//     return address;
//   }
// 
//   public String getSOAPtoURL() {
//     return SOAPtoURL;
//   }
// 
//   public String getProxiedAddress() {
//     return proxiedAddress;
//   }
// 
//   public static class Builder {
// 
//     private String identifier;
//     private InetSocketAddress address;
//     private String SOAPtoURL;
//     private String proxiedAddress;
// 
//     public Builder Identifier(String identifier) {
//       this.identifier = identifier;
//       return this;
//     }
// 
//     public Builder InternetAddress(InetSocketAddress address) {
//       this.address = address;
//       return this;
//     }
// 
//     public Builder ProxiedAddress(String proxiedAddress) {
//       this.proxiedAddress = proxiedAddress;
//       return this;
//     }
// 
//     public SessionInformation build() {
//       SessionInformation sessionInformation = new SessionInformation();
//       sessionInformation.identifier = this.identifier;
//       sessionInformation.address = this.address;
//       sessionInformation.SOAPtoURL = this.SOAPtoURL;
//       sessionInformation.proxiedAddress = this.proxiedAddress;
//       return sessionInformation;
//     }
// 
//     public Builder SOAPtoURL(String toUrl) {
//       this.SOAPtoURL = toUrl;
//       return this;
//     }
//   }
// }


// Path: ocpp-v2_0-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java
import eu.chargetime.ocpp.ServerEvents;
import eu.chargetime.ocpp.UnsupportedFeatureException;
import eu.chargetime.ocpp.feature.Feature;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.SessionInformation;
import java.util.UUID;
import java.util.concurrent.CompletionStage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import eu.chargetime.ocpp.IServerAPI;
import eu.chargetime.ocpp.JSONConfiguration;
import eu.chargetime.ocpp.JSONServer;
import eu.chargetime.ocpp.NotConnectedException;
import eu.chargetime.ocpp.OccurenceConstraintException;

package eu.chargetime.ocpp.test;
/*
   ChargeTime.eu - Java-OCA-OCPP

   MIT License

   Copyright (C) 2018 Thomas Volden <tv@chargetime.eu>

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in all
   copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   SOFTWARE.
*/


public class FakeCentralSystem {
  private static final Logger logger = LoggerFactory.getLogger(FakeCentralSystem.class);
  private final int port = 8887;
  private final String host = "127.0.0.1";

  private IServerAPI server;
  private boolean isStarted;
  private UUID currentSession;
  private Request handlerRequest = null;
  private Confirmation receivedConfirmation;

  public FakeCentralSystem() {
    JSONConfiguration configuration =
        JSONConfiguration.get().setParameter(JSONConfiguration.REUSE_ADDR_PARAMETER, true);
    server = new JSONServer(configuration);
    isStarted = false;
  }

  public void addFeature(Feature feature) {
    FeatureTestDecorator monitoredFeature =
        new FeatureTestDecorator(feature, request -> handlerRequest = request);
    server.addFeature(monitoredFeature);
  }

  public void started() throws Exception {
    if (!isStarted) {
      server.open(
          host,
          port,
          new ServerEvents() {