Skip to content

Commit

Permalink
Added GetVariables feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
TVolden committed Nov 14, 2018
1 parent 1277e9e commit 0f3e760
Show file tree
Hide file tree
Showing 11 changed files with 843 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package eu.chargetime.ocpp.test.features;
/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Copyright (C) 2018 Thomas Volden <[email protected]>
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.
*/

import eu.chargetime.ocpp.features.basic.GetVariablesFeature;
import eu.chargetime.ocpp.features.basic.handlers.IClientGetVariablesRequestHandler;
import eu.chargetime.ocpp.model.basic.GetVariablesConfirmation;
import eu.chargetime.ocpp.model.basic.GetVariablesRequest;
import eu.chargetime.ocpp.model.basic.types.*;

import static eu.chargetime.ocpp.utilities.TestUtilities.aList;

public class GetVariables implements IClientGetVariablesRequestHandler {
private GetVariablesFeature feature;
private GetVariablesConfirmation confirmation;

public GetVariables() {
feature = new GetVariablesFeature(this);
confirmation = createConfirmation();
}

private GetVariablesConfirmation createConfirmation() {
VariableType variableType = new VariableType();
variableType.setName("A name");

ComponentType componentType = new ComponentType();
componentType.setName("A name");

GetVariableResultType getVariableResultType = new GetVariableResultType();
getVariableResultType.setAttributeStatus(GetVariableStatusEnumType.Accepted);
getVariableResultType.setAttributeValue("Some value");
getVariableResultType.setComponent(componentType);
getVariableResultType.setVariable(variableType);

GetVariablesConfirmation confirmation = new GetVariablesConfirmation();
confirmation.setGetVariableResult(aList(getVariableResultType));
return confirmation;
}

public GetVariablesConfirmation getConfirmation() {
return confirmation;
}

public GetVariablesFeature getFeature() {
return feature;
}

public GetVariablesRequest createRequest() {
VariableType variableType = new VariableType();
variableType.setName("A name");

ComponentType componentType = new ComponentType();
componentType.setName("A name");

GetVariableDataType getVariableDataType = new GetVariableDataType();
getVariableDataType.setComponent(componentType);
getVariableDataType.setVariable(variableType);

GetVariablesRequest request = new GetVariablesRequest();
request.setGetVariableData(aList(getVariableDataType));

return request;
}

@Override
public GetVariablesConfirmation handleGetVariablesRequest(GetVariablesRequest request) {
return confirmation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package eu.chargetime.ocpp.test.features

import eu.chargetime.ocpp.test.base.json.BaseSpec
import spock.util.concurrent.PollingConditions

class GetVariablesSpec extends BaseSpec
{
def "The central system sends a Get Variables request and receives a response"() {
def conditions = new PollingConditions(timeout: 11)

given:
def tester = new GetVariables()
chargePoint.addFeature(tester.feature)
centralSystem.addFeature(tester.feature)
def request = tester.createRequest()

when:
centralSystem.send(request)

then:
conditions.eventually {
assert chargePoint.hasHandled(request)
}

then:
conditions.eventually {
assert centralSystem.recieved(tester.confirmation)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package eu.chargetime.ocpp.features.basic;
/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Copyright (C) 2018 Thomas Volden <[email protected]>
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.
*/

import eu.chargetime.ocpp.feature.Feature;
import eu.chargetime.ocpp.features.basic.handlers.IClientGetVariablesRequestHandler;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.basic.GetVariablesConfirmation;
import eu.chargetime.ocpp.model.basic.GetVariablesRequest;

import java.util.UUID;

public class GetVariablesFeature implements Feature {

private final IClientGetVariablesRequestHandler handler;

public GetVariablesFeature(IClientGetVariablesRequestHandler handler) {
this.handler = handler;
}

@Override
public Confirmation handleRequest(UUID sessionIndex, Request request) {
return handler.handleGetVariablesRequest((GetVariablesRequest)request);
}

@Override
public Class<? extends Request> getRequestType() {
return GetVariablesRequest.class;
}

@Override
public Class<? extends Confirmation> getConfirmationType() {
return GetVariablesConfirmation.class;
}

@Override
public String getAction() {
return "GetVariables";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

package eu.chargetime.ocpp.features.basic.handlers;
/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Copyright (C) 2018 Thomas Volden <[email protected]>
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.
*/

import eu.chargetime.ocpp.model.basic.GetVariablesConfirmation;
import eu.chargetime.ocpp.model.basic.GetVariablesRequest;

public interface IClientGetVariablesRequestHandler {
GetVariablesConfirmation handleGetVariablesRequest(GetVariablesRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package eu.chargetime.ocpp.model.basic;
/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Copyright (C) 2018 Thomas Volden <[email protected]>
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.
*/

import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.basic.types.GetVariableResultType;
import eu.chargetime.ocpp.utilities.MoreObjects;

import java.util.Arrays;
import java.util.Objects;

public class GetVariablesConfirmation implements Confirmation {

private GetVariableResultType[] getVariableResult;

/**
* List of requested variables and their values.
* @return {@link GetVariableResultType}
*/
public GetVariableResultType[] getGetVariableResult() {
return getVariableResult;
}

/**
* Required. List of requested variables and their values.
* @param getVariableResult {@link GetVariableResultType}
*/
public void setGetVariableResult(GetVariableResultType[] getVariableResult) {
this.getVariableResult = getVariableResult;
}

@Override
public boolean validate() {
return getVariableResult != null &&
getVariableResult.length > 0 &&
Arrays.stream(getVariableResult).allMatch(getVariableResult -> getVariableResult.validate());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GetVariablesConfirmation that = (GetVariablesConfirmation) o;
return Arrays.equals(getVariableResult, that.getVariableResult);
}

@Override
public int hashCode() {
return Objects.hash(getVariableResult);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("getVariableResult", getVariableResult)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package eu.chargetime.ocpp.model.basic;
/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Copyright (C) 2018 Thomas Volden <[email protected]>
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.
*/

import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.basic.types.GetVariableDataType;
import eu.chargetime.ocpp.utilities.MoreObjects;

import java.util.Arrays;
import java.util.Objects;

public class GetVariablesRequest implements Request {

private GetVariableDataType[] getVariableData;

/**
* List of requested variables.
* @return {@link GetVariableDataType}[]
*/
public GetVariableDataType[] getGetVariableData() {
return getVariableData;
}

/**
* Required. List of requested variables.
* @param getVariableData {@link GetVariableDataType}[]
*/
public void setGetVariableData(GetVariableDataType[] getVariableData) {
this.getVariableData = getVariableData;
}

@Override
public boolean transactionRelated() {
return false;
}

@Override
public boolean validate() {
return getVariableData != null &&
getVariableData.length > 0 &&
Arrays.stream(getVariableData).allMatch(getVariableData -> getVariableData.validate());
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GetVariablesRequest that = (GetVariablesRequest) o;
return Arrays.equals(getVariableData, that.getVariableData);
}

@Override
public int hashCode() {
return Objects.hash(getVariableData);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("getVariableData", getVariableData)
.toString();
}
}
Loading

0 comments on commit 0f3e760

Please sign in to comment.