Commit 770b5e9a authored by abirembaut's avatar abirembaut Committed by benjaminParisel

feat(page metadata edition) Add popup to edit page metadata (#2498)

* Add fields displayName and description
* Display Resources in metadata popup
* add the ability to change the type between form and page

Covers [BS-18802](https://bonitasoft.atlassian.net/browse/BS-18802)
parent f536d9e5
......@@ -15,12 +15,15 @@
package org.bonitasoft.web.designer.controller;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.filterValues;
import static com.google.common.collect.Sets.filter;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import static org.bonitasoft.web.designer.config.WebSocketConfig.PREVIEWABLE_REMOVAL;
import static org.bonitasoft.web.designer.config.WebSocketConfig.PREVIEWABLE_UPDATE;
import static org.bonitasoft.web.designer.controller.ResponseHeadersHelper.getMovedResourceResponse;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
......@@ -31,16 +34,23 @@ import com.fasterxml.jackson.annotation.JsonView;
import com.google.common.base.Optional;
import org.bonitasoft.web.designer.controller.asset.AssetService;
import org.bonitasoft.web.designer.controller.asset.PageAssetPredicate;
import org.bonitasoft.web.designer.controller.export.properties.BonitaResourcePredicate;
import org.bonitasoft.web.designer.controller.export.properties.BonitaResourceTransformer;
import org.bonitasoft.web.designer.controller.export.properties.ConstantPropertyValuePredicate;
import org.bonitasoft.web.designer.controller.export.properties.PagePropertiesBuilder;
import org.bonitasoft.web.designer.experimental.mapping.ContractToPageMapper;
import org.bonitasoft.web.designer.experimental.mapping.FormScope;
import org.bonitasoft.web.designer.model.JsonViewLight;
import org.bonitasoft.web.designer.model.contract.Contract;
import org.bonitasoft.web.designer.model.page.Component;
import org.bonitasoft.web.designer.model.page.Page;
import org.bonitasoft.web.designer.repository.PageRepository;
import org.bonitasoft.web.designer.repository.exception.NotFoundException;
import org.bonitasoft.web.designer.repository.exception.RepositoryException;
import org.bonitasoft.web.designer.service.PageService;
import org.bonitasoft.web.designer.visitor.AssetVisitor;
import org.bonitasoft.web.designer.visitor.AuthRulesCollector;
import org.bonitasoft.web.designer.visitor.ComponentVisitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
......@@ -61,10 +71,13 @@ import org.springframework.web.bind.annotation.RestController;
public class PageResource extends AssetResource<Page> {
protected static final Logger logger = LoggerFactory.getLogger(PageResource.class);
public static final String BONITA_RESOURCE_REGEX = ".+/API/([^ /]*)/([^ /?]*)[/?]?[^/]*"; // matches ..... /API/{}/{}?...
private PageRepository pageRepository;
private SimpMessagingTemplate messagingTemplate;
private ContractToPageMapper contractToPageMapper;
private final PageService pageService;
private final ComponentVisitor componentVisitor;
private final AuthRulesCollector authRulesCollector;
@Inject
public PageResource(
......@@ -73,12 +86,15 @@ public class PageResource extends AssetResource<Page> {
SimpMessagingTemplate messagingTemplate,
ContractToPageMapper contractToPageMapper,
AssetService<Page> pageAssetService,
AssetVisitor assetVisitor) {
AssetVisitor assetVisitor,
ComponentVisitor componentVisitor, AuthRulesCollector authRulesCollector) {
super(pageAssetService, pageRepository, assetVisitor, Optional.of(messagingTemplate));
this.pageRepository = pageRepository;
this.messagingTemplate = messagingTemplate;
this.contractToPageMapper = contractToPageMapper;
this.pageService = pageService;
this.componentVisitor = componentVisitor;
this.authRulesCollector = authRulesCollector;
}
@Override
......@@ -205,4 +221,26 @@ public class PageResource extends AssetResource<Page> {
messagingTemplate.convertAndSend(PREVIEWABLE_REMOVAL, pageId);
}
@RequestMapping(value = "/{pageId}/resources", method = RequestMethod.GET)
public List<String> getResources(@PathVariable("pageId") String pageId){
Page page = pageService.get(pageId);
List<String> resources = newArrayList(transform(
filterValues(page.getData(), new BonitaResourcePredicate(BONITA_RESOURCE_REGEX)).values(),
new BonitaResourceTransformer(BONITA_RESOURCE_REGEX)));
Iterable<Component> components = componentVisitor.visit(page);
if (any(components, new ConstantPropertyValuePredicate("Start process"))) {
resources.add("POST|bpm/process");
}
if (any(components, new ConstantPropertyValuePredicate("Submit task"))) {
resources.add("POST|bpm/userTask");
}
resources.addAll(authRulesCollector.visit(page));
return resources;
}
}
......@@ -20,7 +20,7 @@ import static org.bonitasoft.web.designer.model.data.DataType.URL;
import com.google.common.base.Predicate;
import org.bonitasoft.web.designer.model.data.Data;
class BonitaResourcePredicate implements Predicate<Data> {
public class BonitaResourcePredicate implements Predicate<Data> {
private String bonitaResourceRegex;
......
......@@ -22,7 +22,7 @@ import java.util.regex.Matcher;
import com.google.common.base.Function;
import org.bonitasoft.web.designer.model.data.Data;
class BonitaResourceTransformer implements Function<Data, String> {
public class BonitaResourceTransformer implements Function<Data, String> {
private String bonitaResourceRegex;
......
......@@ -14,68 +14,41 @@
*/
package org.bonitasoft.web.designer.controller.export.properties;
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.filterValues;
import org.bonitasoft.web.designer.controller.PageResource;
import org.bonitasoft.web.designer.model.page.Page;
import org.bonitasoft.web.designer.rendering.GenerationException;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import org.bonitasoft.web.designer.model.page.Component;
import org.bonitasoft.web.designer.model.page.Page;
import org.bonitasoft.web.designer.rendering.GenerationException;
import org.bonitasoft.web.designer.rendering.TemplateEngine;
import org.bonitasoft.web.designer.visitor.AuthRulesCollector;
import org.bonitasoft.web.designer.visitor.ComponentVisitor;
import java.util.Properties;
@Named
public class PagePropertiesBuilder {
private static final String TEMPLATE_NAME = "page.hbs.properties";
private static final String BONITA_RESOURCE_REGEX = ".+/API/([^ /]*)/([^ /?]*)[/?]?[^/]*"; // matches ..... /API/{}/{}?...
private TemplateEngine template;
private ComponentVisitor componentVisitor;
private AuthRulesCollector authRulesCollector;
private final PageResource pageResource;
@Inject
public PagePropertiesBuilder(ComponentVisitor componentVisitor, AuthRulesCollector authRulesCollector) {
this.componentVisitor = componentVisitor;
this.authRulesCollector = authRulesCollector;
template = new TemplateEngine(TEMPLATE_NAME);
public PagePropertiesBuilder(PageResource pageResource) {
this.pageResource = pageResource;
}
public byte[] build(Page page) throws GenerationException, IOException {
List<String> resources = newArrayList(transform(
filterValues(page.getData(), new BonitaResourcePredicate(BONITA_RESOURCE_REGEX)).values(),
new BonitaResourceTransformer(BONITA_RESOURCE_REGEX)));
Iterable<Component> components = componentVisitor.visit(page);
if (any(components, new ConstantPropertyValuePredicate("Start process"))) {
resources.add("POST|bpm/process");
}
if (any(components, new ConstantPropertyValuePredicate("Submit task"))) {
resources.add("POST|bpm/userTask");
}
resources.addAll(authRulesCollector.visit(page));
Map<String, String> context = new HashMap<>();
context.put("name", page.getName());
context.put("resources", resources.toString());
context.put("type", String.valueOf(page.getType()).toLowerCase(Locale.ENGLISH));
// Java properties files must be encoded using ISO_8859_1
return template.build(context).getBytes(StandardCharsets.ISO_8859_1);
List<String> resources = pageResource.getResources(page.getId());
Properties properties = new Properties();
properties.put("name", "custompage_" + page.getName());
properties.put("contentType", String.valueOf(page.getType()).toLowerCase(Locale.ENGLISH));
properties.put("displayName", page.getDisplayName());
properties.put("description", page.getDescription());
properties.put("resources", resources.toString());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
properties.store(byteArrayOutputStream, "Generated by Bonita UI Designer version " + page.getDesignerVersion());
return byteArrayOutputStream.toByteArray();
}
}
......@@ -14,13 +14,29 @@
*/
package org.bonitasoft.web.designer.model.page;
import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;
import static org.bonitasoft.web.designer.model.asset.AssetType.CSS;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.validation.constraints.Pattern;
import com.fasterxml.jackson.annotation.JsonView;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.bonitasoft.web.designer.model.*;
import org.bonitasoft.web.designer.model.Assetable;
import org.bonitasoft.web.designer.model.DesignerArtifact;
import org.bonitasoft.web.designer.model.ElementContainer;
import org.bonitasoft.web.designer.model.Identifiable;
import org.bonitasoft.web.designer.model.JsonViewLight;
import org.bonitasoft.web.designer.model.JsonViewPersistence;
import org.bonitasoft.web.designer.model.asset.Asset;
import org.bonitasoft.web.designer.model.asset.AssetType;
import org.bonitasoft.web.designer.model.data.Data;
......@@ -29,12 +45,6 @@ import org.bonitasoft.web.designer.visitor.ElementVisitor;
import org.hibernate.validator.constraints.NotBlank;
import org.joda.time.Instant;
import javax.validation.constraints.Pattern;
import java.util.*;
import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;
import static org.bonitasoft.web.designer.model.asset.AssetType.CSS;
public abstract class AbstractPage extends DesignerArtifact implements Previewable, Identifiable, ElementContainer, Assetable {
private String id;
......@@ -47,7 +57,7 @@ public abstract class AbstractPage extends DesignerArtifact implements Previewab
private Set<String> inactiveAssets = new HashSet<>();
private Map<String, Data> data = new HashMap<>();
@JsonView({ JsonViewLight.class, JsonViewPersistence.class })
@JsonView({JsonViewLight.class, JsonViewPersistence.class})
public String getId() {
return id;
}
......@@ -56,7 +66,7 @@ public abstract class AbstractPage extends DesignerArtifact implements Previewab
this.id = id;
}
@JsonView({ JsonViewLight.class, JsonViewPersistence.class })
@JsonView({JsonViewLight.class, JsonViewPersistence.class})
public String getName() {
return name;
}
......@@ -65,7 +75,7 @@ public abstract class AbstractPage extends DesignerArtifact implements Previewab
this.name = name;
}
@JsonView({ JsonViewLight.class, JsonViewPersistence.class })
@JsonView({JsonViewLight.class, JsonViewPersistence.class})
public Instant getLastUpdate() {
return lastUpdate;
}
......@@ -74,7 +84,7 @@ public abstract class AbstractPage extends DesignerArtifact implements Previewab
this.lastUpdate = lastUpdate;
}
@JsonView({ JsonViewPersistence.class })
@JsonView({JsonViewPersistence.class})
@Override
public List<List<Element>> getRows() {
return rows;
......@@ -84,7 +94,7 @@ public abstract class AbstractPage extends DesignerArtifact implements Previewab
this.rows = rows;
}
@JsonView({ JsonViewPersistence.class })
@JsonView({JsonViewPersistence.class})
public Set<Asset> getAssets() {
return assets;
}
......@@ -109,7 +119,7 @@ public abstract class AbstractPage extends DesignerArtifact implements Previewab
this.assets = assets;
}
@JsonView({ JsonViewPersistence.class })
@JsonView({JsonViewPersistence.class})
public Set<String> getInactiveAssets() {
return inactiveAssets;
}
......@@ -127,7 +137,7 @@ public abstract class AbstractPage extends DesignerArtifact implements Previewab
});
}
@JsonView({ JsonViewPersistence.class })
@JsonView({JsonViewPersistence.class})
public Map<String, Data> getData() {
return data;
}
......
......@@ -14,39 +14,20 @@
*/
package org.bonitasoft.web.designer.model.page;
import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;
import static org.bonitasoft.web.designer.model.asset.AssetType.CSS;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.validation.constraints.Pattern;
import com.fasterxml.jackson.annotation.JsonView;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.bonitasoft.web.designer.model.*;
import org.bonitasoft.web.designer.model.asset.AssetType;
import org.bonitasoft.web.designer.model.data.Data;
import org.bonitasoft.web.designer.model.asset.Asset;
import org.bonitasoft.web.designer.repository.exception.NotFoundException;
import org.bonitasoft.web.designer.visitor.ElementVisitor;
import org.hibernate.validator.constraints.NotBlank;
import org.joda.time.Instant;
import org.bonitasoft.web.designer.model.HasUUID;
import org.bonitasoft.web.designer.model.JsonViewLight;
import org.bonitasoft.web.designer.model.JsonViewPersistence;
public class Page extends AbstractPage implements HasUUID {
//useful for the index and studio
private String uuid;
private String type = "page";
private String description = "Page generated with Bonita UI designer";
private String displayName = "";
@JsonView({ JsonViewLight.class, JsonViewPersistence.class })
@JsonView({JsonViewLight.class, JsonViewPersistence.class})
public String getType() {
return type;
}
......@@ -55,7 +36,7 @@ public class Page extends AbstractPage implements HasUUID {
this.type = type;
}
@JsonView({ JsonViewLight.class, JsonViewPersistence.class })
@JsonView({JsonViewLight.class, JsonViewPersistence.class})
public String getUUID() {
return uuid;
}
......@@ -63,4 +44,25 @@ public class Page extends AbstractPage implements HasUUID {
public void setUUID(String uuid) {
this.uuid = uuid;
}
@JsonView({JsonViewPersistence.class})
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@JsonView({JsonViewPersistence.class})
public String getDisplayName() {
return "".equals(displayName) ? this.getName().concat(" ").concat(this.type) : displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
}
name=custompage_{{name}}
displayName={{name}} page
description={{name}} page generated with Bonita UI designer
resources={{resources}}
contentType={{type}}
......@@ -16,8 +16,12 @@ package org.bonitasoft.web.designer.controller;
import static com.jayway.jsonassert.impl.matcher.IsCollectionWithSize.hasSize;
import static java.nio.file.Files.readAllBytes;
import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.web.designer.builder.AssetBuilder.anAsset;
import static org.bonitasoft.web.designer.builder.ComponentBuilder.aComponent;
import static org.bonitasoft.web.designer.builder.PageBuilder.aFilledPage;
import static org.bonitasoft.web.designer.builder.PageBuilder.aPage;
import static org.bonitasoft.web.designer.controller.asset.AssetService.OrderType.DECREMENT;
......@@ -25,6 +29,7 @@ import static org.bonitasoft.web.designer.controller.asset.AssetService.OrderTyp
import static org.bonitasoft.web.designer.model.asset.AssetScope.PAGE;
import static org.bonitasoft.web.designer.model.asset.AssetType.JAVASCRIPT;
import static org.bonitasoft.web.designer.model.contract.builders.ContractBuilder.aSimpleContract;
import static org.bonitasoft.web.designer.model.data.DataType.URL;
import static org.bonitasoft.web.designer.utils.RestControllerUtil.convertObjectToJsonBytes;
import static org.bonitasoft.web.designer.utils.UIDesignerMockMvcBuilder.mockServer;
import static org.hamcrest.CoreMatchers.notNullValue;
......@@ -44,6 +49,8 @@ import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import com.fasterxml.jackson.core.FakeJsonProcessingException;
import org.bonitasoft.web.designer.builder.AssetBuilder;
......@@ -55,6 +62,8 @@ import org.bonitasoft.web.designer.model.asset.Asset;
import org.bonitasoft.web.designer.model.asset.AssetScope;
import org.bonitasoft.web.designer.model.asset.AssetType;
import org.bonitasoft.web.designer.model.contract.Contract;
import org.bonitasoft.web.designer.model.data.Data;
import org.bonitasoft.web.designer.model.page.Component;
import org.bonitasoft.web.designer.model.page.Element;
import org.bonitasoft.web.designer.model.page.Page;
import org.bonitasoft.web.designer.repository.PageRepository;
......@@ -62,6 +71,8 @@ import org.bonitasoft.web.designer.repository.exception.NotFoundException;
import org.bonitasoft.web.designer.repository.exception.RepositoryException;
import org.bonitasoft.web.designer.service.PageService;
import org.bonitasoft.web.designer.visitor.AssetVisitor;
import org.bonitasoft.web.designer.visitor.AuthRulesCollector;
import org.bonitasoft.web.designer.visitor.ComponentVisitor;
import org.hamcrest.Matchers;
import org.joda.time.Instant;
import org.junit.Assert;
......@@ -114,6 +125,18 @@ public class PageResourceTest {
private Path widgetRepositoryPath;
private Component startProcessComponent;
private Component submitTaskComponent;
private Page page;
@Mock
private ComponentVisitor componentVisitor;
@Mock
private AuthRulesCollector authRulesCollector;
@Before
public void setUp() throws URISyntaxException {
mockMvc = mockServer(pageResource).build();
......@@ -263,7 +286,7 @@ public class PageResourceTest {
when(pageRepository.getNextAvailableId("page-new-name")).thenReturn("page-new-name");
ResultActions result = mockMvc
ResultActions result = mockMvc
.perform(
put("/rest/pages/my-page").contentType(MediaType.APPLICATION_JSON_VALUE).content(
convertObjectToJsonBytes(pageToBeSaved)))
......@@ -271,7 +294,7 @@ public class PageResourceTest {
.andExpect(header().string(HttpHeaders.LOCATION, "/rest/pages/page-new-name"));
verify(pageRepository).updateLastUpdateAndSave(aPage().withId("page-new-name").withName("page-new-name").build());
verify(pageAssetService).duplicateAsset(pageRepository.resolvePath("my-page"),pageRepository.resolvePath("my-page"), "my-page", "page-new-name");
verify(pageAssetService).duplicateAsset(pageRepository.resolvePath("my-page"), pageRepository.resolvePath("my-page"), "my-page", "page-new-name");
verify(messagingTemplate).convertAndSend("/previewableRemoval", "my-page");
Assert.assertEquals(MediaType.APPLICATION_JSON.toString(), result.andReturn().getResponse().getContentType());
......@@ -418,7 +441,7 @@ public class PageResourceTest {
ArgumentCaptor<Page> pageArgumentCaptor = ArgumentCaptor.forClass(Page.class);
verify(pageRepository).getNextAvailableId(newName);
verify(pageRepository).updateLastUpdateAndSave(pageArgumentCaptor.capture());
verify(pageAssetService).duplicateAsset(pageRepository.resolvePath("my-page"),pageRepository.resolvePath("my-page"), "my-page", "my-page-new-name");
verify(pageAssetService).duplicateAsset(pageRepository.resolvePath("my-page"), pageRepository.resolvePath("my-page"), "my-page", "my-page-new-name");
assertThat(pageArgumentCaptor.getValue().getName()).isEqualTo(newName);
assertThat(pageArgumentCaptor.getValue().getId()).isEqualTo(newName);
......@@ -535,7 +558,7 @@ public class PageResourceTest {
@Test
public void should_list_page_assets() throws Exception {
Page page = mockPageOfId("my-page");
Asset[] assets = new Asset[] {
Asset[] assets = new Asset[]{
anAsset().withName("myCss.css").withType(AssetType.CSS).withScope(AssetScope.WIDGET).withComponentId("widget-id").build(),
anAsset().withName("myJs.js").withType(JAVASCRIPT).withScope(AssetScope.PAGE).build(),
anAsset().withName("https://mycdn.com/myExternalJs.js").withScope(AssetScope.PAGE).withType(JAVASCRIPT).build()
......@@ -555,7 +578,7 @@ public class PageResourceTest {
@Test
public void should_list_page_assets_while_getting_a_page() throws Exception {
Page page = mockPageOfId("my-page");
Asset[] assets = new Asset[] {
Asset[] assets = new Asset[]{
anAsset().withName("myCss.css").withType(AssetType.CSS).withScope(AssetScope.WIDGET).withComponentId("widget-id").build(),
anAsset().withName("myJs.js").withType(AssetType.JAVASCRIPT).withScope(AssetScope.PAGE).build(),
anAsset().withName("https://mycdn.com/myExternalJs.js").withType(AssetType.JAVASCRIPT).withScope(AssetScope.PAGE).build()
......@@ -693,4 +716,64 @@ public class PageResourceTest {
mockMvc.perform(get("/rest/pages/page-id/assets/js/asset.js")).andExpect(status().isInternalServerError());
}
private Data anApiData(String value) {
return new Data(URL, value);
}
private void setUpPageForResourcesTests() {
page = mockPageOfId("myPage");
when(componentVisitor.visit(page)).thenReturn(Collections.<Component>emptyList());
startProcessComponent = aComponent()
.withPropertyValue("foo", "constant", "Start process")
.build();
submitTaskComponent = aComponent()
.withPropertyValue("foo", "constant", "Submit task")
.build();
}
@Test
public void should_add_bonita_resources_found_in_pages_widgets() throws Exception {
setUpPageForResourcesTests();
Set<String> authRules = new TreeSet<>();
authRules.add("GET|living/application-menu");
authRules.add("POST|bpm/process");
page.setData(singletonMap("foo", anApiData("../API/bpm/userTask?filter=mine")));
when(authRulesCollector.visit(page)).thenReturn(authRules);
String properties = new String(pageResource.getResources(page.getId()).toString());
assertThat(properties).contains("[GET|bpm/userTask, GET|living/application-menu, POST|bpm/process]");
}
@Test
public void should_add_start_process_resource_if_a_start_process_submit_is_contained_in_the_page() throws Exception {
setUpPageForResourcesTests();
when(componentVisitor.visit(page)).thenReturn(singleton(startProcessComponent));
String properties = new String(pageResource.getResources(page.getId()).toString());
assertThat(properties).contains("[POST|bpm/process]");
}
@Test
public void should_add_submit_task_resource_if_a_start_submit_task_is_contained_in_the_page() throws Exception {
setUpPageForResourcesTests();
when(componentVisitor.visit(page)).thenReturn(singleton(submitTaskComponent));
String properties = new String(pageResource.getResources(page.getId()).toString());
assertThat(properties).contains("[POST|bpm/userTask]");
}
@Test
public void should_combined_start_process_submit_task_and_bonita_resources() throws Exception {
setUpPageForResourcesTests();
when(componentVisitor.visit(page))
.thenReturn(asList(startProcessComponent, submitTaskComponent));
page.setData(singletonMap("foo", anApiData("/bonita/API/bpm/userTask")));
String properties = new String(pageResource.getResources(page.getId()).toString());
assertThat(properties).contains("[GET|bpm/userTask, POST|bpm/process, POST|bpm/userTask]");
}
}
......@@ -14,23 +14,18 @@
*/
package org.bonitasoft.web.designer.controller.export.properties;
import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.web.designer.builder.ComponentBuilder.aComponent;
import static org.bonitasoft.web.designer.model.data.DataType.URL;
import static org.mockito.Mockito.when;
import java.util.*;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;
import com.google.common.collect.ImmutableSet;
import org.bonitasoft.web.designer.builder.WidgetBuilder;
import org.bonitasoft.web.designer.controller.PageResource;
import org.bonitasoft.web.designer.model.data.Data;
import org.bonitasoft.web.designer.model.page.Component;
import org.bonitasoft.web.designer.model.page.Page;
import org.bonitasoft.web.designer.visitor.AuthRulesCollector;
import org.bonitasoft.web.designer.visitor.ComponentVisitor;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -41,33 +36,19 @@ import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class PagePropertiesBuilderTest {
private static final String LINE_SEPARATOR = System.lineSeparator();
@Mock
private ComponentVisitor componentVisitor;
@Mock
private AuthRulesCollector authRulesCollector;
@InjectMocks
private PagePropertiesBuilder pagePropertiesBuilder;
private Page page;
private Component startProcessComponent;
@Mock
private PageResource pageResource;
private Component submitTaskComponent;
@Before
public void setUp() throws Exception {
page = new Page();
when(componentVisitor.visit(page)).thenReturn(Collections.<Component>emptyList());
startProcessComponent = aComponent()
.withPropertyValue("foo", "constant", "Start process")
.build();
submitTaskComponent = aComponent()
.withPropertyValue("foo", "constant", "Submit task")
.build();
page.setName("myPage");
}
private Data anApiData(String value) {
......@@ -78,19 +59,37 @@ public class PagePropertiesBuilderTest {
public void should_build_a_well_formed_page_property_file() throws Exception {
page.setId("aPageId");
page.setName("aPageName");
page.setDescription("a page description with special characters &'\"é");
page.setDisplayName("a display name with special characters &'\"é");
when(pageResource.getResources(page.getId())).thenReturn(Arrays.asList(""));
String properties = new String(pagePropertiesBuilder.build(page));
assertThat(properties).contains("name=custompage_aPageName" + LINE_SEPARATOR);
assertThat(properties).contains("displayName=aPageName page" + LINE_SEPARATOR);
assertThat(properties).contains("description=aPageName page generated with Bonita UI designer");
assertThat(properties).contains("contentType=page");
assertThat(properties).contains("name=custompage_aPageName");
assertThat(properties).contains("displayName=a display name with special characters &'\"\\u00E9" );
assertThat(properties).contains("description=a page description with special characters &'\"\\u00E9");
assertThat(properties).contains("resources=[]");
}
@Test
public void should_build_a_page_property_file_when_de