|
4 | 4 | import static org.hamcrest.CoreMatchers.equalTo; |
5 | 5 | import static org.hamcrest.CoreMatchers.instanceOf; |
6 | 6 | import static org.junit.Assert.assertThat; |
| 7 | +import static org.mockito.Mockito.times; |
| 8 | +import static org.mockito.Mockito.verify; |
| 9 | +import static org.mockito.Mockito.when; |
7 | 10 |
|
8 | 11 | import eu.chargetime.ocpp.PropertyConstraintException; |
| 12 | +import eu.chargetime.ocpp.model.core.AuthorizationStatus; |
| 13 | +import eu.chargetime.ocpp.model.core.IdTagInfo; |
9 | 14 | import eu.chargetime.ocpp.model.localauthlist.AuthorizationData; |
10 | 15 | import eu.chargetime.ocpp.model.localauthlist.SendLocalListRequest; |
11 | 16 | import eu.chargetime.ocpp.model.localauthlist.UpdateType; |
@@ -107,4 +112,47 @@ public void validate_updateTypeIsNotSet_isNotValid() { |
107 | 112 | // Then |
108 | 113 | assertThat(request.validate(), equalTo(false)); |
109 | 114 | } |
| 115 | + |
| 116 | + @Test |
| 117 | + public void validate_updateTypeFullWithTagInfo_isValid() { |
| 118 | + // When |
| 119 | + request.setListVersion(42); |
| 120 | + request.setUpdateType(UpdateType.Full); |
| 121 | + request.setLocalAuthorizationList(aList(data)); |
| 122 | + |
| 123 | + when(data.validate()).thenReturn(true); |
| 124 | + when(data.getIdTagInfo()).thenReturn(new IdTagInfo(AuthorizationStatus.Accepted)); |
| 125 | + |
| 126 | + // Then |
| 127 | + assertThat(request.validate(), equalTo(true)); |
| 128 | + verify(data, times(1)).getIdTagInfo(); |
| 129 | + verify(data, times(1)).validate(); |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + public void validate_updateTypeFullEmptyTagInfo_isNotValid() { |
| 134 | + // When |
| 135 | + request.setListVersion(42); |
| 136 | + request.setUpdateType(UpdateType.Full); |
| 137 | + request.setLocalAuthorizationList(aList(data)); |
| 138 | + |
| 139 | + when(data.validate()).thenReturn(true); |
| 140 | + when(data.getIdTagInfo()).thenReturn(null); |
| 141 | + |
| 142 | + // Then |
| 143 | + assertThat(request.validate(), equalTo(false)); |
| 144 | + } |
| 145 | + |
| 146 | + @Test |
| 147 | + public void validate_updateTypeDifferentialEmptyIdTagInfo_isValid() { |
| 148 | + // When |
| 149 | + request.setListVersion(42); |
| 150 | + request.setUpdateType(UpdateType.Differential); |
| 151 | + request.setLocalAuthorizationList(aList(data)); |
| 152 | + |
| 153 | + when(data.validate()).thenReturn(true); |
| 154 | + |
| 155 | + // Then |
| 156 | + assertThat(request.validate(), equalTo(true)); |
| 157 | + } |
110 | 158 | } |
0 commit comments