Browse Source

update to dagger 1.1, as bump test deps

4.x
adriancole 11 years ago
parent
commit
321210d3ee
  1. 1
      CHANGES.md
  2. 22
      build.gradle
  3. 134
      feign-core/src/test/java/feign/FeignTest.java
  4. 167
      feign-core/src/test/java/feign/LoggerTest.java
  5. 52
      feign-gson/src/test/java/feign/gson/GsonModuleTest.java

1
CHANGES.md

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
* On `Subscription.unsubscribe()`, `Observer.onNext()` will stop being called.
### Version 3.2
* update to dagger 1.1
* Add wikipedia search example
* Allow `@Path` on types in feign-jaxrs

22
build.gradle

@ -35,13 +35,13 @@ project(':feign-core') { @@ -35,13 +35,13 @@ project(':feign-core') {
}
dependencies {
compile 'com.squareup.dagger:dagger:1.0.1'
provided 'com.squareup.dagger:dagger-compiler:1.0.1'
compile 'com.squareup.dagger:dagger:1.1.0'
provided 'com.squareup.dagger:dagger-compiler:1.1.0'
testCompile 'com.google.guava:guava:14.0.1'
testCompile 'com.google.code.gson:gson:2.2.4'
testCompile 'com.fasterxml.jackson.core:jackson-databind:2.2.2'
testCompile 'org.testng:testng:6.8.1'
testCompile 'com.google.mockwebserver:mockwebserver:20130505'
testCompile 'org.testng:testng:6.8.5'
testCompile 'com.google.mockwebserver:mockwebserver:20130706'
}
}
@ -55,8 +55,8 @@ project(':feign-gson') { @@ -55,8 +55,8 @@ project(':feign-gson') {
dependencies {
compile project(':feign-core')
compile 'com.google.code.gson:gson:2.2.4'
provided 'com.squareup.dagger:dagger-compiler:1.0.1'
testCompile 'org.testng:testng:6.8.1'
provided 'com.squareup.dagger:dagger-compiler:1.1.0'
testCompile 'org.testng:testng:6.8.5'
}
}
@ -70,12 +70,12 @@ project(':feign-jaxrs') { @@ -70,12 +70,12 @@ project(':feign-jaxrs') {
dependencies {
compile project(':feign-core')
compile 'javax.ws.rs:jsr311-api:1.1.1'
provided 'com.squareup.dagger:dagger-compiler:1.0.1'
provided 'com.squareup.dagger:dagger-compiler:1.1.0'
// for example classes
testCompile project(':feign-core').sourceSets.test.output
testCompile project(':feign-gson')
testCompile 'com.google.guava:guava:14.0.1'
testCompile 'org.testng:testng:6.8.1'
testCompile 'org.testng:testng:6.8.5'
}
}
@ -89,8 +89,8 @@ project(':feign-ribbon') { @@ -89,8 +89,8 @@ project(':feign-ribbon') {
dependencies {
compile project(':feign-core')
compile 'com.netflix.ribbon:ribbon-core:0.2.0'
provided 'com.squareup.dagger:dagger-compiler:1.0.1'
testCompile 'org.testng:testng:6.8.1'
testCompile 'com.google.mockwebserver:mockwebserver:20130505'
provided 'com.squareup.dagger:dagger-compiler:1.1.0'
testCompile 'org.testng:testng:6.8.5'
testCompile 'com.google.mockwebserver:mockwebserver:20130706'
}
}

134
feign-core/src/test/java/feign/FeignTest.java

@ -125,7 +125,7 @@ public class FeignTest { @@ -125,7 +125,7 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(), new TestInterface.Module());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
final AtomicBoolean success = new AtomicBoolean();
@ -159,7 +159,7 @@ public class FeignTest { @@ -159,7 +159,7 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(), new TestInterface.Module());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
final AtomicBoolean success = new AtomicBoolean();
@ -193,7 +193,7 @@ public class FeignTest { @@ -193,7 +193,7 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(), new TestInterface.Module());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
final AtomicBoolean success = new AtomicBoolean();
@ -228,7 +228,7 @@ public class FeignTest { @@ -228,7 +228,7 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(), new TestInterface.Module());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
final CountDownLatch latch = new CountDownLatch(2);
@ -265,7 +265,7 @@ public class FeignTest { @@ -265,7 +265,7 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(), new TestInterface.Module());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
api.login("netflix", "denominator", "password");
assertEquals(new String(server.takeRequest().getBody()),
@ -282,7 +282,7 @@ public class FeignTest { @@ -282,7 +282,7 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(), new TestInterface.Module());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
api.form("netflix", "denominator", "password");
assertEquals(new String(server.takeRequest().getBody()),
@ -299,7 +299,7 @@ public class FeignTest { @@ -299,7 +299,7 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(), new TestInterface.Module());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
api.body(Arrays.asList("netflix", "denominator", "password"));
assertEquals(new String(server.takeRequest().getBody()), "[netflix, denominator, password]");
@ -314,29 +314,32 @@ public class FeignTest { @@ -314,29 +314,32 @@ public class FeignTest {
String.class)), "TestInterface#uriParam(String,URI,String)");
}
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "zone not found")
public void canOverrideErrorDecoder() throws IOException, InterruptedException {
@dagger.Module(overrides = true, includes = TestInterface.Module.class) class Overrides {
@Provides @Singleton ErrorDecoder errorDecoder() {
return new ErrorDecoder.Default() {
@Override
public Exception decode(String methodKey, Response response) {
if (response.status() == 404)
return new IllegalArgumentException("zone not found");
return super.decode(methodKey, response);
}
@dagger.Module(overrides = true, library = true, includes = TestInterface.Module.class)
static class IllegalArgumentExceptionOn404 {
@Provides @Singleton ErrorDecoder errorDecoder() {
return new ErrorDecoder.Default() {
};
}
@Override
public Exception decode(String methodKey, Response response) {
if (response.status() == 404)
return new IllegalArgumentException("zone not found");
return super.decode(methodKey, response);
}
};
}
}
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "zone not found")
public void canOverrideErrorDecoder() throws IOException, InterruptedException {
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setResponseCode(404).setBody("foo"));
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(), new Overrides());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
new IllegalArgumentExceptionOn404());
api.post();
} finally {
@ -351,7 +354,7 @@ public class FeignTest { @@ -351,7 +354,7 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(),
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
new TestInterface.Module());
api.post();
@ -362,23 +365,26 @@ public class FeignTest { @@ -362,23 +365,26 @@ public class FeignTest {
}
}
@dagger.Module(overrides = true, library = true, includes = TestInterface.Module.class)
static class DecodeFail {
@Provides(type = SET) Decoder decoder() {
return new Decoder.TextStream<String>() {
@Override
public String decode(Reader reader, Type type) throws IOException {
return "fail";
}
};
}
}
public void overrideTypeSpecificDecoder() throws IOException, InterruptedException {
MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setResponseCode(200).setBody("success!".getBytes()));
server.play();
try {
@dagger.Module(overrides = true, includes = TestInterface.Module.class) class Overrides {
@Provides(type = SET) Decoder decoder() {
return new Decoder.TextStream<String>() {
@Override
public String decode(Reader reader, Type type) throws IOException {
return "fail";
}
};
}
}
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(), new Overrides());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
new DecodeFail());
assertEquals(api.post(), "fail");
} finally {
@ -387,6 +393,21 @@ public class FeignTest { @@ -387,6 +393,21 @@ public class FeignTest {
}
}
@dagger.Module(overrides = true, library = true, includes = TestInterface.Module.class)
static class RetryableExceptionOnRetry {
@Provides(type = SET) Decoder decoder() {
return new StringDecoder() {
@Override
public String decode(Reader reader, Type type) throws RetryableException, IOException {
String string = super.decode(reader, type);
if ("retry!".equals(string))
throw new RetryableException(string, null);
return string;
}
};
}
}
/**
* when you must parse a 2xx status to determine if the operation succeeded or not.
*/
@ -397,20 +418,8 @@ public class FeignTest { @@ -397,20 +418,8 @@ public class FeignTest {
server.play();
try {
@dagger.Module(overrides = true, includes = TestInterface.Module.class) class Overrides {
@Provides(type = SET) Decoder decoder() {
return new StringDecoder() {
@Override
public String decode(Reader reader, Type type) throws RetryableException, IOException {
String string = super.decode(reader, type);
if ("retry!".equals(string))
throw new RetryableException(string, null);
return string;
}
};
}
}
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(), new Overrides());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
new RetryableExceptionOnRetry());
assertEquals(api.post(), "success!");
} finally {
@ -419,6 +428,18 @@ public class FeignTest { @@ -419,6 +428,18 @@ public class FeignTest {
}
}
@dagger.Module(overrides = true, library = true, includes = TestInterface.Module.class)
static class IOEOnDecode {
@Provides(type = SET) Decoder decoder() {
return new Decoder.TextStream<String>() {
@Override
public String decode(Reader reader, Type type) throws IOException {
throw new IOException("error reading response");
}
};
}
}
@Test(expectedExceptions = FeignException.class, expectedExceptionsMessageRegExp = "error reading response POST http://.*")
public void doesntRetryAfterResponseIsSent() throws IOException, InterruptedException {
MockWebServer server = new MockWebServer();
@ -426,17 +447,8 @@ public class FeignTest { @@ -426,17 +447,8 @@ public class FeignTest {
server.play();
try {
@dagger.Module(overrides = true, includes = TestInterface.Module.class) class Overrides {
@Provides(type = SET) Decoder decoder() {
return new Decoder.TextStream<String>() {
@Override
public String decode(Reader reader, Type type) throws IOException {
throw new IOException("error reading response");
}
};
}
}
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(), new Overrides());
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
new IOEOnDecode());
api.post();
} finally {
@ -459,7 +471,7 @@ public class FeignTest { @@ -459,7 +471,7 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(),
TestInterface api = Feign.create(TestInterface.class, "https://localhost:" + server.getPort(),
new TestInterface.Module(), new TrustSSLSockets());
api.post();
} finally {
@ -475,7 +487,7 @@ public class FeignTest { @@ -475,7 +487,7 @@ public class FeignTest {
server.play();
try {
TestInterface api = Feign.create(TestInterface.class, server.getUrl("").toString(),
TestInterface api = Feign.create(TestInterface.class, "https://localhost:" + server.getPort(),
new TestInterface.Module(), new TrustSSLSockets());
api.post();
assertEquals(server.getRequestCount(), 2);

167
feign-core/src/test/java/feign/LoggerTest.java

@ -105,26 +105,9 @@ public class LoggerTest { @@ -105,26 +105,9 @@ public class LoggerTest {
server.enqueue(new MockResponse().setBody("foo"));
server.play();
@dagger.Module(overrides = true, library = true) class Module {
@Provides(type = SET) Encoder defaultEncoder() {
return new Encoder.Text<Object>() {
@Override public String encode(Object object) {
return object.toString();
}
};
}
@Provides @Singleton Logger logger() {
return logger;
}
@Provides @Singleton Logger.Level level() {
return logLevel;
}
}
try {
SendsStuff api = Feign.create(SendsStuff.class, "http://localhost:" + server.getUrl("").getPort(), new Module());
SendsStuff api = Feign.create(SendsStuff.class, "http://localhost:" + server.getUrl("").getPort(),
new DefaultModule(logger, logLevel));
api.login("netflix", "denominator", "password");
@ -140,6 +123,32 @@ public class LoggerTest { @@ -140,6 +123,32 @@ public class LoggerTest {
}
}
static @dagger.Module(overrides = true, library = true) class DefaultModule {
final Logger logger;
final Logger.Level logLevel;
DefaultModule(Logger logger, Logger.Level logLevel) {
this.logger = logger;
this.logLevel = logLevel;
}
@Provides(type = SET) Encoder defaultEncoder() {
return new Encoder.Text<Object>() {
@Override public String encode(Object object) {
return object.toString();
}
};
}
@Provides @Singleton Logger logger() {
return logger;
}
@Provides @Singleton Logger.Level level() {
return logLevel;
}
}
@DataProvider(name = "levelToReadTimeoutOutput")
public Object[][] levelToReadTimeoutOutput() {
Object[][] data = new Object[4][2];
@ -179,36 +188,23 @@ public class LoggerTest { @@ -179,36 +188,23 @@ public class LoggerTest {
return data;
}
@dagger.Module(overrides = true, library = true)
static class LessReadTimeoutModule {
@Provides Request.Options lessReadTimeout() {
return new Request.Options(10 * 1000, 50);
}
}
@Test(dataProvider = "levelToReadTimeoutOutput")
public void readTimeoutEmits(final Logger.Level logLevel, List<String> expectedMessages) throws IOException, InterruptedException {
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBytesPerSecond(1).setBody("foo"));
server.play();
@dagger.Module(overrides = true, library = true) class Module {
@Provides Request.Options lessReadTimeout() {
return new Request.Options(10 * 1000, 50);
}
@Provides(type = SET) Encoder defaultEncoder() {
return new Encoder.Text<Object>() {
@Override public String encode(Object object) {
return object.toString();
}
};
}
@Provides @Singleton Logger logger() {
return logger;
}
@Provides @Singleton Logger.Level level() {
return logLevel;
}
}
try {
SendsStuff api = Feign.create(SendsStuff.class, "http://localhost:" + server.getUrl("").getPort(), new Module());
SendsStuff api = Feign.create(SendsStuff.class, "http://localhost:" + server.getUrl("").getPort(),
new LessReadTimeoutModule(), new DefaultModule(logger, logLevel));
api.login("netflix", "denominator", "password");
@ -257,37 +253,23 @@ public class LoggerTest { @@ -257,37 +253,23 @@ public class LoggerTest {
return data;
}
@dagger.Module(overrides = true, library = true)
static class DontRetryModule {
@Provides Retryer retryer() {
return new Retryer() {
@Override public void continueOrPropagate(RetryableException e) {
throw e;
}
};
}
}
@Test(dataProvider = "levelToUnknownHostOutput")
public void unknownHostEmits(final Logger.Level logLevel, List<String> expectedMessages) throws IOException, InterruptedException {
@dagger.Module(overrides = true, library = true) class Module {
@Provides Retryer retryer() {
return new Retryer() {
@Override public void continueOrPropagate(RetryableException e) {
throw e;
}
};
}
@Provides(type = SET) Encoder defaultEncoder() {
return new Encoder.Text<Object>() {
@Override public String encode(Object object) {
return object.toString();
}
};
}
@Provides @Singleton Logger logger() {
return logger;
}
@Provides @Singleton Logger.Level level() {
return logLevel;
}
}
try {
SendsStuff api = Feign.create(SendsStuff.class, "http://robofu.abc", new Module());
SendsStuff api = Feign.create(SendsStuff.class, "http://robofu.abc",
new DontRetryModule(), new DefaultModule(logger, logLevel));
api.login("netflix", "denominator", "password");
@ -297,43 +279,28 @@ public class LoggerTest { @@ -297,43 +279,28 @@ public class LoggerTest {
}
}
@dagger.Module(overrides = true, library = true)
static class RetryOnceModule {
@Provides Retryer retryer() {
return new Retryer() {
boolean retried;
public void retryEmits() throws IOException, InterruptedException {
@dagger.Module(overrides = true, library = true) class Module {
@Provides Retryer retryer() {
return new Retryer() {
boolean retried;
@Override public void continueOrPropagate(RetryableException e) {
if (!retried) {
retried = true;
return;
}
throw e;
@Override public void continueOrPropagate(RetryableException e) {
if (!retried) {
retried = true;
return;
}
};
}
@Provides(type = SET) Encoder defaultEncoder() {
return new Encoder.Text<Object>() {
@Override public String encode(Object object) {
return object.toString();
}
};
}
@Provides @Singleton Logger logger() {
return logger;
}
@Provides @Singleton Logger.Level level() {
return Logger.Level.BASIC;
}
throw e;
}
};
}
}
public void retryEmits() throws IOException, InterruptedException {
try {
SendsStuff api = Feign.create(SendsStuff.class, "http://robofu.abc", new Module());
SendsStuff api = Feign.create(SendsStuff.class, "http://robofu.abc",
new RetryOnceModule(), new DefaultModule(logger, Logger.Level.BASIC));
api.login("netflix", "denominator", "password");

52
feign-gson/src/test/java/feign/gson/GsonModuleTest.java

@ -40,15 +40,15 @@ import static org.testng.Assert.fail; @@ -40,15 +40,15 @@ import static org.testng.Assert.fail;
@Test
public class GsonModuleTest {
@Module(includes = GsonModule.class, library = true, injects = EncodersAndDecoders.class)
static class EncodersAndDecoders {
@Inject Set<Encoder> encoders;
@Inject Set<Decoder> decoders;
@Inject Set<IncrementalDecoder> incrementalDecoders;
}
@Test public void providesEncoderDecoderAndIncrementalDecoder() throws Exception {
@Module(includes = GsonModule.class, injects = SetBindings.class) class SetBindings {
@Inject Set<Encoder> encoders;
@Inject Set<Decoder> decoders;
@Inject Set<IncrementalDecoder> incrementalDecoders;
}
SetBindings bindings = new SetBindings();
EncodersAndDecoders bindings = new EncodersAndDecoders();
ObjectGraph.create(bindings).inject(bindings);
assertEquals(bindings.encoders.size(), 1);
@ -59,12 +59,13 @@ public class GsonModuleTest { @@ -59,12 +59,13 @@ public class GsonModuleTest {
assertEquals(bindings.incrementalDecoders.iterator().next().getClass(), GsonModule.GsonCodec.class);
}
@Test public void encodesMapObjectNumericalValuesAsInteger() throws Exception {
@Module(includes = GsonModule.class, injects = SetBindings.class) class SetBindings {
@Inject Set<Encoder> encoders;
}
@Module(includes = GsonModule.class, library = true, injects = Encoders.class)
static class Encoders {
@Inject Set<Encoder> encoders;
}
SetBindings bindings = new SetBindings();
@Test public void encodesMapObjectNumericalValuesAsInteger() throws Exception {
Encoders bindings = new Encoders();
ObjectGraph.create(bindings).inject(bindings);
Map<String, Object> map = new LinkedHashMap<String, Object>();
@ -77,11 +78,8 @@ public class GsonModuleTest { @@ -77,11 +78,8 @@ public class GsonModuleTest {
}
@Test public void encodesFormParams() throws Exception {
@Module(includes = GsonModule.class, injects = SetBindings.class) class SetBindings {
@Inject Set<Encoder> encoders;
}
SetBindings bindings = new SetBindings();
Encoders bindings = new Encoders();
ObjectGraph.create(bindings).inject(bindings);
Map<String, Object> form = new LinkedHashMap<String, Object>();
@ -116,12 +114,13 @@ public class GsonModuleTest { @@ -116,12 +114,13 @@ public class GsonModuleTest {
private static final long serialVersionUID = 1L;
}
@Test public void decodes() throws Exception {
@Module(includes = GsonModule.class, injects = SetBindings.class) class SetBindings {
@Inject Set<Decoder> decoders;
}
@Module(includes = GsonModule.class, library = true, injects = Decoders.class)
static class Decoders {
@Inject Set<Decoder> decoders;
}
SetBindings bindings = new SetBindings();
@Test public void decodes() throws Exception {
Decoders bindings = new Decoders();
ObjectGraph.create(bindings).inject(bindings);
List<Zone> zones = new LinkedList<Zone>();
@ -133,12 +132,13 @@ public class GsonModuleTest { @@ -133,12 +132,13 @@ public class GsonModuleTest {
}.getType()), zones);
}
@Test public void decodesIncrementally() throws Exception {
@Module(includes = GsonModule.class, injects = SetBindings.class) class SetBindings {
@Inject Set<IncrementalDecoder> decoders;
}
@Module(includes = GsonModule.class, library = true, injects = IncrementalDecoders.class)
static class IncrementalDecoders {
@Inject Set<IncrementalDecoder> decoders;
}
SetBindings bindings = new SetBindings();
@Test public void decodesIncrementally() throws Exception {
IncrementalDecoders bindings = new IncrementalDecoders();
ObjectGraph.create(bindings).inject(bindings);
final List<Zone> zones = new LinkedList<Zone>();

Loading…
Cancel
Save