From f6dcf7f89bd96e8fc8211372d203b43b76428e48 Mon Sep 17 00:00:00 2001
From: petruki <31597636+petruki@users.noreply.github.com>
Date: Wed, 24 May 2023 20:48:56 -0700
Subject: [PATCH] #233 - Standardized Switcher Remote Exception
---
pom.xml | 14 +--
.../switcherapi/client/SwitcherExecutor.java | 4 +-
.../SwitcherAPIConnectionException.java | 17 ---
...rKeyNotAvailableForComponentException.java | 13 ---
.../exception/SwitcherRemoteException.java | 21 ++++
.../exception/SwitcherSnapshoException.java | 12 --
.../exception/SwitcherValidatorException.java | 13 ---
.../client/remote/ClientWSImpl.java | 107 ++++++++----------
.../service/remote/ClientRemoteService.java | 12 +-
.../service/remote/SwitcherRemoteService.java | 6 +-
.../client/SwitcherApiMock2Test.java | 4 +-
.../client/SwitcherApiMockTest.java | 75 ++++--------
.../client/SwitcherOnlineUnavailableTest.java | 4 +-
13 files changed, 118 insertions(+), 184 deletions(-)
delete mode 100644 src/main/java/com/github/switcherapi/client/exception/SwitcherAPIConnectionException.java
delete mode 100644 src/main/java/com/github/switcherapi/client/exception/SwitcherKeyNotAvailableForComponentException.java
create mode 100644 src/main/java/com/github/switcherapi/client/exception/SwitcherRemoteException.java
delete mode 100644 src/main/java/com/github/switcherapi/client/exception/SwitcherSnapshoException.java
delete mode 100644 src/main/java/com/github/switcherapi/client/exception/SwitcherValidatorException.java
diff --git a/pom.xml b/pom.xml
index 76153091..30855801 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
com.github.switcherapi
switcher-client
jar
- 2.0.1
+ 2.0.2-SNAPSHOT
Switcher Client
Switcher Client SDK for working with Switcher API
@@ -51,9 +51,9 @@
${java.version}
- 3.1.1
- 3.1.1
- 3.1.1
+ 3.1.2
+ 3.1.2
+ 3.1.2
2.10.1
@@ -170,19 +170,19 @@
com.fasterxml.jackson.core
jackson-annotations
- 2.14.2
+ 2.15.1
com.fasterxml.jackson.core
jackson-databind
- 2.14.2
+ 2.15.1
com.fasterxml.jackson.module
jackson-module-jakarta-xmlbind-annotations
- 2.14.2
+ 2.15.1
diff --git a/src/main/java/com/github/switcherapi/client/SwitcherExecutor.java b/src/main/java/com/github/switcherapi/client/SwitcherExecutor.java
index 372babe5..6eb632b4 100644
--- a/src/main/java/com/github/switcherapi/client/SwitcherExecutor.java
+++ b/src/main/java/com/github/switcherapi/client/SwitcherExecutor.java
@@ -7,7 +7,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import com.github.switcherapi.client.exception.SwitcherAPIConnectionException;
+import com.github.switcherapi.client.exception.SwitcherRemoteException;
import com.github.switcherapi.client.exception.SwitcherSnapshotWriteException;
import com.github.switcherapi.client.model.ContextKey;
import com.github.switcherapi.client.model.Switcher;
@@ -99,7 +99,7 @@ protected Domain initializeSnapshotFromAPI() {
environment);
return snapshot.getDomain();
- } catch (SwitcherAPIConnectionException | SwitcherSnapshotWriteException e) {
+ } catch (SwitcherRemoteException | SwitcherSnapshotWriteException e) {
logger.error(e);
throw e;
}
diff --git a/src/main/java/com/github/switcherapi/client/exception/SwitcherAPIConnectionException.java b/src/main/java/com/github/switcherapi/client/exception/SwitcherAPIConnectionException.java
deleted file mode 100644
index 387e154f..00000000
--- a/src/main/java/com/github/switcherapi/client/exception/SwitcherAPIConnectionException.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.github.switcherapi.client.exception;
-
-/**
- * @author Roger Floriano (petruki)
- * @since 2019-12-24
- */
-public class SwitcherAPIConnectionException extends SwitcherException {
-
- public SwitcherAPIConnectionException(final String url, final Exception e) {
- super(String.format("It was not possible to reach the Switcher-API on this endpoint: %s", url), e);
- }
-
- public SwitcherAPIConnectionException(final String url) {
- super(String.format("This action will redirect to the Silent Mode. The endpoint used was: %s", url), null);
- }
-
-}
diff --git a/src/main/java/com/github/switcherapi/client/exception/SwitcherKeyNotAvailableForComponentException.java b/src/main/java/com/github/switcherapi/client/exception/SwitcherKeyNotAvailableForComponentException.java
deleted file mode 100644
index 28b9faf8..00000000
--- a/src/main/java/com/github/switcherapi/client/exception/SwitcherKeyNotAvailableForComponentException.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.github.switcherapi.client.exception;
-
-/**
- * @author Roger Floriano (petruki)
- * @since 2020-07-30
- */
-public class SwitcherKeyNotAvailableForComponentException extends SwitcherException {
-
- public SwitcherKeyNotAvailableForComponentException(final String component, final String switcherKey) {
- super(String.format("Component %s is not registered to %s", component, switcherKey), null);
- }
-
-}
diff --git a/src/main/java/com/github/switcherapi/client/exception/SwitcherRemoteException.java b/src/main/java/com/github/switcherapi/client/exception/SwitcherRemoteException.java
new file mode 100644
index 00000000..56b5c1b7
--- /dev/null
+++ b/src/main/java/com/github/switcherapi/client/exception/SwitcherRemoteException.java
@@ -0,0 +1,21 @@
+package com.github.switcherapi.client.exception;
+
+/**
+ * @author Roger Floriano (petruki)
+ * @since 2019-12-24
+ */
+public class SwitcherRemoteException extends SwitcherException {
+
+ public SwitcherRemoteException(final String url, final Exception e) {
+ super(String.format("It was not possible to reach the Switcher-API on this endpoint: %s", url), e);
+ }
+
+ public SwitcherRemoteException(final String url, int status) {
+ super(String.format("It was not possible to reach the Switcher-API on this endpoint: %s - status: %s", url, status), null);
+ }
+
+ public SwitcherRemoteException(final String url) {
+ super(String.format("It was not possible to reach the Switcher-API on this endpoint: %s", url), null);
+ }
+
+}
diff --git a/src/main/java/com/github/switcherapi/client/exception/SwitcherSnapshoException.java b/src/main/java/com/github/switcherapi/client/exception/SwitcherSnapshoException.java
deleted file mode 100644
index 72e6b253..00000000
--- a/src/main/java/com/github/switcherapi/client/exception/SwitcherSnapshoException.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.github.switcherapi.client.exception;
-
-/**
- * @author Roger Floriano (petruki)
- * @since 2022-06-12
- */
-public class SwitcherSnapshoException extends SwitcherException {
-
- public SwitcherSnapshoException(final String operation) {
- super(String.format("Unable to execute %s", operation), null);
- }
-}
diff --git a/src/main/java/com/github/switcherapi/client/exception/SwitcherValidatorException.java b/src/main/java/com/github/switcherapi/client/exception/SwitcherValidatorException.java
deleted file mode 100644
index 9bc28e6b..00000000
--- a/src/main/java/com/github/switcherapi/client/exception/SwitcherValidatorException.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.github.switcherapi.client.exception;
-
-/**
- * @author Roger Floriano (petruki)
- * @since 2023-02-17
- */
-public class SwitcherValidatorException extends SwitcherException {
-
- public SwitcherValidatorException(final String input, final String value) {
- super(String.format("Failed to process input [%s] for [%s]", input, value), null);
- }
-
-}
diff --git a/src/main/java/com/github/switcherapi/client/remote/ClientWSImpl.java b/src/main/java/com/github/switcherapi/client/remote/ClientWSImpl.java
index 64a7510a..51c7a372 100644
--- a/src/main/java/com/github/switcherapi/client/remote/ClientWSImpl.java
+++ b/src/main/java/com/github/switcherapi/client/remote/ClientWSImpl.java
@@ -3,6 +3,7 @@
import java.util.Optional;
import java.util.Set;
+import com.github.switcherapi.client.exception.*;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
@@ -13,10 +14,6 @@
import org.apache.logging.log4j.Logger;
import com.github.switcherapi.client.SwitcherContextBase;
-import com.github.switcherapi.client.exception.SwitcherException;
-import com.github.switcherapi.client.exception.SwitcherKeyNotAvailableForComponentException;
-import com.github.switcherapi.client.exception.SwitcherKeyNotFoundException;
-import com.github.switcherapi.client.exception.SwitcherSnapshoException;
import com.github.switcherapi.client.model.ContextKey;
import com.github.switcherapi.client.model.Switcher;
import com.github.switcherapi.client.model.criteria.Snapshot;
@@ -64,19 +61,16 @@ public CriteriaResponse executeCriteriaService(final Switcher switcher, final St
.header(HEADER_AUTHORIZATION, String.format(TOKEN_TEXT, token))
.post(Entity.json(switcher.getInputRequest()));
- if (response.getStatus() == 401) {
- throw new SwitcherKeyNotAvailableForComponentException(
- SwitcherContextBase.contextStr(ContextKey.COMPONENT), switcher.getSwitcherKey());
- } else if (response.getStatus() != 200) {
- throw new SwitcherKeyNotFoundException(switcher.getSwitcherKey());
+ if (response.getStatus() == 200) {
+ final CriteriaResponse criteriaResponse = response.readEntity(CriteriaResponse.class);
+ criteriaResponse.setSwitcherKey(switcher.getSwitcherKey());
+ criteriaResponse.setEntry(switcher.getEntry());
+ response.close();
+
+ return criteriaResponse;
}
-
- final CriteriaResponse criteriaResponse = response.readEntity(CriteriaResponse.class);
- criteriaResponse.setSwitcherKey(switcher.getSwitcherKey());
- criteriaResponse.setEntry(switcher.getEntry());
- response.close();
-
- return criteriaResponse;
+
+ throw new SwitcherRemoteException(url, response.getStatus());
}
@Override
@@ -86,27 +80,27 @@ public Optional auth() {
authRequest.setComponent(SwitcherContextBase.contextStr(ContextKey.COMPONENT));
authRequest.setEnvironment(SwitcherContextBase.contextStr(ContextKey.ENVIRONMENT));
- final WebTarget myResource = client.target(String.format(AUTH_URL,
- SwitcherContextBase.contextStr(ContextKey.URL)));
+ final String url = SwitcherContextBase.contextStr(ContextKey.URL);
+ final WebTarget myResource = client.target(String.format(AUTH_URL, url));
final Response response = myResource.request(MediaType.APPLICATION_JSON)
.header(HEADER_APIKEY, SwitcherContextBase.contextStr(ContextKey.APIKEY))
.post(Entity.json(authRequest));
-
- if (response.getStatus() == 401) {
- throw new SwitcherException("Unauthorized API access", null);
+
+ if (response.getStatus() == 200) {
+ Optional authResponse = Optional.of(response.readEntity(AuthResponse.class));
+ response.close();
+
+ return authResponse;
}
-
- Optional authResponse = Optional.of(response.readEntity(AuthResponse.class));
- response.close();
-
- return authResponse;
+
+ throw new SwitcherRemoteException(url, response.getStatus());
}
@Override
public Snapshot resolveSnapshot(final String token) {
- final WebTarget myResource = client.target(String.format(SNAPSHOT_URL,
- SwitcherContextBase.contextStr(ContextKey.URL)));
+ final String url = SwitcherContextBase.contextStr(ContextKey.URL);
+ final WebTarget myResource = client.target(String.format(SNAPSHOT_URL, url));
final Response response = myResource.request(MediaType.APPLICATION_JSON)
.header(HEADER_AUTHORIZATION, String.format(TOKEN_TEXT, token))
@@ -114,34 +108,34 @@ public Snapshot resolveSnapshot(final String token) {
SwitcherContextBase.contextStr(ContextKey.DOMAIN),
SwitcherContextBase.contextStr(ContextKey.ENVIRONMENT),
SwitcherContextBase.contextStr(ContextKey.COMPONENT))));
-
- if (response.getStatus() != 200) {
- throw new SwitcherSnapshoException("resolveSnapshot");
+
+ if (response.getStatus() == 200) {
+ final Snapshot snapshot = response.readEntity(Snapshot.class);
+ response.close();
+
+ return snapshot;
}
-
- final Snapshot snapshot = response.readEntity(Snapshot.class);
- response.close();
-
- return snapshot;
+
+ throw new SwitcherRemoteException(url, response.getStatus());
}
@Override
public SnapshotVersionResponse checkSnapshotVersion(final long version, final String token) {
- final WebTarget myResource = client.target(String.format(SNAPSHOT_VERSION_CHECK,
- SwitcherContextBase.contextStr(ContextKey.URL), version));
+ final String url = SwitcherContextBase.contextStr(ContextKey.URL);
+ final WebTarget myResource = client.target(String.format(SNAPSHOT_VERSION_CHECK, url, version));
final Response response = myResource.request(MediaType.APPLICATION_JSON)
.header(HEADER_AUTHORIZATION, String.format(TOKEN_TEXT, token))
.get();
-
- if (response.getStatus() != 200) {
- throw new SwitcherSnapshoException("resolveSnapshot");
+
+ if (response.getStatus() == 200) {
+ final SnapshotVersionResponse snapshotVersionResponse = response.readEntity(SnapshotVersionResponse.class);
+ response.close();
+
+ return snapshotVersionResponse;
}
-
- final SnapshotVersionResponse snapshotVersionResponse = response.readEntity(SnapshotVersionResponse.class);
- response.close();
-
- return snapshotVersionResponse;
+
+ throw new SwitcherRemoteException(url, response.getStatus());
}
@Override
@@ -158,22 +152,21 @@ public boolean isAlive() {
@Override
public SwitchersCheck checkSwitchers(Set switchers, final String token) {
- final WebTarget myResource = client.target(String.format(CHECK_SWITCHERS,
- SwitcherContextBase.contextStr(ContextKey.URL)));
+ final String url = SwitcherContextBase.contextStr(ContextKey.URL);
+ final WebTarget myResource = client.target(String.format(CHECK_SWITCHERS, url));
final Response response = myResource.request(MediaType.APPLICATION_JSON)
.header(HEADER_AUTHORIZATION, String.format(TOKEN_TEXT, token))
.post(Entity.json(new SwitchersCheck(switchers)));
-
- if (response.getStatus() != 200) {
- throw new SwitcherException(
- String.format("API returned an HTTP/1.1 %s", response.getStatus()), null);
+
+ if (response.getStatus() == 200) {
+ final SwitchersCheck switchersResponse = response.readEntity(SwitchersCheck.class);
+ response.close();
+
+ return switchersResponse;
}
-
- final SwitchersCheck switchersResponse = response.readEntity(SwitchersCheck.class);
- response.close();
-
- return switchersResponse;
+
+ throw new SwitcherRemoteException(url, response.getStatus());
}
}
diff --git a/src/main/java/com/github/switcherapi/client/service/remote/ClientRemoteService.java b/src/main/java/com/github/switcherapi/client/service/remote/ClientRemoteService.java
index 170d6002..e627ae2d 100644
--- a/src/main/java/com/github/switcherapi/client/service/remote/ClientRemoteService.java
+++ b/src/main/java/com/github/switcherapi/client/service/remote/ClientRemoteService.java
@@ -5,7 +5,7 @@
import java.util.Set;
import com.github.switcherapi.client.SwitcherContextBase;
-import com.github.switcherapi.client.exception.SwitcherAPIConnectionException;
+import com.github.switcherapi.client.exception.SwitcherRemoteException;
import com.github.switcherapi.client.exception.SwitcherException;
import com.github.switcherapi.client.exception.SwitcherInvalidDateTimeArgumentException;
import com.github.switcherapi.client.model.ContextKey;
@@ -80,7 +80,7 @@ public SwitchersCheck checkSwitchers(final Set switchers) {
return this.clientWs.checkSwitchers(switchers,
this.authResponse.orElseGet(AuthResponse::new).getToken());
} catch (final Exception e) {
- throw new SwitcherAPIConnectionException(SwitcherContextBase.contextStr(ContextKey.URL), e);
+ throw new SwitcherRemoteException(SwitcherContextBase.contextStr(ContextKey.URL), e);
}
}
@@ -91,21 +91,21 @@ private void auth() {
throw e;
} catch (final Exception e) {
this.setSilentModeExpiration();
- throw new SwitcherAPIConnectionException(SwitcherContextBase.contextStr(ContextKey.URL), e);
+ throw new SwitcherRemoteException(SwitcherContextBase.contextStr(ContextKey.URL), e);
}
}
- private boolean isTokenValid() throws SwitcherAPIConnectionException,
+ private boolean isTokenValid() throws SwitcherRemoteException,
SwitcherInvalidDateTimeArgumentException {
if (this.authResponse.isPresent()) {
if (this.authResponse.get().getToken().equals(ContextKey.SILENT_MODE.getParam())
&& !this.authResponse.get().isExpired()) {
- throw new SwitcherAPIConnectionException(SwitcherContextBase.contextStr(ContextKey.URL));
+ throw new SwitcherRemoteException(SwitcherContextBase.contextStr(ContextKey.URL));
} else {
if (!this.clientWs.isAlive()) {
this.setSilentModeExpiration();
- throw new SwitcherAPIConnectionException(SwitcherContextBase.contextStr(ContextKey.URL));
+ throw new SwitcherRemoteException(SwitcherContextBase.contextStr(ContextKey.URL));
}
return !this.authResponse.orElseGet(AuthResponse::new).isExpired();
diff --git a/src/main/java/com/github/switcherapi/client/service/remote/SwitcherRemoteService.java b/src/main/java/com/github/switcherapi/client/service/remote/SwitcherRemoteService.java
index 3cecce6f..1f2feec8 100644
--- a/src/main/java/com/github/switcherapi/client/service/remote/SwitcherRemoteService.java
+++ b/src/main/java/com/github/switcherapi/client/service/remote/SwitcherRemoteService.java
@@ -9,7 +9,7 @@
import com.github.switcherapi.client.SwitcherContextBase;
import com.github.switcherapi.client.SwitcherExecutor;
-import com.github.switcherapi.client.exception.SwitcherAPIConnectionException;
+import com.github.switcherapi.client.exception.SwitcherRemoteException;
import com.github.switcherapi.client.exception.SwitchersValidationException;
import com.github.switcherapi.client.model.ContextKey;
import com.github.switcherapi.client.model.Switcher;
@@ -46,14 +46,14 @@ public CriteriaResponse executeCriteria(final Switcher switcher) {
}
return response;
- } catch (final SwitcherAPIConnectionException e) {
+ } catch (final SwitcherRemoteException e) {
logger.error("Failed to execute criteria - {}", e.getMessage());
return executeSilentCriteria(switcher, e);
}
}
private CriteriaResponse executeSilentCriteria(final Switcher switcher,
- final SwitcherAPIConnectionException e) {
+ final SwitcherRemoteException e) {
if (SwitcherContextBase.contextBol(ContextKey.SILENT_MODE)) {
CriteriaResponse response = this.switcherOffline.executeCriteria(switcher);
if (logger.isDebugEnabled()) {
diff --git a/src/test/java/com/github/switcherapi/client/SwitcherApiMock2Test.java b/src/test/java/com/github/switcherapi/client/SwitcherApiMock2Test.java
index 5b124b82..897fa8bb 100644
--- a/src/test/java/com/github/switcherapi/client/SwitcherApiMock2Test.java
+++ b/src/test/java/com/github/switcherapi/client/SwitcherApiMock2Test.java
@@ -1,7 +1,7 @@
package com.github.switcherapi.client;
import com.github.switcherapi.Switchers;
-import com.github.switcherapi.client.exception.SwitcherKeyNotAvailableForComponentException;
+import com.github.switcherapi.client.exception.SwitcherRemoteException;
import com.github.switcherapi.client.model.Switcher;
import com.github.switcherapi.client.remote.ClientWSImpl;
import com.github.switcherapi.client.service.remote.ClientRemoteService;
@@ -94,7 +94,7 @@ void shouldReturnError_componentNotRegistered() {
givenResponse(generateStatusResponse("401"));
Switcher switcher = Switchers.getSwitcher(Switchers.ONLINE_KEY);
- assertThrows(SwitcherKeyNotAvailableForComponentException.class, switcher::isItOn);
+ assertThrows(SwitcherRemoteException.class, switcher::isItOn);
}
}
diff --git a/src/test/java/com/github/switcherapi/client/SwitcherApiMockTest.java b/src/test/java/com/github/switcherapi/client/SwitcherApiMockTest.java
index 2d252620..b3670ea9 100644
--- a/src/test/java/com/github/switcherapi/client/SwitcherApiMockTest.java
+++ b/src/test/java/com/github/switcherapi/client/SwitcherApiMockTest.java
@@ -1,45 +1,7 @@
package com.github.switcherapi.client;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import mockwebserver3.MockResponse;
-import mockwebserver3.MockWebServer;
-import mockwebserver3.QueueDispatcher;
-import org.apache.commons.lang3.StringUtils;
-import org.glassfish.jersey.internal.guava.Sets;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.MethodOrderer;
-import org.junit.jupiter.api.Order;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestMethodOrder;
-
import com.github.switcherapi.Switchers;
-import com.github.switcherapi.client.exception.SwitcherAPIConnectionException;
-import com.github.switcherapi.client.exception.SwitcherException;
-import com.github.switcherapi.client.exception.SwitcherKeyNotAvailableForComponentException;
-import com.github.switcherapi.client.exception.SwitcherKeyNotFoundException;
-import com.github.switcherapi.client.exception.SwitcherSnapshoException;
-import com.github.switcherapi.client.exception.SwitcherSnapshotWriteException;
-import com.github.switcherapi.client.exception.SwitchersValidationException;
+import com.github.switcherapi.client.exception.*;
import com.github.switcherapi.client.model.Entry;
import com.github.switcherapi.client.model.StrategyValidator;
import com.github.switcherapi.client.model.Switcher;
@@ -51,6 +13,25 @@
import com.github.switcherapi.client.utils.SnapshotLoader;
import com.github.switcherapi.client.utils.SwitcherUtils;
import com.google.gson.Gson;
+import mockwebserver3.MockResponse;
+import mockwebserver3.MockWebServer;
+import mockwebserver3.QueueDispatcher;
+import org.apache.commons.lang3.StringUtils;
+import org.glassfish.jersey.internal.guava.Sets;
+import org.junit.jupiter.api.*;
+
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.*;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SwitcherApiMockTest {
@@ -274,7 +255,7 @@ void shouldReturnError_keyNotFound() {
givenResponse(generateStatusResponse("404"));
Switcher switcher = Switchers.getSwitcher(Switchers.ONLINE_KEY);
- assertThrows(SwitcherKeyNotFoundException.class, switcher::isItOn);
+ assertThrows(SwitcherRemoteException.class, switcher::isItOn);
}
@Test
@@ -283,9 +264,7 @@ void shouldReturnError_unauthorizedAPIAccess() {
givenResponse(generateStatusResponse("401"));
Switcher switcher = Switchers.getSwitcher(Switchers.ONLINE_KEY);
- Exception ex = assertThrows(SwitcherException.class, switcher::isItOn);
-
- assertEquals("Something went wrong: Unauthorized API access", ex.getMessage());
+ assertThrows(SwitcherException.class, switcher::isItOn);
}
@Test
@@ -419,11 +398,7 @@ void shouldNotLookupForSnapshot_serviceUnavailable() {
givenResponse(generateStatusResponse("503"));
//test
- Exception ex = assertThrows(SwitcherSnapshoException.class,
- Switchers::initializeClient);
-
- assertEquals("Something went wrong: Unable to execute resolveSnapshot",
- ex.getMessage());
+ assertThrows(SwitcherRemoteException.class, Switchers::initializeClient);
}
@Test
@@ -491,7 +466,7 @@ void shouldNotValidateAndLoadSnapshot_serviceUnavailable() {
givenResponse(generateStatusResponse("503"));
//test
- assertThrows(SwitcherSnapshoException.class, Switchers::validateSnapshot);
+ assertThrows(SwitcherRemoteException.class, Switchers::validateSnapshot);
}
@Test
@@ -595,7 +570,7 @@ void shouldNotValidateSwitchers_serviceUnavailable() {
givenResponse(generateStatusResponse("503"));
//test
- assertThrows(SwitcherAPIConnectionException.class, Switchers::checkSwitchers);
+ assertThrows(SwitcherRemoteException.class, Switchers::checkSwitchers);
}
@Test
diff --git a/src/test/java/com/github/switcherapi/client/SwitcherOnlineUnavailableTest.java b/src/test/java/com/github/switcherapi/client/SwitcherOnlineUnavailableTest.java
index 19940d54..323ff053 100644
--- a/src/test/java/com/github/switcherapi/client/SwitcherOnlineUnavailableTest.java
+++ b/src/test/java/com/github/switcherapi/client/SwitcherOnlineUnavailableTest.java
@@ -6,7 +6,7 @@
import org.junit.jupiter.api.Test;
import com.github.switcherapi.Switchers;
-import com.github.switcherapi.client.exception.SwitcherAPIConnectionException;
+import com.github.switcherapi.client.exception.SwitcherRemoteException;
import com.github.switcherapi.client.model.Switcher;
class SwitcherOnlineUnavailableTest {
@@ -24,7 +24,7 @@ void shouldReturnError_noConnection() {
//test
Switcher switcher = Switchers.getSwitcher(Switchers.ONLINE_KEY);
- assertThrows(SwitcherAPIConnectionException.class, switcher::isItOn);
+ assertThrows(SwitcherRemoteException.class, switcher::isItOn);
}
}