-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(REST):Create clearing request for a project
Signed-off-by: afsahsyeda <[email protected]>
- Loading branch information
afsahsyeda
committed
Jan 30, 2024
1 parent
ecce96c
commit 558a347
Showing
6 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,16 @@ | |
import org.apache.thrift.TException; | ||
import org.eclipse.sw360.datahandler.common.SW360Constants; | ||
import org.eclipse.sw360.datahandler.common.SW360Utils; | ||
import org.eclipse.sw360.datahandler.thrift.ClearingRequestState; | ||
import org.eclipse.sw360.datahandler.thrift.ClearingRequestType; | ||
import org.eclipse.sw360.datahandler.thrift.CycloneDxComponentType; | ||
import org.eclipse.sw360.datahandler.thrift.MainlineState; | ||
import org.eclipse.sw360.datahandler.thrift.ProjectReleaseRelationship; | ||
import org.eclipse.sw360.datahandler.thrift.ReleaseRelationship; | ||
import org.eclipse.sw360.datahandler.thrift.RequestStatus; | ||
import org.eclipse.sw360.datahandler.thrift.RequestSummary; | ||
import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus; | ||
import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary; | ||
import org.eclipse.sw360.datahandler.thrift.Source; | ||
import org.eclipse.sw360.datahandler.thrift.Visibility; | ||
import org.eclipse.sw360.datahandler.thrift.attachments.Attachment; | ||
|
@@ -41,6 +45,7 @@ | |
import org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatVariant; | ||
import org.eclipse.sw360.datahandler.thrift.packages.Package; | ||
import org.eclipse.sw360.datahandler.thrift.packages.PackageManager; | ||
import org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest; | ||
import org.eclipse.sw360.datahandler.thrift.projects.Project; | ||
import org.eclipse.sw360.datahandler.thrift.projects.ProjectClearingState; | ||
import org.eclipse.sw360.datahandler.thrift.projects.ProjectProjectRelationship; | ||
|
@@ -446,6 +451,12 @@ public void before() throws TException, IOException { | |
RequestSummary requestSummaryForCycloneDX = new RequestSummary(); | ||
requestSummaryForCycloneDX.setMessage("{\"projectId\":\"" + cycloneDXProject.getId() + "\"}"); | ||
|
||
AddDocumentRequestSummary requestSummaryForCR = new AddDocumentRequestSummary(); | ||
requestSummaryForCR.setMessage("Clearing request created successfully"); | ||
requestSummaryForCR.setRequestStatus(AddDocumentRequestStatus.SUCCESS); | ||
requestSummaryForCR.setId("CR-1"); | ||
|
||
given(this.projectServiceMock.createClearingRequest(any(),any())).willReturn(requestSummaryForCR); | ||
given(this.projectServiceMock.importSPDX(any(),any())).willReturn(requestSummaryForSPDX); | ||
given(this.projectServiceMock.importCycloneDX(any(),any(),any())).willReturn(requestSummaryForCycloneDX); | ||
given(this.sw360ReportServiceMock.getProjectBuffer(any(),anyBoolean())).willReturn(ByteBuffer.allocate(10000)); | ||
|
@@ -583,6 +594,8 @@ public void before() throws TException, IOException { | |
new User("[email protected]", "sw360").setId("123456789")); | ||
given(this.userServiceMock.getUserByEmail("[email protected]")).willReturn( | ||
new User("[email protected]", "sw360").setId("209582812")); | ||
given(this.userServiceMock.getUserByEmail("[email protected]")).willReturn( | ||
new User("[email protected]", "sw360").setId("2012312")); | ||
OutputFormatInfo outputFormatInfo = new OutputFormatInfo(); | ||
outputFormatInfo.setFileExtension("html"); | ||
given(this.licenseInfoMockService.getOutputFormatInfoForGeneratorClass(any())) | ||
|
@@ -1467,6 +1480,41 @@ public void should_document_get_project_attachment() throws Exception { | |
.andDo(this.documentationHandler.document()); | ||
} | ||
|
||
@Test | ||
public void should_document_create_clearing_request() throws Exception { | ||
Map<String, Object> cr = new HashMap<>(); | ||
cr.put("clearingType", ClearingRequestType.HIGH.toString()); | ||
cr.put("clearingTeam", "[email protected]"); | ||
cr.put("requestedClearingDate", "2024-02-24"); | ||
cr.put("requestingUserComment", "New clearing"); | ||
|
||
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword); | ||
this.mockMvc.perform(post("/api/projects/" + project.getId() + "/clearingRequest") | ||
.contentType(MediaTypes.HAL_JSON) | ||
.content(this.objectMapper.writeValueAsString(cr)) | ||
.header("Authorization", "Bearer " + accessToken)) | ||
.andExpect(status().isCreated()) | ||
.andDo(this.documentationHandler.document( | ||
links(linkWithRel("self").description("The <<resources-projects,Projects resource>>")), | ||
requestFields(fieldWithPath("clearingTeam").description("Email of the clearing team."), | ||
fieldWithPath("requestedClearingDate").description( | ||
"Requested clearing date of the project. It should be a current or future date in the format yyyy-MM-dd."), | ||
fieldWithPath("clearingType").description("Clearing type of the project. Possible values are: " + Arrays.asList(ClearingRequestType.values()).toString()), | ||
fieldWithPath("requestingUserComment").description("Requesting user comment on the clearing of the project.") | ||
), | ||
responseFields(fieldWithPath("id").description("Clearing request id."), | ||
fieldWithPath("projectId").description("Project id associated with clearing request."), | ||
fieldWithPath("clearingState").description("Clearing state of the project."), | ||
fieldWithPath("clearingTeam").description("Clearing team of the project."), | ||
fieldWithPath("requestedClearingDate") | ||
.description("Requested clearing date of the project."), | ||
fieldWithPath("clearingType").description("Clearing type of the project."), | ||
fieldWithPath("requestingUser").description("User requesting the clearing of the project."), | ||
fieldWithPath("requestingUserComment").description("Requesting user comment on the clearing of the project."), | ||
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources") | ||
))); | ||
} | ||
|
||
@Test | ||
public void should_document_create_project() throws Exception { | ||
Map<String, Object> project = new HashMap<>(); | ||
|