PageResource extends AssetResource<Page> { private Predicate<? super Component> withId(String id) { return component -> Objects.equals(id,component.getId()); } @Inject  PageResource(
            PageService pageService,
            PageRepository pageRepository,
            SimpMessagingTemplate messagingTemplate,
            ContractToPageMapper contractToPageMapper,
            AssetService<Page> pageAssetService,
            AssetVisitor assetVisitor,
            ComponentVisitor componentVisitor, AuthRulesCollector authRulesCollector); @RequestMapping(method = RequestMethod.GET) @JsonView(JsonViewLight.class) List<Page> list(); @RequestMapping(method = RequestMethod.POST) ResponseEntity<Page> create(@RequestBody Page page,
            @RequestParam(value = "duplicata", required = false) String sourcePageId); @RequestMapping(value = "/contract/{scope}/{name}", method = RequestMethod.POST) ResponseEntity<Page> create(@RequestBody Contract contract, @PathVariable("scope") String scope,
            @PathVariable("name") String name); @RequestMapping(value = "/{pageId}", method = RequestMethod.PUT) ResponseEntity<Void> save(HttpServletRequest request, @PathVariable("pageId") String pageId,
            @RequestBody Page page); @RequestMapping(value = "/{pageId}/name", method = RequestMethod.PUT) ResponseEntity<Void> rename(HttpServletRequest request, @PathVariable("pageId") String pageId,
            @RequestBody String name); @RequestMapping(value = "/{pageId}/favorite", method = RequestMethod.PUT) void favorite(@PathVariable("pageId") String pageId, @RequestBody Boolean favorite); @RequestMapping(value = "/{pageId}", method = RequestMethod.GET) MappingJacksonValue get(@PathVariable("pageId") String pageId); @RequestMapping(value = "/{pageId}", method = RequestMethod.DELETE) void delete(@PathVariable("pageId") String pageId); @RequestMapping(value = "/{pageId}/resources", method = RequestMethod.GET) List<String> getResources(@PathVariable("pageId") String pageId); static final String BONITA_RESOURCE_REGEX; static final String EXTENSION_RESOURCE_REGEX; }
@Test public void should_create_a_page_from_a_Page() throws Exception { Page pageToBeSaved = aPage().withId("my-page").build(); List<Element> emptyRow = Collections.emptyList(); List<List<Element>> rows = Collections.singletonList(emptyRow); pageToBeSaved.setRows(rows); pageToBeSaved.setName("test"); when(pageRepository.getNextAvailableId("test")).thenReturn("test"); mockMvc .perform(post("/rest/pages") .contentType(MediaType.APPLICATION_JSON_VALUE) .content(convertObjectToJsonBytes(pageToBeSaved))) .andExpect(status().isCreated()) .andExpect(jsonPath("$.id", notNullValue())); verify(pageRepository).updateLastUpdateAndSave(notNull(Page.class)); verify(pageAssetService).loadDefaultAssets(any(Page.class)); }
@Test public void should_respond_500_internal_error_if_error_occurs_while_saving_a_page() throws Exception { Page page = aPage().withId("my-page").build(); Mockito.doThrow(new RepositoryException("exception occurs", new Exception())).when(pageRepository).updateLastUpdateAndSave(page); mockMvc .perform( put("/rest/pages/my-page").contentType(MediaType.APPLICATION_JSON_VALUE).content( convertObjectToJsonBytes(page))) .andExpect(status().isInternalServerError()); }
@Test public void should_upload_a_local_asset() throws Exception { MockMultipartFile file = new MockMultipartFile("file", "myfile.js", "application/javascript", "foo".getBytes()); Page page = mockPageOfId("my-page"); Asset expectedAsset = anAsset().withId("assetId").active().withName("myfile.js").withOrder(2).withScope(PAGE) .withType(AssetType.JAVASCRIPT).build(); when(pageAssetService.upload(file, page, "js")).thenReturn(expectedAsset); mockMvc.perform(fileUpload("/rest/pages/my-page/assets/js").file(file)) .andExpect(status().isCreated()) .andExpect(jsonPath("$.id").value("assetId")) .andExpect(jsonPath("$.name").value("myfile.js")) .andExpect(jsonPath("$.scope").value(PAGE.toString())) .andExpect(jsonPath("$.type").value("js")) .andExpect(jsonPath("$.order").value(2)); verify(pageAssetService).upload(file, page, "js"); }