Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AuthPermissions {
public static final String CONNECTION_DELETE = "connection-delete";

public static final String PROCESS_DEFINITION_LIST = "process-definition-list";
public static final String PROCESS_DEFINITION_FORM = "process-definition-form";
public static final String PROCESS_DIAGRAM = "process-diagram";

public static final String GROUP_LIST = "group-list";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.entando.plugins.pda.controller;

import static org.entando.plugins.pda.controller.AuthPermissions.PROCESS_DEFINITION_FORM;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.entando.plugins.pda.core.engine.Connection;
import org.entando.plugins.pda.core.engine.Engine;
import org.entando.plugins.pda.core.model.form.Form;
import org.entando.plugins.pda.engine.EngineFactory;
import org.entando.plugins.pda.service.ConnectionService;
import org.entando.web.response.SimpleRestResponse;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Api(tags = "Process")
@RequestMapping(path = "/connections/{connId}/processes")
@RequiredArgsConstructor
public class ProcessFormController {

private final ConnectionService connectionService;

private final EngineFactory engineFactory;

@Secured(PROCESS_DEFINITION_FORM)
@ApiOperation(notes = "Get process form metadata", nickname = "getProcessForm", value = "GET ProcessForm")
@GetMapping(path = "/definitions/{id}/form", produces = {APPLICATION_JSON_VALUE})
public SimpleRestResponse<List<Form>> getProcessForm(@PathVariable String connId,
@PathVariable String id) {
log.info("Retrieving a process form definitions for connection {} and processId {}", connId, id);
Connection connection = connectionService.get(connId);
Engine engine = engineFactory.getEngine(connection.getEngine());
return new SimpleRestResponse<>(
engine.getProcessFormService().getProcessForm(connection, id));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.entando.plugins.pda.controller;

import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.entando.plugins.pda.core.utils.TestUtils.readFromFile;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -88,8 +89,9 @@ public void testGetProcessDiagram() throws Exception {
.andReturn();

String diagram = result.getResponse().getContentAsString();
String expected = readFromFile(FakeProcessService.PROCESS_DIAGRAM_FILENAME_1);

assertThat(diagram.length()).isEqualTo(FakeProcessService.PROCESS_DIAGRAM_LENGTH_1);
assertThat(diagram).isEqualTo(expected);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.entando.plugins.pda.controller;

import static org.entando.plugins.pda.core.utils.TestUtils.PROCESS_ID_1;
import static org.entando.plugins.pda.core.utils.TestUtils.PROCESS_ID_2;
import static org.entando.plugins.pda.core.utils.TestUtils.PROCESS_NAME_1;
import static org.entando.plugins.pda.core.utils.TestUtils.PROCESS_NAME_2;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import org.entando.connectionconfigconnector.config.ConnectionConfigConfiguration;
import org.entando.connectionconfigconnector.model.ConnectionConfig;
import org.entando.plugins.pda.util.ConnectionTestHelper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.web.client.ExpectedCount;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.client.RestTemplate;

@AutoConfigureMockMvc
@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class})
@SpringBootTest(classes = TestConnectionConfigConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT,
properties = "entando.plugin.security.level=LENIENT")
public class ProcessFormControllerIntegrationTest {

@Autowired
private MockMvc mockMvc;

@Autowired
@Qualifier(ConnectionConfigConfiguration.CONFIG_REST_TEMPLATE)
private RestTemplate configRestTemplate;

private ObjectMapper mapper = new ObjectMapper();

@Before
public void setup() throws IOException {
ConnectionConfig connectionConfig = ConnectionTestHelper.generateConnectionConfig();
MockRestServiceServer mockServer = MockRestServiceServer.createServer(configRestTemplate);
mockServer.expect(ExpectedCount.manyTimes(), requestTo(
containsString(TestConnectionConfigConfiguration.URL_PREFIX + "/config/fakeProduction")))
.andExpect(method(HttpMethod.GET))
.andRespond(
withSuccess(mapper.writeValueAsString(connectionConfig), MediaType.APPLICATION_JSON));
}

@Test
public void testGetProcessForm() throws Exception {
mockMvc.perform(get("/connections/fakeProduction/processes/definitions/{id}/form"
.replace("{id}", PROCESS_ID_1)))
.andDo(print())
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("errors", hasSize(0)))
.andExpect(jsonPath("payload.size()", is(2)))
.andExpect(jsonPath("payload[0].id", is(PROCESS_ID_1)))
.andExpect(jsonPath("payload[0].name", is(PROCESS_NAME_1)))
.andExpect(jsonPath("payload[1].id", is(PROCESS_ID_2)))
.andExpect(jsonPath("payload[1].name", is(PROCESS_NAME_2)));
}

}