Skip to content

Commit 7895305

Browse files
committed
Working on MeterValues feature.
1 parent 3d9f881 commit 7895305

File tree

12 files changed

+644
-25
lines changed

12 files changed

+644
-25
lines changed

ocpp-test/src/main/java/eu/chargetime/ocpp/model/test/TestModel.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package eu.chargetime.ocpp.model.test;
22

33
import java.util.Calendar;
4+
import java.util.List;
45

56
/**
67
ChargeTime.eu - Java-OCA-OCPP
@@ -40,6 +41,15 @@ public class TestModel {
4041
private Boolean booleanTest;
4142
private boolean genericBoleanTest;
4243
private TestModel objectTest;
44+
private Integer[] arrayTest;
45+
46+
public Integer[] getArrayTest() {
47+
return arrayTest;
48+
}
49+
50+
public void setArrayTest(Integer[] arrayTest) {
51+
this.arrayTest = arrayTest;
52+
}
4353

4454
public TestModel getObjectTest() {
4555
return objectTest;

ocpp-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public void sendHeartbeatRequest() {
106106
send(request);
107107
}
108108

109+
public void sendMeterValuesRequest() {
110+
Request request = core.createMeterValuesRequest();
111+
send(request);
112+
}
113+
109114
public void sendDataTransferRequest(String vendorId, String messageId, String data) {
110115
try {
111116
DataTransferRequest request = core.createDataTransferRequest(vendorId);

ocpp-test/src/main/java/eu/chargetime/ocpp/test/TestUtilities.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ protected String aString(int length) {
4444
protected <T> T[] aList(T... objects) {
4545
return objects;
4646
}
47+
48+
protected String join(String delimiter, Object[] array) {
49+
StringBuilder output = new StringBuilder();
50+
51+
for (Object current: array)
52+
output.append(String.format("%s%s", delimiter, current));
53+
54+
return output.toString().substring(1);
55+
}
56+
4757
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package core_features
2+
3+
import eu.chargetime.ocpp.test.FakeCentralSystem
4+
import eu.chargetime.ocpp.test.FakeChargePoint
5+
import spock.lang.Shared
6+
import spock.lang.Specification
7+
import spock.util.concurrent.PollingConditions;
8+
9+
class MeterValues extends Specification
10+
{
11+
@Shared FakeCentralSystem centralSystem = FakeCentralSystem.getInstance();
12+
@Shared FakeChargePoint chargePoint = new FakeChargePoint();
13+
14+
def setupSpec() {
15+
// When a Central System is running
16+
centralSystem.started();
17+
}
18+
19+
def setup() {
20+
chargePoint.connect();
21+
}
22+
23+
def cleanup() {
24+
chargePoint.disconnect();
25+
}
26+
27+
def "Charge point sends MeterValues request and receives a response"() {
28+
def conditions = new PollingConditions(timeout: 1);
29+
when:
30+
chargePoint.sendMeterValuesRequest();
31+
32+
33+
then:
34+
conditions.eventually {
35+
centralSystem.hasReceivedMeterValues();
36+
}
37+
38+
when:
39+
centralSystem.sendMeterValuesConfirmation();
40+
41+
then:
42+
conditions.eventually {
43+
chargePoint.hasReceivedMeterValuesConfirmation();
44+
}
45+
46+
}
47+
48+
}

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/CoreProfile.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public HeartbeatRequest createHeartbeatRequest() {
6767
return new HeartbeatRequest();
6868
}
6969

70+
public MeterValuesRequest createMeterValuesRequest() {
71+
return null;
72+
}
73+
7074
@Override
7175
public Feature[] getFeatureList() {
7276
return features.toArray(new Feature[0]);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package eu.chargetime.ocpp.model;
2+
3+
import eu.chargetime.ocpp.PropertyConstraintException;
4+
5+
import java.util.Calendar;
6+
7+
/**
8+
* ChargeTime.eu - Java-OCA-OCPP
9+
*
10+
* MIT License
11+
*
12+
* Copyright (C) 2016 Thomas Volden <[email protected]>
13+
*
14+
* Permission is hereby granted, free of charge, to any person obtaining a copy
15+
* of this software and associated documentation files (the "Software"), to deal
16+
* in the Software without restriction, including without limitation the rights
17+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18+
* copies of the Software, and to permit persons to whom the Software is
19+
* furnished to do so, subject to the following conditions:
20+
*
21+
* The above copyright notice and this permission notice shall be included in all
22+
* copies or substantial portions of the Software.
23+
*
24+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*/
32+
public class MeterValue implements validatable {
33+
34+
private Calendar timestamp;
35+
private SampledValue[] sampledValue;
36+
37+
@Override
38+
public boolean validate() {
39+
boolean valid = true;
40+
if (valid &= sampledValue != null) {
41+
for (SampledValue value : sampledValue)
42+
valid &= value.validate();
43+
}
44+
return valid;
45+
}
46+
47+
public void setTimestamp(Calendar timestamp) throws PropertyConstraintException {
48+
if (timestamp == null)
49+
throw new PropertyConstraintException("timestamp", timestamp);
50+
51+
this.timestamp = timestamp;
52+
}
53+
54+
public Calendar getTimestamp() {
55+
return timestamp;
56+
}
57+
58+
public void setSampledValue(SampledValue[] sampledValue) throws PropertyConstraintException {
59+
if (sampledValue == null)
60+
throw new PropertyConstraintException("sampledValue", sampledValue);
61+
62+
this.sampledValue = sampledValue;
63+
}
64+
65+
public SampledValue[] getSampledValue() {
66+
return sampledValue;
67+
}
68+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package eu.chargetime.ocpp.model;
2+
3+
import eu.chargetime.ocpp.PropertyConstraintException;
4+
5+
/**
6+
* ChargeTime.eu - Java-OCA-OCPP
7+
*
8+
* MIT License
9+
*
10+
* Copyright (C) 2016 Thomas Volden <[email protected]>
11+
*
12+
* Permission is hereby granted, free of charge, to any person obtaining a copy
13+
* of this software and associated documentation files (the "Software"), to deal
14+
* in the Software without restriction, including without limitation the rights
15+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
* copies of the Software, and to permit persons to whom the Software is
17+
* furnished to do so, subject to the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be included in all
20+
* copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28+
* SOFTWARE.
29+
*/
30+
public class MeterValuesRequest implements Request {
31+
32+
private int connectorId;
33+
private int transactionId;
34+
private MeterValue[] meterValue;
35+
36+
@Override
37+
public boolean validate() {
38+
boolean valid = true;
39+
valid &= this.connectorId >= 0;
40+
if (valid &= this.meterValue != null) {
41+
for (MeterValue current: this.meterValue)
42+
valid &= current != null && current.validate();
43+
}
44+
return valid;
45+
}
46+
47+
public void setConnectorId(int connectorId) throws PropertyConstraintException {
48+
if (connectorId < 0)
49+
throw new PropertyConstraintException("connectorId", connectorId);
50+
51+
this.connectorId = connectorId;
52+
}
53+
54+
public int getConnectorId() {
55+
return connectorId;
56+
}
57+
58+
public void setTransactionId(int transactionId) {
59+
this.transactionId = transactionId;
60+
}
61+
62+
public int getTransactionId() {
63+
return transactionId;
64+
}
65+
66+
public void setMeterValue(MeterValue[] meterValue) throws PropertyConstraintException {
67+
if (meterValue == null)
68+
throw new PropertyConstraintException("meterValue", meterValue);
69+
70+
this.meterValue = meterValue;
71+
}
72+
73+
public MeterValue[] getMeterValue() {
74+
return meterValue;
75+
}
76+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package eu.chargetime.ocpp.model;
2+
3+
/**
4+
* ChargeTime.eu - Java-OCA-OCPP
5+
*
6+
* MIT License
7+
*
8+
* Copyright (C) 2016 Thomas Volden <[email protected]>
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included in all
18+
* copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
* SOFTWARE.
27+
*/
28+
public class SampledValue implements validatable{
29+
private String value;
30+
31+
@Override
32+
public boolean validate() {
33+
return false;
34+
}
35+
36+
public void setValue(String value) {
37+
this.value = value;
38+
}
39+
40+
public String getValue() {
41+
return value;
42+
}
43+
}

0 commit comments

Comments
 (0)