Skip to content

Commit

Permalink
Core: Make app required field for module storage (#3294)
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiiNahornyi authored Jul 10, 2024
1 parent 172a85d commit cc651ee
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
17 changes: 13 additions & 4 deletions src/main/java/org/prebid/server/cache/BasicModuleCacheService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Future<Void> storeModuleEntry(String key,
String moduleCode) {

try {
validateStoreData(key, value, type, moduleCode);
validateStoreData(key, value, application, type, moduleCode);
} catch (PreBidException e) {
return Future.failedFuture(e);
}
Expand All @@ -74,6 +74,7 @@ public Future<Void> storeModuleEntry(String key,

private static void validateStoreData(String key,
String value,
String application,
ModuleCacheType type,
String moduleCode) {

Expand All @@ -85,6 +86,10 @@ private static void validateStoreData(String key,
throw new PreBidException("Module cache 'value' can not be blank");
}

if (StringUtils.isBlank(application)) {
throw new PreBidException("Module cache 'application' can not be blank");
}

if (type == null) {
throw new PreBidException("Module cache 'type' can not be empty");
}
Expand Down Expand Up @@ -124,7 +129,7 @@ public Future<ModuleCacheResponse> retrieveModuleEntry(String key,
String application) {

try {
validateRetrieveData(key, moduleCode);
validateRetrieveData(key, application, moduleCode);
} catch (PreBidException e) {
return Future.failedFuture(e);
}
Expand All @@ -137,11 +142,15 @@ public Future<ModuleCacheResponse> retrieveModuleEntry(String key,

}

private static void validateRetrieveData(String key, String moduleCode) {
private static void validateRetrieveData(String key, String application, String moduleCode) {
if (StringUtils.isBlank(key)) {
throw new PreBidException("Module cache 'key' can not be blank");
}

if (StringUtils.isBlank(application)) {
throw new PreBidException("Module cache 'application' can not be blank");
}

if (StringUtils.isBlank(moduleCode)) {
throw new PreBidException("Module cache 'moduleCode' can not be blank");
}
Expand All @@ -153,7 +162,7 @@ private String getRetrieveEndpoint(String key,

return endpointUrl
+ "?k=" + constructEntryKey(key, moduleCode)
+ "&a=" + StringUtils.defaultString(application);
+ "&a=" + application;
}

private ModuleCacheResponse toModuleCacheResponse(int statusCode, String responseBody) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ public void storeModuleEntryShouldReturnFailedFutureIfValueIsMissed() {
assertThat(result.cause().getMessage()).isEqualTo("Module cache 'value' can not be blank");
}

@Test
public void storeModuleEntryShouldReturnFailedFutureIfApplicationIsMissed() {
// when
final Future<Void> result = target.storeModuleEntry("some-key",
"some-value",
ModuleCacheType.TEXT,
12,
null,
"some-module-code");

// then
assertThat(result.failed()).isTrue();
assertThat(result.cause()).isInstanceOf(PreBidException.class);
assertThat(result.cause().getMessage()).isEqualTo("Module cache 'application' can not be blank");
}

@Test
public void storeModuleEntryShouldReturnFailedFutureIfTypeIsMissed() {
// when
Expand Down Expand Up @@ -222,6 +238,18 @@ public void retrieveModuleEntryShouldReturnFailedFutureIfModuleKeyIsMissed() {
assertThat(result.cause().getMessage()).isEqualTo("Module cache 'key' can not be blank");
}

@Test
public void retrieveModuleEntryShouldReturnFailedFutureIfModuleApplicationIsMissed() {
// when
final Future<ModuleCacheResponse> result =
target.retrieveModuleEntry("some-key", "some-module-code", null);

// then
assertThat(result.failed()).isTrue();
assertThat(result.cause()).isInstanceOf(PreBidException.class);
assertThat(result.cause().getMessage()).isEqualTo("Module cache 'application' can not be blank");
}

@Test
public void retrieveModuleEntryShouldReturnFailedFutureIfModuleCodeIsMissed() {
// when
Expand Down Expand Up @@ -255,17 +283,6 @@ public void retrieveModuleEntryShouldCreateCallWithKeyInParams() {
.isEqualTo("http://cache-service/cache?k=module.some-module-code.some-key&a=some-app");
}

@Test
public void retrieveModuleEntryShouldCreateCallWithBlankAppInParams() {
// when
target.retrieveModuleEntry("some-key", "some-module-code", null);

// then
final String result = captureRetrieveUrl();
assertThat(result)
.isEqualTo("http://cache-service/cache?k=module.some-module-code.some-key&a=");
}

@Test
public void retrieveModuleEntryShouldReturnExpectedResponse() {
// when
Expand Down

0 comments on commit cc651ee

Please sign in to comment.