Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBPM-9247] Fields attribute isn't processed in Accept header #2163

Merged
merged 1 commit into from
Jul 22, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
Expand All @@ -40,6 +42,8 @@ public class RestEasy960Util {
public static List<Variant> variants
= Variant.mediaTypes(MediaType.APPLICATION_XML_TYPE,
new MediaType("application", "json", Collections.singletonMap("strict", "true")),
new MediaType("application", "json", Collections.singletonMap("fields", "not_null")),
new MediaType("application", "json", mapOf("strict", "true", "fields", "not_null")),
MediaType.APPLICATION_JSON_TYPE)
.add().build();
public static Variant defaultVariant
Expand Down Expand Up @@ -70,4 +74,11 @@ public static Variant getVariant(HttpHeaders headers) {
}
return null;
}

private static Map<String, String> mapOf(String key1, String value1, String key2, String value2) {
Map<String, String> result = new HashMap<>();
result.put(key1, value1);
result.put(key2, value2);
return Collections.unmodifiableMap(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.kie.server.integrationtests.jbpm.rest;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -37,8 +38,11 @@
import org.kie.server.api.model.ReleaseId;
import org.kie.server.api.model.instance.DocumentInstance;
import org.kie.server.api.model.instance.DocumentInstanceList;
import org.kie.server.api.model.instance.ProcessInstance;
import org.kie.server.api.model.instance.TaskSummary;
import org.kie.server.api.model.type.JaxbLong;
import org.kie.server.api.model.type.JaxbString;
import org.kie.server.api.rest.RestURI;
import org.kie.server.integrationtests.config.TestConfig;
import org.kie.server.integrationtests.shared.KieServerDeployer;
import org.kie.server.integrationtests.shared.KieServerUtil;
Expand All @@ -49,6 +53,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.kie.server.api.rest.RestURI.ABORT_PROCESS_INST_DEL_URI;
import static org.kie.server.api.rest.RestURI.CONTAINER_ID;
import static org.kie.server.api.rest.RestURI.DOCUMENT_ID;
Expand All @@ -59,13 +64,17 @@
import static org.kie.server.api.rest.RestURI.PROCESS_ID;
import static org.kie.server.api.rest.RestURI.PROCESS_INST_ID;
import static org.kie.server.api.rest.RestURI.PROCESS_URI;
import static org.kie.server.api.rest.RestURI.QUERY_URI;
import static org.kie.server.api.rest.RestURI.START_PROCESS_POST_URI;
import static org.kie.server.api.rest.RestURI.TASK_GET_URI;
import static org.kie.server.api.rest.RestURI.TASK_INSTANCE_ID;
import static org.kie.server.api.rest.RestURI.build;


public class JbpmRestIntegrationTest extends RestJbpmBaseIntegrationTest {

private static ReleaseId releaseId = new ReleaseId("org.kie.server.testing", "rest-processes", "1.0.0.Final");
private static ReleaseId releaseIdDefinitionProject = new ReleaseId("org.kie.server.testing", "definition-project", "1.0.0.Final");

private static Logger logger = LoggerFactory.getLogger(JbpmRestIntegrationTest.class);

Expand All @@ -75,11 +84,13 @@ public class JbpmRestIntegrationTest extends RestJbpmBaseIntegrationTest {
public static void buildAndDeployArtifacts() {
KieServerDeployer.buildAndDeployCommonMavenParent();
KieServerDeployer.buildAndDeployMavenProjectFromResource("/kjars-sources/rest-processes");
KieServerDeployer.buildAndDeployMavenProjectFromResource("/kjars-sources/definition-project");
// set the accepted formats with quality param to express preference
acceptHeadersByFormat.put(MarshallingFormat.JAXB, "application/xml;q=0.9,application/json;q=0.3");// xml is preferred over json
acceptHeadersByFormat.put(MarshallingFormat.JSON, "application/json;q=0.9,application/xml;q=0.3");// json is preferred over xml

createContainer(CONTAINER, releaseId);
createContainer(CONTAINER_ID, releaseIdDefinitionProject);
}

/**
Expand Down Expand Up @@ -218,6 +229,23 @@ public void testBasicJbpmRequestManyAcceptHeaders() throws Exception {

}

@Test
public void testBasicJbpmRequestAcceptHeadersStrictAndField() throws Exception {
assumeTrue(marshallingFormat == MarshallingFormat.JSON);

long processId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK);
ProcessInstance desc = processClient.getProcessInstance(CONTAINER_ID, processId);
TaskSummary[] tasks = desc.getActiveUserTasks().getTasks();
assertTrue(tasks.length > 0);

WebTarget target = newRequest(RestURI.build(TestConfig.getKieServerHttpUrl(), QUERY_URI + "/" + TASK_GET_URI, Collections.singletonMap(TASK_INSTANCE_ID, tasks[0].getId())));
Assertions.assertThat(target.request(MediaType.APPLICATION_JSON_TYPE).get(String.class)).contains("null");
Assertions.assertThat(target.request().header("content-type", MediaType.APPLICATION_JSON + ";fields=not_null;strict=true").get(String.class)).doesNotContain("null");
Assertions.assertThat(target.request().header("content-type", MediaType.APPLICATION_JSON + ";fields=not_null").get(String.class)).doesNotContain("null");
Assertions.assertThat(target.request().header("accept", MediaType.APPLICATION_JSON + ";fields=not_null;strict=true").get(String.class)).doesNotContain("null");
sutaakar marked this conversation as resolved.
Show resolved Hide resolved
Assertions.assertThat(target.request().header("accept", MediaType.APPLICATION_JSON + ";fields=not_null").get(String.class)).doesNotContain("null");
MarianMacik marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void testUploadListDownloadDocument() throws Exception {
KieServerUtil.deleteDocumentStorageFolder();
Expand Down

This file was deleted.