[OLINGO-337] more tests and fixes

This commit is contained in:
Stephan Klevenz 2014-07-08 10:07:16 +02:00
parent 6383ab0b12
commit aff42fcee5
5 changed files with 40 additions and 23 deletions

View File

@ -30,6 +30,7 @@ import org.apache.olingo.client.core.ODataClientFactory;
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.junit.Before;
import org.junit.Test;
@ -49,7 +50,6 @@ public class BasicITCase {
public void readServiceDocument() {
ODataServiceDocumentRequest request =
odata.getRetrieveRequestFactory().getServiceDocumentRequest(REF_SERVICE);
request.setAccept("application/json;odata.metadata=minimal");
assertNotNull(request);
ODataRetrieveResponse<ODataServiceDocument> response = request.execute();
@ -73,6 +73,7 @@ public class BasicITCase {
assertEquals(200, response.getStatusCode());
Edm edm = response.getBody();
assertNotNull(edm);
assertEquals("com.sap.odata.test1", edm.getSchema("com.sap.odata.test1").getNamespace());
assertEquals("Namespace1_Alias", edm.getSchema("com.sap.odata.test1").getAlias());

View File

@ -193,9 +193,6 @@ public class AcceptType {
for (final String key : parameters.keySet()) {
result.append(';').append(key).append('=').append(parameters.get(key));
}
if (quality < 1F) {
result.append(';').append(TypeUtil.PARAMETER_Q).append('=').append(quality);
}
return result.toString();
}
@ -225,8 +222,9 @@ public class AcceptType {
}
Map<String, String> compareParameters = contentType.getParameters();
for (final String key : parameters.keySet()) {
if (compareParameters.containsKey(key)) {
if (!parameters.get(key).equalsIgnoreCase(compareParameters.get(key))) {
if (compareParameters.containsKey(key) || TypeUtil.PARAMETER_Q.equalsIgnoreCase(key)) {
if (!parameters.get(key).equalsIgnoreCase(compareParameters.get(key))
&& !TypeUtil.PARAMETER_Q.equalsIgnoreCase(key)) {
return false;
}
} else {

View File

@ -45,7 +45,6 @@ import java.util.TreeMap;
*/
public class ContentType {
public static final ContentType APPLICATION_XML = create("application", "xml");
public static final ContentType APPLICATION_XML_CS_UTF_8 = create(APPLICATION_XML, TypeUtil.PARAMETER_CHARSET,
TypeUtil.CHARSET_UTF_8);
@ -53,23 +52,23 @@ public class ContentType {
public static final ContentType APPLICATION_ATOM_XML_CS_UTF_8 = create(APPLICATION_ATOM_XML,
TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
public static final ContentType APPLICATION_ATOM_XML_ENTRY =
create(APPLICATION_ATOM_XML,TypeUtil. PARAMETER_TYPE, "entry");
create(APPLICATION_ATOM_XML, TypeUtil.PARAMETER_TYPE, "entry");
public static final ContentType APPLICATION_ATOM_XML_ENTRY_CS_UTF_8 = create(APPLICATION_ATOM_XML_ENTRY,
TypeUtil. PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
public static final ContentType APPLICATION_ATOM_XML_FEED =
create(APPLICATION_ATOM_XML,TypeUtil. PARAMETER_TYPE, "feed");
create(APPLICATION_ATOM_XML, TypeUtil.PARAMETER_TYPE, "feed");
public static final ContentType APPLICATION_ATOM_XML_FEED_CS_UTF_8 = create(APPLICATION_ATOM_XML_FEED,
TypeUtil. PARAMETER_CHARSET,TypeUtil.CHARSET_UTF_8);
TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
public static final ContentType APPLICATION_ATOM_SVC = create("application", "atomsvc+xml");
public static final ContentType APPLICATION_ATOM_SVC_CS_UTF_8 = create(APPLICATION_ATOM_SVC,
TypeUtil. PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
public static final ContentType APPLICATION_JSON = create("application", "json");
public static final ContentType APPLICATION_JSON_CS_UTF_8 = create(APPLICATION_JSON,
TypeUtil. PARAMETER_CHARSET,TypeUtil. CHARSET_UTF_8);
TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
public static final ContentType APPLICATION_OCTET_STREAM = create("application", "octet-stream");
public static final ContentType TEXT_PLAIN = create("text", "plain");
public static final ContentType TEXT_PLAIN_CS_UTF_8 =
create(TEXT_PLAIN, TypeUtil.PARAMETER_CHARSET,TypeUtil. CHARSET_UTF_8);
create(TEXT_PLAIN, TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
public static final ContentType MULTIPART_MIXED = create("multipart", "mixed");
public static final ContentType APPLICATION_XHTML_XML = create("application", "xhtml+xml");
@ -209,10 +208,10 @@ public class ContentType {
}
} else {
throw new IllegalArgumentException(
"Too many '" +TypeUtil.TYPE_SUBTYPE_SEPARATOR + "' in format '" + format + "'.");
"Too many '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR + "' in format '" + format + "'.");
}
} else {
throw new IllegalArgumentException("No separator '" +TypeUtil.TYPE_SUBTYPE_SEPARATOR
throw new IllegalArgumentException("No separator '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR
+ "' was found in format '" + format + "'.");
}

View File

@ -20,6 +20,7 @@ package org.apache.olingo.commons.api.format;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
@ -45,6 +46,24 @@ public class AcceptTypeTest {
assertEquals("a/a", atl.get(0).toString());
}
@Test
public void testWithQParameter() {
List<AcceptType> atl = AcceptType.create("application/json;q=0.2");
assertEquals(1, atl.size());
assertEquals("application", atl.get(0).getType());
assertEquals("json", atl.get(0).getSubtype());
assertEquals("0.2", atl.get(0).getParameters().get("q"));
assertEquals("application/json;q=0.2", atl.get(0).toString());
}
@Test
public void testMatchWithQParameter() {
List<AcceptType> atl = AcceptType.create("application/json;q=0.2");
assertEquals(1, atl.size());
assertTrue(atl.get(0).matches(ContentType.APPLICATION_JSON));
}
@Test(expected = IllegalArgumentException.class)
public void testWrongQParameter() {
AcceptType.create(" a/a;q=z ");

View File

@ -104,7 +104,7 @@ public class ContentNegotiatorTest {
@Test
public void testServiceDocumentSingleCase() {
String[] useCase = { ACCEPT_CASE_FULL, null, ACCEPT_CASE_FULL, "dummy", ACCEPT_CASE_FULL };
String[] useCase = { "application/json", null, ACCEPT_CASE_JSON, null, null };
testContentNegotiation(useCase, ServiceDocumentProcessor.class);
}