@Test public void should_add_trust_anchor() throws Exception { ResultActions result = mvc.perform( post("/api/trust-anchors") .accept(ValidatorApi.API_MIME_TYPE) .contentType(ValidatorApi.API_MIME_TYPE) .content(objectMapper.writeValueAsString(ApiCommand.of(AddTrustAnchor.builder() .type(TrustAnchor.TYPE) .name(TEST_CA_NAME) .locations(Arrays.asList("rsync: .subjectPublicKeyInfo("jdfakljkldf;adsfjkdsfkl;nasdjfnsldajfklsd;ajfk;ljdsakjfkla;sdhfkjdshfkljadsl;kjfdklfjdaksl;jdfkl;jafkldjsfkl;adjsfkl;adjsf;lkjkl;dj;adskjfdljadjbkfbkjblafkjdfbasfjlka") .build() ))) ); result .andExpect(status().isCreated()) .andExpect(content().contentType(ValidatorApi.API_MIME_TYPE)); ApiResponse<TrustAnchorResource> response = addTrustAnchorResponse(result); assertThat(response.getData()).isNotNull(); TrustAnchorResource resource = response.getData(); Link selfRel = resource.getLinks().getLink("self"); mvc.perform( get(selfRel.getHref()) .accept(ValidatorApi.API_MIME_TYPE) ) .andExpect(status().isOk()) .andExpect(content().contentType(ValidatorApi.API_MIME_TYPE)) .andExpect(jsonPath("$.data.name").value(TEST_CA_NAME)); }
@ApiOperation("Get a trust anchor by (numeric) identifier") @GetMapping(path = "/{id}") public ResponseEntity<ApiResponse<TrustAnchorResource>> get(@PathVariable long id, Locale locale) { return storage.readTx(tx -> trustAnchors.get(tx, Key.of(id)) .map(ta -> ResponseEntity.ok(trustAnchorResource(tx, ta, locale))) .orElse(ResponseEntity.notFound().build())); }
TrustAnchorController { @ApiOperation("Get a trust anchor by (numeric) identifier") @GetMapping(path = "/{id}") public ResponseEntity<ApiResponse<TrustAnchorResource>> get(@PathVariable long id, Locale locale) { return storage.readTx(tx -> trustAnchors.get(tx, Key.of(id)) .map(ta -> ResponseEntity.ok(trustAnchorResource(tx, ta, locale))) .orElse(ResponseEntity.notFound().build())); } }
TrustAnchorController { @ApiOperation("Get a trust anchor by (numeric) identifier") @GetMapping(path = "/{id}") public ResponseEntity<ApiResponse<TrustAnchorResource>> get(@PathVariable long id, Locale locale) { return storage.readTx(tx -> trustAnchors.get(tx, Key.of(id)) .map(ta -> ResponseEntity.ok(trustAnchorResource(tx, ta, locale))) .orElse(ResponseEntity.notFound().build())); }  }
TrustAnchorController { @ApiOperation("Get a trust anchor by (numeric) identifier") @GetMapping(path = "/{id}") public ResponseEntity<ApiResponse<TrustAnchorResource>> get(@PathVariable long id, Locale locale) { return storage.readTx(tx -> trustAnchors.get(tx, Key.of(id)) .map(ta -> ResponseEntity.ok(trustAnchorResource(tx, ta, locale))) .orElse(ResponseEntity.notFound().build())); }  @ApiOperation("List the configured Trust Anchors") @GetMapping ResponseEntity<ApiResponse<List<TrustAnchorResource>>> list(Locale locale); @ApiOperation("Add a Trust Anchor using a JSON payload") @PostMapping(consumes = { ValidatorApi.API_MIME_TYPE, "application/json" }) ResponseEntity<ApiResponse<TrustAnchorResource>> add(@RequestBody @Valid ApiCommand<AddTrustAnchor> command, Locale locale); @ApiOperation("Add a Trust Anchor from a file") @PostMapping(path = "/upload", consumes = "multipart/form-data") ResponseEntity<ApiResponse<TrustAnchorResource>> add(@RequestParam("file") MultipartFile trustAnchorLocator, Locale locale); @ApiOperation("Get a trust anchor by (numeric) identifier") @GetMapping(path = "/{id}") ResponseEntity<ApiResponse<TrustAnchorResource>> get(@PathVariable long id, Locale locale); @GetMapping(path = "/{id}/validation-run") ResponseEntity<ApiResponse<ValidationRunResource>> validationResults(@PathVariable long id, HttpServletResponse response, Locale locale); @ApiOperation("Get validation issues") @GetMapping(path = "/{id}/validation-checks") ResponseEntity<ApiResponse<Stream<ValidationCheckResource>>> validationChecks(
        @PathVariable long id,
        @RequestParam(name = "startFrom", defaultValue = "0") long startFrom,
        @RequestParam(name = "pageSize", defaultValue = "20") long pageSize,
        @RequestParam(name = "search", required = false) String searchString,
        @ApiParam(allowableValues = SORT_BY_ALLOWABLE_VALUES)
        @RequestParam(name = "sortBy", defaultValue = "location") String sortBy,
        @ApiParam(allowableValues = SORT_DIRECTION_ALLOWABLE_VALUES)
        @RequestParam(name = "sortDirection", defaultValue = "asc") String sortDirection,
        Locale locale
    ); @ApiOperation("Get the statuses of all configured trust anchors") @GetMapping(path = "/statuses") ApiResponse<List<TaStatus>> statuses(); @ApiOperation("Delete a trust anchor by id") @DeleteMapping(path = "/{id}") ResponseEntity<?> delete(@PathVariable long id); }
TrustAnchorController { @ApiOperation("Get a trust anchor by (numeric) identifier") @GetMapping(path = "/{id}") public ResponseEntity<ApiResponse<TrustAnchorResource>> get(@PathVariable long id, Locale locale) { return storage.readTx(tx -> trustAnchors.get(tx, Key.of(id)) .map(ta -> ResponseEntity.ok(trustAnchorResource(tx, ta, locale))) .orElse(ResponseEntity.notFound().build())); }  @ApiOperation("List the configured Trust Anchors") @GetMapping ResponseEntity<ApiResponse<List<TrustAnchorResource>>> list(Locale locale); @ApiOperation("Add a Trust Anchor using a JSON payload") @PostMapping(consumes = { ValidatorApi.API_MIME_TYPE, "application/json" }) ResponseEntity<ApiResponse<TrustAnchorResource>> add(@RequestBody @Valid ApiCommand<AddTrustAnchor> command, Locale locale); @ApiOperation("Add a Trust Anchor from a file") @PostMapping(path = "/upload", consumes = "multipart/form-data") ResponseEntity<ApiResponse<TrustAnchorResource>> add(@RequestParam("file") MultipartFile trustAnchorLocator, Locale locale); @ApiOperation("Get a trust anchor by (numeric) identifier") @GetMapping(path = "/{id}") ResponseEntity<ApiResponse<TrustAnchorResource>> get(@PathVariable long id, Locale locale); @GetMapping(path = "/{id}/validation-run") ResponseEntity<ApiResponse<ValidationRunResource>> validationResults(@PathVariable long id, HttpServletResponse response, Locale locale); @ApiOperation("Get validation issues") @GetMapping(path = "/{id}/validation-checks") ResponseEntity<ApiResponse<Stream<ValidationCheckResource>>> validationChecks(
        @PathVariable long id,
        @RequestParam(name = "startFrom", defaultValue = "0") long startFrom,
        @RequestParam(name = "pageSize", defaultValue = "20") long pageSize,
        @RequestParam(name = "search", required = false) String searchString,
        @ApiParam(allowableValues = SORT_BY_ALLOWABLE_VALUES)
        @RequestParam(name = "sortBy", defaultValue = "location") String sortBy,
        @ApiParam(allowableValues = SORT_DIRECTION_ALLOWABLE_VALUES)
        @RequestParam(name = "sortDirection", defaultValue = "asc") String sortDirection,
        Locale locale
    ); @ApiOperation("Get the statuses of all configured trust anchors") @GetMapping(path = "/statuses") ApiResponse<List<TaStatus>> statuses(); @ApiOperation("Delete a trust anchor by id") @DeleteMapping(path = "/{id}") ResponseEntity<?> delete(@PathVariable long id);  }