-
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.
- Loading branch information
Showing
12 changed files
with
382 additions
and
29 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
102 changes: 102 additions & 0 deletions
102
src/test/java/git/tracehub/pmo/controller/ProjectControllerTest.java
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to read | ||
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify, | ||
* merge, publish, distribute, sublicense, and/or sell copies of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package git.tracehub.pmo.controller; | ||
|
||
import git.tracehub.pmo.project.Projects; | ||
import io.github.eocqrs.eokson.Jocument; | ||
import io.github.eocqrs.eokson.JsonOf; | ||
import org.cactoos.io.ResourceOf; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; | ||
|
||
/** | ||
* Test suite for {@link ProjectController}. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
@ActiveProfiles("web") | ||
@ExtendWith(SpringExtension.class) | ||
@WebMvcTest(controllers = ProjectController.class) | ||
final class ProjectControllerTest { | ||
|
||
/** | ||
* Mocked mvc. | ||
*/ | ||
@Autowired | ||
private MockMvc mvc; | ||
|
||
/** | ||
* Projects. | ||
*/ | ||
@MockBean | ||
@SuppressWarnings("PMD.UnusedPrivateField") | ||
private Projects projects; | ||
|
||
@Test | ||
void returnsForbiddenOnUnauthorizedUser() throws Exception { | ||
this.mvc.perform( | ||
MockMvcRequestBuilders.post("/") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
).andExpect(MockMvcResultMatchers.status().isForbidden()); | ||
} | ||
|
||
@Test | ||
void returnsProjectByUser() throws Exception { | ||
this.mvc.perform( | ||
MockMvcRequestBuilders.get("/") | ||
.with(SecurityMockMvcRequestPostProcessors.jwt()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
).andExpect(MockMvcResultMatchers.status().isOk()); | ||
} | ||
|
||
@Test | ||
void returnsProjectById() throws Exception { | ||
this.mvc.perform( | ||
MockMvcRequestBuilders.get("/74bb5ec8-0e6b-4618-bfa4-a0b76b7b312d") | ||
.with(SecurityMockMvcRequestPostProcessors.jwt()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
).andExpect(MockMvcResultMatchers.status().isOk()); | ||
} | ||
|
||
@Test | ||
void createsNewProject() throws Exception { | ||
this.mvc.perform( | ||
MockMvcRequestBuilders.post("/") | ||
.with(SecurityMockMvcRequestPostProcessors.jwt()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content( | ||
new Jocument( | ||
new JsonOf( | ||
new ResourceOf("data/project.json").stream() | ||
) | ||
).toString() | ||
) | ||
).andExpect(MockMvcResultMatchers.status().isCreated()); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/test/java/git/tracehub/pmo/controller/package-info.java
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to read | ||
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify, | ||
* merge, publish, distribute, sublicense, and/or sell copies of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* Controllers Tests. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
package git.tracehub.pmo.controller; |
62 changes: 62 additions & 0 deletions
62
src/test/java/git/tracehub/pmo/platforms/github/InviteCollaboratorTest.java
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to read | ||
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify, | ||
* merge, publish, distribute, sublicense, and/or sell copies of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package git.tracehub.pmo.platforms.github; | ||
|
||
import com.jcabi.github.Repo; | ||
import com.jcabi.github.Repos; | ||
import com.jcabi.github.mock.MkGithub; | ||
import java.io.IOException; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.core.IsEqual; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test suite for {@link InviteCollaborator}. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
final class InviteCollaboratorTest { | ||
|
||
@Test | ||
void invitesCollaboratorSuccessfully() throws IOException { | ||
final String collaborator = "name"; | ||
final MkGithub github = new MkGithub("user"); | ||
final Repo repo = github.repos().create( | ||
new Repos.RepoCreate("repo", false) | ||
); | ||
new InviteCollaborator("user/repo", collaborator, github).exec(); | ||
MatcherAssert.assertThat( | ||
"Collaborator %s isn't invited as expected" | ||
.formatted(collaborator), | ||
repo.collaborators().isCollaborator(collaborator), | ||
new IsEqual<>(true) | ||
); | ||
} | ||
|
||
@Test | ||
void trowsOnInvalidLocation() { | ||
Assertions.assertThrows( | ||
IllegalArgumentException.class, | ||
() -> new InviteCollaborator("user", "user", new MkGithub("user")) | ||
.exec(), | ||
"Exception is not thrown or valid" | ||
); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/test/java/git/tracehub/pmo/platforms/github/package-info.java
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Tracehub.git | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to read | ||
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify, | ||
* merge, publish, distribute, sublicense, and/or sell copies of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* Github Platform Tests. | ||
* | ||
* @since 0.0.0 | ||
*/ | ||
package git.tracehub.pmo.platforms.github; |
Oops, something went wrong.
748f413
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
1-ecd686dc
disappeared fromsrc/main/java/git/tracehub/pmo/security/IdpToken.java
), that's why I closed #17. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.