private static ConfigurationSyncResponse convert(ConfigurationServerSync source) { if (source == null) { return null; } ConfigurationSyncResponse sync = new ConfigurationSyncResponse(); sync.setConfDeltaBody(source.getConfDeltaBody()); sync.setConfSchemaBody(source.getConfSchemaBody()); sync.setResponseStatus(convert(source.getResponseStatus())); return sync; }
@Override public void onConfigurationResponse(ConfigurationSyncResponse response) throws IOException { if (clientState != null && configProcessor != null) { ByteBuffer schemaBody = response.getConfSchemaBody(); if (schemaBody != null && schemaProcessor != null) { schemaProcessor.loadSchema(schemaBody); } ByteBuffer confBody = response.getConfDeltaBody(); if (confBody != null) { configProcessor.processConfigurationData(confBody, response.getResponseStatus().equals(SyncResponseStatus.RESYNC)); } syncAck(response.getResponseStatus()); LOG.info("Processed configuration response."); } }
@Override public ConfigurationSyncResponse build() { try { ConfigurationSyncResponse record = new ConfigurationSyncResponse(); record.responseStatus = fieldSetFlags()[0] ? this.responseStatus : (org.kaaproject.kaa.common.endpoint.gen.SyncResponseStatus) defaultValue(fields()[0]); record.confSchemaBody = fieldSetFlags()[1] ? this.confSchemaBody : (java.nio.ByteBuffer) defaultValue(fields()[1]); record.confDeltaBody = fieldSetFlags()[2] ? this.confDeltaBody : (java.nio.ByteBuffer) defaultValue(fields()[2]); return record; } catch (Exception e) { throw new org.apache.avro.AvroRuntimeException(e); } } }
response.setConfigurationSyncResponse(new ConfigurationSyncResponse(SyncResponseStatus.DELTA, null, null)); response.setEventSyncResponse(new EventSyncResponse()); response.setNotificationSyncResponse(new NotificationSyncResponse(SyncResponseStatus.DELTA, null, null));
@Test public void testOnConfigurationResponse() throws Exception { KaaClientState clientState = Mockito.mock(KaaClientState.class); SchemaProcessor schemaProcessor = Mockito.mock(SchemaProcessor.class); ConfigurationProcessor configProcessor = Mockito.mock(ConfigurationProcessor.class); ConfigurationSyncResponse response = new ConfigurationSyncResponse(); response.setResponseStatus(SyncResponseStatus.DELTA); KaaChannelManager channelManagerMock = Mockito.mock(KaaChannelManager.class); ConfigurationTransport transport = new DefaultConfigurationTransport(); transport.setChannelManager(channelManagerMock); transport.onConfigurationResponse(response); transport.setClientState(clientState); transport.onConfigurationResponse(response); transport.setConfigurationProcessor(configProcessor); transport.onConfigurationResponse(response); transport.setSchemaProcessor(schemaProcessor); transport.onConfigurationResponse(response); response.setConfDeltaBody(ByteBuffer.wrap(new byte[]{1, 2, 3})); transport.onConfigurationResponse(response); response.setConfSchemaBody(ByteBuffer.wrap(new byte[]{1, 2, 3})); transport.onConfigurationResponse(response); Mockito.verify(schemaProcessor, Mockito.times(1)).loadSchema(Mockito.eq(ByteBuffer.wrap(new byte[]{1, 2, 3}))); Mockito.verify(configProcessor, Mockito.times(2)).processConfigurationData(Mockito.eq(ByteBuffer.wrap(new byte[]{1, 2, 3})), Mockito.eq(false)); }
@Test public void testResponseWithNullTransports() throws Exception { KaaClientState state = Mockito.mock(KaaClientState.class); DefaultOperationDataProcessor operationsDataProcessor = new DefaultOperationDataProcessor(state); SyncResponse response = new SyncResponse(); response.setStatus(SyncResponseResultType.SUCCESS); response.setConfigurationSyncResponse(new ConfigurationSyncResponse(SyncResponseStatus.DELTA, null, null)); response.setEventSyncResponse(new EventSyncResponse()); response.setNotificationSyncResponse(new NotificationSyncResponse(SyncResponseStatus.DELTA, null, null)); response.setProfileSyncResponse(new ProfileSyncResponse(SyncResponseStatus.DELTA)); response.setRedirectSyncResponse(new RedirectSyncResponse(1)); response.setUserSyncResponse(new UserSyncResponse()); LogDeliveryStatus status = new LogDeliveryStatus(REQUEST_ID, SyncResponseResultType.SUCCESS, null); response.setLogSyncResponse(new LogSyncResponse(Collections.singletonList(status))); AvroByteArrayConverter<SyncResponse> converter = new AvroByteArrayConverter<>(SyncResponse.class); operationsDataProcessor.processResponse(converter.toByteArray(response)); }