use of com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaFile in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeOtaFileTest method testOpenFile.
@Test
public void testOpenFile() throws IOException {
Path file = FileSystems.getDefault().getPath("./src/test/resource/", "test_ota_file.test");
byte[] fileData = Files.readAllBytes(file);
ZigBeeOtaFile otaFile = new ZigBeeOtaFile(fileData);
System.out.println(otaFile);
assertEquals(Integer.valueOf(0x1234), otaFile.getManufacturerCode());
assertEquals(Integer.valueOf(0x0006), otaFile.getImageType());
assertEquals(Integer.valueOf(0x12345678), otaFile.getFileVersion());
assertEquals(ZigBeeStackType.ZIGBEE_PRO, otaFile.getStackVersion());
assertEquals("A.String", otaFile.getHeaderString());
assertEquals(Integer.valueOf(78), otaFile.getImageSize());
assertEquals(new ByteArray(new byte[] { 0x1E, (byte) 0xF1, (byte) 0xEE, 0x0B }), otaFile.getImageData(0, 4));
assertEquals(new ByteArray(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04 }), otaFile.getImageData(62, 5));
}
use of com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaFile in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeOtaServerTest method testNotify.
@Test
public void testNotify() {
ArgumentCaptor<ZigBeeCommand> mockedCommandCaptor = ArgumentCaptor.forClass(ZigBeeCommand.class);
NodeDescriptor nodeDescriptor = new NodeDescriptor();
IeeeAddress ieeeAddress = new IeeeAddress("1234567890ABCDEF");
ZigBeeEndpointAddress networkAddress = new ZigBeeEndpointAddress(1234, 56);
ZigBeeNetworkManager mockedNetworkManager = Mockito.mock(ZigBeeNetworkManager.class);
ZigBeeNode node = new ZigBeeNode(mockedNetworkManager, ieeeAddress);
node.setNetworkAddress(networkAddress.getAddress());
node.setNodeDescriptor(nodeDescriptor);
ZigBeeEndpoint endpoint = new ZigBeeEndpoint(mockedNetworkManager, node, networkAddress.getEndpoint());
// device.setIeeeAddress(ieeeAddress);
List<Integer> outClusters = new ArrayList<Integer>();
outClusters.add(ZclOtaUpgradeCluster.CLUSTER_ID);
endpoint.setOutputClusterIds(outClusters);
ZigBeeOtaStatusCallback mockedCallback = Mockito.mock(ZigBeeOtaStatusCallback.class);
otaStatusCapture = new ArrayList<ZigBeeOtaServerStatus>();
Set<ZigBeeEndpoint> devices = new HashSet<ZigBeeEndpoint>();
devices.add(endpoint);
Mockito.when(mockedNetworkManager.getNode((IeeeAddress) Matchers.anyObject())).thenReturn(node);
// Mockito.when(mockedNetworkManager.getDevice((ZigBeeAddress) Matchers.anyObject())).thenReturn(endpoint);
// Mockito.when(mockedNetworkManager.getNodeDevices((IeeeAddress) Matchers.anyObject())).thenReturn(devices);
// ZigBeeTransportTransmit mockedTransport = Mockito.mock(ZigBeeTransportTransmit.class);
// ArgumentCaptor<ZigBeeApsFrame> mockedApsFrameListener = ArgumentCaptor.forClass(ZigBeeApsFrame.class);
// try {
// Mockito.doNothing().when(mockedTransport).sendCommand(mockedApsFrameListener.capture());
// } catch (ZigBeeException e) {
// e.printStackTrace();
// }
Mockito.doAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) {
return 0;
}
}).when(mockedNetworkManager).sendCommand(mockedCommandCaptor.capture());
Mockito.doAnswer(new Answer<Future<CommandResult>>() {
@Override
public Future<CommandResult> answer(InvocationOnMock invocation) {
return null;
}
}).when(mockedNetworkManager).unicast(mockedCommandCaptor.capture(), (ZigBeeTransactionMatcher) Matchers.anyObject());
ZclOtaUpgradeCluster cluster = new ZclOtaUpgradeCluster(mockedNetworkManager, endpoint);
ZigBeeOtaServer server = new ZigBeeOtaServer();
assertTrue(server.appStartup(cluster));
server.addListener(this);
ZigBeeOtaFile otaFile = Mockito.mock(ZigBeeOtaFile.class);
// Set the firmware and send notification
server.setFirmware(otaFile);
assertEquals(1, mockedCommandCaptor.getAllValues().size());
org.awaitility.Awaitility.await().until(otaListenerUpdated(), org.hamcrest.Matchers.equalTo(1));
assertEquals(1, otaStatusCapture.size());
ZigBeeOtaServerStatus status = otaStatusCapture.get(0);
assertEquals(ZigBeeOtaServerStatus.OTA_WAITING, status);
ZigBeeCommand command = mockedCommandCaptor.getValue();
assertEquals(Integer.valueOf(0x19), command.getClusterId());
assertTrue(command instanceof ImageNotifyCommand);
ImageNotifyCommand notifyCommand = (ImageNotifyCommand) command;
assertEquals(new ZigBeeEndpointAddress(1234, 56), notifyCommand.getDestinationAddress());
assertTrue(notifyCommand.getQueryJitter() >= 1 && notifyCommand.getQueryJitter() <= 100);
}
Aggregations