PagePropertiesBuilder { public byte[] build(Page page) throws GenerationException, IOException { 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", StringUtils.isBlank(page.getDisplayName())? page.getName() : 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(); } @Inject  PagePropertiesBuilder(PageResource pageResource); byte[] build(Page page);  }
@Test 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("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_description_and_displayName_are_not_updated() throws Exception { page.setId("aPageId"); page.setName("aPageName"); String properties = new String(pagePropertiesBuilder.build(page)); when(pageResource.getResources(page.getId())).thenReturn(Arrays.asList("")); assertThat(properties).contains("contentType=page"); assertThat(properties).contains("name=custompage_aPageName"); assertThat(properties).contains("displayName=aPageName" ); assertThat(properties).contains("description=Page generated with Bonita UI designer"); assertThat(properties).contains("resources=[]"); }
@Test public void should_add_bonita_resource_found_in_page_data() throws Exception { page.setData(singletonMap("foo", anApiData("/bonita/API/living/application-menu"))); when(pageResource.getResources(page.getId())).thenReturn(Arrays.asList("GET|living/application-menu")); String properties = new String(pagePropertiesBuilder.build(page)); assertThat(properties).contains("resources=[GET|living/application-menu]"); }
@Test public void should_add_relative_bonita_resource_found_in_page_data() throws Exception { Map<String, Data> dataMap = new TreeMap<String, Data>(); dataMap.put("foo", anApiData("../API/bpm/userTask?filter=mine")); dataMap.put("bar", anApiData("../API/identity/user/1")); dataMap.put("other", anApiData("../API/identity/group/1?param=value")); dataMap.put("archived", anApiData("../API/bpm/archivedUserTask?filter=mine&o=name DESC")); page.setData(dataMap); when(pageResource.getResources(page.getId())).thenReturn(Arrays.asList("GET|bpm/archivedUserTask", "GET|identity/user", "GET|bpm/userTask", "GET|identity/group")); String properties = new String(pagePropertiesBuilder.build(page)); assertThat(properties).contains("resources=[GET|bpm/archivedUserTask, GET|identity/user, GET|bpm/userTask, GET|identity/group]"); }
@Test public void should_not_add_a_resource_which_is_not_a_bonita_resource() throws Exception { page.setData(singletonMap("foo", anApiData("../API/path/to/wathever/resource"))); when(pageResource.getResources(page.getId())).thenReturn(Arrays.asList("")); String properties = new String(pagePropertiesBuilder.build(page)); assertThat(properties).contains("resources=[]"); }
@Test public void should_add_contentType() throws Exception { page.setType("layout"); when(pageResource.getResources(page.getId())).thenReturn(Arrays.asList("")); String properties = new String(pagePropertiesBuilder.build(page)); assertThat(properties).contains("contentType=layout"); }