fix issue #661 for Advanced aggregations (#704)

* Add Advanced Aggregation Feature

* fix overwrite error

* distinct data for better performance

* remove constructor parameter

* fix tests issue

* fix tests

* fix tests issue

* Add UnitTest and AcceptanceTest

* fix responseKeys typo

* Update SimpleJsonResponseAggregator.cs

* change port
This commit is contained in:
Abolfazl
2019-02-04 15:51:50 +03:30
committed by Marcelo Castagna
parent 44dccf1fce
commit faaabbe7a7
11 changed files with 352 additions and 59 deletions

View File

@ -141,6 +141,100 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
[Fact]
public void should_return_response_200_with_advanced_aggregate_configs()
{
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
{
new FileReRoute
{
DownstreamPathTemplate = "/",
DownstreamScheme = "http",
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new FileHostAndPort
{
Host = "localhost",
Port = 51889,
}
},
UpstreamPathTemplate = "/Comments",
UpstreamHttpMethod = new List<string> { "Get" },
Key = "Comments"
},
new FileReRoute
{
DownstreamPathTemplate = "/users/{userId}",
DownstreamScheme = "http",
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new FileHostAndPort
{
Host = "localhost",
Port = 51890,
}
},
UpstreamPathTemplate = "/UserDetails",
UpstreamHttpMethod = new List<string> { "Get" },
Key = "UserDetails"
},
new FileReRoute
{
DownstreamPathTemplate = "/posts/{postId}",
DownstreamScheme = "http",
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new FileHostAndPort
{
Host = "localhost",
Port = 51887,
}
},
UpstreamPathTemplate = "/PostDetails",
UpstreamHttpMethod = new List<string> { "Get" },
Key = "PostDetails"
}
},
Aggregates = new List<FileAggregateReRoute>
{
new FileAggregateReRoute
{
UpstreamPathTemplate = "/",
UpstreamHost = "localhost",
ReRouteKeys = new List<string>
{
"Comments",
"UserDetails",
"PostDetails"
},
ReRouteKeysConfig = new List<AggregateReRouteConfig>()
{
new AggregateReRouteConfig(){ReRouteKey = "UserDetails",JsonPath = "$[*].writerId",Parameter = "userId"},
new AggregateReRouteConfig(){ReRouteKey = "PostDetails",JsonPath = "$[*].postId",Parameter = "postId"}
},
}
}
};
var userDetailsResponseContent = @"{""id"":1,""firstName"":""abolfazl"",""lastName"":""rajabpour""}";
var postDetailsResponseContent = @"{""id"":1,""title"":""post1""}";
var commentsResponseContent = @"[{""id"":1,""writerId"":1,""postId"":2,""text"":""text1""},{""id"":2,""writerId"":1,""postId"":2,""text"":""text2""}]";
var expected = "{\"Comments\":" + commentsResponseContent + ",\"UserDetails\":" + userDetailsResponseContent + ",\"PostDetails\":" + postDetailsResponseContent + "}";
this.Given(x => x.GivenServiceOneIsRunning("http://localhost:51889", "/", 200, commentsResponseContent))
.Given(x => x.GivenServiceTwoIsRunning("http://localhost:51890", "/users/1", 200, userDetailsResponseContent))
.Given(x => x.GivenServiceTwoIsRunning("http://localhost:51887", "/posts/2", 200, postDetailsResponseContent))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => _steps.ThenTheResponseBodyShouldBe(expected))
.BDDfy();
}
[Fact]
public void should_return_response_200_with_simple_url_user_defined_aggregate()
{
@ -189,8 +283,8 @@ namespace Ocelot.AcceptanceTests
UpstreamHost = "localhost",
ReRouteKeys = new List<string>
{
"Tom",
"Laura"
"Laura",
"Tom"
},
Aggregator = "FakeDefinedAggregator"
}
@ -258,8 +352,8 @@ namespace Ocelot.AcceptanceTests
UpstreamHost = "localhost",
ReRouteKeys = new List<string>
{
"Tom",
"Laura"
"Laura",
"Tom"
}
}
}
@ -326,8 +420,9 @@ namespace Ocelot.AcceptanceTests
UpstreamHost = "localhost",
ReRouteKeys = new List<string>
{
"Tom",
"Laura"
"Laura",
"Tom"
}
}
}
@ -394,8 +489,8 @@ namespace Ocelot.AcceptanceTests
UpstreamHost = "localhost",
ReRouteKeys = new List<string>
{
"Tom",
"Laura"
"Laura",
"Tom"
}
}
}
@ -462,8 +557,8 @@ namespace Ocelot.AcceptanceTests
UpstreamHost = "localhost",
ReRouteKeys = new List<string>
{
"Tom",
"Laura"
"Laura",
"Tom"
}
}
}