SPQRNodeManagementResource { @Produces(value = "application/json") @Timed(name = "node-registration") @POST public NodeRegistrationResponse registerNode(final NodeRegistrationRequest request) { if(request == null) return new NodeRegistrationResponse("", NodeRegistrationState.MISSING_REQUEST, "Missing request body carrying required node information"); return this.nodeManager.registerNode(request.getProtocol(), request.getHost(), request.getServicePort(), request.getAdminPort()); } SPQRNodeManagementResource(final SPQRNodeManager nodeManager); @Produces(value = "application/json") @Timed(name = "node-registration") @POST NodeRegistrationResponse registerNode(final NodeRegistrationRequest request); @Produces(value = "application/json") @Timed(name = "node-deregistration") @Path("{nodeId}") @DELETE NodeDeRegistrationResponse deregisterNode(@PathParam("nodeId") final String nodeId);  }
@Test public void testRegisterNode_withNullInput() { Assert.assertEquals("Invalid input", NodeRegistrationState.MISSING_REQUEST, new SPQRNodeManagementResource(Mockito.mock(SPQRNodeManager.class)).registerNode(null).getState()); }
@Test public void testRegisterNode_withValidInput() { SPQRNodeManager mockedNodeManager = Mockito.mock(SPQRNodeManager.class); NodeRegistrationRequest request = new NodeRegistrationRequest("http", "localhost", 8080, 8081); Mockito.when(mockedNodeManager.registerNode(request.getProtocol(), request.getHost(), request.getServicePort(), request.getAdminPort())). thenReturn(new NodeRegistrationResponse("test", NodeRegistrationState.OK)); Assert.assertEquals("Valid input provided", NodeRegistrationState.OK, new SPQRNodeManagementResource(mockedNodeManager).registerNode(request).getState()); Mockito.verify(mockedNodeManager).registerNode(request.getProtocol(), request.getHost(), request.getServicePort(), request.getAdminPort()); }