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
4 changes: 2 additions & 2 deletions .github/workflows/master-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
build-scan:
name: SonarCloud Scan
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"

steps:
Expand All @@ -35,7 +35,7 @@ jobs:
fail-fast: false
matrix:
java: [ '11', '17', '18', '21']
os: [ ubuntu-20.04, windows-latest ]
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/github/switcherapi/client/ContextBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ public static void preConfigure(SwitcherProperties switcherProperties) {
context = builder();
context.preBuild(switcherProperties);
}


/**
* Initialize the ContextBuilder preserving the existing context
* @return ContextBuilder
*/
public static ContextBuilder builder() {
context = builder(false);
return context;
}

/**
* Initialize the ContextBuilder using existing context or create a new one
*
* @param init true/false to create a new context
* @return ContextBuilder
*/
public static ContextBuilder builder(boolean init) {
if (context == null || init)
context = new ContextBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ void shouldUpdateSnapshot_local() {
givenSnapshotUpdateResponse(false);

//that
Switchers.configure(ContextBuilder.builder()
Switchers.configure(ContextBuilder.builder(true)
.contextLocation(Switchers.class.getCanonicalName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.snapshotLocation(SNAPSHOTS_LOCAL)
.environment("generated_mock_default_2")
Expand All @@ -165,8 +166,12 @@ void shouldUpdateSnapshot_remote() {
givenSnapshotUpdateResponse(false);

//that
Switchers.configure(ContextBuilder.builder()
Switchers.configure(ContextBuilder.builder(true)
.contextLocation(Switchers.class.getCanonicalName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.apiKey("[API_KEY]")
.domain("Test")
.component("switcher-test")
.snapshotLocation(SNAPSHOTS_LOCAL)
.environment("generated_mock_default_3")
.local(false)
Expand All @@ -188,7 +193,8 @@ void shouldNotUpdateSnapshot_whenNoUpdateAvailable() {
givenSnapshotUpdateResponse(true);

//that
Switchers.configure(ContextBuilder.builder()
Switchers.configure(ContextBuilder.builder(true)
.contextLocation(Switchers.class.getCanonicalName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.snapshotLocation(SNAPSHOTS_LOCAL)
.environment("generated_mock_default_4")
Expand All @@ -214,7 +220,8 @@ void shouldUpdateSnapshot_remote_inMemory() {
givenResponse(generateSnapshotResponse("default.json")); //graphql

//that
Switchers.configure(ContextBuilder.builder()
Switchers.configure(ContextBuilder.builder(true)
.contextLocation(Switchers.class.getCanonicalName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.snapshotLocation(null)
.environment("generated_mock_default_5")
Expand All @@ -238,7 +245,8 @@ void shouldNotKillThread_whenAPI_wentLocal() {
givenResponse(generateSnapshotResponse("default_outdated.json")); //graphql

//that
Switchers.configure(ContextBuilder.builder()
Switchers.configure(ContextBuilder.builder(true)
.contextLocation(Switchers.class.getCanonicalName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.snapshotLocation(null)
.environment("generated_mock_default_6")
Expand Down Expand Up @@ -268,7 +276,8 @@ void shouldPreventSnapshotAutoUpdateToStart_whenAlreadySetup() {
givenResponse(generateSnapshotResponse("default.json")); //graphql

//that
Switchers.configure(ContextBuilder.builder()
Switchers.configure(ContextBuilder.builder(true)
.contextLocation(Switchers.class.getCanonicalName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.snapshotLocation(null)
.environment("generated_mock_default_6")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SnapshotWatcherErrorTest {
@Test
void shouldNotWatchSnapshotWhenRemote() {
//given
SwitchersBase.configure(ContextBuilder.builder()
SwitchersBase.configure(ContextBuilder.builder(true)
.contextLocation(SwitchersBase.class.getCanonicalName())
.url("https://api.switcherapi.com")
.apiKey("[API_KEY]")
Expand Down