Skip to content

Commit

Permalink
chore(merge): release-10.2.0 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bonita-ci committed Jul 17, 2024
2 parents 1a6cd72 + 150495d commit d5100ce
Show file tree
Hide file tree
Showing 28 changed files with 1,376 additions and 353 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ public void createApplication_returns_application_based_on_ApplicationCreator_in
getLivingApplicationAPI().deleteApplication(application.getId());
}

@Test
public void createApplicationLink_returns_application_based_on_ApplicationCreator_information() throws Exception {
//given
final Profile profile = getProfileUser();
final ApplicationLinkCreator creator = new ApplicationLinkCreator("My-Application",
"My application display name",
"1.0");
creator.setDescription("This is my application");
creator.setIconPath("/icon.jpg");
creator.setProfileId(profile.getId());

//when
final ApplicationLink application = getLivingApplicationAPI().createApplicationLink(creator);

//then
assertThat(application).isNotNull();
assertThat(application.getToken()).isEqualTo("My-Application");
assertThat(application.getDisplayName()).isEqualTo("My application display name");
assertThat(application.getVersion()).isEqualTo("1.0");
assertThat(application.getId()).isGreaterThan(0);
assertThat(application.getDescription()).isEqualTo("This is my application");
assertThat(application.getIconPath()).isEqualTo("/icon.jpg");
assertThat(application.getCreatedBy()).isEqualTo(getUser().getId());
assertThat(application.getUpdatedBy()).isEqualTo(getUser().getId());
assertThat(application.getProfileId()).isEqualTo(profile.getId());

getLivingApplicationAPI().deleteApplication(application.getId());
}

@Test
public void createApplication_without_profile_should_have_null_profileId() throws Exception {
//given
Expand Down Expand Up @@ -112,6 +141,42 @@ public void updateApplication_should_return_application_up_to_date() throws Exce
getLivingApplicationAPI().deleteApplication(application.getId());
}

@Test
public void updateApplicationLink_should_return_application_up_to_date() throws Exception {
//given
final Profile profile = getProfileUser();
final ApplicationLinkCreator creator = new ApplicationLinkCreator("My-Application",
"My application display name",
"1.0");
final ApplicationLink application = getLivingApplicationAPI().createApplicationLink(creator);

final ApplicationLinkUpdater updater = new ApplicationLinkUpdater();
updater.setToken("My-updated-app");
updater.setDisplayName("Updated display name");
updater.setVersion("1.1");
updater.setDescription("Up description");
updater.setIconPath("/newIcon.jpg");
updater.setProfileId(profile.getId());
updater.setState(ApplicationState.ACTIVATED.name());

//when
final ApplicationLink updatedApplication = getLivingApplicationAPI().updateApplicationLink(application.getId(),
updater);

//then
assertThat(updatedApplication).isNotNull();
assertThat(updatedApplication.getToken()).isEqualTo("My-updated-app");
assertThat(updatedApplication.getDisplayName()).isEqualTo("Updated display name");
assertThat(updatedApplication.getVersion()).isEqualTo("1.1");
assertThat(updatedApplication.getDescription()).isEqualTo("Up description");
assertThat(updatedApplication.getIconPath()).isEqualTo("/newIcon.jpg");
assertThat(updatedApplication.getProfileId()).isEqualTo(profile.getId());
assertThat(updatedApplication.getState()).isEqualTo(ApplicationState.ACTIVATED.name());
assertThat(updatedApplication).isEqualTo(getLivingApplicationAPI().getIApplication(application.getId()));

getLivingApplicationAPI().deleteApplication(application.getId());
}

