Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http mock update #79

Merged
merged 8 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,27 @@
<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-7</azure.functions.maven.plugin.version>
<azure.functions.java.library.version>1.0.0-beta-5</azure.functions.java.library.version>
<azure.functions.java.library.version>1.0.0-beta-7-SNAPSHOT</azure.functions.java.library.version>
<functionAppName>${appName}</functionAppName>
<functionAppRegion>${appRegion}</functionAppRegion>
<stagingDirectory>${project.build.directory}/azure-functions/${functionAppName}</stagingDirectory>
<functionResourceGroup>${resourceGroup}</functionResourceGroup>
</properties>

<repositories>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the <repositories> attribute only exist for test purpose?

<repository>
<id>maven.snapshots</id>
<name>Maven Central Snapshot Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,76 @@
import java.util.Map;

/**
* The mock for HttpResponseMessage, can be used in unit tests to verify if the returned response by HTTP trigger function is correct or not.
* The mock for HttpResponseMessage, can be used in unit tests to verify if the
* returned response by HTTP trigger function is correct or not.
*/
public class HttpResponseMessageMock implements HttpResponseMessage {
private HttpStatus status;
private Map<String, String> headers;
private int httpStatusCode;
private HttpStatusType httpStatus;
private Object body;
private Map<String, String> headers;

public HttpResponseMessageMock(HttpStatus status, Map<String, String> headers, Object body) {
this.status = status;
public HttpResponseMessageMock(HttpStatusType status, Map<String, String> headers, Object body) {
this.httpStatus = status;
this.httpStatusCode = status.value();
this.headers = headers;
this.body = body;
}


@Override
public HttpStatusType getStatus() {
return this.httpStatus;
}

@Override
public HttpStatus getStatus() {
return this.status;
public int getStatusCode() {
return httpStatusCode;
}

@Override
public String getHeader(String key) {
return this.headers.get(key);
}

@Override
public Object getBody() {
return this.body;
}

public static class HttpResponseMessageBuilderMock implements HttpResponseMessage.Builder {
private HttpStatus status;
private Map<String, String> headers;
private Object body;
private int httpStatusCode;
private Map<String, String> headers;
private HttpStatusType httpStatus;

public Builder status(HttpStatus status) {
this.httpStatusCode = status.value();
this.httpStatus = status;
return this;
}

@Override
public HttpResponseMessage.Builder status(HttpStatus status) {
this.status = status;
public Builder status(HttpStatusType httpStatusType) {
this.httpStatusCode = httpStatusType.value();
this.httpStatus = httpStatusType;
return this;
}

@Override
public HttpResponseMessage.Builder header(String key, String value) {
this.headers.put(key, value);
return this;
}

@Override
public HttpResponseMessage.Builder body(Object body) {
this.body = body;
return this;
}

@Override
public HttpResponseMessage build() {
return new HttpResponseMessageMock(this.status, this.headers, this.body);
return new HttpResponseMessageMock(this.httpStatus, this.headers, this.body);
}
}
}