-
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 new endpoint to delete ModerationRequests by id.
Signed-off-by: Nikesh kumar <[email protected]>
- Loading branch information
Nikesh kumar
committed
Apr 14, 2024
1 parent
f051d63
commit 45e31e4
Showing
4 changed files
with
166 additions
and
17 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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import org.apache.thrift.TException; | ||
import org.eclipse.sw360.datahandler.thrift.ModerationState; | ||
import org.eclipse.sw360.datahandler.thrift.PaginationData; | ||
import org.eclipse.sw360.datahandler.thrift.RequestStatus; | ||
import org.eclipse.sw360.datahandler.thrift.Visibility; | ||
import org.eclipse.sw360.datahandler.thrift.components.ComponentType; | ||
import org.eclipse.sw360.datahandler.thrift.components.ECCStatus; | ||
|
@@ -52,8 +53,10 @@ | |
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyBoolean; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel; | ||
import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; | ||
|
@@ -62,6 +65,7 @@ | |
import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath; | ||
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.delete; | ||
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; | ||
|
@@ -84,6 +88,9 @@ public class ModerationRequestSpecTest extends TestRestDocsSpecBase { | |
@MockBean | ||
private Sw360ModerationRequestService moderationRequestServiceMock; | ||
|
||
@MockBean | ||
private ModerationRequest moderationRequest; | ||
|
||
@Before | ||
public void before() throws TException, IOException { | ||
Set<String> moderatorList = new HashSet<>(); | ||
|
@@ -129,7 +136,7 @@ public void before() throws TException, IOException { | |
project2Deletions.setProjectType(ProjectType.CUSTOMER); | ||
project2Deletions.setVisbility(Visibility.BUISNESSUNIT_AND_MODERATORS); | ||
|
||
ModerationRequest moderationRequest = new ModerationRequest(); | ||
moderationRequest = new ModerationRequest(); | ||
moderationRequest.setId("MR-101"); | ||
moderationRequest.setTimestamp(System.currentTimeMillis() / 1000L - 172800); | ||
moderationRequest.setDocumentId("R-101"); | ||
|
@@ -494,4 +501,33 @@ public void should_document_get_moderationrequests_submission() throws Exception | |
subsectionWithPath("_links").description("<<resources-index-links,Links>> to other resources") | ||
))); | ||
} | ||
|
||
@Test | ||
public void should_document_get_moderationrequests_delete() throws Exception { | ||
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword); | ||
User sw360User = new User(); | ||
sw360User.setEmail("[email protected]"); | ||
ModerationRequest moderationRequest1 = new ModerationRequest(); | ||
moderationRequest1.setRequestingUser("[email protected]"); | ||
when(moderationRequestServiceMock.getModerationRequestById("id1")).thenReturn(moderationRequest1); | ||
when(moderationRequestServiceMock.deleteModerationRequestInfo(any(User.class), anyString(), | ||
any(ModerationRequest.class), any(ModerationState.class))); | ||
if (testUserId != "[email protected]") { | ||
mockMvc.perform(delete("/api/moderationrequest/delete/") | ||
.content("[\"id1\", \"id2\"]") | ||
.header("Authorization", "Bearer " + accessToken) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.accept(MediaTypes.HAL_JSON)) | ||
.andExpect(status() | ||
.isInternalServerError()); | ||
} else { | ||
mockMvc.perform(delete("/api/moderationrequest/delete/") | ||
.content("[\"id1\", \"id2\"]") | ||
.header("Authorization", "Bearer " + accessToken) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.accept(MediaTypes.HAL_JSON)) | ||
.andExpect(status() | ||
.isOk()); | ||
} | ||
} | ||
} |