Skip to content

Commit

Permalink
Added tests for Array inputs with transformation
Browse files Browse the repository at this point in the history
Signed-off-by:Phillip Kruger <phillip.kruger@gmail.com>
  • Loading branch information
phillip-kruger committed Jan 16, 2020
1 parent bcb8edc commit b9ae37e
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -165,6 +166,14 @@ public Collection<SuperHero> createNewHeroes(@Name("heroes") List<SuperHero> new
return newHeroes;
}

@Mutation
public SuperHero[] createNewHeroesWithArray(@Name("heroes") SuperHero[] newHeroes) throws DuplicateSuperHeroException, UnknownHeroException {
LOG.log(Level.INFO, "createNewHeroesWithArray invoked [{0}]", newHeroes);
List<SuperHero> asList = Arrays.asList(newHeroes);
heroDB.addHeroes(asList);
return newHeroes;
}

@Mutation
@Description("Adds a hero to the specified team and returns the updated team.")
public Team addHeroToTeam(@Name("hero") String heroName,
Expand Down Expand Up @@ -321,7 +330,7 @@ public SuperHero updateNetWorthInUSD(@Name("name") String name,
@Mutation
@Description("Log the last place the hero was seen")
public SuperHero logLocation(@Name("name") String name,
@Name("coordinates") List<BigDecimal> coordinates) throws UnknownHeroException {
@Name("coordinates") ArrayList<BigDecimal> coordinates) throws UnknownHeroException {
LOG.log(Level.INFO, "logLocation invoked [{0}],[{1}]", new Object[]{name, coordinates});
SuperHero superHero = heroDB.getHero(name);
if(superHero!=null){
Expand All @@ -343,6 +352,31 @@ public SuperHero logLocationLongLat(@Name("name") String name,
return superHero;
}

@Mutation
@Description("Log the last place the hero was seen using an array")
public SuperHero logLocationWithArray(@Name("name") String name,
@Name("coordinates") BigDecimal[] coordinates) throws UnknownHeroException {
LOG.log(Level.INFO, "logLocationWithArray invoked [{0}],[{1}]", new Object[]{name, coordinates});
SuperHero superHero = heroDB.getHero(name);
if(superHero!=null){
superHero.setLastKnownCoordinates(Arrays.asList(coordinates));
}
return superHero;
}

@Mutation
@Description("Log the last place the hero was seen (Long Lat) using an array")
public SuperHero logLocationLongLatWithArray(@Name("name") String name,
@JsonbNumberFormat("00.0000000 'longlat'")
@Name("coordinates") BigDecimal[] coordinates) throws UnknownHeroException {
LOG.log(Level.INFO, "logLocationLongLatWithArray invoked [{0}],[{1}]", new Object[]{name, coordinates});
SuperHero superHero = heroDB.getHero(name);
if(superHero!=null){
superHero.setLastKnownCoordinates(Arrays.asList(coordinates));
}
return superHero;
}

@Mutation
@Description("Update an item's powerLevel in persentage")
public Item updateItemPowerLevelPersentage(@Name("itemID") long itemID,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation removeHero {
removeHero(hero: "Captain America") {
name
}
}
16 changes: 16 additions & 0 deletions tck/src/main/resources/tests/createNewHerosArray/input.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mutation createNewHeroesWithArray {
createNewHeroesWithArray(heroes:[{
name: "Captain America"
realName: "Steven Rogers"
superPowers: ["Super strength", "Vibranium Shield"]
primaryLocation: "New York, NY"
teamAffiliations: [{name: "Avengers"}]
idNumber: "6578,4312"
}]) {
name
primaryLocation
superPowers
realName
idNumber
}
}
16 changes: 16 additions & 0 deletions tck/src/main/resources/tests/createNewHerosArray/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"data": {
"createNewHeroesWithArray": [
{
"name": "Captain America",
"primaryLocation": "New York, NY",
"superPowers": [
"Super strength",
"Vibranium Shield"
],
"realName": "Steven Rogers",
"idNumber": "6578,4312"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore=false
priority=200
6 changes: 6 additions & 0 deletions tck/src/main/resources/tests/locationArray/input.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mutation logLocationForHero {
logLocationWithArray(name:"Starlord", coordinates:[-25.926804, 28.203392]) {
name
lastKnownCoordinates
}
}
8 changes: 8 additions & 0 deletions tck/src/main/resources/tests/locationArray/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"data": {
"logLocationWithArray": {
"name": "Starlord",
"lastKnownCoordinates": [-25.926804, 28.203392]
}
}
}
2 changes: 2 additions & 0 deletions tck/src/main/resources/tests/locationArray/test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore=false
priority=200
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mutation logLocationForHero {
logLocationLongLatWithArray(name:"Starlord", coordinates:["-25.926804 longlat" , "28.203392 longlat"]) {
name
lastKnownCoordinates
}
}
8 changes: 8 additions & 0 deletions tck/src/main/resources/tests/locationLongLatArray/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"data": {
"logLocationLongLatWithArray": {
"name": "Starlord",
"lastKnownCoordinates": [-25.926804, 28.203392]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore=false
priority=200

0 comments on commit b9ae37e

Please sign in to comment.