-
Notifications
You must be signed in to change notification settings - Fork 7
Load gameboard question limit from config #718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5a0cf32
Load gameboard question limit from config
mwtrew 0868b5e
Restore default generated gameboard size
mwtrew f4cd894
Merge branch 'main' of github.com:isaacphysics/isaac-api into improve…
mwtrew 02c48b4
Add tests for gameboard question limit
mwtrew c099b8d
Merge branch 'main' of github.com:isaacphysics/isaac-api into improve…
mwtrew 7a6a9b9
Use default gameboard size as limit if config property absent
mwtrew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
src/test/java/uk/ac/cam/cl/dtg/isaac/api/CookieJarFilter.java
This file contains hidden or 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,33 @@ | ||
package uk.ac.cam.cl.dtg.isaac.api; | ||
|
||
import jakarta.ws.rs.client.ClientRequestContext; | ||
import jakarta.ws.rs.client.ClientRequestFilter; | ||
import jakarta.ws.rs.client.ClientResponseContext; | ||
import jakarta.ws.rs.client.ClientResponseFilter; | ||
import jakarta.ws.rs.core.HttpHeaders; | ||
import jakarta.ws.rs.core.NewCookie; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.stream.Collectors; | ||
|
||
/* | ||
* JAX-RS Client filter for storing and retrieving cookies across requests. | ||
*/ | ||
public class CookieJarFilter implements ClientRequestFilter, ClientResponseFilter { | ||
private final Map<String, NewCookie> cookieJar = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public void filter(final ClientRequestContext requestContext) { | ||
if (!cookieJar.isEmpty()) { | ||
String header = cookieJar.values().stream() | ||
.map(c -> c.getName() + "=" + c.getValue()) | ||
.collect(Collectors.joining("; ")); | ||
requestContext.getHeaders().putSingle(HttpHeaders.COOKIE, header); | ||
} | ||
} | ||
|
||
@Override | ||
public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) { | ||
responseContext.getCookies().values().forEach(c -> cookieJar.put(c.getName(), c)); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
src/test/java/uk/ac/cam/cl/dtg/isaac/api/GameboardsFacadeIT.java
This file contains hidden or 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,94 @@ | ||
package uk.ac.cam.cl.dtg.isaac.api; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import uk.ac.cam.cl.dtg.isaac.dto.GameFilter; | ||
import uk.ac.cam.cl.dtg.isaac.dto.GameboardDTO; | ||
import uk.ac.cam.cl.dtg.isaac.dto.GameboardItem; | ||
import uk.ac.cam.cl.dtg.segue.api.AuthenticationFacade; | ||
|
||
import jakarta.ws.rs.core.Response; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static uk.ac.cam.cl.dtg.isaac.api.ITConstants.ASSIGNMENT_TEST_PAGE_ID; | ||
|
||
public class GameboardsFacadeIT extends IsaacIntegrationTestWithREST { | ||
TestServer subject() throws Exception { | ||
return startServer( | ||
new AuthenticationFacade(properties, userAccountManager, logManager, misuseMonitor), | ||
new GameboardsFacade(properties, logManager, gameManager, questionManager, userAccountManager, | ||
fastTrackManger) | ||
); | ||
} | ||
|
||
@Test | ||
public void saveNewGameboard_validGameboard_isAccepted() throws Exception { | ||
// Arrange | ||
GameboardDTO gameboardDTO = new GameboardDTO(); | ||
gameboardDTO.setTitle("Test Gameboard"); | ||
|
||
// Create gameboard | ||
GameFilter gameFilter = new GameFilter(); | ||
List<String> subjects = new ArrayList<>(); | ||
subjects.add("physics"); | ||
gameFilter.setSubjects(subjects); | ||
gameboardDTO.setGameFilter(gameFilter); | ||
|
||
// Add 30 questions | ||
List<GameboardItem> questions = new ArrayList<>(); | ||
for (int i = 0; i < 30; i++) { | ||
GameboardItem item = new GameboardItem(); | ||
item.setId(ASSIGNMENT_TEST_PAGE_ID); | ||
item.setTitle(ASSIGNMENT_TEST_PAGE_ID); | ||
questions.add(item); | ||
} | ||
gameboardDTO.setContents(questions); | ||
|
||
TestClient client = subject().client(); | ||
|
||
// Log in as student | ||
client.loginAs(integrationTestUsers.TEST_STUDENT); | ||
|
||
// Act | ||
TestResponse r = client.post("/gameboards", gameboardDTO); | ||
|
||
// Assert | ||
assertEquals(200, r.response.getStatus()); | ||
} | ||
|
||
@Test | ||
public void saveNewGameboard_tooManyQuestions_isRejected() throws Exception { | ||
// Arrange | ||
GameboardDTO gameboardDTO = new GameboardDTO(); | ||
gameboardDTO.setTitle("Test Gameboard"); | ||
|
||
// Create an otherwise valid gameboard | ||
GameFilter gameFilter = new GameFilter(); | ||
List<String> subjects = new ArrayList<>(); | ||
subjects.add("physics"); | ||
gameFilter.setSubjects(subjects); | ||
gameboardDTO.setGameFilter(gameFilter); | ||
|
||
// Add over 30 questions | ||
List<GameboardItem> questions = new ArrayList<>(); | ||
for (int i = 0; i < 31; i++) { | ||
GameboardItem item = new GameboardItem(); | ||
item.setId(ASSIGNMENT_TEST_PAGE_ID); | ||
item.setTitle(ASSIGNMENT_TEST_PAGE_ID); | ||
questions.add(item); | ||
} | ||
gameboardDTO.setContents(questions); | ||
mwtrew marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
TestClient client = subject().client(); | ||
|
||
// Log in as student | ||
client.loginAs(integrationTestUsers.TEST_STUDENT); | ||
|
||
// Act | ||
TestResponse r = client.post("/gameboards", gameboardDTO); | ||
|
||
// Assert | ||
r.assertError("The gameboard you provided is invalid", Response.Status.BAD_REQUEST); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.