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
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>com.switcherapi</groupId>
<artifactId>switcher-client</artifactId>
<packaging>jar</packaging>
<version>2.4.2-SNAPSHOT</version>
<version>2.5.0-SNAPSHOT</version>

<name>Switcher Client</name>
<description>Switcher Client SDK for working with Switcher API</description>
Expand Down Expand Up @@ -59,19 +59,19 @@

<!-- test -->
<okhttp.version>5.1.0</okhttp.version>
<junit-jupiter.version>5.13.4</junit-jupiter.version>
<junit-jupiter.version>5.14.0</junit-jupiter.version>
<junit-pioneer.version>2.3.0</junit-pioneer.version>
<junit-platform-launcher.version>1.13.4</junit-platform-launcher.version>
<junit-platform-launcher.version>1.14.0</junit-platform-launcher.version>

<!-- Plugins -->
<maven-compiler-plugin.version>3.14.0</maven-compiler-plugin.version>
<maven-compiler-plugin.version>3.14.1</maven-compiler-plugin.version>
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.12.0</maven-javadoc-plugin.version>
<maven-surefire-plugin.version>3.5.4</maven-surefire-plugin.version>
<maven-gpg-plugin.version>3.2.8</maven-gpg-plugin.version>
<sonar-maven-plugin.version>5.2.0.4988</sonar-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.13</jacoco-maven-plugin.version>
<central-publishing-maven-plugin.version>0.8.0</central-publishing-maven-plugin.version>
<central-publishing-maven-plugin.version>0.9.0</central-publishing-maven-plugin.version>

