@Test public void testOddNumbers() throws Exception { CloseableHttpClient client = mock(CloseableHttpClient.class); CloseableHttpResponse res = mock(CloseableHttpResponse.class); doReturn(res).when(client).execute(any()); OddOrEvenQueue.client = client; OddOrEvenQueue function = new OddOrEvenQueue(); function.queueHandler("3", generateContext()); verify(client).execute(argThat(h -> { try { HttpPost req = (HttpPost)h; BufferedReader reader = new BufferedReader(new InputStreamReader(req.getEntity().getContent())); String content = reader.readLine(); assertEquals("Odd", content); return true; } catch (Exception e) { return false; } })); }
@FunctionName("OddOrEvenQueue") public void queueHandler( @QueueTrigger(name = "myNumber", queueName = "numbers", connection = "AzureWebJobsStorage") String myNumber, final ExecutionContext context ) throws NumberFormatException, ClientProtocolException, IOException { try { context.getLogger().info("Java Odd or Even Queue trigger function processed a message."); int number = Integer.parseInt(myNumber); if(number % 2 == 0) { context.getLogger().info("Was even"); HttpPost httpPost = new HttpPost("http: httpPost.setEntity(new StringEntity("Even")); CloseableHttpResponse response = client.execute(httpPost); response.close(); } else { context.getLogger().info("Was odd"); HttpPost httpPost = new HttpPost("http: httpPost.setEntity(new StringEntity("Odd")); CloseableHttpResponse response = client.execute(httpPost); } } catch(Exception e) { throw e; } finally { } }
OddOrEvenQueue { @FunctionName("OddOrEvenQueue") public void queueHandler( @QueueTrigger(name = "myNumber", queueName = "numbers", connection = "AzureWebJobsStorage") String myNumber, final ExecutionContext context ) throws NumberFormatException, ClientProtocolException, IOException { try { context.getLogger().info("Java Odd or Even Queue trigger function processed a message."); int number = Integer.parseInt(myNumber); if(number % 2 == 0) { context.getLogger().info("Was even"); HttpPost httpPost = new HttpPost("http: httpPost.setEntity(new StringEntity("Even")); CloseableHttpResponse response = client.execute(httpPost); response.close(); } else { context.getLogger().info("Was odd"); HttpPost httpPost = new HttpPost("http: httpPost.setEntity(new StringEntity("Odd")); CloseableHttpResponse response = client.execute(httpPost); } } catch(Exception e) { throw e; } finally { } } }
OddOrEvenQueue { @FunctionName("OddOrEvenQueue") public void queueHandler( @QueueTrigger(name = "myNumber", queueName = "numbers", connection = "AzureWebJobsStorage") String myNumber, final ExecutionContext context ) throws NumberFormatException, ClientProtocolException, IOException { try { context.getLogger().info("Java Odd or Even Queue trigger function processed a message."); int number = Integer.parseInt(myNumber); if(number % 2 == 0) { context.getLogger().info("Was even"); HttpPost httpPost = new HttpPost("http: httpPost.setEntity(new StringEntity("Even")); CloseableHttpResponse response = client.execute(httpPost); response.close(); } else { context.getLogger().info("Was odd"); HttpPost httpPost = new HttpPost("http: httpPost.setEntity(new StringEntity("Odd")); CloseableHttpResponse response = client.execute(httpPost); } } catch(Exception e) { throw e; } finally { } }  }
OddOrEvenQueue { @FunctionName("OddOrEvenQueue") public void queueHandler( @QueueTrigger(name = "myNumber", queueName = "numbers", connection = "AzureWebJobsStorage") String myNumber, final ExecutionContext context ) throws NumberFormatException, ClientProtocolException, IOException { try { context.getLogger().info("Java Odd or Even Queue trigger function processed a message."); int number = Integer.parseInt(myNumber); if(number % 2 == 0) { context.getLogger().info("Was even"); HttpPost httpPost = new HttpPost("http: httpPost.setEntity(new StringEntity("Even")); CloseableHttpResponse response = client.execute(httpPost); response.close(); } else { context.getLogger().info("Was odd"); HttpPost httpPost = new HttpPost("http: httpPost.setEntity(new StringEntity("Odd")); CloseableHttpResponse response = client.execute(httpPost); } } catch(Exception e) { throw e; } finally { } }  @FunctionName("OddOrEvenQueue") void queueHandler(
        @QueueTrigger(name = "myNumber", queueName = "numbers", connection = "AzureWebJobsStorage") String myNumber,
        final ExecutionContext context
    ); }
OddOrEvenQueue { @FunctionName("OddOrEvenQueue") public void queueHandler( @QueueTrigger(name = "myNumber", queueName = "numbers", connection = "AzureWebJobsStorage") String myNumber, final ExecutionContext context ) throws NumberFormatException, ClientProtocolException, IOException { try { context.getLogger().info("Java Odd or Even Queue trigger function processed a message."); int number = Integer.parseInt(myNumber); if(number % 2 == 0) { context.getLogger().info("Was even"); HttpPost httpPost = new HttpPost("http: httpPost.setEntity(new StringEntity("Even")); CloseableHttpResponse response = client.execute(httpPost); response.close(); } else { context.getLogger().info("Was odd"); HttpPost httpPost = new HttpPost("http: httpPost.setEntity(new StringEntity("Odd")); CloseableHttpResponse response = client.execute(httpPost); } } catch(Exception e) { throw e; } finally { } }  @FunctionName("OddOrEvenQueue") void queueHandler(
        @QueueTrigger(name = "myNumber", queueName = "numbers", connection = "AzureWebJobsStorage") String myNumber,
        final ExecutionContext context
    ); static CloseableHttpClient client; }