@Override public EndpointAttachResponse build() { try { EndpointAttachResponse record = new EndpointAttachResponse(); record.requestId = fieldSetFlags()[0] ? this.requestId : (java.lang.Integer) defaultValue(fields()[0]); record.endpointKeyHash = fieldSetFlags()[1] ? this.endpointKeyHash : (java.lang.String) defaultValue(fields()[1]); record.result = fieldSetFlags()[2] ? this.result : (org.kaaproject.kaa.common.endpoint.gen.SyncResponseResultType) defaultValue(fields()[2]); return record; } catch (Exception e) { throw new org.apache.avro.AvroRuntimeException(e); } } }
for (EndpointAttachResponse attached : response.getEndpointAttachResponses()) { EndpointAccessToken attachedToken = attachEndpointRequests.remove( attached.getRequestId()); if (attached.getResult() == SyncResponseResultType.SUCCESS) { if (attachedToken != null) { LOG.info("Token {}", attachedToken); attachedEndpoints.put(attachedToken, new EndpointKeyHash(attached.getEndpointKeyHash())); hasChanges = true; } else { LOG.warn("Endpoint {} is already attached!", attached.getEndpointKeyHash()); attached.getEndpointKeyHash(), attached.getRequestId());
@Test public void onUserResponse() throws Exception { Map<Integer, EndpointAccessToken> attachingEPs = new HashMap<>(); attachingEPs.put(REQUEST_ID_1, new EndpointAccessToken("token1")); attachingEPs.put(REQUEST_ID_2, new EndpointAccessToken("token2")); Map<Integer, EndpointKeyHash> dettachingEPs = new HashMap<>(); dettachingEPs.put(REQUEST_ID_1, new EndpointKeyHash("keyhash1")); dettachingEPs.put(REQUEST_ID_2, new EndpointKeyHash("keyhash2")); KaaClientState clientState = Mockito.mock(KaaClientState.class); EndpointRegistrationProcessor processor = Mockito.mock(EndpointRegistrationProcessor.class); Mockito.when(processor.getAttachEndpointRequests()).thenReturn(attachingEPs); Mockito.when(processor.getDetachEndpointRequests()).thenReturn(dettachingEPs); UserTransport transport = new DefaultUserTransport(); UserSyncResponse response1 = new UserSyncResponse(); response1.setEndpointAttachResponses(Arrays.asList( new EndpointAttachResponse(REQUEST_ID_1, "keyhash1", SyncResponseResultType.SUCCESS), new EndpointAttachResponse(REQUEST_ID_2, "keyhash2", SyncResponseResultType.SUCCESS), new EndpointAttachResponse(REQUEST_ID_1 + 1, "keyhash2", SyncResponseResultType.FAILURE))); response1.setEndpointDetachResponses(Arrays.asList( new EndpointDetachResponse(REQUEST_ID_1, SyncResponseResultType.SUCCESS), new EndpointDetachResponse(REQUEST_ID_1 + 2, SyncResponseResultType.FAILURE))); transport.setEndpointRegistrationProcessor(processor); transport.setClientState(clientState); transport.onUserResponse(response1); Mockito.verify(processor, Mockito.times(1)).onUpdate(Mockito.anyListOf(EndpointAttachResponse.class), Mockito.anyListOf(EndpointDetachResponse.class), Mockito.any(UserAttachResponse.class), Mockito.any(UserAttachNotification.class), Mockito.any(UserDetachNotification.class)); Mockito.verify(clientState, Mockito.times(1)).setAttachedEndpointsList(Mockito.anyMap()); }
notifyAttachedListener(attached.getResult(), endpointAttachListeners.remove(attached.getRequestId()), new EndpointKeyHash( attached.getEndpointKeyHash())); attachEndpointRequests.remove(attached.getRequestId());
@Test public void onDuplicateUserAttachResponse() throws Exception { KaaClientState clientState = Mockito.mock(KaaClientState.class); EndpointRegistrationProcessor processor = Mockito.mock(EndpointRegistrationProcessor.class); Map<Integer, EndpointAccessToken> attachingEPs = new HashMap<>(); attachingEPs.put(REQUEST_ID_1, new EndpointAccessToken("token1")); Mockito.when(processor.getAttachEndpointRequests()).thenReturn(attachingEPs); UserTransport transport = new DefaultUserTransport(); UserSyncResponse response1 = new UserSyncResponse(); response1.setEndpointAttachResponses(Arrays.asList( new EndpointAttachResponse(REQUEST_ID_1, "keyhash1", SyncResponseResultType.SUCCESS))); transport.setClientState(clientState); transport.setEndpointRegistrationProcessor(processor); Map<EndpointAccessToken, EndpointKeyHash> map = new HashMap<>(); map.put(new EndpointAccessToken("token1"), new EndpointKeyHash("keyhash1")); transport.onUserResponse(response1); Mockito.verify(clientState, Mockito.times(1)).setAttachedEndpointsList(map); transport.onUserResponse(response1); Mockito.verify(clientState, Mockito.times(1)).setAttachedEndpointsList(map); }
attach.add(new EndpointAttachResponse(REQUEST_ID, "keyHash", SyncResponseResultType.SUCCESS)); sr.setEndpointAttachResponses(attach); transport.onUserResponse(sr);
for (org.kaaproject.kaa.server.sync.EndpointAttachResponse response : source.getEndpointAttachResponses()) { responses.add(new EndpointAttachResponse( response.getRequestId(), response.getEndpointKeyHash(), convert(response .getResult())));