<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
Expand Down
66 changes: 32 additions & 34 deletions snapshots/default.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
{
"data": {
"domain": {
"name": "Playground",
"version": 1613542022439,
"group": [
{
"name": "Release 1",
"config": [
{
"key": "MY_SWITCHER",
"strategies": [
{
"strategy": "VALUE_VALIDATION",
"operation": "EXIST",
"values": [
"user_1"
],
"activated": false
}
],
"components": [
"switcher-playground"
],
"description": "My first switcher",
"activated": false
}
],
"description": "",
"activated": true
}
],
"description": "My playground",
"activated": true
}
"domain": {
"name": "Playground",
"version": 1613542022439,
"group": [
{
"name": "Release 1",
"config": [
{
"key": "MY_SWITCHER",
"strategies": [
{
"strategy": "VALUE_VALIDATION",
"operation": "EXIST",
"values": [
"user_1"
],
"activated": false
}
],
"components": [
"switcher-playground"
],
"description": "My first switcher",
"activated": false
}
],
"description": "",
"activated": true
}
],
"description": "My playground",
"activated": true
}
}
48 changes: 23 additions & 25 deletions snapshots/dev1.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
{
"data": {
"domain": {
"name": "Playground",
"version": 1613542022439,
"group": [
{
"name": "Release 1",
"config": [
{
"key": "MY_SWITCHER",
"strategies": [],
"components": [
"switcher-playground"
],
"description": "My first switcher",
"activated": true
}
],
"description": "",
"activated": true
}
],
"description": "My playground",
"activated": true
}
"domain": {
"name": "Playground",
"version": 1613542022439,
"group": [
{
"name": "Release 1",
"config": [
{
"key": "MY_SWITCHER",
"strategies": [],
"components": [
"switcher-playground"
],
"description": "My first switcher",
"activated": true
}
],
"description": "",
"activated": true
}
],
"description": "My playground",
"activated": true
}
}
19 changes: 0 additions & 19 deletions src/main/java/com/switcherapi/client/model/criteria/Data.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
*/
public class Snapshot {

private Data data;
private Domain domain;

public Domain getDomain() {
return data != null ? data.getDomain() : new Domain();
return domain != null ? domain : new Domain();
}

public Data getData() {
return data;
}

public void setData(Data data) {
this.data = data;
public void setDomain(Domain domain) {
this.domain = domain;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Snapshot resolveSnapshot(final String token) {
throw new SwitcherRemoteException(url, response.statusCode());
}

return gson.fromJson(response.body(), Snapshot.class);
return gson.fromJson(response.body(), SnapshotDataResponse.class).getData();
} catch (Exception e) {
return exceptionHandler(e, url);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.switcherapi.client.remote.dto;

import com.switcherapi.client.model.criteria.Snapshot;

public class SnapshotDataResponse {

private Snapshot data;

public Snapshot getData() {
return data;
}

public void setData(Snapshot data) {
this.data = data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@
}
]
},
{
"name": "com.switcherapi.client.model.criteria.Data",
"condition": {
"typeReachable": "com.switcherapi.client.model.criteria.Snapshot"
},
"allDeclaredFields": true,
"methods": [
{
"name": "<init>",
"parameterTypes": []
}
]
},
{
"name": "com.switcherapi.client.model.criteria.Domain",
"condition": {
Expand Down Expand Up @@ -210,5 +197,18 @@
"parameterTypes": []
}
]
},
{
"name": "com.switcherapi.client.remote.dto.SnapshotDataResponse",
"condition": {
"typeReachable": "com.switcherapi.client.remote.ClientWSImpl"
},
"allDeclaredFields": true,
"methods": [
{
"name": "<init>",
"parameterTypes": []
}
]
}
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.switcherapi.client;

import com.switcherapi.Switchers;
import com.switcherapi.client.model.criteria.Data;
import com.switcherapi.client.model.criteria.Domain;
import com.switcherapi.client.model.criteria.Snapshot;
import com.switcherapi.client.utils.SnapshotLoader;
Expand Down Expand Up @@ -60,9 +59,7 @@ void restoreStubs() {

static void generateFixture(String environment) {
final Snapshot mockedSnapshot = new Snapshot();
final Data data = new Data();
data.setDomain(DOMAIN_OUTDATED);
mockedSnapshot.setData(data);
mockedSnapshot.setDomain(DOMAIN_OUTDATED);

SnapshotLoader.saveSnapshot(mockedSnapshot, SNAPSHOTS_LOCAL, environment);
}
Expand Down
8 changes: 0 additions & 8 deletions src/test/java/com/switcherapi/client/model/ModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ void testCriteriaPackage() {
assertSame("Name", domain.getName());
assertEquals(10000000000L, domain.getVersion());
assertSame(groups, domain.getGroup());

final Data data = new Data();
data.setDomain(domain);

final Snapshot snapshot = new Snapshot();
snapshot.setData(data);

assertSame(data, snapshot.getData());
}

}
21 changes: 8 additions & 13 deletions src/test/java/com/switcherapi/client/utils/SnapshotTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.switcherapi.client.utils;

import com.switcherapi.SwitchersBase;
import com.switcherapi.client.model.criteria.Data;
import com.switcherapi.client.model.criteria.Domain;
import com.switcherapi.client.model.criteria.Snapshot;
import com.switcherapi.client.service.WorkerName;
Expand Down Expand Up @@ -33,25 +32,21 @@ protected static void removeGeneratedFiles() throws IOException {

protected static void generateFixture() {
final Snapshot mockedSnapshot = new Snapshot();
final Data data = new Data();
data.setDomain(SnapshotLoader.loadSnapshot(SNAPSHOTS_LOCAL + "/snapshot_watcher.json"));
mockedSnapshot.setData(data);
mockedSnapshot.setDomain(SnapshotLoader.loadSnapshot(SNAPSHOTS_LOCAL + "/snapshot_watcher.json"));

SnapshotLoader.saveSnapshot(mockedSnapshot, SNAPSHOTS_LOCAL, "generated_watcher_default");
}

protected void changeFixture() {
final Snapshot mockedSnapshot = new Snapshot();
final Data data = new Data();
data.setDomain(SnapshotLoader.loadSnapshot(SNAPSHOTS_LOCAL + "/snapshot_watcher.json"));
mockedSnapshot.setData(data);
mockedSnapshot.setDomain(SnapshotLoader.loadSnapshot(SNAPSHOTS_LOCAL + "/snapshot_watcher.json"));

data.setDomain(new Domain(
data.getDomain().getName(),
data.getDomain().getDescription(),
!data.getDomain().isActivated(),
data.getDomain().getVersion(),
data.getDomain().getGroup()));
mockedSnapshot.setDomain(new Domain(
mockedSnapshot.getDomain().getName(),
mockedSnapshot.getDomain().getDescription(),
!mockedSnapshot.getDomain().isActivated(),
mockedSnapshot.getDomain().getVersion(),
mockedSnapshot.getDomain().getGroup()));

final Gson gson = new GsonBuilder().setPrettyPrinting().create();
writeFixture(gson.toJson(mockedSnapshot));
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/com/switcherapi/fixture/MockWebServerHelper.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.switcherapi.fixture;

import com.switcherapi.client.model.criteria.Data;
import com.switcherapi.client.model.criteria.Snapshot;
import com.switcherapi.client.remote.ClientWSImpl;
import com.switcherapi.client.remote.dto.CriteriaRequest;
import com.switcherapi.client.remote.dto.SnapshotDataResponse;
import com.switcherapi.client.utils.SnapshotLoader;
import com.switcherapi.client.utils.SwitcherUtils;
import com.google.gson.Gson;
Expand Down Expand Up @@ -71,13 +71,14 @@ protected MockResponse generateSnapshotResponse(String resourcesPath) {
*/
protected MockResponse generateSnapshotResponse(String snapshotFile, String resourcesPath) {
final Snapshot mockedSnapshot = new Snapshot();
final Data data = new Data();
data.setDomain(SnapshotLoader.loadSnapshot(resourcesPath + "/" + snapshotFile));
mockedSnapshot.setData(data);
mockedSnapshot.setDomain(SnapshotLoader.loadSnapshot(resourcesPath + "/" + snapshotFile));

final SnapshotDataResponse data = new SnapshotDataResponse();
data.setData(mockedSnapshot);

Gson gson = new Gson();
MockResponse.Builder builder = new MockResponse.Builder();
builder.body(gson.toJson(mockedSnapshot));
builder.body(gson.toJson(data));
builder.addHeader("Content-Type", "application/json");
return builder.build();
}
Expand Down
Loading