private static ProfileSyncResponse convert(ProfileServerSync profileSyncResponse) { if (profileSyncResponse == null) { return null; } return new ProfileSyncResponse(convert(profileSyncResponse.getResponseStatus())); }
@Override public void onProfileResponse(ProfileSyncResponse response) throws Exception { if (response.getResponseStatus() == SyncResponseStatus.RESYNC) { clientState.setIfNeedProfileResync(true); sync(); } else if (clientState != null && !clientState.isRegistered()) { clientState.setRegistered(true); } LOG.info("Processed profile response"); }
@Test public void onProfileResponse() throws Exception { KaaChannelManager channelManager = Mockito.mock(KaaChannelManager.class); KaaClientState clientState1 = Mockito.mock(KaaClientState.class); ProfileTransport transport = new DefaultProfileTransport(); transport.setChannelManager(channelManager); transport.setClientState(clientState1); ProfileSyncResponse response1 = new ProfileSyncResponse(); response1.setResponseStatus(SyncResponseStatus.RESYNC); transport.onProfileResponse(response1); Mockito.verify(channelManager, Mockito.times(1)).syncAll(TransportType.PROFILE); ProfileSyncResponse response2 = new ProfileSyncResponse(); response2.setResponseStatus(SyncResponseStatus.DELTA); transport.setClientState(null); transport.onProfileResponse(response2); Mockito.verify(clientState1, Mockito.times(0)).setRegistered(Mockito.anyBoolean()); Mockito.when(clientState1.isRegistered()).thenReturn(false); transport.setClientState(clientState1); transport.onProfileResponse(response2); Mockito.verify(clientState1, Mockito.times(1)).setRegistered(Mockito.eq(true)); KaaClientState clientState2 = Mockito.mock(KaaClientState.class); Mockito.when(clientState2.isRegistered()).thenReturn(true); transport.setClientState(clientState2); transport.onProfileResponse(response2); Mockito.verify(clientState2, Mockito.times(0)).setRegistered(Mockito.anyBoolean()); }
@Override public ProfileSyncResponse build() { try { ProfileSyncResponse record = new ProfileSyncResponse(); record.responseStatus = fieldSetFlags()[0] ? this.responseStatus : (org.kaaproject.kaa.common.endpoint.gen.SyncResponseStatus) defaultValue(fields()[0]); return record; } catch (Exception e) { throw new org.apache.avro.AvroRuntimeException(e); } } }
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());
@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)); }