Skip to content

Commit

Permalink
Add DiagnosticsStatusNotification support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Kladkevich committed Apr 15, 2018
1 parent 72e5393 commit 985079f
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest;

/*
ChargeTime.eu - Java-OCA-OCPP
Copyright (C) 2015-2016 Thomas Volden <tv@chargetime.eu>
MIT License
Copyright (C) 2016-2018 Thomas Volden
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 DiagnosticsStatusNotificationFeature extends Feature {

public DiagnosticsStatusNotificationFeature(Profile ownerProfile) {
super(ownerProfile);
}

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

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

@Override
public String getAction() {
return "DiagnosticsStatusNotification";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package eu.chargetime.ocpp.model.firmware;

/*
* ChargeTime.eu - Java-OCA-OCPP
*
* MIT License
*
* Copyright (C) 2016-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.
*/

/**
* Accepted values used with {@link DiagnosticsStatusNotificationRequest}.
*/
public enum DiagnosticsStatus {
Idle,
Uploaded,
UploadFailed,
Uploading
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package eu.chargetime.ocpp.model.firmware;

/*
* ChargeTime.eu - Java-OCA-OCPP
*
* MIT License
*
* Copyright (C) 2016 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.
*/

import eu.chargetime.ocpp.model.Confirmation;

import javax.xml.bind.annotation.XmlRootElement;

/**
* Sent by the Charge Point to the Central System in response to an {@link DiagnosticsStatusNotificationRequest}.
*/
@XmlRootElement(name = "diagnosticsStatusNotificationResponse")
public class DiagnosticsStatusNotificationConfirmation implements Confirmation {

public DiagnosticsStatusNotificationConfirmation() {
}

@Override
public boolean validate() {
return true;
}

@Override
public boolean equals(Object o) {
return this == o || o != null && getClass() == o.getClass();
}

@Override
public int hashCode() {
return 5;
}

@Override
public String toString() {
return "DiagnosticsStatusNotificationConfirmation{}" + "{isValid=" + String.valueOf(validate()) + "}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package eu.chargetime.ocpp.model.firmware;

import eu.chargetime.ocpp.PropertyConstraintException;
import eu.chargetime.ocpp.model.Request;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import java.util.Objects;

/*
* ChargeTime.eu - Java-OCA-OCPP
*
* MIT License
*
* Copyright (C) 2016-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.
*/

/**
* Sent by the Central System to the Charge Point.
*/
@XmlRootElement
public class DiagnosticsStatusNotificationRequest implements Request {
private DiagnosticsStatus status;

public DiagnosticsStatusNotificationRequest() { }

/**
* Set required fields.
*
* @param status Diagnostics status, see {@link #setStatus(DiagnosticsStatus)}.
*/
public DiagnosticsStatusNotificationRequest(DiagnosticsStatus status) {
this.status = status;
}

@Override
public boolean validate() {
return status != null;
}

/**
* This contains the status.
*
* @return connector.
*/
public DiagnosticsStatus getStatus() {
return status;
}

/**
* Required. This contains the identifier of the status.
*
* @param status DiagnosticsStatus, value != 0.
* @throws PropertyConstraintException Value was zero or negative.
*/
@XmlElement
public void setStatus(DiagnosticsStatus status) throws PropertyConstraintException {
if (status == null)
throw new PropertyConstraintException("status", null);

this.status = status;
}

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

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

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

@Override
public String toString() {
return "DiagnosticsStatusNotificationRequest{" +
"status=" + status +
", isValid=" + String.valueOf(validate()) +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package eu.chargetime.ocpp.model.firmware.test;
/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Copyright (C) 2016-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.
*/

import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationConfirmation;
import eu.chargetime.ocpp.utilities.TestUtilities;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class DiagnosticsStatusNotificationConfirmationTest extends TestUtilities {

private DiagnosticsStatusNotificationConfirmation confirmation;

@Before
public void setup() {
confirmation = new DiagnosticsStatusNotificationConfirmation();
}

@Test
public void validate_returnsTrue() {
// When
boolean result = confirmation.validate();

// Then
assertThat(result, is(true));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package eu.chargetime.ocpp.model.firmware.test;
/*
ChargeTime.eu - Java-OCA-OCPP
MIT License
Copyright (C) 2016-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.
*/

import eu.chargetime.ocpp.PropertyConstraintException;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatus;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class DiagnosticsStatusNotificationRequestTest {

private DiagnosticsStatusNotificationRequest request;

@Before
public void setup() {
request = new DiagnosticsStatusNotificationRequest();
}

@Test
public void validate_statusIsNotSet_returnsFalse() {
// When
boolean result = request.validate();

// Then
assertThat(result, is(false));
}

@Test
public void validate_statusIsSet_returnsTrue() throws PropertyConstraintException {
// Given
DiagnosticsStatus status = DiagnosticsStatus.Uploading;
request.setStatus(status);

// When
boolean result = request.validate();

// Then
assertThat(result, is(true));
}

}

0 comments on commit 985079f

Please sign in to comment.