/** * Tests the publish method with invalid input parameters * * @throws HubException */ @Test public void testPublishInvalidInputs() throws HubException { errors.add("Error string"); when(hubValidator.validatePing(mode, url)).thenReturn(errors); try { controller.publish(mode, url); } catch (RestException e) { HubErrors he = e.getHubException().getError(); assertEquals(1001, he.getCode()); assertEquals(HttpStatus.BAD_REQUEST, he.getHttpStatus()); assertEquals("One or more input parameter(s) may be wrong", he.getMessage()); } verify(hubValidator).validatePing(mode, url); }
/** * Tests the subscribe method with invalid input parameters * * @throws HubException */ @Test public void testSubscribeInvalidInputs() throws HubException { errors.add("Error string"); when(hubValidator.validateSubscription(callbackUrl, mode, topic, leaseSeconds, secret)) .thenReturn(errors); try { controller.subscribe(callbackUrl, mode, topic, leaseSeconds, secret); } catch (RestException e) { HubErrors he = e.getHubException().getError(); assertEquals(1001, he.getCode()); assertEquals(HttpStatus.BAD_REQUEST, he.getHttpStatus()); assertEquals("One or more input parameter(s) may be wrong", he.getMessage()); } verify(hubValidator).validateSubscription(callbackUrl, mode, topic, leaseSeconds, secret); }
/** * Tests the subscribe method with valid input parameters * * @throws HubException */ @Test public void testSubscribe() throws HubException { when(hubValidator.validateSubscription(callbackUrl, mode, topic, leaseSeconds, secret)) .thenReturn(errors); doAnswer( new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); assertNotNull(args); assertEquals(5, args.length); String callbackUrl = (String) args[0]; Modes mode = (Modes) args[1]; String topic = (String) args[2]; String leaseSeconds = (String) args[3]; String secret = (String) args[4]; assertNotNull(callbackUrl); assertNotNull(mode); assertNotNull(topic); assertNotNull(leaseSeconds); assertNotNull(secret); assertEquals("callback_url", callbackUrl); assertEquals(Modes.SUBSCRIBE, mode); assertEquals("topic_url", topic); assertEquals("20", leaseSeconds); assertEquals("secret", secret); return null; } }) .when(controller.getSubscriptionService()) .subscribe(callbackUrl, Modes.SUBSCRIBE, topic, leaseSeconds, secret); controller.subscribe(callbackUrl, mode, topic, leaseSeconds, secret); verify(hubValidator).validateSubscription(callbackUrl, mode, topic, leaseSeconds, secret); verify(subscriptionService) .subscribe(callbackUrl, Modes.SUBSCRIBE, topic, leaseSeconds, secret); }