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#580 from siemens/fix/GenerateLicense…
…InfoREST fix(rest): Download licenseinfo file rest endpoint. tested-by: [email protected] review-by: [email protected]
- Loading branch information
Showing
4 changed files
with
57 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,16 @@ | |
import org.eclipse.sw360.datahandler.thrift.components.ECCStatus; | ||
import org.eclipse.sw360.datahandler.thrift.components.EccInformation; | ||
import org.eclipse.sw360.datahandler.thrift.components.Release; | ||
import org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoFile; | ||
import org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatInfo; | ||
import org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatVariant; | ||
import org.eclipse.sw360.datahandler.thrift.projects.Project; | ||
import org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship; | ||
import org.eclipse.sw360.datahandler.thrift.projects.ProjectType; | ||
import org.eclipse.sw360.datahandler.thrift.users.User; | ||
import org.eclipse.sw360.rest.resourceserver.TestHelper; | ||
import org.eclipse.sw360.rest.resourceserver.attachment.Sw360AttachmentService; | ||
import org.eclipse.sw360.rest.resourceserver.licenseinfo.Sw360LicenseInfoService; | ||
import org.eclipse.sw360.rest.resourceserver.project.Sw360ProjectService; | ||
import org.eclipse.sw360.rest.resourceserver.release.Sw360ReleaseService; | ||
import org.eclipse.sw360.rest.resourceserver.user.Sw360UserService; | ||
|
@@ -51,6 +55,8 @@ | |
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.*; | ||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; | ||
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
@@ -76,6 +82,9 @@ public class ProjectSpecTest extends TestRestDocsSpecBase { | |
@MockBean | ||
private Sw360AttachmentService attachmentServiceMock; | ||
|
||
@MockBean | ||
private Sw360LicenseInfoService licenseInfoMockService; | ||
|
||
private Project project; | ||
private Attachment attachment; | ||
|
||
|
@@ -246,6 +255,14 @@ 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")); | ||
OutputFormatInfo outputFormatInfo = new OutputFormatInfo(); | ||
outputFormatInfo.setFileExtension("html"); | ||
given(this.licenseInfoMockService.getOutputFormatInfoForGeneratorClass(anyObject())) | ||
.willReturn(outputFormatInfo); | ||
LicenseInfoFile licenseInfoFile = new LicenseInfoFile(); | ||
licenseInfoFile.setGeneratedOutput(new byte[0]); | ||
given(this.licenseInfoMockService.getLicenseInfoFile(anyObject(), anyObject(), anyObject(), anyObject(), | ||
anyObject())).willReturn(licenseInfoFile); | ||
} | ||
|
||
@Test | ||
|
@@ -595,4 +612,20 @@ public void should_document_link_releases() throws Exception { | |
.content(this.objectMapper.writeValueAsString(releaseIds)) | ||
.header("Authorization", "Bearer " + accessToken)).andExpect(status().isCreated()); | ||
} | ||
|
||
@Test | ||
public void should_document_get_download_license_info() throws Exception { | ||
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword); | ||
this.mockMvc.perform(get("/api/projects/" + project.getId()+ "/licenseinfo?generatorClassName=XhtmlGenerator&variant=DISCLOSURE") | ||
.header("Authorization", "Bearer " + accessToken) | ||
.accept("application/xhtml+xml")) | ||
.andExpect(status().isOk()) | ||
.andDo(this.documentationHandler | ||
.document(requestParameters( | ||
parameterWithName("generatorClassName") | ||
.description("All possible values for output generator class names are " | ||
+ Arrays.asList("DocxGenerator", "XhtmlGenerator", "TextGenerator")), | ||
parameterWithName("variant").description("All the possible values for variants are " | ||
+ Arrays.asList(OutputFormatVariant.values()))))); | ||
} | ||
} |