@Test
public void getApplication_returns_application_with_the_given_id() throws Exception {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
**/
package org.bonitasoft.web.rest.server.api.application;

import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.web.rest.server.api.page.builder.PageItemBuilder.aPageItem;
import static org.junit.Assert.*;
import static org.mockito.Mockito.spy;
Expand All @@ -22,6 +23,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.io.IOUtils;
import org.bonitasoft.engine.api.ApplicationAPI;
Expand All @@ -39,7 +41,6 @@
import org.bonitasoft.web.rest.server.api.applicationpage.APIApplicationDataStoreFactory;
import org.bonitasoft.web.rest.server.datastore.application.ApplicationDataStoreCreator;
import org.bonitasoft.web.test.AbstractConsoleTest;
import org.bonitasoft.web.toolkit.client.common.exception.api.APIException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -99,33 +100,41 @@ private PageItem addPageItemToRepository(final String pageContentName, final byt
}

@Test
public void add_ApplicationLink_is_forbidden() {
public void should_add_ApplicationLink() {
// Given
final ApplicationLinkItem linkItem = ApplicationLinkDefinition.get().createItem();
linkItem.setToken("tokenLink");
linkItem.setDisplayName("Link");
linkItem.setVersion("1.0");
linkItem.setProfileId(2L);
linkItem.setState("Activated");
linkItem.setState("ACTIVATED");

// When, Then exception
assertThrows("Expected exception: This deprecated API is not supported for application links.",
APIException.class, () -> apiApplication.add(linkItem));
// When
var createdLink = apiApplication.add(linkItem);

// Then
Map<String, String> attributes = new HashMap<>(linkItem.getAttributes().size());
linkItem.getAttributes().keySet().forEach(k -> attributes.put(k, createdLink.getAttributes().get(k)));
Assert.assertEquals(new HashMap<>(linkItem.getAttributes()), attributes);
assertThat(createdLink.isLink()).isTrue();
}

@Test
public void should_add_LegacyApplication() throws Exception {
// Given
var legacyApp = createLegacyApplication();
var pair = createLegacyApplicationWithOriginal();
var original = pair.getKey();
var legacyApp = pair.getValue();

// Then
Map<String, String> attributes = new HashMap<>(legacyApp.getAttributes().size());
legacyApp.getAttributes().keySet().forEach(k -> attributes.put(k, legacyApp.getAttributes().get(k)));
Assert.assertEquals(new HashMap<>(legacyApp.getAttributes()), attributes);
Map<String, String> attributes = new HashMap<>(original.getAttributes().size());
original.getAttributes().keySet().forEach(k -> attributes.put(k, legacyApp.getAttributes().get(k)));
Assert.assertEquals(new HashMap<>(original.getAttributes()), attributes);
assertThat(legacyApp.isLink()).isFalse();
}

@Test
public void update_ApplicationLink_is_forbidden_and_not_effective() throws Exception {
public void should_update_ApplicationLink() throws Exception {
// Given
getApplicationAPI().importApplications(
IOUtils.toByteArray(getClass().getResourceAsStream(APP_LINK_DESCRIPTOR)),
Expand All @@ -134,12 +143,13 @@ public void update_ApplicationLink_is_forbidden_and_not_effective() throws Excep
.search(0, 1, null, null, Collections.singletonMap("token", "app1")).getResults().get(0);
Map<String, String> attributes = Map.of(AbstractApplicationItem.ATTRIBUTE_DISPLAY_NAME, "Link Updated");

// When, Then exception
assertThrows(
"Expected exception: This deprecated API is not supported for application links.",
APIException.class, () -> apiApplication.update(linkItem.getId(), attributes));
// Then not updated
assertEquals("Application 1", apiApplication.get(linkItem.getId()).getDisplayName());
// When
var updatedLink = apiApplication.update(linkItem.getId(), attributes);

// Then updated
assertEquals("Link Updated", updatedLink.getDisplayName());
assertEquals("Link Updated", apiApplication.get(linkItem.getId()).getDisplayName());
assertThat(linkItem.isLink()).isTrue();
}

@Test
Expand All @@ -153,6 +163,7 @@ public void should_update_LegacyApplication() throws Exception {

// Then
assertEquals("Legacy Updated", updatedItem.getDisplayName());
assertThat(updatedItem.isLink()).isFalse();
}

@Test
Expand All @@ -172,7 +183,17 @@ public void should_search_not_support_filtering_on_ApplicationLinks() throws Exc
BonitaRuntimeException.class, () -> apiApplication.search(0, 1, search, orders, filters));
}

private AbstractApplicationItem createLegacyApplication() throws Exception {
private ApplicationItem createLegacyApplication() throws Exception {
return createLegacyApplicationWithOriginal().getValue();
}

/**
* Create a legacy application.
*
* @return a pair with the constructed item as key and the api call result as value.
* @throws Exception exception during creation
*/
private Entry<ApplicationItem, ApplicationItem> createLegacyApplicationWithOriginal() throws Exception {
addPage(HOME_PAGE_ZIP);
final PageItem layout = addPage(LAYOUT_ZIP);
final PageItem theme = addPage(THEME_ZIP);
Expand All @@ -185,7 +206,8 @@ private AbstractApplicationItem createLegacyApplication() throws Exception {
legacyItem.setLayoutId(layout.getId().toLong());
legacyItem.setThemeId(theme.getId().toLong());

return apiApplication.add(legacyItem);
return Collections.singletonMap(legacyItem, (ApplicationItem) apiApplication.add(legacyItem)).entrySet()
.iterator().next();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import org.bonitasoft.engine.business.application.Application;
import org.bonitasoft.engine.business.application.ApplicationCreator;
import org.bonitasoft.engine.business.application.ApplicationImportPolicy;
import org.bonitasoft.engine.business.application.ApplicationLink;
import org.bonitasoft.engine.business.application.ApplicationLinkCreator;
import org.bonitasoft.engine.business.application.ApplicationLinkUpdater;
import org.bonitasoft.engine.business.application.ApplicationMenu;
import org.bonitasoft.engine.business.application.ApplicationMenuCreator;
import org.bonitasoft.engine.business.application.ApplicationMenuNotFoundException;
Expand Down Expand Up @@ -64,6 +67,22 @@ public interface ApplicationAPI {
Application createApplication(ApplicationCreator applicationCreator)
throws AlreadyExistsException, CreationException;

/**
* Creates a new {@link ApplicationLink} based on the supplied {@link ApplicationLinkCreator}
*
* @param applicationLinkCreator creator describing characteristics of application link to be created
* @return the created <code>ApplicationLink</code>
* @throws AlreadyExistsException if an application already exists with the same name
* @throws CreationException if an error occurs during the creation
* @see ApplicationLink
* @see ApplicationLinkCreator
* @deprecated as of 9.0.0, Applications should be created at startup. This also concerns application links
* introduced in 10.2.0.
*/
@Deprecated(since = "10.2.0")
ApplicationLink createApplicationLink(ApplicationLinkCreator applicationLinkCreator)
throws AlreadyExistsException, CreationException;

/**
* Retrieves an {@link Application} from its identifier.
*
Expand Down Expand Up @@ -142,7 +161,7 @@ default Application getApplicationByToken(final String applicationToken) throws
* @param updater an <code>ApplicationUpdater</code> describing the fields to be updated.
* @return the <code>Application</code> as it is after the update.
* @throws ApplicationNotFoundException if no <code>Application</code> is found for the given id
* @throws AlreadyExistsException if another <code>Application</code> already exists with the new name value
* @throws AlreadyExistsException if another <code>IApplication</code> already exists with the new name value
* @throws UpdateException if an error occurs during the update
* @see Application
* @see ApplicationUpdater
Expand All @@ -152,6 +171,24 @@ default Application getApplicationByToken(final String applicationToken) throws
Application updateApplication(long applicationId, ApplicationUpdater updater)
throws ApplicationNotFoundException, UpdateException, AlreadyExistsException;

/**
* Updates an {@link ApplicationLink} based on the information supplied by the {@link ApplicationLinkUpdater}
*
* @param applicationId a long representing the application identifier
* @param updater an <code>ApplicationLinkUpdater</code> describing the fields to be updated.
* @return the <code>ApplicationLink</code> as it is after the update.
* @throws ApplicationNotFoundException if no <code>ApplicationLink</code> is found for the given id
* @throws AlreadyExistsException if another <code>IApplication</code> already exists with the new name value
* @throws UpdateException if an error occurs during the update
* @see ApplicationLink
* @see ApplicationLinkUpdater
* @deprecated as of 9.0.0, Applications should be updated at startup. This also concerns application links
* introduced in 10.2.0.
*/
@Deprecated(since = "10.2.0")
ApplicationLink updateApplicationLink(long applicationId, ApplicationLinkUpdater updater)
throws ApplicationNotFoundException, UpdateException, AlreadyExistsException;

/**
* Searches for {@link Application}s with specific search criteria. Use
* {@link org.bonitasoft.engine.business.application.ApplicationSearchDescriptor} to
Expand Down
Loading

0 comments on commit d5100ce

Please sign in to comment.