Skip to content

Commit

Permalink
throw 404 exception when get non-existing asset (#480)
Browse files Browse the repository at this point in the history
Co-authored-by: Yang Yang <[email protected]>
  • Loading branch information
yangyangv2 and Yang Yang authored Nov 26, 2024
1 parent fd38c99 commit 6623691
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ public Task<ASSET> getAsset(@ActionParam(PARAM_URN) @Nonnull String urnString,

return RestliUtils.toTask(() -> {
final URN urn = parseUrnParam(urnString);

if (!getLocalDAO().exists(urn)) {
throw RestliUtils.resourceNotFoundException();
}

final Set<AspectKey<URN, ? extends RecordTemplate>> keys = parseAspectsParam(aspectNames, true).stream()
.map(aspectClass -> new AspectKey<>(aspectClass, urn, LATEST_VERSION))
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,8 @@ public void testGetAsset() {
ImmutableMap.of(fooKey, Optional.of(foo), fooEvolvedKey, Optional.of(fooEvolved), barKey, Optional.of(bar),
fooBarKey, Optional.of(fooBar), attKey, Optional.of(attributes)));

when(_mockLocalDAO.exists(urn)).thenReturn(true);

EntityAsset asset = runAndWait(_resource.getAsset(urn.toString(), null));

assertEquals(asset.getUrn(), urn);
Expand All @@ -1459,6 +1461,19 @@ public void testGetAsset() {
assertEquals(asset.getAspectAttributes(), attributes);
}

@Test
public void testGetNonExistAsset() {
// Test get non existing assets
FooUrn nonExist = makeFooUrn(2);
when(_mockLocalDAO.exists(nonExist)).thenReturn(false);
try {
runAndWait(_resource.getAsset(nonExist.toString(), null));
fail("get non-exist asset should fail");
} catch (RestLiServiceException restLiServiceException) {
// expected failure
}
}

@Test
public void testRawIngestSkipPreIngestionUpdates() {
FooUrn urn = makeFooUrn(1);
Expand Down

0 comments on commit 6623691

Please sign in to comment.