Skip to content

Commit

Permalink
tweak things around
Browse files Browse the repository at this point in the history
  • Loading branch information
qinfchen committed Jul 20, 2018
1 parent 9e8f4fd commit 7fb8ae5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 41 deletions.
8 changes: 1 addition & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,16 @@ allprojects {
}

configure(subprojects - project(':example-api')) {
apply plugin: 'java'
apply plugin: 'com.palantir.baseline-checkstyle'
apply plugin: 'com.palantir.baseline-eclipse'
apply plugin: 'com.palantir.baseline-error-prone'
apply plugin: 'com.palantir.baseline-idea'
apply plugin: 'java-library'
apply plugin: 'org.inferred.processors'

sourceCompatibility = 1.8

tasks.withType(JavaCompile) {
options.compilerArgs += ['-XepDisableWarningsInGeneratedCode', '-Werror']
}

// Run `./gradlew test -Drecreate=true` to recreate all the expected
// generated code that we have checked into the repo.
tasks.withType(Test) {
systemProperty 'recreate', System.getProperty('recreate', 'false')
}
}
6 changes: 3 additions & 3 deletions example-api/src/main/conjure/example-api.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
types:
definitions:
default-package: com.palantir.conjure.recipes.api
default-package: com.palantir.conjure.examples.recipes.api
objects:
Temperature:
fields:
Expand Down Expand Up @@ -39,7 +39,7 @@ types:
services:
RecipeBookService:
name: Recipe Book
package: com.palantir.conjure.recipes.api
package: com.palantir.conjure.examples.recipes.api
base-path: /
docs: |
APIs for retrieving recipes
Expand All @@ -65,7 +65,7 @@ services:
getAllRecipes:
http: GET /recipes
returns: list<Recipe>
returns: set<Recipe>

deleteRecipe:
http: DELETE /recipes/{name}
Expand Down
13 changes: 0 additions & 13 deletions example-server/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'com.palantir.baseline-checkstyle'
apply plugin: 'com.palantir.baseline-eclipse'
apply plugin: 'com.palantir.baseline-error-prone'
apply plugin: 'com.palantir.baseline-idea'
apply plugin: 'com.palantir.launch-config'
apply plugin: 'org.inferred.processors'

tasks.withType(JavaCompile) {
options.compilerArgs += ['-XepDisableWarningsInGeneratedCode', '-Werror']
}

sourceCompatibility = '1.8'

dependencies {
processor 'org.immutables:value'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@
package com.palantir.conjure.examples;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import com.palantir.conjure.recipes.api.Recipe;
import com.google.common.collect.ImmutableSet;
import com.palantir.conjure.examples.recipes.api.Recipe;
import io.dropwizard.Configuration;
import java.util.List;
import java.util.Set;
import org.hibernate.validator.constraints.NotEmpty;

public final class RecipeBookConfiguration extends Configuration {

@NotEmpty
private List<Recipe> recipes;
private Set<Recipe> recipes;

@JsonProperty
public List<Recipe> getRecipes() {
public Set<Recipe> getRecipes() {
return recipes;
}

@JsonProperty
public void setRecipes(List<Recipe> recipes) {
this.recipes = ImmutableList.copyOf(recipes);
this.recipes = ImmutableSet.copyOf(recipes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
package com.palantir.conjure.examples.resources;

import com.google.common.base.Preconditions;
import com.palantir.conjure.recipes.api.Recipe;
import com.palantir.conjure.recipes.api.RecipeBookService;
import com.palantir.conjure.recipes.api.RecipeErrors;
import com.palantir.conjure.recipes.api.RecipeName;
import java.util.ArrayList;
import java.util.List;
import com.palantir.conjure.examples.recipes.api.Recipe;
import com.palantir.conjure.examples.recipes.api.RecipeBookService;
import com.palantir.conjure.examples.recipes.api.RecipeErrors;
import com.palantir.conjure.examples.recipes.api.RecipeName;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

public final class RecipeBookResource implements RecipeBookService {

private final Map<RecipeName, Recipe> recipes;

public RecipeBookResource(List<Recipe> recipes) {
public RecipeBookResource(Set<Recipe> recipes) {
this.recipes = recipes.stream()
.collect(Collectors.toMap(Recipe::getName, Function.identity()));
.collect(Collectors.toConcurrentMap(Recipe::getName, Function.identity()));
}

@Override
Expand All @@ -52,8 +52,8 @@ public void createRecipe(Recipe createRecipeRequest) {
}

@Override
public List<Recipe> getAllRecipes() {
return new ArrayList<>(recipes.values());
public Set<Recipe> getAllRecipes() {
return new HashSet<>(recipes.values());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
import static org.junit.Assert.assertEquals;

import com.google.common.io.Resources;
import com.palantir.conjure.recipes.api.Recipe;
import com.palantir.conjure.recipes.api.RecipeBookService;
import com.palantir.conjure.recipes.api.RecipeName;
import com.palantir.conjure.examples.recipes.api.Recipe;
import com.palantir.conjure.examples.recipes.api.RecipeBookService;
import com.palantir.conjure.examples.recipes.api.RecipeName;
import feign.Client;
import feign.Feign;
import feign.FeignException;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import feign.jaxrs.JAXRSContract;
import io.dropwizard.testing.junit.DropwizardAppRule;
import java.util.Set;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
Expand Down Expand Up @@ -67,5 +68,8 @@ public void getRecipe() {
Recipe expectedRecipe = RULE.getConfiguration().getRecipes().stream()
.filter(r -> r.getName().equals(recipeName)).findFirst().get();
assertEquals(expectedRecipe, recipe);

Set<Recipe> recipes = client.getAllRecipes();
assertEquals(RULE.getConfiguration().getRecipes(), recipes);
}
}

0 comments on commit 7fb8ae5

Please sign in to comment.