[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.domain.ODataServiceDocument;
import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -49,7 +50,6 @@ public class BasicITCase {
public void readServiceDocument() { public void readServiceDocument() {
ODataServiceDocumentRequest request = ODataServiceDocumentRequest request =
odata.getRetrieveRequestFactory().getServiceDocumentRequest(REF_SERVICE); odata.getRetrieveRequestFactory().getServiceDocumentRequest(REF_SERVICE);
request.setAccept("application/json;odata.metadata=minimal");
assertNotNull(request); assertNotNull(request);
ODataRetrieveResponse<ODataServiceDocument> response = request.execute(); ODataRetrieveResponse<ODataServiceDocument> response = request.execute();
@ -73,6 +73,7 @@ public class BasicITCase {
assertEquals(200, response.getStatusCode()); assertEquals(200, response.getStatusCode());
Edm edm = response.getBody(); Edm edm = response.getBody();
assertNotNull(edm); assertNotNull(edm);
assertEquals("com.sap.odata.test1", edm.getSchema("com.sap.odata.test1").getNamespace()); assertEquals("com.sap.odata.test1", edm.getSchema("com.sap.odata.test1").getNamespace());
assertEquals("Namespace1_Alias", edm.getSchema("com.sap.odata.test1").getAlias()); 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()) { for (final String key : parameters.keySet()) {
result.append(';').append(key).append('=').append(parameters.get(key)); result.append(';').append(key).append('=').append(parameters.get(key));
} }
if (quality < 1F) {
result.append(';').append(TypeUtil.PARAMETER_Q).append('=').append(quality);
}
return result.toString(); return result.toString();
} }
@ -225,8 +222,9 @@ public class AcceptType {
} }
Map<String, String> compareParameters = contentType.getParameters(); Map<String, String> compareParameters = contentType.getParameters();
for (final String key : parameters.keySet()) { for (final String key : parameters.keySet()) {
if (compareParameters.containsKey(key)) { if (compareParameters.containsKey(key) || TypeUtil.PARAMETER_Q.equalsIgnoreCase(key)) {
if (!parameters.get(key).equalsIgnoreCase(compareParameters.get(key))) { if (!parameters.get(key).equalsIgnoreCase(compareParameters.get(key))
&& !TypeUtil.PARAMETER_Q.equalsIgnoreCase(key)) {
return false; return false;
} }
} else { } else {

View File

@ -45,31 +45,30 @@ import java.util.TreeMap;
*/ */
public class ContentType { public class ContentType {
public static final ContentType APPLICATION_XML = create("application", "xml"); public static final ContentType APPLICATION_XML = create("application", "xml");
public static final ContentType APPLICATION_XML_CS_UTF_8 = create(APPLICATION_XML, TypeUtil.PARAMETER_CHARSET, public static final ContentType APPLICATION_XML_CS_UTF_8 = create(APPLICATION_XML, TypeUtil.PARAMETER_CHARSET,
TypeUtil.CHARSET_UTF_8); TypeUtil.CHARSET_UTF_8);
public static final ContentType APPLICATION_ATOM_XML = create("application", "atom+xml"); public static final ContentType APPLICATION_ATOM_XML = create("application", "atom+xml");
public static final ContentType APPLICATION_ATOM_XML_CS_UTF_8 = create(APPLICATION_ATOM_XML, public static final ContentType APPLICATION_ATOM_XML_CS_UTF_8 = create(APPLICATION_ATOM_XML,
TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8); TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
public static final ContentType APPLICATION_ATOM_XML_ENTRY = 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, 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 = 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, 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 = create("application", "atomsvc+xml");
public static final ContentType APPLICATION_ATOM_SVC_CS_UTF_8 = create(APPLICATION_ATOM_SVC, 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 = create("application", "json");
public static final ContentType APPLICATION_JSON_CS_UTF_8 = 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 APPLICATION_OCTET_STREAM = create("application", "octet-stream");
public static final ContentType TEXT_PLAIN = create("text", "plain"); public static final ContentType TEXT_PLAIN = create("text", "plain");
public static final ContentType TEXT_PLAIN_CS_UTF_8 = 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 MULTIPART_MIXED = create("multipart", "mixed");
public static final ContentType APPLICATION_XHTML_XML = create("application", "xhtml+xml"); public static final ContentType APPLICATION_XHTML_XML = create("application", "xhtml+xml");
@ -209,10 +208,10 @@ public class ContentType {
} }
} else { } else {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Too many '" +TypeUtil.TYPE_SUBTYPE_SEPARATOR + "' in format '" + format + "'."); "Too many '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR + "' in format '" + format + "'.");
} }
} else { } else {
throw new IllegalArgumentException("No separator '" +TypeUtil.TYPE_SUBTYPE_SEPARATOR throw new IllegalArgumentException("No separator '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR
+ "' was found in format '" + format + "'."); + "' was found in format '" + format + "'.");
} }
@ -305,7 +304,7 @@ public class ContentType {
} }
return compatible.booleanValue(); return compatible.booleanValue();
} }
/** /**
* Check equal without parameters. * Check equal without parameters.
* It is possible that no decision about <code>equal/none equal</code> can be determined a <code>NULL</code> is * It is possible that no decision about <code>equal/none equal</code> can be determined a <code>NULL</code> is

View File

@ -20,6 +20,7 @@ package org.apache.olingo.commons.api.format;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List; import java.util.List;
@ -45,15 +46,33 @@ public class AcceptTypeTest {
assertEquals("a/a", atl.get(0).toString()); 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) @Test(expected = IllegalArgumentException.class)
public void testWrongQParameter() { public void testWrongQParameter() {
AcceptType.create(" a/a;q=z "); AcceptType.create(" a/a;q=z ");
} }
@Test @Test
public void testWildcard() { public void testWildcard() {
List<AcceptType> atl = AcceptType.create("*; q=.2"); List<AcceptType> atl = AcceptType.create("*; q=.2");
assertNotNull(atl); assertNotNull(atl);
assertEquals(1, atl.size()); assertEquals(1, atl.size());
assertEquals("*", atl.get(0).getType()); assertEquals("*", atl.get(0).getType());

View File

@ -104,7 +104,7 @@ public class ContentNegotiatorTest {
@Test @Test
public void testServiceDocumentSingleCase() { 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); testContentNegotiation(useCase, ServiceDocumentProcessor.class);
} }