Skip to content

Fix GetProductsColumnTypesSerialization Test in Java #576

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

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion test/Integration/SqlOutputBindingIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public void AddProductArrayTest(SupportedLanguages lang)
/// <param name="lang">The language to run the test against</param>
[Theory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.PowerShell, SupportedLanguages.OutOfProc)]
// Java issue: https://github.com/Azure/azure-functions-sql-extension/issues/521
[UnsupportedLanguages(SupportedLanguages.Java, SupportedLanguages.PowerShell, SupportedLanguages.OutOfProc)]
public void AddProductColumnTypesTest(SupportedLanguages lang)
{
this.StartFunctionHost(nameof(AddProductColumnTypes), lang, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.microsoft.azure.functions.sql.annotation.SQLOutput;
import com.function.Common.ProductColumnTypes;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.Optional;

public class AddProductColumnTypes {
Expand All @@ -37,8 +37,8 @@ public HttpResponseMessage run(

ProductColumnTypes p = new ProductColumnTypes(
Integer.parseInt(request.getQueryParameters().get("productId")),
new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis()));
new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis()));
product.setValue(p);

// Items were inserted successfully so return success, an exception would be thrown if there
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

package com.function.Common;

import java.sql.Date;
import java.sql.Timestamp;

public class ProductColumnTypes {
private int ProductId;
private Date Datetime;
private Date Datetime2;
private Timestamp Datetime;
private Timestamp Datetime2;

public ProductColumnTypes(int productId, Date datetime, Date datetime2) {
public ProductColumnTypes(int productId, Timestamp datetime, Timestamp datetime2) {
ProductId = productId;
Datetime = datetime;
Datetime2 = datetime2;
Expand All @@ -23,19 +23,23 @@ public int getProductId() {
return ProductId;
}

public Date getDatetime() {
public void setProductId(int productId) {
ProductId = productId;
}

public Timestamp getDatetime() {
return Datetime;
}

public void setDatetime(Date datetime) {
public void setDatetime(Timestamp datetime) {
Datetime = datetime;
}

public Date getDatetime2() {
public Timestamp getDatetime2() {
return Datetime2;
}

public void setDatetime2(Date datetime2) {
public void setDatetime2(Timestamp datetime2) {
Datetime2 = datetime2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.text.SimpleDateFormat;
import java.util.Optional;
import java.util.logging.Level;
import java.util.Calendar;
import java.sql.Timestamp;

public class GetProductsColumnTypesSerialization {
@FunctionName("GetProductsColumnTypesSerialization")
Expand All @@ -44,6 +46,12 @@ public HttpResponseMessage run(
SimpleDateFormat df = new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSSXXX");
mapper.setDateFormat(df);
for (ProductColumnTypes product : products) {
// Convert the datetimes to UTC (Java worker returns the datetimes in local timezone)
long datetime = product.getDatetime().getTime();
long datetime2 = product.getDatetime2().getTime();
int offset = Calendar.getInstance().getTimeZone().getOffset(product.getDatetime().getTime());
product.setDatetime(new Timestamp(datetime - offset));
product.setDatetime2(new Timestamp(datetime2 - offset));
context.getLogger().log(Level.INFO, mapper.writeValueAsString(product));
}
return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(mapper.writeValueAsString(products)).build();
Expand Down