Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ODP Segments support in Audience Evaluation #474

Merged
merged 28 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2ba5621
OASIS-8309 Added qualified segments to User Context, updated evaluate…
genemitelmanopti May 23, 2022
6d1924a
OASIS-8309 Updated UserAttribute evaluate to check qualified segments.
genemitelmanopti May 24, 2022
0d9d3b8
Added unit tests and fixed issues
NomanShoaib Jun 16, 2022
a8d0c3f
Updated header
NomanShoaib Jun 16, 2022
b461f82
resolved comments
NomanShoaib Jun 21, 2022
8ccd995
Resolved spotbugs error
NomanShoaib Jun 21, 2022
f449dda
removed unnecessary null check
NomanShoaib Jun 21, 2022
a9c8d05
Merge branch 'master' into gene/ats
mnoman09 Jun 27, 2022
315a9c9
Comment added
NomanShoaib Jun 28, 2022
0469623
1. Implemented parsing of integrations in all four Datafile Parsers.
zashraf1985 Jul 16, 2022
15bfe93
Update core-api/src/main/java/com/optimizely/ab/OptimizelyUserContext…
mnoman09 Jul 18, 2022
b8eaae1
Resolved comment and fixed
NomanShoaib Jul 18, 2022
eb2e8c8
trying to fix a test
zashraf1985 Jul 18, 2022
1ba1b3e
trying ignoing some tests
zashraf1985 Jul 18, 2022
9910be8
IGNORED the correct test
zashraf1985 Jul 18, 2022
6af28aa
Merge branch 'master' into gene/ats
msohailhussain Jul 18, 2022
226d3ae
Enabled ignored tests
zashraf1985 Jul 19, 2022
24396e9
test
mnoman09 Jul 19, 2022
12d92ee
test
mnoman09 Jul 19, 2022
889e405
Reverting assertEqual to assertThat
mnoman09 Jul 19, 2022
29750c4
test
mnoman09 Jul 19, 2022
cc4ee31
test
mnoman09 Jul 19, 2022
4f61e54
using macos as in git action there is some problem with ubuntu 18.04
mnoman09 Jul 19, 2022
99a7f0a
change os version to macos latest for unit test
mnoman09 Jul 19, 2022
aad5d0b
added integrations to parsing tests
zashraf1985 Jul 19, 2022
c0f0284
Incorporate review feedback
zashraf1985 Jul 20, 2022
d6ec898
Added unit tests for integrations parsing
zashraf1985 Jul 21, 2022
5df10d4
Added some more unit tests
zashraf1985 Jul 21, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ private List<Integration> parseIntegrations(JSONArray integrationsJson) {
Object obj = integrationsJson.get(i);
JSONObject integrationObject = (JSONObject) obj;
String key = integrationObject.getString("key");
String host = integrationObject.getString("host");
String publicKey = integrationObject.getString("publicKey");
String host = integrationObject.has("host") ? integrationObject.getString("host") : null;
String publicKey = integrationObject.has("publicKey") ? integrationObject.getString("publicKey") : null;
integrations.add(new Integration(key, host, publicKey));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,52 @@ public void nullJsonExceptionWrapping() throws Exception {
parser.parseProjectConfig(null);
}

@Test
public void integrationsArrayAbsent() throws Exception {
GsonConfigParser parser = new GsonConfigParser();
ProjectConfig actual = parser.parseProjectConfig(nullFeatureEnabledConfigJsonV4());
assertEquals(actual.getHostForODP(), "");
assertEquals(actual.getPublicKeyForODP(), "");
}

@Test
public void integrationsArrayHasODP() throws Exception {
GsonConfigParser parser = new GsonConfigParser();
ProjectConfig actual = parser.parseProjectConfig(validConfigJsonV4());
assertEquals(actual.getHostForODP(), "https://example.com");
assertEquals(actual.getPublicKeyForODP(), "test-key");
}

@Test
public void integrationsArrayHasOtherIntegration() throws Exception {
GsonConfigParser parser = new GsonConfigParser();
String integrationsObject = ", \"integrations\": [" +
"{ \"key\": \"not-odp\", " +
"\"host\": \"https://example.com\", " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"\"host\": \"https://example.com\", " +
"\"any-key\": \"any-value\", " +

Let's check if it can tolerate future fields. Same for other parsers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"\"publicKey\": \"test-key\" }" +
"]}";
String datafile = nullFeatureEnabledConfigJsonV4();
datafile = datafile.substring(0, datafile.lastIndexOf("}")) + integrationsObject;
ProjectConfig actual = parser.parseProjectConfig(datafile);
assertEquals(actual.getIntegrations().size(), 1);
assertEquals(actual.getHostForODP(), "");
assertEquals(actual.getPublicKeyForODP(), "");
}

@Test
public void integrationsArrayHasMissingHost() throws Exception {
GsonConfigParser parser = new GsonConfigParser();
String integrationsObject = ", \"integrations\": [" +
"{ \"key\": \"odp\", " +
"\"publicKey\": \"test-key\" }" +
"]}";
String datafile = nullFeatureEnabledConfigJsonV4();
datafile = datafile.substring(0, datafile.lastIndexOf("}")) + integrationsObject;
ProjectConfig actual = parser.parseProjectConfig(datafile);
assertEquals(actual.getHostForODP(), null);
assertEquals(actual.getPublicKeyForODP(), "test-key");
}

@Test
public void testToJson() {
Map<String, Object> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,52 @@ public void nullJsonExceptionWrapping() throws Exception {
parser.parseProjectConfig(null);
}

@Test
public void integrationsArrayAbsent() throws Exception {
JacksonConfigParser parser = new JacksonConfigParser();
ProjectConfig actual = parser.parseProjectConfig(nullFeatureEnabledConfigJsonV4());
assertEquals(actual.getHostForODP(), "");
assertEquals(actual.getPublicKeyForODP(), "");
}

@Test
public void integrationsArrayHasODP() throws Exception {
JacksonConfigParser parser = new JacksonConfigParser();
ProjectConfig actual = parser.parseProjectConfig(validConfigJsonV4());
assertEquals(actual.getHostForODP(), "https://example.com");
assertEquals(actual.getPublicKeyForODP(), "test-key");
}

@Test
public void integrationsArrayHasOtherIntegration() throws Exception {
JacksonConfigParser parser = new JacksonConfigParser();
String integrationsObject = ", \"integrations\": [" +
"{ \"key\": \"not-odp\", " +
"\"host\": \"https://example.com\", " +
"\"publicKey\": \"test-key\" }" +
"]}";
String datafile = nullFeatureEnabledConfigJsonV4();
datafile = datafile.substring(0, datafile.lastIndexOf("}")) + integrationsObject;
ProjectConfig actual = parser.parseProjectConfig(datafile);
assertEquals(actual.getIntegrations().size(), 1);
assertEquals(actual.getHostForODP(), "");
assertEquals(actual.getPublicKeyForODP(), "");
}

@Test
public void integrationsArrayHasMissingHost() throws Exception {
JacksonConfigParser parser = new JacksonConfigParser();
String integrationsObject = ", \"integrations\": [" +
"{ \"key\": \"odp\", " +
"\"publicKey\": \"test-key\" }" +
"]}";
String datafile = nullFeatureEnabledConfigJsonV4();
datafile = datafile.substring(0, datafile.lastIndexOf("}")) + integrationsObject;
ProjectConfig actual = parser.parseProjectConfig(datafile);
assertEquals(actual.getHostForODP(), null);
assertEquals(actual.getPublicKeyForODP(), "test-key");
}

@Test
public void testToJson() {
Map<String, Object> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,52 @@ public void nullJsonExceptionWrapping() throws Exception {
parser.parseProjectConfig(null);
}

@Test
public void integrationsArrayAbsent() throws Exception {
JsonConfigParser parser = new JsonConfigParser();
ProjectConfig actual = parser.parseProjectConfig(nullFeatureEnabledConfigJsonV4());
assertEquals(actual.getHostForODP(), "");
assertEquals(actual.getPublicKeyForODP(), "");
}

@Test
public void integrationsArrayHasODP() throws Exception {
JsonConfigParser parser = new JsonConfigParser();
ProjectConfig actual = parser.parseProjectConfig(validConfigJsonV4());
assertEquals(actual.getHostForODP(), "https://example.com");
assertEquals(actual.getPublicKeyForODP(), "test-key");
}

@Test
public void integrationsArrayHasOtherIntegration() throws Exception {
JsonConfigParser parser = new JsonConfigParser();
String integrationsObject = ", \"integrations\": [" +
"{ \"key\": \"not-odp\", " +
"\"host\": \"https://example.com\", " +
"\"publicKey\": \"test-key\" }" +
"]}";
String datafile = nullFeatureEnabledConfigJsonV4();
datafile = datafile.substring(0, datafile.lastIndexOf("}")) + integrationsObject;
ProjectConfig actual = parser.parseProjectConfig(datafile);
assertEquals(actual.getIntegrations().size(), 1);
assertEquals(actual.getHostForODP(), "");
assertEquals(actual.getPublicKeyForODP(), "");
}

@Test
public void integrationsArrayHasMissingHost() throws Exception {
JsonConfigParser parser = new JsonConfigParser();
String integrationsObject = ", \"integrations\": [" +
"{ \"key\": \"odp\", " +
"\"publicKey\": \"test-key\" }" +
"]}";
String datafile = nullFeatureEnabledConfigJsonV4();
datafile = datafile.substring(0, datafile.lastIndexOf("}")) + integrationsObject;
ProjectConfig actual = parser.parseProjectConfig(datafile);
assertEquals(actual.getHostForODP(), null);
assertEquals(actual.getPublicKeyForODP(), "test-key");
}

@Test
public void testToJson() {
Map<String, Object> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,52 @@ public void nullJsonExceptionWrapping() throws Exception {
parser.parseProjectConfig(null);
}

@Test
public void integrationsArrayAbsent() throws Exception {
JsonSimpleConfigParser parser = new JsonSimpleConfigParser();
ProjectConfig actual = parser.parseProjectConfig(nullFeatureEnabledConfigJsonV4());
assertEquals(actual.getHostForODP(), "");
assertEquals(actual.getPublicKeyForODP(), "");
}

@Test
public void integrationsArrayHasODP() throws Exception {
JsonSimpleConfigParser parser = new JsonSimpleConfigParser();
ProjectConfig actual = parser.parseProjectConfig(validConfigJsonV4());
assertEquals(actual.getHostForODP(), "https://example.com");
assertEquals(actual.getPublicKeyForODP(), "test-key");
}

@Test
public void integrationsArrayHasOtherIntegration() throws Exception {
JsonSimpleConfigParser parser = new JsonSimpleConfigParser();
String integrationsObject = ", \"integrations\": [" +
"{ \"key\": \"not-odp\", " +
"\"host\": \"https://example.com\", " +
"\"publicKey\": \"test-key\" }" +
"]}";
String datafile = nullFeatureEnabledConfigJsonV4();
datafile = datafile.substring(0, datafile.lastIndexOf("}")) + integrationsObject;
ProjectConfig actual = parser.parseProjectConfig(datafile);
assertEquals(actual.getIntegrations().size(), 1);
assertEquals(actual.getHostForODP(), "");
assertEquals(actual.getPublicKeyForODP(), "");
}

@Test
public void integrationsArrayHasMissingHost() throws Exception {
JsonSimpleConfigParser parser = new JsonSimpleConfigParser();
String integrationsObject = ", \"integrations\": [" +
"{ \"key\": \"odp\", " +
"\"publicKey\": \"test-key\" }" +
"]}";
String datafile = nullFeatureEnabledConfigJsonV4();
datafile = datafile.substring(0, datafile.lastIndexOf("}")) + integrationsObject;
ProjectConfig actual = parser.parseProjectConfig(datafile);
assertEquals(actual.getHostForODP(), null);
assertEquals(actual.getPublicKeyForODP(), "test-key");
}

@Test
public void testToJson() {
Map<String, Object> map = new HashMap<>();
Expand Down