forked from eclipse-sw360/sw360
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eclipse-sw360#1968 from toshiba/release/feature-ap…
…i_import_sbom_for_component feat(api): create new endpoint import bom for component Reviewed by: [email protected] Tested by: [email protected]
- Loading branch information
Showing
6 changed files
with
246 additions
and
4 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 |
---|---|---|
|
@@ -14,6 +14,12 @@ | |
import com.google.common.collect.ImmutableSet; | ||
import org.apache.thrift.TException; | ||
import org.eclipse.sw360.datahandler.thrift.*; | ||
import org.eclipse.sw360.datahandler.thrift.ImportBomRequestPreparation; | ||
import org.eclipse.sw360.datahandler.thrift.RequestStatus; | ||
import org.eclipse.sw360.datahandler.thrift.Visibility; | ||
import org.eclipse.sw360.datahandler.thrift.VerificationState; | ||
import org.eclipse.sw360.datahandler.thrift.VerificationStateInfo; | ||
import org.eclipse.sw360.datahandler.thrift.RequestSummary; | ||
import org.eclipse.sw360.datahandler.thrift.attachments.Attachment; | ||
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent; | ||
import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentType; | ||
|
@@ -41,8 +47,11 @@ | |
import org.springframework.hateoas.EntityModel; | ||
import org.springframework.hateoas.CollectionModel; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.mock.web.MockMultipartFile; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
import java.io.IOException; | ||
import java.text.SimpleDateFormat; | ||
|
@@ -90,6 +99,10 @@ public class ComponentSpecTest extends TestRestDocsSpecBase { | |
|
||
private Project project; | ||
|
||
private Component sBOMComponent; | ||
private Attachment sBOMAttachment; | ||
private RequestSummary requestSummary = new RequestSummary(); | ||
|
||
@Before | ||
public void before() throws TException, IOException { | ||
Set<Attachment> attachmentList = new HashSet<>(); | ||
|
@@ -354,6 +367,46 @@ public void before() throws TException, IOException { | |
given(this.vulnerabilityServiceMock.updateReleaseVulnerabilityRelation(any(), any())).willReturn(RequestStatus.SUCCESS); | ||
given(this.vulnerabilityServiceMock.getVulnerabilitiesByReleaseId(any(), any())).willReturn(vulDtos); | ||
angularComponent.setReleases(releaseList); | ||
|
||
sBOMAttachment = new Attachment("3331231254", "bom.spdx.rdf"); | ||
sBOMAttachment.setSha1("df90312312312534543544375345345383"); | ||
sBOMAttachment.setAttachmentType(AttachmentType.SBOM); | ||
Set<Attachment> attachments = new HashSet<>(); | ||
attachments.add(sBOMAttachment); | ||
|
||
sBOMComponent = new Component(); | ||
sBOMComponent.setId("2222222"); | ||
sBOMComponent.setName("Maven"); | ||
sBOMComponent.setCreatedOn("2023-04-30"); | ||
sBOMComponent.setBusinessUnit("sw360 BA"); | ||
sBOMComponent.setComponentType(ComponentType.SERVICE); | ||
sBOMComponent.setCreatedBy("[email protected]"); | ||
sBOMComponent.setAttachments(attachments); | ||
|
||
Release release1 = new Release(); | ||
release1.setId("3333333"); | ||
release1.setComponentId("2222222"); | ||
release1.setName("Green Web"); | ||
release1.setVersion("1.0.0"); | ||
release1.setCreatedOn("2023-04-30"); | ||
release1.setComponentType(ComponentType.SERVICE); | ||
release1.setCreatedBy("[email protected]"); | ||
|
||
requestSummary.setMessage(sBOMComponent.getId()); | ||
requestSummary.setRequestStatus(RequestStatus.SUCCESS); | ||
|
||
ImportBomRequestPreparation importBomRequestPreparation = new ImportBomRequestPreparation(); | ||
importBomRequestPreparation.setComponentsName(sBOMComponent.getName()); | ||
StringBuilder relesaeName = new StringBuilder(); | ||
relesaeName.append(release1.getName()); | ||
relesaeName.append(" "); | ||
relesaeName.append(release1.getVersion()); | ||
importBomRequestPreparation.setReleasesName(relesaeName.toString()); | ||
|
||
given(this.componentServiceMock.prepareImportSBOM(any(),any())).willReturn(importBomRequestPreparation); | ||
given(this.componentServiceMock.importSBOM(any(),any())).willReturn(requestSummary); | ||
given(this.componentServiceMock.getReleaseById(any(),any())).willReturn(release1); | ||
given(this.componentServiceMock.getComponentForUserById(eq(sBOMComponent.getId()), any())).willReturn(sBOMComponent); | ||
} | ||
|
||
@Test | ||
|
@@ -990,4 +1043,27 @@ public void should_document_get_releases_by_component() throws Exception { | |
))); | ||
} | ||
|
||
@Test | ||
public void should_document_import_sbom_for_component() throws Exception { | ||
MockMultipartFile file = new MockMultipartFile("file","file=@/bom.spdx.rdf".getBytes()); | ||
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword); | ||
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.post("/api/components/import/SBOM") | ||
.content(file.getBytes()) | ||
.contentType(MediaType.MULTIPART_FORM_DATA) | ||
.header("Authorization", "Bearer " + accessToken) | ||
.queryParam("type", "SPDX"); | ||
this.mockMvc.perform(builder).andExpect(status().isOk()).andDo(this.documentationHandler.document()); | ||
} | ||
|
||
@Test | ||
public void should_document_prepare_import_sbom_for_component() throws Exception { | ||
MockMultipartFile file = new MockMultipartFile("file","file=@/bom.spdx.rdf".getBytes()); | ||
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword); | ||
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.post("/api/components/prepareImport/SBOM") | ||
.content(file.getBytes()) | ||
.contentType(MediaType.MULTIPART_FORM_DATA) | ||
.header("Authorization", "Bearer " + accessToken) | ||
.queryParam("type", "SPDX"); | ||
this.mockMvc.perform(builder).andExpect(status().isOk()).andDo(this.documentationHandler.document()); | ||
} | ||
} |