Skip to content

Commit

Permalink
Update to 1.0.0-beta-5 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
pragnagopa authored and jdneo committed Jul 25, 2018
1 parent 4155d84 commit 34c7673
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<azure.functions.maven.plugin.version>1.0.0-beta-3</azure.functions.maven.plugin.version>
<azure.functions.java.library.version>1.0.0-beta-4</azure.functions.java.library.version>
<azure.functions.java.library.version>1.0.0-beta-5</azure.functions.java.library.version>
<functionAppName>${appName}</functionAppName>
<functionAppRegion>${appRegion}</functionAppRegion>
<stagingDirectory>${project.build.directory}/azure-functions/${functionAppName}</stagingDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class Function {
* 2. curl {your host}/api/HttpTrigger-Java?name=HTTP%20Query
*/
@FunctionName("HttpTrigger-Java")
public HttpResponseMessage<String> HttpTriggerJava(
@HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
public HttpResponseMessage HttpTriggerJava(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
context.getLogger().info("Java HTTP trigger processed a request.");

Expand All @@ -24,9 +24,9 @@ public HttpResponseMessage<String> 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package $package;

import org.junit.Test;

import com.microsoft.azure.functions.*;

import java.util.HashMap;
Expand All @@ -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;
Expand All @@ -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<Optional<String>> req = mock(HttpRequestMessage.class);

Expand All @@ -34,8 +35,13 @@ public void testHello() throws Exception {
final Optional<String> 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();
Expand Down

0 comments on commit 34c7673

Please sign in to comment.