-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Release): Get linked releases of release
- Loading branch information
Showing
6 changed files
with
190 additions
and
2 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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.Mockito.doCallRealMethod; | ||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel; | ||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; | ||
|
@@ -54,6 +55,7 @@ | |
import org.eclipse.sw360.datahandler.thrift.components.ExternalToolProcessStatus; | ||
import org.eclipse.sw360.datahandler.thrift.components.ExternalToolProcessStep; | ||
import org.eclipse.sw360.datahandler.thrift.components.Release; | ||
import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink; | ||
import org.eclipse.sw360.datahandler.thrift.licenses.License; | ||
import org.eclipse.sw360.datahandler.thrift.packages.Package; | ||
import org.eclipse.sw360.datahandler.thrift.packages.PackageManager; | ||
|
@@ -68,6 +70,7 @@ | |
import org.eclipse.sw360.rest.resourceserver.TestHelper; | ||
import org.eclipse.sw360.rest.resourceserver.attachment.AttachmentInfo; | ||
import org.eclipse.sw360.rest.resourceserver.attachment.Sw360AttachmentService; | ||
import org.eclipse.sw360.rest.resourceserver.core.RestControllerHelper; | ||
import org.eclipse.sw360.rest.resourceserver.license.Sw360LicenseService; | ||
import org.eclipse.sw360.rest.resourceserver.packages.SW360PackageService; | ||
import org.eclipse.sw360.rest.resourceserver.licenseinfo.Sw360LicenseInfoService; | ||
|
@@ -130,7 +133,7 @@ public class ReleaseSpecTest extends TestRestDocsSpecBase { | |
@MockBean | ||
private Sw360LicenseInfoService licenseInfoMockService; | ||
|
||
private Release release, release3, releaseTest; | ||
private Release release, release3, releaseTest, release5; | ||
private Attachment attachment; | ||
Component component; | ||
private Project project; | ||
|
@@ -325,6 +328,8 @@ public void before() throws TException, IOException { | |
release2.setClearingInformation(clearingInfo); | ||
release2.setCotsDetails(cotsDetails); | ||
release2.setEccInformation(eccInformation); | ||
release2.setMainLicenseIds(Set.of("MIT", "GPL")); | ||
release2.setOtherLicenseIds(Set.of("MIT")); | ||
releaseList.add(release2); | ||
|
||
Package package2 = new Package() | ||
|
@@ -355,6 +360,31 @@ public void before() throws TException, IOException { | |
release3.setCreatedOn("2016-12-18"); | ||
release3.setCreatedBy("[email protected]"); | ||
release3.setComponentId("1234"); | ||
release3.setMainLicenseIds(Set.of("MIT", "GPL 2+")); | ||
release3.setClearingState(ClearingState.APPROVED); | ||
release3.setMainlineState(MainlineState.MAINLINE); | ||
release3.setOtherLicenseIds(Set.of("MIT")); | ||
|
||
Release release4 = new Release(); | ||
release4.setId("90876"); | ||
release4.setName("Numpy"); | ||
release4.setVersion("1.19.5"); | ||
release4.setMainLicenseIds(Set.of("MIT")); | ||
release4.setClearingState(ClearingState.APPROVED); | ||
release4.setOtherLicenseIds(Collections.emptySet()); | ||
|
||
ReleaseLink releaseLink4 = new ReleaseLink(); | ||
releaseLink4.setId(release4.getId()); | ||
releaseLink4.setName(release4.getName()); | ||
releaseLink4.setVersion(release4.getVersion()); | ||
releaseLink4.setLicenseIds(release4.getMainLicenseIds()); | ||
releaseLink4.setClearingState(release4.getClearingState()); | ||
releaseLink4.setReleaseRelationship(ReleaseRelationship.CODE_SNIPPET); | ||
|
||
release5 = new Release(); | ||
release5.setId("3333333"); | ||
release5.setReleaseIdToRelationship(Map.of(release2.getId(), ReleaseRelationship.DYNAMICALLY_LINKED, release3.getId(), ReleaseRelationship.CODE_SNIPPET)); | ||
|
||
Attachment attachment3 = new Attachment(attachment); | ||
attachment3.setAttachmentContentId("34535345"); | ||
attachment3.setAttachmentType(AttachmentType.SOURCE); | ||
|
@@ -402,6 +432,8 @@ public void before() throws TException, IOException { | |
given(this.releaseServiceMock.getRecentReleases(any())).willReturn(releaseList); | ||
given(this.releaseServiceMock.getReleaseSubscriptions(any())).willReturn(releaseList); | ||
given(this.releaseServiceMock.getReleaseForUserById(eq(release.getId()), any())).willReturn(release); | ||
given(this.releaseServiceMock.getReleaseForUserById(eq(release2.getId()), any())).willReturn(release2); | ||
given(this.releaseServiceMock.getReleaseForUserById(eq(release5.getId()), any())).willReturn(release5); | ||
given(this.releaseServiceMock.getReleaseForUserById(eq(testRelease.getId()), any())).willReturn(testRelease); | ||
given(this.releaseServiceMock.getProjectsByRelease(eq(release.getId()), any())).willReturn(projectList); | ||
given(this.releaseServiceMock.getUsingComponentsForRelease(eq(release.getId()), any())).willReturn(usedByComponent); | ||
|
@@ -418,6 +450,9 @@ public void before() throws TException, IOException { | |
when(this.releaseServiceMock.createRelease(any(), any())).then(invocation -> | ||
new Release("Test Release", "1.0", component.getId()) | ||
.setId("1234567890")); | ||
doCallRealMethod().when(this.releaseServiceMock).addEmbeddedLinkedRelease(any(), any(), any(), any()); | ||
given(this.releaseServiceMock.getReleaseForUserById(eq("90876"), any())).willReturn(release4); | ||
given(this.releaseServiceMock.convertToEmbeddedLinkedRelease(any(), any())).willReturn(releaseLink4); | ||
|
||
given(this.userServiceMock.getUserByEmailOrExternalId("[email protected]")).willReturn( | ||
new User("[email protected]", "sw360").setId("123456789")); | ||
|
@@ -1237,6 +1272,48 @@ public void should_document_load_spdx_licenses_info_from_clx_or_cli() throws Exc | |
.andExpect(status().isOk()); | ||
} | ||
|
||
@Test | ||
public void should_document_get_direct_linked_releases() throws Exception { | ||
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword); | ||
mockMvc.perform(get("/api/releases/" + release5.getId() + "/releases") | ||
.header("Authorization", "Bearer " + accessToken) | ||
.param("transitive", "false") | ||
.accept(MediaTypes.HAL_JSON)) | ||
.andExpect(status().isOk()) | ||
.andDo(this.documentationHandler.document( | ||
requestParameters( | ||
parameterWithName("transitive").description("Get the transitive releases") | ||
), | ||
links( | ||
linkWithRel("curies").description("Curies are used for online documentation") | ||
), | ||
responseFields( | ||
subsectionWithPath("_embedded.sw360:releaseLinks").description("An array of <<resources-releases, Releases resources>>"), | ||
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources") | ||
))); | ||
} | ||
|
||
@Test | ||
public void should_document_get_linked_releases_transitively() throws Exception { | ||
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword); | ||
mockMvc.perform(get("/api/releases/" + release5.getId() + "/releases") | ||
.header("Authorization", "Bearer " + accessToken) | ||
.param("transitive", "true") | ||
.accept(MediaTypes.HAL_JSON)) | ||
.andExpect(status().isOk()) | ||
.andDo(this.documentationHandler.document( | ||
requestParameters( | ||
parameterWithName("transitive").description("Get the transitive releases") | ||
), | ||
links( | ||
linkWithRel("curies").description("Curies are used for online documentation") | ||
), | ||
responseFields( | ||
subsectionWithPath("_embedded.sw360:releaseLinks").description("An array of <<resources-releases, Releases resources>>"), | ||
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources") | ||
))); | ||
} | ||
|
||
public void mockLicensesInfo(AttachmentType attachmentType) throws TException{ | ||
Set<Attachment> listAttachment = new HashSet<>(); | ||
Attachment attachmentTest = new Attachment(); | ||
|