Commit 08eb3295 authored by Adrien's avatar Adrien Committed by Romain Bioteau

fix(layout creation) add empty raw list when creating new layout from Studio (#1509)

* fix(layout creation) add empty raw list when creating new layout from
Studio
parent 5bb0332a
package org.bonitasoft.studio.designer.core.operation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.util.List;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.designer.core.PageDesignerURLFactory;
import org.bonitasoft.studio.designer.core.operation.CreateUIDArtifactOperation.ArtifactyType;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
@SuppressWarnings("unchecked")
public class CreateUIDArtifactOperationTest {
private static final String TYPE = "type";
private static final String ROWS = "rows";
private RepositoryAccessor repositoryAccessor;
private PageDesignerURLFactory pageDesignerURLFactory;
private CreatePageOperation createPageOperation;
private CreateLayoutOperation createLayoutOperation;
private CreateFormOperation createFormOperation;
@Before
public void init() {
repositoryAccessor = mock(RepositoryAccessor.class);
pageDesignerURLFactory = mock(PageDesignerURLFactory.class);
createPageOperation = new CreatePageOperation(pageDesignerURLFactory, repositoryAccessor);
createLayoutOperation = new CreateLayoutOperation(pageDesignerURLFactory, repositoryAccessor);
createFormOperation = new CreateFormOperation(pageDesignerURLFactory, repositoryAccessor);
}
@Test
public void should_create_request_body_according_to_type() throws Exception {
validateJsonBodyForPages();
validateJsonBodyForForms();
validateJsonBodyForLayouts();
}
private void validateJsonBodyForPages() throws Exception {
JSONObject pageBody = createPageOperation.createBody();
assertThat(pageBody.get(TYPE)).isEqualTo(ArtifactyType.PAGE);
JSONArray rows = (JSONArray) pageBody.get(ROWS);
assertThat(rows.length()).isEqualTo(1);
assertThat((List) rows.get(0)).isEmpty();
}
private void validateJsonBodyForForms() throws Exception {
JSONObject pageBody = createFormOperation.createBody();
assertThat(pageBody.get(TYPE)).isEqualTo(ArtifactyType.FORM);
JSONArray rows = (JSONArray) pageBody.get(ROWS);
assertThat(rows.length()).isEqualTo(1);
assertThat((List) rows.get(0)).isEmpty();
}
private void validateJsonBodyForLayouts() throws Exception {
JSONObject pageBody = createLayoutOperation.createBody();
assertThat(pageBody.get(TYPE)).isEqualTo(ArtifactyType.LAYOUT);
JSONArray rows = (JSONArray) pageBody.get(ROWS);
assertThat(rows.length()).isEqualTo(1);
assertThat((List) rows.get(0)).isEmpty();
}
}
......@@ -85,9 +85,7 @@ public abstract class CreateUIDArtifactOperation implements IRunnableWithProgres
JSONObject jsonObject = new JSONObject();
jsonObject.put("type", getArtifactType());
jsonObject.put("name", artifactName);
if (getArtifactType() == ArtifactyType.FORM
|| getArtifactType() == ArtifactyType.PAGE
|| getArtifactType() == ArtifactyType.FRAGMENT) {
if (getArtifactType() != ArtifactyType.WIDGET) {
jsonObject.put("rows", Arrays.asList(new ArrayList<>()));
}
return jsonObject;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment