From 34c767316a5e735d9e505e29f122c5fa2a83a927 Mon Sep 17 00:00:00 2001 From: Pragna Gopa Date: Tue, 24 Jul 2018 18:58:26 -0700 Subject: [PATCH] Update to 1.0.0-beta-5 (#40) --- .../src/main/resources/archetype-resources/pom.xml | 2 +- .../archetype-resources/src/main/java/Function.java | 8 ++++---- .../src/test/java/FunctionTest.java | 12 +++++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/azure-functions-archetype/src/main/resources/archetype-resources/pom.xml b/azure-functions-archetype/src/main/resources/archetype-resources/pom.xml index e7f6f8f..8916668 100644 --- a/azure-functions-archetype/src/main/resources/archetype-resources/pom.xml +++ b/azure-functions-archetype/src/main/resources/archetype-resources/pom.xml @@ -15,7 +15,7 @@ 1.8 1.8 1.0.0-beta-3 - 1.0.0-beta-4 + 1.0.0-beta-5 ${appName} ${appRegion} ${project.build.directory}/azure-functions/${functionAppName} diff --git a/azure-functions-archetype/src/main/resources/archetype-resources/src/main/java/Function.java b/azure-functions-archetype/src/main/resources/archetype-resources/src/main/java/Function.java index c85119e..23b8d7f 100644 --- a/azure-functions-archetype/src/main/resources/archetype-resources/src/main/java/Function.java +++ b/azure-functions-archetype/src/main/resources/archetype-resources/src/main/java/Function.java @@ -14,8 +14,8 @@ public class Function { * 2. curl {your host}/api/HttpTrigger-Java?name=HTTP%20Query */ @FunctionName("HttpTrigger-Java") - public HttpResponseMessage HttpTriggerJava( - @HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage> request, + public HttpResponseMessage HttpTriggerJava( + @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage> request, final ExecutionContext context) { context.getLogger().info("Java HTTP trigger processed a request."); @@ -24,9 +24,9 @@ public HttpResponseMessage HttpTriggerJava( String name = request.getBody().orElse(query); if (name == null) { - return request.createResponse(400, "Please pass a name on the query string or in the request body"); + return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build(); } else { - return request.createResponse(200, "Hello, " + name); + return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build(); } } } diff --git a/azure-functions-archetype/src/main/resources/archetype-resources/src/test/java/FunctionTest.java b/azure-functions-archetype/src/main/resources/archetype-resources/src/test/java/FunctionTest.java index 7079553..bd656ad 100644 --- a/azure-functions-archetype/src/main/resources/archetype-resources/src/test/java/FunctionTest.java +++ b/azure-functions-archetype/src/main/resources/archetype-resources/src/test/java/FunctionTest.java @@ -1,6 +1,7 @@ package $package; import org.junit.Test; + import com.microsoft.azure.functions.*; import java.util.HashMap; @@ -9,7 +10,7 @@ import java.util.logging.Logger; import static org.junit.Assert.assertSame; -import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -23,7 +24,7 @@ public class FunctionTest { * Unit test for HttpTriggerJava method. */ @Test - public void testHello() throws Exception { + public void testHttpTriggerJava() throws Exception { // Setup final HttpRequestMessage> req = mock(HttpRequestMessage.class); @@ -34,8 +35,13 @@ public void testHello() throws Exception { final Optional queryBody = Optional.empty(); doReturn(queryBody).when(req).getBody(); + + final HttpResponseMessage.Builder builder = mock(HttpResponseMessage.Builder.class); + doReturn(builder).when(req).createResponseBuilder(any(HttpStatus.class)); + doReturn(builder).when(builder).body(anyString()); + final HttpResponseMessage res = mock(HttpResponseMessage.class); - doReturn(res).when(req).createResponse(anyInt(), anyString()); + doReturn(res).when(builder).build(); final ExecutionContext context = mock(ExecutionContext.class); doReturn(Logger.getGlobal()).when(context).getLogger();