SPQRResourceManagerClient { public NodeDeRegistrationResponse deregisterNode(final String nodeId) throws RequiredInputMissingException, RemoteClientConnectionFailedException { if(StringUtils.isBlank(nodeId)) throw new RequiredInputMissingException("Missing required node identifier"); StringBuffer url = new StringBuffer(this.resourceManagerServiceBaseUrl).append("/nodes/").append(nodeId); if(logger.isDebugEnabled()) logger.debug("De-registering processing node [nodeId="+nodeId+"] at resource manager " + url.toString()); try { final WebTarget webTarget = this.restClient.target(url.toString()); return webTarget.request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).delete(NodeDeRegistrationResponse.class); } catch(Exception e) { throw new RemoteClientConnectionFailedException("Failed to establish a connection with the remote resource manager [url="+url.toString()+"]. Error: " + e.getMessage()); } } SPQRResourceManagerClient(final String resourceManagerProtocol, final String resourceManagerRemoteHost, 
			final int resourceManagerServicePort, final Client resourceManagerClient); NodeRegistrationResponse registerNode(final String nodeProtocol, final String nodeHost, final int nodeServicePort, final int nodeAdminPort); NodeDeRegistrationResponse deregisterNode(final String nodeId);  }
@Test public void testDeRegisterNode_withEmptyInput() throws Exception { try { new SPQRResourceManagerClient("http", "localhost", 8080, Mockito.mock(Client.class)).deregisterNode(null); Assert.fail("Invalid input"); } catch(RequiredInputMissingException e) { } }
@Test public void testDeRegisterNode_withValidInput() throws Exception { String remoteUrl = "http: NodeDeRegistrationResponse expectedResponse = new NodeDeRegistrationResponse("test-id", NodeDeRegistrationState.OK, ""); Builder builder2 = Mockito.mock(Builder.class); Mockito.when(builder2.delete(NodeDeRegistrationResponse.class)).thenReturn(expectedResponse); Builder builder1 = Mockito.mock(Builder.class); Mockito.when(builder1.accept(MediaType.APPLICATION_JSON)).thenReturn(builder2); WebTarget mockWebTarget = Mockito.mock(WebTarget.class); Mockito.when(mockWebTarget.request(MediaType.APPLICATION_JSON)).thenReturn(builder1); Client mockClient = Mockito.mock(Client.class); Mockito.when(mockClient.target(remoteUrl)).thenReturn(mockWebTarget); SPQRResourceManagerClient client = new SPQRResourceManagerClient("http", "localhost", 7070, mockClient); NodeDeRegistrationResponse response = client.deregisterNode("test-id"); Assert.assertNotNull("The response must not be null", response); Assert.assertEquals("No errors expected", NodeDeRegistrationState.OK, response.getState()); Mockito.verify(mockClient).target(remoteUrl); Mockito.verify(mockWebTarget).request(MediaType.APPLICATION_JSON); Mockito.verify(builder1).accept(MediaType.APPLICATION_JSON); Mockito.verify(builder2).delete(NodeDeRegistrationResponse.class); }