WidgetResource extends AssetResource<Widget> { @RequestMapping(value = "/{widgetId}", method = RequestMethod.DELETE) public void delete(@PathVariable("widgetId") String widgetId) throws RepositoryException, NotFoundException, NotAllowedException { Widget widget = widgetRepository.get(widgetId); if (!widget.isCustom()) { throw new NotAllowedException("We can only delete a custom widget"); } fillWithUsedBy(widget); if (widget.isUsed()) { throw new InUseException(buildErrorMessage(widget)); } widgetRepository.delete(widgetId); } @Inject  WidgetResource(JacksonObjectMapper objectMapper,
                          WidgetRepository widgetRepository,
                          WidgetService widgetService,
                          AssetService<Widget> widgetAssetService,
                          @Named("widgetPath") Path widgetPath,
                          List<WidgetContainerRepository> widgetContainerRepositories,
                          AssetVisitor assetVisitor); @RequestMapping(method = RequestMethod.GET) ResponseEntity<String> getAll(@RequestParam(value = "view", defaultValue = "full") String view); @RequestMapping(value = "/{widgetId}", method = RequestMethod.GET) Widget get(@PathVariable("widgetId") String widgetId); @RequestMapping(method = RequestMethod.POST) Widget create(@RequestBody Widget widget, @RequestParam(value = "duplicata", required = false) String sourceWidgetId); @RequestMapping(value = "/{widgetId}", method = RequestMethod.PUT) void save(@PathVariable("widgetId") String widgetId, @RequestBody Widget widget); @RequestMapping(value = "/{widgetId}", method = RequestMethod.DELETE) void delete(@PathVariable("widgetId") String widgetId); @RequestMapping(value = "/{widgetId}/properties", method = RequestMethod.POST) List<Property> addProperty(@PathVariable("widgetId") String widgetId, @RequestBody Property property); @RequestMapping(value = "/{widgetId}/properties/{propertyName}", method = RequestMethod.PUT) List<Property> updateProperty(@PathVariable("widgetId") String widgetId, @PathVariable("propertyName") String propertyName, @RequestBody Property property); @RequestMapping(value = "/{widgetId}/properties/{propertyName}", method = RequestMethod.DELETE) List<Property> deleteProperty(@PathVariable("widgetId") String widgetId, @PathVariable("propertyName") String propertyName); @RequestMapping(value = "/{widgetId}/favorite", method = RequestMethod.PUT) void favorite(@PathVariable("widgetId") String pageId, @RequestBody Boolean favorite); @RequestMapping(value = "/{widgetId}/help", method = RequestMethod.GET, produces = "text/html; charset=UTF-8") void serveWidgetFiles(HttpServletRequest request, HttpServletResponse response, @PathVariable("widgetId") String widgetId);  }
@Test public void should_not_allow_to_delete_a_property_of_a_pb_widget() throws Exception { mockMvc.perform(delete("/rest/widgets/pbLabel/properties/toBeDeleted") .contentType(MediaType.APPLICATION_JSON_VALUE) .content(convertObjectToJsonBytes(aProperty().build()))) .andExpect(status().isForbidden()) .andExpect(jsonPath("message").value("Not allowed to modify a non custom widgets")); }