|
27 | 27 | *
|
28 | 28 | */
|
29 | 29 | public class ApsDataEntityTest {
|
| 30 | + public static final int FRAGMENTATION_LENGTH = 65; |
30 | 31 | private static int TIMEOUT = 5000;
|
31 | 32 |
|
32 | 33 | @Test
|
@@ -226,6 +227,83 @@ public void receiveCommandState() {
|
226 | 227 | assertTrue(aps.receiveCommandState(0, ZigBeeTransportProgressState.RX_ACK));
|
227 | 228 | }
|
228 | 229 |
|
| 230 | + @Test |
| 231 | + public void shouldExpectOneFrameReceivedForPayloadShorterThanFragmentationLength() { |
| 232 | + ZigBeeTransportTransmit transport = Mockito.mock(ZigBeeTransportTransmit.class); |
| 233 | + ApsDataEntity aps = new ApsDataEntity(transport); |
| 234 | + |
| 235 | + aps.setFragmentationLength(FRAGMENTATION_LENGTH); |
| 236 | + |
| 237 | + ZigBeeApsFrame apsFrame = new ZigBeeApsFrame(); |
| 238 | + apsFrame.setApsCounter(1); |
| 239 | + apsFrame.setPayload(createData(0, FRAGMENTATION_LENGTH-1)); |
| 240 | + |
| 241 | + aps.send(0, apsFrame); |
| 242 | + |
| 243 | + assertTrue(aps.receiveCommandState(0, ZigBeeTransportProgressState.TX_ACK)); |
| 244 | + assertTrue(aps.receiveCommandState(0, ZigBeeTransportProgressState.RX_ACK)); |
| 245 | + } |
| 246 | + |
| 247 | + @Test |
| 248 | + public void shouldExpectOneFrameReceivedForPayloadEqualToFragmentationLength() { |
| 249 | + ZigBeeTransportTransmit transport = Mockito.mock(ZigBeeTransportTransmit.class); |
| 250 | + ApsDataEntity aps = new ApsDataEntity(transport); |
| 251 | + |
| 252 | + aps.setFragmentationLength(FRAGMENTATION_LENGTH); |
| 253 | + |
| 254 | + ZigBeeApsFrame apsFrame = new ZigBeeApsFrame(); |
| 255 | + apsFrame.setApsCounter(1); |
| 256 | + apsFrame.setPayload(createData(0, FRAGMENTATION_LENGTH)); |
| 257 | + |
| 258 | + aps.send(0, apsFrame); |
| 259 | + |
| 260 | + assertTrue(aps.receiveCommandState(0, ZigBeeTransportProgressState.TX_ACK)); |
| 261 | + assertTrue(aps.receiveCommandState(0, ZigBeeTransportProgressState.RX_ACK)); |
| 262 | + } |
| 263 | + |
| 264 | + @Test |
| 265 | + public void shouldExpectTwoFramesReceivedForPayloadFittingInTwoFragments() { |
| 266 | + ZigBeeTransportTransmit transport = Mockito.mock(ZigBeeTransportTransmit.class); |
| 267 | + ApsDataEntity aps = new ApsDataEntity(transport); |
| 268 | + |
| 269 | + aps.setFragmentationLength(FRAGMENTATION_LENGTH); |
| 270 | + |
| 271 | + ZigBeeApsFrame apsFrame = new ZigBeeApsFrame(); |
| 272 | + apsFrame.setApsCounter(1); |
| 273 | + apsFrame.setPayload(createData(0, FRAGMENTATION_LENGTH+1)); |
| 274 | + |
| 275 | + aps.send(0, apsFrame); |
| 276 | + |
| 277 | + assertFalse(aps.receiveCommandState(0, ZigBeeTransportProgressState.TX_ACK)); |
| 278 | + assertFalse(aps.receiveCommandState(0, ZigBeeTransportProgressState.RX_ACK)); |
| 279 | + |
| 280 | + assertTrue(aps.receiveCommandState(0, ZigBeeTransportProgressState.TX_ACK)); |
| 281 | + assertTrue(aps.receiveCommandState(0, ZigBeeTransportProgressState.RX_ACK)); |
| 282 | + } |
| 283 | + |
| 284 | + @Test |
| 285 | + public void shouldExpectThreeFramesReceivedForPayloadFittingInThreeFragments() { |
| 286 | + ZigBeeTransportTransmit transport = Mockito.mock(ZigBeeTransportTransmit.class); |
| 287 | + ApsDataEntity aps = new ApsDataEntity(transport); |
| 288 | + |
| 289 | + aps.setFragmentationLength(FRAGMENTATION_LENGTH); |
| 290 | + |
| 291 | + ZigBeeApsFrame apsFrame = new ZigBeeApsFrame(); |
| 292 | + apsFrame.setApsCounter(1); |
| 293 | + apsFrame.setPayload(createData(0, FRAGMENTATION_LENGTH*2+1)); |
| 294 | + |
| 295 | + aps.send(0, apsFrame); |
| 296 | + |
| 297 | + assertFalse(aps.receiveCommandState(0, ZigBeeTransportProgressState.TX_ACK)); |
| 298 | + assertFalse(aps.receiveCommandState(0, ZigBeeTransportProgressState.RX_ACK)); |
| 299 | + |
| 300 | + assertFalse(aps.receiveCommandState(0, ZigBeeTransportProgressState.TX_ACK)); |
| 301 | + assertFalse(aps.receiveCommandState(0, ZigBeeTransportProgressState.RX_ACK)); |
| 302 | + |
| 303 | + assertTrue(aps.receiveCommandState(0, ZigBeeTransportProgressState.TX_ACK)); |
| 304 | + assertTrue(aps.receiveCommandState(0, ZigBeeTransportProgressState.RX_ACK)); |
| 305 | + } |
| 306 | + |
229 | 307 | private int[] createData(int start, int length) {
|
230 | 308 | int[] data = new int[length];
|
231 | 309 |
|
|
0 commit comments