Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ Create `src/main/resources/switcherapi.properties`:
# Required Configuration
switcher.context=com.example.MyAppFeatures
switcher.url=https://api.switcherapi.com
switcher.apikey=YOUR_API_KEY
switcher.component=my-application
switcher.domain=MY_DOMAIN
switcher.apikey=[API_KEY]
switcher.component=[COMPONENT_NAME]
switcher.domain=[DOMAIN_NAME}

# Optional Configuration
switcher.environment=default
Expand Down Expand Up @@ -188,10 +188,10 @@ public class MyAppFeatures extends SwitcherContextBase {
static {
configure(ContextBuilder.builder()
.context(MyAppFeatures.class.getName())
.apiKey("YOUR_API_KEY")
.apiKey("[API_KEY]")
.url("https://api.switcherapi.com")
.domain("MY_DOMAIN")
.component("my-application")
.domain("[DOMAIN_NAME]")
.component("[COMPONENT_NAME]")
.environment("default"));

initializeClient();
Expand Down Expand Up @@ -337,9 +337,9 @@ Default mode that communicates directly with Switcher API.
```java
MyAppFeatures.configure(ContextBuilder.builder()
.url("https://api.switcherapi.com")
.apiKey("YOUR_API_KEY")
.domain("MY_DOMAIN")
.component("my-app"));
.apiKey("[API_KEY]")
.domain("[DOMAIN_NAME]")
.component("[COMPONENT_NAME]"));

MyAppFeatures.initializeClient();
```
Expand Down Expand Up @@ -382,12 +382,12 @@ switcher.forceRemote().isItOn();
```java
MyAppFeatures.configure(ContextBuilder.builder()
.url("https://api.switcherapi.com")
.apiKey("YOUR_API_KEY")
.domain("MY_DOMAIN")
.apiKey("[API_KEY]")
.domain("[DOMAIN_NAME]")
.local(true)
.snapshotAutoLoad(true)
.snapshotAutoUpdateInterval("30s") // Check for updates every 30 seconds
.component("my-app"));
.component("[COMPONENT_NAME]"));

MyAppFeatures.initializeClient();

Expand Down Expand Up @@ -418,10 +418,10 @@ Here is an example - in-memory snapshot with auto-update every 30 seconds:
```java
MyAppFeatures.configure(ContextBuilder.builder()
.context(MyAppFeatures.class.getName())
.apiKey("YOUR_API_KEY")
.apiKey("[API_KEY]")
.url("https://api.switcherapi.com")
.domain("MY_DOMAIN")
.component("my-application")
.domain("[DOMAIN_NAME")
.component("[COMPONENT_NAME]")
.silentMode("5m")
.snapshotAutoUpdateInterval("30s")
);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/switcherapi/client/SwitcherContextBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@
* public void configureClient() {
* Features.configure(ContextBuilder.builder()
* .context(Features.class.getName())
* .apiKey("API_KEY")
* .domain("Playground")
* .component("switcher-playground")
* .environment("default"));
* .apiKey("[API_KEY]")
* .domain("[DOMAIN_NAME]")
* .component("[COMPONENT_NAME]"));
*
* Features.initializeClient();
* }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.switcherapi.client;

import com.switcherapi.Switchers;
import com.switcherapi.SwitchersBase;
import com.switcherapi.client.model.SwitcherBuilder;
import com.switcherapi.client.model.SwitcherRequest;
import com.switcherapi.client.model.SwitcherResult;
Expand All @@ -21,33 +21,30 @@
class SwitcherBasicCriteriaResponseTest extends MockWebServerHelper {

private boolean authTokenGenerated = false;

@BeforeAll
static void setup() throws IOException {
setupMockServer();

Switchers.loadProperties(); // Load default properties from resources
Switchers.configure(ContextBuilder.builder() // Override default properties
SwitchersBase.configure(ContextBuilder.builder(true)
.context(SwitchersBase.class.getName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.local(false)
.snapshotLocation(null)
.snapshotSkipValidation(false)
.environment(DEFAULT_ENV)
.silentMode(null)
.snapshotAutoLoad(false)
.snapshotAutoUpdateInterval(null));
.domain("domain")
.apiKey("apiKey")
.component("component")
.environment(DEFAULT_ENV));
}

@AfterAll
static void tearDown() {
tearDownMockServer();
}

@BeforeEach
void resetSwitcherContextState() {
((QueueDispatcher) mockBackEnd.getDispatcher()).clear();

Switchers.initializeClient();
SwitchersBase.initializeClient();
}

@Test
Expand All @@ -59,7 +56,7 @@ void shouldReturnCriteriaResponse() {
givenResponse(generateCriteriaResponse("true", "Success"));

//test
SwitcherRequest switcher = Switchers.getSwitcher(Switchers.REMOTE_KEY);
SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11);
SwitcherResult response = switcher.submit();

assertTrue(response.isItOn());
Expand All @@ -75,7 +72,7 @@ void shouldReturnCriteriaResponseWithInputs() {
givenResponse(generateCriteriaResponse("false", "Strategy VALUE_VALIDATION does not agree"));

//test
SwitcherRequest switcher = Switchers.getSwitcher(Switchers.REMOTE_KEY);
SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11);
SwitcherResult response = switcher
.checkValue("value")
.checkNumeric("10")
Expand All @@ -87,8 +84,8 @@ void shouldReturnCriteriaResponseWithInputs() {

@Test
void shouldFlushStrategyInputs() {
SwitcherBuilder switcherBuilder = Switchers
.getSwitcher(Switchers.REMOTE_KEY)
SwitcherBuilder switcherBuilder = SwitchersBase
.getSwitcher(SwitchersBase.USECASE11)
.checkValue("value")
.checkNumeric("10");

Expand All @@ -111,7 +108,7 @@ void shouldReturnCriteriaResponseWithMetadata() {
givenResponse(generateCriteriaResponse(new MetadataSample("123")));

//test
SwitcherRequest switcher = Switchers.getSwitcher(Switchers.REMOTE_KEY);
SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11);
SwitcherResult response = switcher.submit();

assertEquals("123", response.getMetadata(MetadataSample.class).getTransactionId());
Expand All @@ -126,7 +123,7 @@ void shouldReturnCriteriaResponseWithWrongMetadata() {
givenResponse(generateCriteriaResponse(new MetadataErrorSample("123")));

//test
SwitcherRequest switcher = Switchers.getSwitcher(Switchers.REMOTE_KEY);
SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11);
SwitcherResult response = switcher.submit();

assertNotNull(response.getMetadata(MetadataSample.class));
Expand Down
25 changes: 11 additions & 14 deletions src/test/java/com/switcherapi/client/SwitcherBasicTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.switcherapi.client;

import com.switcherapi.Switchers;
import com.switcherapi.SwitchersBase;
import com.switcherapi.client.model.SwitcherRequest;
import com.switcherapi.fixture.MockWebServerHelper;
import mockwebserver3.QueueDispatcher;
Expand All @@ -22,17 +22,14 @@ class SwitcherBasicTest extends MockWebServerHelper {
@BeforeAll
static void setup() throws IOException {
setupMockServer();

Switchers.loadProperties(); // Load default properties from resources
Switchers.configure(ContextBuilder.builder() // Override default properties
SwitchersBase.configure(ContextBuilder.builder(true)
.context(SwitchersBase.class.getName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.local(false)
.snapshotLocation(null)
.snapshotSkipValidation(false)
.environment(DEFAULT_ENV)
.silentMode(null)
.snapshotAutoLoad(false)
.snapshotAutoUpdateInterval(null));
.domain("domain")
.apiKey("apiKey")
.component("component")
.environment(DEFAULT_ENV));
}

@AfterAll
Expand All @@ -44,7 +41,7 @@ static void tearDown() {
void resetSwitcherContextState() {
((QueueDispatcher) mockBackEnd.getDispatcher()).clear();

Switchers.initializeClient();
SwitchersBase.initializeClient();
}

@Test
Expand All @@ -56,7 +53,7 @@ void shouldReturnTrue() {
givenResponse(generateCriteriaResponse("true", false));

//test
SwitcherRequest switcher = Switchers.getSwitcher(Switchers.REMOTE_KEY);
SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11);
assertTrue(switcher.isItOn());
}

Expand All @@ -69,7 +66,7 @@ void shouldReturnFalse() {
givenResponse(generateCriteriaResponse("false", false));

//test
SwitcherRequest switcher = Switchers.getSwitcher(Switchers.REMOTE_KEY);
SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11);
assertFalse(switcher.isItOn());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void shouldUseNativeContextFromProperties() {
assertTrue(SwitchersBaseNative.getSwitcher(SwitchersBaseNative.USECASE11).isItOn());
assertEquals("switcher-client", context.component);
assertEquals("switcher-domain", context.domain);
assertEquals("[API_KEY]", context.apikey);
assertEquals("apiKey", context.apikey);
assertEquals("http://localhost:3000", context.url);
assertEquals("fixture1", context.environment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ void shouldReturnSuccess() {
configure(ContextBuilder.builder(true)
.context(SwitchersBase.class.getName())
.url("http://localhost:3000")
.apiKey("API_KEY")
.domain("switcher-domain")
.component("switcher-client")
.apiKey("apiKey")
.domain("domain")
.component("component")
.environment(DEFAULT_ENV)
.snapshotLocation(SNAPSHOTS_LOCAL)
.local(true));
Expand All @@ -44,9 +44,9 @@ void shouldReturnError_snapshotNotLoaded() {
configure(ContextBuilder.builder(true)
.context(SwitchersBase.class.getName())
.url("http://localhost:3000")
.apiKey("API_KEY")
.domain("switcher-domain")
.component("switcher-client")
.apiKey("apiKey")
.domain("domain")
.component("component")
.environment(DEFAULT_ENV)
.snapshotLocation(null)
.local(true));
Expand All @@ -61,7 +61,7 @@ void shouldThrowError_wrongContextKeyTypeUsage() {
//given
configure(ContextBuilder.builder(true)
.context(SwitchersBase.class.getName())
.domain("switcher-domain")
.domain("domain")
.snapshotLocation(SNAPSHOTS_LOCAL)
.local(true));

Expand Down
28 changes: 12 additions & 16 deletions src/test/java/com/switcherapi/client/SwitcherSilentModeTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.switcherapi.client;

import com.switcherapi.Switchers;
import com.switcherapi.SwitchersBase;
import com.switcherapi.client.model.SwitcherRequest;
import com.switcherapi.fixture.CountDownHelper;
import com.switcherapi.fixture.MockWebServerHelper;
Expand All @@ -24,9 +24,6 @@ class SwitcherSilentModeTest extends MockWebServerHelper {
@BeforeAll
static void setup() throws IOException {
setupMockServer();

Switchers.loadProperties();
Switchers.configure(ContextBuilder.builder().url(String.format("http://localhost:%s", mockBackEnd.getPort())));
}

@AfterAll
Expand All @@ -38,25 +35,24 @@ static void tearDown() {
void resetSwitcherContextState() {
((QueueDispatcher) mockBackEnd.getDispatcher()).clear();

Switchers.configure(ContextBuilder.builder()
.local(false)
.snapshotLocation(null)
.snapshotSkipValidation(false)
.environment(DEFAULT_ENV)
.silentMode(null)
.snapshotAutoLoad(false)
.snapshotAutoUpdateInterval(null));
SwitchersBase.configure(ContextBuilder.builder(true)
.context(SwitchersBase.class.getName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.domain("domain")
.apiKey("apiKey")
.component("component")
.environment(DEFAULT_ENV));
}

@Test
void shouldReturnTrue_silentMode() {
//given
Switchers.configure(ContextBuilder.builder()
SwitchersBase.configure(ContextBuilder.builder()
.snapshotLocation(SNAPSHOTS_LOCAL)
.environment("fixture1")
.silentMode("5s"));
Switchers.initializeClient();

SwitchersBase.initializeClient();

//auth
givenResponse(generateMockAuth(10));
Expand All @@ -65,7 +61,7 @@ void shouldReturnTrue_silentMode() {
givenResponse(generateCriteriaResponse("true", false));

//test
SwitcherRequest switcher = Switchers.getSwitcher(Switchers.USECASE11);
SwitcherRequest switcher = SwitchersBase.getSwitcher(SwitchersBase.USECASE11);
assertTrue(switcher.isItOn());

CountDownHelper.wait(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void shouldNotKillThread_whenAPI_wentLocal() {
Switchers.configure(ContextBuilder.builder(true)
.context(Switchers.class.getName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.apiKey("[API_KEY]")
.apiKey("apiKey")
.environment("generated_mock_default_6")
.local(true)
.snapshotAutoLoad(true)
Expand All @@ -65,8 +65,8 @@ void shouldNotKillThread_whenAPI_wentLocal() {
givenResponse(generateSnapshotResponse("default.json", SNAPSHOTS_LOCAL)); //graphql

//test
CountDownHelper.wait(2);
assertEquals(2, Switchers.getSnapshotVersion());
assertEquals(2,
CountDownHelper.waitUntil(10, 2L, Switchers::getSnapshotVersion));
}

}
Loading
Loading