@Test public void testOddNumbers() throws Exception { final Map<String, String> queryParams = new HashMap<>(); queryParams.put("number", "3"); final HttpResponseMessage.Builder builder = mock(HttpResponseMessage.Builder.class); HttpRequestMessage<Optional<String>> req = generateHttpRequest(queryParams, builder); ExecutionContext context = generateContext(); new OddOrEven().HttpTriggerJava(req, context); verify(builder).body("Odd"); verify(req).createResponseBuilder(HttpStatus.OK); }
@FunctionName("HttpTrigger-Java") public HttpResponseMessage HttpTriggerJava( @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, final ExecutionContext context) { try { context.getLogger().info("Java HTTP trigger processed a request."); String numberQueryValue = request.getQueryParameters().get("number"); int number = Integer.parseInt(numberQueryValue); return request .createResponseBuilder(HttpStatus.OK) .body(number % 2 == 0 ? "Even" : "Odd") .build(); } catch(NumberFormatException nfe) { return request .createResponseBuilder(HttpStatus.BAD_REQUEST) .body("Unable to parse") .build(); } }
OddOrEven { @FunctionName("HttpTrigger-Java") public HttpResponseMessage HttpTriggerJava( @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, final ExecutionContext context) { try { context.getLogger().info("Java HTTP trigger processed a request."); String numberQueryValue = request.getQueryParameters().get("number"); int number = Integer.parseInt(numberQueryValue); return request .createResponseBuilder(HttpStatus.OK) .body(number % 2 == 0 ? "Even" : "Odd") .build(); } catch(NumberFormatException nfe) { return request .createResponseBuilder(HttpStatus.BAD_REQUEST) .body("Unable to parse") .build(); } } }
OddOrEven { @FunctionName("HttpTrigger-Java") public HttpResponseMessage HttpTriggerJava( @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, final ExecutionContext context) { try { context.getLogger().info("Java HTTP trigger processed a request."); String numberQueryValue = request.getQueryParameters().get("number"); int number = Integer.parseInt(numberQueryValue); return request .createResponseBuilder(HttpStatus.OK) .body(number % 2 == 0 ? "Even" : "Odd") .build(); } catch(NumberFormatException nfe) { return request .createResponseBuilder(HttpStatus.BAD_REQUEST) .body("Unable to parse") .build(); } }  }
OddOrEven { @FunctionName("HttpTrigger-Java") public HttpResponseMessage HttpTriggerJava( @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, final ExecutionContext context) { try { context.getLogger().info("Java HTTP trigger processed a request."); String numberQueryValue = request.getQueryParameters().get("number"); int number = Integer.parseInt(numberQueryValue); return request .createResponseBuilder(HttpStatus.OK) .body(number % 2 == 0 ? "Even" : "Odd") .build(); } catch(NumberFormatException nfe) { return request .createResponseBuilder(HttpStatus.BAD_REQUEST) .body("Unable to parse") .build(); } }  @FunctionName("HttpTrigger-Java") HttpResponseMessage HttpTriggerJava(
            @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context); }
OddOrEven { @FunctionName("HttpTrigger-Java") public HttpResponseMessage HttpTriggerJava( @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, final ExecutionContext context) { try { context.getLogger().info("Java HTTP trigger processed a request."); String numberQueryValue = request.getQueryParameters().get("number"); int number = Integer.parseInt(numberQueryValue); return request .createResponseBuilder(HttpStatus.OK) .body(number % 2 == 0 ? "Even" : "Odd") .build(); } catch(NumberFormatException nfe) { return request .createResponseBuilder(HttpStatus.BAD_REQUEST) .body("Unable to parse") .build(); } }  @FunctionName("HttpTrigger-Java") HttpResponseMessage HttpTriggerJava(
            @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context);  }