-
Notifications
You must be signed in to change notification settings - Fork 64
Tests for MySql Extensions #755
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
Draft
guptaheena
wants to merge
12
commits into
dev
Choose a base branch
from
heenagupta/mysqlextensiontests
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ec103fe
Tests for mysql extensions
guptaheena 633968f
changes to new yml files
guptaheena b2579f4
Update java version
guptaheena 14b033d
test: trigger e2e tests
YunchuWang c3b5f0e
Merge branch 'dev' into heenagupta/mysqlextensiontests
YunchuWang f10853c
revert: copy public br to internal for testing
YunchuWang 4892ee9
Update MySqlTriggerTests.java
guptaheena ca693a6
Update MySqlTriggerTests.java
guptaheena 50402d6
Update version
guptaheena e52de55
Fix indentation in local.settings.json
guptaheena de9536a
updating java mysql version
guptaheena 6ef1ad4
Merge branch 'dev' into heenagupta/mysqlextensiontests
manvkaur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...tests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/MySqlEndToEndTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Azure.Functions.Java.Tests.E2E | ||
{ | ||
[Collection(Constants.FunctionAppCollectionName)] | ||
public class MySqlEndToEndTests | ||
{ | ||
private readonly FunctionAppFixture _fixture; | ||
|
||
public MySqlEndToEndTests(FunctionAppFixture fixture) | ||
{ | ||
this._fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task MySqlInput_Output_Succeeds() | ||
{ | ||
TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1); | ||
int id = (int) t.TotalSeconds; | ||
var product = new Dictionary<string, object>() | ||
{ | ||
{ "ProductId", id }, | ||
{ "Name", "test" }, | ||
{ "Cost", 100 } | ||
}; | ||
|
||
var productString = JsonConvert.SerializeObject(product); | ||
// Insert a row into Products table using MySqlOutput | ||
Assert.True(await Utilities.InvokeHttpTriggerPost("AddProduct", productString, HttpStatusCode.OK)); | ||
|
||
// Read row from Products table using MySqlInput | ||
Assert.True(await Utilities.InvokeHttpTrigger("GetProducts", "/" + id.ToString(), HttpStatusCode.OK, productString)); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/MySqlTriggerTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.microsoft.azure.functions.endtoend; | ||
|
||
import com.microsoft.azure.functions.annotation.*; | ||
import com.google.gson.Gson; | ||
import com.microsoft.azure.functions.*; | ||
import com.microsoft.azure.functions.HttpMethod; | ||
import com.microsoft.azure.functions.mysql.annotation.CommandType; | ||
import com.microsoft.azure.functions.mysql.annotation.MySqlInput; | ||
import com.microsoft.azure.functions.mysql.annotation.MySqlOutput; | ||
import com.microsoft.azure.functions.mysql.annotation.MySqlTrigger; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.Array; | ||
import java.util.*; | ||
|
||
/** | ||
* Azure Functions with Azure MySql Database. | ||
*/ | ||
public class MySqlTriggerTests { | ||
|
||
@FunctionName("GetProducts") | ||
public HttpResponseMessage GetProducts(@HttpTrigger(name = "req", methods = { HttpMethod.GET, | ||
HttpMethod.POST }, route = "getproducts/{productid}", authLevel = AuthorizationLevel.ANONYMOUS) | ||
HttpRequestMessage<Optional<String>> request, | ||
@MySqlInput(name = "products", commandText = "SELECT TOP 1 * FROM Products WHERE ProductId = @ProductId", | ||
commandType = CommandType.Text, parameters = "@ProductId={productid}", | ||
connectionStringSetting = "AzureWebJobsMySqlConnectionString") Product[] products, | ||
final ExecutionContext context) { | ||
|
||
context.getLogger().info("Java HTTP trigger processed a MySql Input Binding request."); | ||
|
||
if (products.length != 0) { | ||
return request.createResponseBuilder(HttpStatus.OK).body(products[0].toString()).build(); | ||
} else { | ||
return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body("Did not find expected product in table Products").build(); | ||
} | ||
} | ||
|
||
@FunctionName("AddProduct") | ||
public HttpResponseMessage AddProduct(@HttpTrigger(name = "req", methods = { HttpMethod.GET, | ||
HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, | ||
@MySqlOutput(name = "product", commandText = "Products", connectionStringSetting = "AzureWebJobsMySqlConnectionString") OutputBinding<Product> product, | ||
final ExecutionContext context) { | ||
context.getLogger().info("Java HTTP trigger processed a MySql Output Binding request."); | ||
|
||
String json = request.getBody().get(); | ||
product.setValue(new Gson().fromJson(json, Product.class)); | ||
|
||
return request.createResponseBuilder(HttpStatus.OK).body(product).build(); | ||
} | ||
|
||
public class Product { | ||
public int ProductId; | ||
public String Name; | ||
public int Cost; | ||
|
||
public String toString() { | ||
return "{\"ProductId\":" + ProductId + ",\"Name\":\"" + Name + "\",\"Cost\":" + Cost + "}"; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldn't be checked-in