Skip to content

Commit

Permalink
fix: show revision in the exception message if it was provided as a p… (
Browse files Browse the repository at this point in the history
#128)

* fix: show revision in the exception message if it was provided as a parameter for getting an entity
* fix: by reverting changes done to maven-build.yml for triggering

---------

Co-authored-by: Adam Ruberti <adam.ruberti@sbb.ch>
  • Loading branch information
Jumas and ariwk authored Aug 22, 2024
1 parent 41895a1 commit 107e96e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
name: maven-build
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
branches: ['**/**']
jobs:
build:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public IProject getProject(@NotNull String projectId, @Nullable String revision)

//Note: it seems that there is no way to get project for already deleted project (unlike workitems/modules & collections)
//so method below will throw exception in this case
return getResolvableObjectOrThrow(projectService.getProject(projectId), revision, String.format("Project '%s' not found", projectId));
return getResolvableObjectOrThrow(projectService.getProject(projectId), revision, String.format("Project '%s'%s not found", projectId, getRevisionMessagePart(revision)));
}

@NotNull
Expand All @@ -120,7 +120,7 @@ public IWorkItem getWorkItem(@NotNull String projectId, @NotNull String workItem
throw new IllegalArgumentException("Parameter 'workItemId' should be provided");
}

return getResolvableObjectOrThrow(trackerProject.getWorkItem(workItemId), revision, String.format("WorkItem '%s' not found in project '%s'", workItemId, projectId));
return getResolvableObjectOrThrow(trackerProject.getWorkItem(workItemId), revision, String.format("WorkItem '%s'%s not found in project '%s'", workItemId, getRevisionMessagePart(revision), projectId));
}

@NotNull
Expand All @@ -139,7 +139,7 @@ public IModule getModule(@NotNull String projectId, @NotNull String spaceId, @No
}

ILocation location = Location.getLocation(spaceId + "/" + documentName);
return getResolvableObjectOrThrow(getModule(project, location), revision, String.format("Document '%s' not found in space '%s' of project '%s'", documentName, spaceId, projectId));
return getResolvableObjectOrThrow(getModule(project, location), revision, String.format("Document '%s'%s not found in space '%s' of project '%s'", documentName, getRevisionMessagePart(revision), spaceId, projectId));
}

@NotNull
Expand All @@ -166,7 +166,7 @@ public IBaselineCollection getCollection(@NotNull String projectId, @NotNull Str
.getOldApi()
)
);
return getResolvableObjectOrThrow(collection, revision, String.format("Collection with id '%s' not found in project '%s'", collectionId, projectId));
return getResolvableObjectOrThrow(collection, revision, String.format("Collection with id '%s'%s not found in project '%s'", collectionId, getRevisionMessagePart(revision), projectId));
}

public <T extends IPObject> T getResolvableObjectOrThrow(@NotNull IPObject object, @Nullable String revision, @NotNull String notFoundMessage) {
Expand Down Expand Up @@ -293,4 +293,8 @@ public IRepositoryConnection getConnection(@NotNull ILocation location) {
public IRepositoryReadOnlyConnection getReadOnlyConnection(@NotNull ILocation location) {
return repositoryService.getReadOnlyConnection(location);
}

private String getRevisionMessagePart(String revision) {
return StringUtils.isEmpty(revision) ? "" : " (rev. %s)".formatted(revision);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,35 @@ void init() {
void testGetNotExistentProject() {
mockProject(Boolean.FALSE);

assertThrows(ObjectNotFoundException.class, () -> polarionService.getProject(PROJECT_ID, null));
ObjectNotFoundException exception = assertThrows(ObjectNotFoundException.class, () -> polarionService.getProject(PROJECT_ID, null));
assertEquals("Project 'project_id' not found", exception.getMessage());

exception = assertThrows(ObjectNotFoundException.class, () -> polarionService.getProject(PROJECT_ID, "123"));
assertEquals("Project 'project_id' (rev. 123) not found", exception.getMessage());
}

@Test
void testGetNotExistentWorkItem() {
IProject project = mockProject(Boolean.TRUE);
mockWorkItem(project, Boolean.FALSE);

assertThrows(ObjectNotFoundException.class, () -> polarionService.getWorkItem(PROJECT_ID, WI_ID));
ObjectNotFoundException exception = assertThrows(ObjectNotFoundException.class, () -> polarionService.getWorkItem(PROJECT_ID, WI_ID));
assertEquals("WorkItem 'wi_id' not found in project 'project_id'", exception.getMessage());

exception = assertThrows(ObjectNotFoundException.class, () -> polarionService.getWorkItem(PROJECT_ID, WI_ID, "123"));
assertEquals("WorkItem 'wi_id' (rev. 123) not found in project 'project_id'", exception.getMessage());
}

@Test
void testGetNotExistentModule() {
IProject project = mockProject(Boolean.TRUE);
mockModule(project, Boolean.FALSE);

assertThrows(ObjectNotFoundException.class, () -> polarionService.getModule(PROJECT_ID, SPACE_ID, DOCUMENT_NAME));
ObjectNotFoundException exception = assertThrows(ObjectNotFoundException.class, () -> polarionService.getModule(PROJECT_ID, SPACE_ID, DOCUMENT_NAME));
assertEquals("Document 'document_name' not found in space 'space_id' of project 'project_id'", exception.getMessage());

exception = assertThrows(ObjectNotFoundException.class, () -> polarionService.getModule(PROJECT_ID, SPACE_ID, DOCUMENT_NAME, "123"));
assertEquals("Document 'document_name' (rev. 123) not found in space 'space_id' of project 'project_id'", exception.getMessage());
}

@Test
Expand All @@ -113,7 +125,11 @@ void testGetNotExistentCollection() {
IBaselineCollection collection = mockCollection(Boolean.FALSE);
transactionalExecutorMockedStatic.when(() -> TransactionalExecutor.executeSafelyInReadOnlyTransaction(any())).thenReturn(collection);

assertThrows(ObjectNotFoundException.class, () -> polarionService.getCollection(PROJECT_ID, COLLECTION_ID));
ObjectNotFoundException exception = assertThrows(ObjectNotFoundException.class, () -> polarionService.getCollection(PROJECT_ID, COLLECTION_ID));
assertEquals("Collection with id '1' not found in project 'project_id'", exception.getMessage());

exception = assertThrows(ObjectNotFoundException.class, () -> polarionService.getCollection(PROJECT_ID, COLLECTION_ID, "123"));
assertEquals("Collection with id '1' (rev. 123) not found in project 'project_id'", exception.getMessage());
}
}

Expand Down

0 comments on commit 107e96e

Please sign in to comment.