mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 12:38:15 +08:00
* 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:

committed by
Marcelo Castagna

parent
44dccf1fce
commit
faaabbe7a7
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user