TimestampResource { @GET @Produces(MEDIA_TYPE) @Operation(summary = "Find a range of timestamps") @ApiResponse(responseCode = "200", description = "Response contains the timestamp satisfying the applied filters.", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Timestamp.class)))) @ApiResponse(responseCode = "400", description = "Invalid query parameters") @Parameters({ @Parameter(in = ParameterIn.QUERY, name = "page[size]", description = "Controls the size, i.e., amount of entities, of each page."), @Parameter(in = ParameterIn.QUERY, name = "page[number]", description = "Index of the page to return."), @Parameter(in = ParameterIn.QUERY, name = "filter[type]", description = "Response only contains the given type ({landscape, replay})."), @Parameter(in = ParameterIn.QUERY, name = "filter[from]", description = "Lower bound for the timestamp to return."), @Parameter(in = ParameterIn.QUERY, name = "filter[to]", description = "Upper bound for the timestamp to return.")}) public QueryResult<Timestamp> getTimestamps(@Context final UriInfo uriInfo) { final Query<Timestamp> q = Query.fromParameterMap(uriInfo.getQueryParameters(true)); try { return this.timestampRepo.query(q); } catch (final QueryException e) { throw new BadRequestException(e); } } @Inject  TimestampResource(final TimestampRepository timestampRepo); @GET @Produces(MEDIA_TYPE) @Operation(summary = "Find a range of timestamps") @ApiResponse(responseCode = "200", description = "Response contains the timestamp satisfying the applied filters.", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Timestamp.class)))) @ApiResponse(responseCode = "400", description = "Invalid query parameters") @Parameters({ @Parameter(in = ParameterIn.QUERY, name = "page[size]", description = "Controls the size, i.e., amount of entities, of each page."), @Parameter(in = ParameterIn.QUERY, name = "page[number]", description = "Index of the page to return."), @Parameter(in = ParameterIn.QUERY, name = "filter[type]", description = "Response only contains the given type ({landscape, replay})."), @Parameter(in = ParameterIn.QUERY, name = "filter[from]", description = "Lower bound for the timestamp to return."), @Parameter(in = ParameterIn.QUERY, name = "filter[to]", description = "Upper bound for the timestamp to return.")}) QueryResult<Timestamp> getTimestamps(@Context final UriInfo uriInfo);  }
@Test @DisplayName("Return all service-generated timestamps.") public void giveAllServiceGenerated() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("filter[type]", "landscape"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); assertEquals(this.reverse(this.serviceGeneratedTimestamps), this.timestampResource.getTimestamps(ui).getData(), "No params returned wrong value for timestamp resource."); }
@Test @DisplayName("Return all user-uploaded timestamps.") public void giveAllUserUploadedOnlyFlag() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("filter[type]", "replay"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); assertEquals(this.reverse(this.userUploadedTimestamps), this.timestampResource.getTimestamps(ui).getData(), "User-uploaded flag returned wrong value for timestamp resource."); }
@Test @DisplayName("Return first two service-generated timestamps.") public void giveServiceGeneratedBasedOnMaxLength() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("page[number]", "2"); params.add("page[size]", "2"); params.add("filter[type]", "landscape"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); final List<Timestamp> resultList = (List<Timestamp>) this.timestampResource.getTimestamps(ui).getData(); final List<Timestamp> expectedList = new ArrayList<>(); expectedList.add(new Timestamp("1", 1556302800L, 300)); expectedList.add(new Timestamp("2", 1556302810L, 400)); assertEquals(this.reverse(expectedList), resultList, "MaxLength returned wrong value."); }
@Test @DisplayName("Return first two user-uploaded timestamps.") public void giveUserUploadedOnlyFlagBasedOnMaxLength() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("page[number]", "2"); params.add("page[size]", "2"); params.add("filter[type]", "replay"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); final List<Timestamp> resultList = (List<Timestamp>) this.timestampResource.getTimestamps(ui).getData(); final List<Timestamp> expectedList = new ArrayList<>(); expectedList.add(new Timestamp("7", 1556302860L, 600)); expectedList.add(new Timestamp("8", 1556302870L, 700)); assertEquals(this.reverse(expectedList), resultList, "User-uploaded flag and maxLength returned wrong value."); }
@Test @DisplayName("Return all service-generated timestamps, which come after the passed one.") public void giveAllServiceTimestampsAfterPassedTimestamp() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("filter[from]", "1556302820"); params.add("filter[type]", "landscape"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); final List<Timestamp> resultList = (List<Timestamp>) this.timestampResource.getTimestamps(ui).getData(); final List<Timestamp> expectedList = new ArrayList<>(); expectedList.add(new Timestamp("3", 1556302820L, 500)); expectedList.add(new Timestamp("4", 1556302830L, 600)); expectedList.add(new Timestamp("5", 1556302840L, 700)); expectedList.add(new Timestamp("6", 1556302850L, 800)); assertEquals(this.reverse(expectedList), resultList, "Invalid return value for filtered service-generated timestamps."); }
@Test @DisplayName("Return all user-uploaded timestamps, which come after the passed one.") public void giveAllUserUploadedAllParams() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("filter[from]", "1556302880"); params.add("filter[type]", "replay"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); final List<Timestamp> resultList = (List<Timestamp>) this.timestampResource.getTimestamps(ui).getData(); final List<Timestamp> expectedList = new ArrayList<>(); expectedList.add(new Timestamp("9", 1556302880L, 800)); expectedList.add(new Timestamp("10", 1556302890L, 900)); expectedList.add(new Timestamp("11", 1556302900L, 1000)); expectedList.add(new Timestamp("12", 1556302910L, 1100)); assertEquals(this.reverse(expectedList), resultList, "Invalid return value for filtered user-uploaded timestamps."); }
@Test @DisplayName("Return concrete interval of user-uploaded timestamps.") public void giveConcreteIntervalOfUserUploadedTimestamps() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("filter[from]", "1556302880"); params.add("filter[to]", "1556302900"); params.add("filter[type]", "replay"); params.add("page[size]", "3"); params.add("page[number]", "0"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); final List<Timestamp> resultList = (List<Timestamp>) this.timestampResource.getTimestamps(ui).getData(); final List<Timestamp> expectedList = new ArrayList<>(); expectedList.add(new Timestamp("9", 1556302880L, 800)); expectedList.add(new Timestamp("10", 1556302890L, 900)); expectedList.add(new Timestamp("11", 1556302900L, 1000)); assertEquals(this.reverse(expectedList), resultList, "Invalid return value for concrete interval of user-uploaded timestamps."); }
@Test @DisplayName("Return remaining interval of user-uploaded timestamps.") public void giveRemainingIntervalOfUserUploadedTimestamps() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("filter[from]", "1556302880"); params.add("filter[type]", "replay"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); final List<Timestamp> resultList = (List<Timestamp>) this.timestampResource.getTimestamps(ui).getData(); final List<Timestamp> expectedList = new ArrayList<>(); expectedList.add(new Timestamp("9", 1556302880L, 800)); expectedList.add(new Timestamp("10", 1556302890L, 900)); expectedList.add(new Timestamp("11", 1556302900L, 1000)); expectedList.add(new Timestamp("12", 1556302910L, 1100)); assertEquals(this.reverse(expectedList), resultList, "Invalid return value for remaining interval of user-uploaded timestamps."); }
@Test @DisplayName("Return concrete interval of service-generated timestamps.") public void giveConcreteIntervalOfServiceGeneratedTimestamps() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("filter[from]", "1556302810"); params.add("filter[type]", "landscape"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); final List<Timestamp> resultList = (List<Timestamp>) this.timestampResource.getTimestamps(ui).getData(); final List<Timestamp> expectedList = new ArrayList<>(); expectedList.add(new Timestamp("2", 1556302810L, 400)); expectedList.add(new Timestamp("3", 1556302820L, 500)); expectedList.add(new Timestamp("4", 1556302830L, 600)); expectedList.add(new Timestamp("5", 1556302840L, 700)); expectedList.add(new Timestamp("6", 1556302850L, 800)); assertEquals(this.reverse(expectedList), resultList, "Invalid return value for concrete interval of service-generated timestamps."); }
@Test @DisplayName("Return remaining interval of service-generated timestamps.") public void giveRemainingIntervalOfServiceGeneratedTimestamps() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("filter[from]", "1556302809"); params.add("filter[type]", "landscape"); params.add("page[number]", "0"); params.add("page[size]", "5"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); final List<Timestamp> resultList = (List<Timestamp>) this.timestampResource.getTimestamps(ui).getData(); final List<Timestamp> expectedList = new ArrayList<>(); expectedList.add(new Timestamp("2", 1556302810L, 400)); expectedList.add(new Timestamp("3", 1556302820L, 500)); expectedList.add(new Timestamp("4", 1556302830L, 600)); expectedList.add(new Timestamp("5", 1556302840L, 700)); expectedList.add(new Timestamp("6", 1556302850L, 800)); assertEquals(this.reverse(expectedList), resultList, "Invalid return value for remaining interval of service-generated timestamps."); }
@Test @DisplayName("Return interval of user-uploaded timestamps starting at newest, when no timestamp was passed.") public void giveMaxLengthIntervalOfUserPloadedTimestamps() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("filter[type]", "replay"); params.add("page[number]", "0"); params.add("page[size]", "2"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); final List<Timestamp> resultList = (List<Timestamp>) this.timestampResource.getTimestamps(ui).getData(); final List<Timestamp> expectedList = new ArrayList<>(); expectedList.add(new Timestamp("11", 1556302900L, 1000)); expectedList.add(new Timestamp("12", 1556302910L, 1100)); assertEquals(this.reverse(expectedList), resultList, "Invalid return value for interval of user-uploaded timestamps."); }
@Test @DisplayName("Return interval of service-generated timestamps starting at newest, when no timestamp was passed.") public void giveMaxLengthIntervalOfServiceGeneratedTimestamps() { final MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>(); params.add("filter[type]", "landscape"); params.add("page[number]", "0"); params.add("page[size]", "2"); final UriInfo ui = Mockito.mock(UriInfo.class); when(ui.getQueryParameters(true)).thenReturn(params); final List<Timestamp> resultList = (List<Timestamp>) this.timestampResource.getTimestamps(ui).getData(); final List<Timestamp> expectedList = new ArrayList<>(); expectedList.add(new Timestamp("6", 1556302850L, 800)); expectedList.add(new Timestamp("5", 1556302840L, 700)); assertEquals(expectedList, resultList, "Invalid return value for interval of service-generated timestamps."); }