Repository: Unleash/unleash-client-java (java)

Issue:
Unable to detect failures in HttpToggleFetcher
The current API of Unleash/HttpToggleFetcher makes it difficult to detect if HttpToggleFetcher is actually able to fetch toggles or if it experiences for example network failures, authentication/authorization failures or simply 404s because because somebody shut down or moved the unleash server.

It would be nice if applications are able to observe such problems through the API.

Pull request:
Introduced UNAVAILABLE as possible status in FeatureToggleResponse
closes #49

Patch:
diff --git a/src/main/java/no/finn/unleash/repository/FeatureToggleResponse.java b/src/main/java/no/finn/unleash/repository/FeatureToggleResponse.java
index cc639b14..cd90636d 100644
--- a/src/main/java/no/finn/unleash/repository/FeatureToggleResponse.java
+++ b/src/main/java/no/finn/unleash/repository/FeatureToggleResponse.java
@@ -6,7 +6,7 @@ import java.util.Collections;
 import java.util.List;
 
 public final class FeatureToggleResponse {
-    enum Status {NOT_CHANGED, CHANGED}
+    public enum Status {NOT_CHANGED, CHANGED, UNAVAILABLE}
 
     private final Status status;
     private final ToggleCollection toggleCollection;
diff --git a/src/main/java/no/finn/unleash/repository/HttpToggleFetcher.java b/src/main/java/no/finn/unleash/repository/HttpToggleFetcher.java
index d4e5c1c1..8a5c5058 100644
--- a/src/main/java/no/finn/unleash/repository/HttpToggleFetcher.java
+++ b/src/main/java/no/finn/unleash/repository/HttpToggleFetcher.java
@@ -39,8 +39,10 @@ public final class HttpToggleFetcher implements ToggleFetcher {
             int responseCode = connection.getResponseCode();
             if(responseCode < 300) {
                 return getToggleResponse(connection);
-            } else {
+            } else if (responseCode == 304) {
                 return new FeatureToggleResponse(FeatureToggleResponse.Status.NOT_CHANGED);
+            } else{
+                return new FeatureToggleResponse(FeatureToggleResponse.Status.UNAVAILABLE);
             }
         } catch (IOException e) {
             throw new UnleashException("Could not fetch toggles", e);


Test patch:
diff --git a/src/test/java/no/finn/unleash/repository/HttpToggleFetcherTest.java b/src/test/java/no/finn/unleash/repository/HttpToggleFetcherTest.java
index 81aebaa5..7fe27fa2 100644
--- a/src/test/java/no/finn/unleash/repository/HttpToggleFetcherTest.java
+++ b/src/test/java/no/finn/unleash/repository/HttpToggleFetcherTest.java
@@ -126,7 +126,7 @@ public class HttpToggleFetcherTest {
         stubFor(get(urlEqualTo("/api/client/features"))
                 .withHeader("Accept", equalTo("application/json"))
                 .willReturn(aResponse()
-                        .withStatus(302)
+                        .withStatus(304)
                         .withHeader("Content-Type", "application/json")));
 
         URI uri = new URI("http://localhost:"+wireMockRule.port() + "/api/");
@@ -154,7 +154,7 @@ public class HttpToggleFetcherTest {
             UnleashConfig config = UnleashConfig.builder().appName("test").unleashAPI(uri).build();
             HttpToggleFetcher httpToggleFetcher = new HttpToggleFetcher(config);
             FeatureToggleResponse response = httpToggleFetcher.fetchToggles();
-            assertEquals("Should return status NOT_CHANGED", response.getStatus(), FeatureToggleResponse.Status.NOT_CHANGED);
+            assertEquals("Should return status UNAVAILABLE", response.getStatus(), FeatureToggleResponse.Status.UNAVAILABLE);
 
             verify(getRequestedFor(urlMatching("/api/client/features"))
                     .withHeader("Content-Type", matching("application/json")));
diff --git a/src/test/java/no/finn/unleash/util/UnleashConfigTest.java b/src/test/java/no/finn/unleash/util/UnleashConfigTest.java
index e5e24000..3fe05535 100644
--- a/src/test/java/no/finn/unleash/util/UnleashConfigTest.java
+++ b/src/test/java/no/finn/unleash/util/UnleashConfigTest.java
@@ -1,5 +1,6 @@
 package no.finn.unleash.util;
 
+import java.io.File;
 import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
@@ -49,7 +50,7 @@ public class UnleashConfigTest {
                 .build();
 
         assertThat(config.getAppName(), is("my-app"));
-        assertThat(config.getBackupFile(), is(System.getProperty("java.io.tmpdir") + "/unleash-my-app-repo.json"));
+        assertThat(config.getBackupFile(), is(System.getProperty("java.io.tmpdir") + File.separatorChar + "unleash-my-app-repo.json"));
     }
 
     @Test