Skip to content
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

Validate timestamp parameters in sample xapi-server #191

Merged
merged 4 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* /* Copyright 2016-2023 Berry Cloud Ltd. All rights reserved.
*/

package dev.learning.xapi.samples.xapiserver;

import dev.learning.xapi.jackson.model.strict.XapiTimestamp;
import java.time.Instant;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
* <p>
* InstantConverter class.
* </p>
*
* @author István Rátkai (Selindek)
* @author Thomas Turrell-Croft
*/
@Component
public class InstantConverter implements Converter<String, Instant> {

/**
* Converts string to {@link java.time.Instant}. If the timezone is not specified in string, UTC
* will be used.
*
* @param source the String representation of the datetime in ISO 8601 format (e.q.
* '2011-12-03T10:15:30+01:00')
*
* @return {@link java.time.Instant} of source input
*/
@Override
public Instant convert(String source) {

return XapiTimestamp.parse(source);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.learning.xapi.model.StatementResult;
import dev.learning.xapi.model.validation.constraints.Statements;
import jakarta.validation.Valid;
import java.time.Instant;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -80,7 +81,24 @@ public ResponseEntity<Statement> getStatement(@RequestParam(required = true) UUI
* "https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Communication.md#213-get-statements">GET
* Statements</a>
*/
@GetMapping(params = {"!statementId, !voidedStatementId"})
@GetMapping(params = "since")
public ResponseEntity<Void> getStatementsSince(@RequestParam Instant since) {

log.debug("GET statements since");

return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build();
}

/**
* Get Statements.
*
* @return the ResponseEntity
*
* @see <a href=
* "https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Communication.md#213-get-statements">GET
* Statements</a>
*/
@GetMapping(params = {"!statementId, !voidedStatementId", "!since"})
public ResponseEntity<StatementResult> getStatements() {

log.debug("GET statements");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package dev.learning.xapi.samples.xapiserver;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand Down Expand Up @@ -69,4 +70,26 @@ void whenPostingMultipleStatementsThenStatusIsOk() throws Exception {
.andExpect(status().isOk());
}

@Test
void whenGettingMultipleStatementsWithSinceParameterThenStatusIsNotImplemented()
throws Exception {

// When Getting Multiple Statements With Since Parameter
mvc.perform(get("/xapi/statements?since=2017-03-01T12:30:00.000+00"))

// Then Status Is Not Implemented
.andExpect(status().isNotImplemented());
}

@Test
void whenGettingMultipleStatementsWithNegativeTimezoneOffsetThenStatusIsBadRequest()
throws Exception {

// When Getting Multiple Statements With Negative Timezone Offset
mvc.perform(get("/xapi/statements?since=2017-03-01T12:30:00.000-00"))

// Then Status Is Bad Request
.andExpect(status().isBadRequest());
}

}