[OLINGO-806] Minor clean-up
Signed-off-by: Michael Bolz <michael.bolz@sap.com>
This commit is contained in:
parent
17e4a3aeff
commit
837c3565a1
|
@ -30,6 +30,7 @@ import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
|||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmSchema;
|
||||
import org.apache.olingo.commons.api.edm.EdmTerm;
|
||||
|
@ -37,7 +38,7 @@ import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
|||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.TargetType;
|
||||
import org.apache.olingo.commons.api.edm.annotation.EdmRecord;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmBoolean;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MetadataTestITCase extends AbstractTestITCase {
|
||||
|
@ -57,7 +58,7 @@ public class MetadataTestITCase extends AbstractTestITCase {
|
|||
|
||||
final EdmTerm isBoss = edm.getTerm(new FullQualifiedName(edm.getSchemas().get(0).getNamespace(), "IsBoss"));
|
||||
assertNotNull(isBoss);
|
||||
assertEquals(EdmBoolean.getInstance(), isBoss.getType());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean), isBoss.getType());
|
||||
|
||||
final EdmEntitySet orders = edm.getSchemas().get(0).getEntityContainer().getEntitySet("Orders");
|
||||
assertNotNull(orders);
|
||||
|
@ -102,10 +103,10 @@ public class MetadataTestITCase extends AbstractTestITCase {
|
|||
final EdmSchema coreAlias = edm.getSchema("Core");
|
||||
assertEquals(core, coreAlias);
|
||||
|
||||
final EdmTerm descriptionTerm = edm.getTerm(new FullQualifiedName("Core.Description"));
|
||||
final EdmTerm descriptionTerm = edm.getTerm(new FullQualifiedName("Core", "Description"));
|
||||
assertNotNull(descriptionTerm);
|
||||
assertEquals(descriptionTerm.getFullQualifiedName(),
|
||||
edm.getTerm(new FullQualifiedName("Org.OData.Core.V1.Description")).getFullQualifiedName());
|
||||
edm.getTerm(new FullQualifiedName("Org.OData.Core.V1", "Description")).getFullQualifiedName());
|
||||
|
||||
final EdmAnnotation description = core.getAnnotation(descriptionTerm, null);
|
||||
assertNotNull(description);
|
||||
|
@ -114,15 +115,16 @@ public class MetadataTestITCase extends AbstractTestITCase {
|
|||
assertEquals("Core terms needed to write vocabularies",
|
||||
description.getExpression().asConstant().getValueAsString());
|
||||
|
||||
final EdmTerm isLanguageDependent = edm.getTerm(new FullQualifiedName("Core.IsLanguageDependent"));
|
||||
final EdmTerm isLanguageDependent = edm.getTerm(new FullQualifiedName("Core", "IsLanguageDependent"));
|
||||
assertNotNull(isLanguageDependent);
|
||||
assertTrue(isLanguageDependent.getAppliesTo().contains(TargetType.Property));
|
||||
assertTrue(isLanguageDependent.getAppliesTo().contains(TargetType.Term));
|
||||
assertEquals(edm.getTypeDefinition(new FullQualifiedName("Core.Tag")), isLanguageDependent.getType());
|
||||
assertEquals(EdmBoolean.getInstance(), ((EdmTypeDefinition) isLanguageDependent.getType()).getUnderlyingType());
|
||||
assertEquals(edm.getTypeDefinition(new FullQualifiedName("Core", "Tag")), isLanguageDependent.getType());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean),
|
||||
((EdmTypeDefinition) isLanguageDependent.getType()).getUnderlyingType());
|
||||
assertNotNull(isLanguageDependent.getAnnotation(descriptionTerm, null));
|
||||
|
||||
final EdmTerm permissions = edm.getTerm(new FullQualifiedName("Core.Permissions"));
|
||||
final EdmTerm permissions = edm.getTerm(new FullQualifiedName("Core", "Permissions"));
|
||||
assertNotNull(permissions);
|
||||
assertTrue(permissions.getType() instanceof EdmEnumType);
|
||||
|
||||
|
@ -130,18 +132,18 @@ public class MetadataTestITCase extends AbstractTestITCase {
|
|||
final EdmSchema measures = edm.getSchema("UoM");
|
||||
assertNotNull(measures);
|
||||
|
||||
final EdmTerm scale = edm.getTerm(new FullQualifiedName("UoM.Scale"));
|
||||
final EdmTerm scale = edm.getTerm(new FullQualifiedName("UoM", "Scale"));
|
||||
assertNotNull(scale);
|
||||
|
||||
final EdmAnnotation requiresTypeInScale =
|
||||
scale.getAnnotation(edm.getTerm(new FullQualifiedName("Core.RequiresType")), null);
|
||||
scale.getAnnotation(edm.getTerm(new FullQualifiedName("Core", "RequiresType")), null);
|
||||
assertNotNull(requiresTypeInScale);
|
||||
assertEquals("Edm.Decimal", requiresTypeInScale.getExpression().asConstant().getValueAsString());
|
||||
|
||||
// 3. capabilities
|
||||
final EdmTerm deleteRestrictions = edm.getTerm(new FullQualifiedName("Capabilities.DeleteRestrictions"));
|
||||
final EdmTerm deleteRestrictions = edm.getTerm(new FullQualifiedName("Capabilities", "DeleteRestrictions"));
|
||||
assertNotNull(deleteRestrictions);
|
||||
assertEquals(deleteRestrictions.getType().getFullQualifiedName(),
|
||||
edm.getComplexType(new FullQualifiedName("Capabilities.DeleteRestrictionsType")).getFullQualifiedName());
|
||||
edm.getComplexType(new FullQualifiedName("Capabilities", "DeleteRestrictionsType")).getFullQualifiedName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.olingo.fit.base;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
|
@ -103,26 +104,26 @@ public class OAuth2TestITCase extends AbstractTestITCase {
|
|||
public void testOAuth() {
|
||||
try {
|
||||
readAsAtom();
|
||||
} catch (Exception e) {
|
||||
System.out.println("failed for readAsAtom");
|
||||
} catch (RuntimeException e) {
|
||||
fail("failed for readAsAtom");
|
||||
}
|
||||
|
||||
try {
|
||||
readAsFullJSON();
|
||||
} catch (Exception e) {
|
||||
System.out.println("failed for readAsFullJSON");
|
||||
} catch (RuntimeException e) {
|
||||
fail("failed for readAsFullJSON");
|
||||
}
|
||||
|
||||
try {
|
||||
readAsJSON();
|
||||
} catch (Exception e) {
|
||||
System.out.println("failed for readAsJSON");
|
||||
} catch (RuntimeException e) {
|
||||
fail("failed for readAsJSON");
|
||||
}
|
||||
|
||||
try {
|
||||
createAndDelete();
|
||||
} catch (Exception e) {
|
||||
System.out.println("failed for createAndDelete");
|
||||
} catch (RuntimeException e) {
|
||||
fail("failed for createAndDelete");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ public final class AsyncSupportITCase extends AbstractParamTecSvcITCase {
|
|||
URI uri = client.newURIBuilder(SERVICE_URI)
|
||||
.appendEntitySetSegment(ES_ALL_PRIM).build();
|
||||
|
||||
ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETAllPrim"));
|
||||
ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETAllPrim"));
|
||||
newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyInt64",
|
||||
getFactory().newPrimitiveValueBuilder().buildInt32(42)));
|
||||
newEntity.addLink(getFactory().newEntityNavigationLink(NAV_PROPERTY_ET_TWO_PRIM_ONE,
|
||||
|
|
|
@ -134,14 +134,14 @@ public class ConditionalITCase extends AbstractParamTecSvcITCase {
|
|||
public void updateWithoutIfMatch() throws Exception {
|
||||
executeAndExpectError(
|
||||
getClient().getCUDRequestFactory().getEntityUpdateRequest(
|
||||
uriEntity, UpdateType.PATCH, getFactory().newEntity(new FullQualifiedName("olingo.Order"))),
|
||||
uriEntity, UpdateType.PATCH, getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "Order"))),
|
||||
HttpStatusCode.PRECONDITION_REQUIRED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateWithWrongIfMatch() throws Exception {
|
||||
ODataEntityUpdateRequest<ClientEntity> request = getClient().getCUDRequestFactory().getEntityUpdateRequest(
|
||||
uriEntity, UpdateType.PATCH, getFactory().newEntity(new FullQualifiedName("olingo.Order")));
|
||||
uriEntity, UpdateType.PATCH, getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "Order")));
|
||||
request.setIfMatch("W/\"1\"");
|
||||
executeAndExpectError(request, HttpStatusCode.PRECONDITION_FAILED);
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ public class ConditionalITCase extends AbstractParamTecSvcITCase {
|
|||
final ODataDeleteResponse response = deleteRequest.execute();
|
||||
|
||||
ODataEntityUpdateRequest<ClientEntity> request = getClient().getCUDRequestFactory().getEntityUpdateRequest(
|
||||
uriEntity, UpdateType.PATCH, getFactory().newEntity(new FullQualifiedName("olingo.Order")));
|
||||
uriEntity, UpdateType.PATCH, getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "Order")));
|
||||
request.setIfMatch(eTag);
|
||||
// This request has to be in the same session as the first in order to access the same data provider.
|
||||
request.addCustomHeader(HttpHeader.COOKIE, response.getHeader(HttpHeader.SET_COOKIE).iterator().next());
|
||||
|
|
|
@ -273,7 +273,7 @@ public class FilterSystemQueryITCase extends AbstractParamTecSvcITCase {
|
|||
// Create new Entries
|
||||
final String filterString = "PropertyString eq null";
|
||||
|
||||
ClientEntity entity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1.ETAllPrim"));
|
||||
ClientEntity entity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETAllPrim"));
|
||||
|
||||
entity.getProperties().add(
|
||||
getFactory().newPrimitiveProperty("PropertyInt16", getFactory().newPrimitiveValueBuilder()
|
||||
|
@ -903,7 +903,7 @@ public class FilterSystemQueryITCase extends AbstractParamTecSvcITCase {
|
|||
// is still there, but filled is null values (primitive types)
|
||||
// We define a filter, which returns all entry where PropertyCompComp/PropertyComp/PropertyInt16 is equals to 1
|
||||
|
||||
ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
|
||||
ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETKeyNav"));
|
||||
newEntity.getProperties().add(getFactory().newComplexProperty("PropertyCompCompNav", null));
|
||||
newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyInt16",
|
||||
getFactory().newPrimitiveValueBuilder().buildInt16((short) 4)));
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.io.BufferedReader;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StringReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -55,10 +54,7 @@ public class StringHelper {
|
|||
}
|
||||
|
||||
public int byteLength() {
|
||||
if(data == null) {
|
||||
return -1;
|
||||
}
|
||||
return data.length;
|
||||
return data == null ? -1 : data.length;
|
||||
}
|
||||
|
||||
public String asString() {
|
||||
|
@ -69,15 +65,6 @@ public class StringHelper {
|
|||
return new String(data, Charset.forName(charsetName));
|
||||
}
|
||||
|
||||
public Stream print(final OutputStream out) throws IOException {
|
||||
out.write(data);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Stream print() throws IOException {
|
||||
return print(System.out);
|
||||
}
|
||||
|
||||
public String asStringWithLineSeparation(String separator) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new StringReader(asString()));
|
||||
StringBuilder sb = new StringBuilder(br.readLine());
|
||||
|
|
|
@ -259,7 +259,9 @@ public final class URIUtils {
|
|||
? quoteString((String) obj, singleQuoteEscape)
|
||||
: obj.toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (final EdmPrimitiveTypeException e) {
|
||||
value = obj.toString();
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
value = obj.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,6 @@ public class JSONTest extends AbstractTest {
|
|||
final StringWriter writer = new StringWriter();
|
||||
getClient().getSerializer(contentType).write(writer, getClient().getDeserializer(contentType).toEntity(
|
||||
getClass().getResourceAsStream(filename + "." + getSuffix(contentType))).getPayload());
|
||||
System.out.println(writer.toString());
|
||||
assertSimilar(filename + "." + getSuffix(contentType), writer.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -331,7 +331,7 @@ public class CsdlSchema extends CsdlAbstractEdmItem implements CsdlAnnotatable {
|
|||
|
||||
/**
|
||||
* Sets a list of annotations
|
||||
* @param annotations list of annotations
|
||||
* @param annotationGroups list of annotations
|
||||
* @return this instance
|
||||
*/
|
||||
public CsdlSchema setAnnotationsGroup(final List<CsdlAnnotations> annotationGroups) {
|
||||
|
|
|
@ -33,7 +33,7 @@ public abstract class CsdlExpression extends CsdlAbstractEdmItem {
|
|||
}
|
||||
|
||||
/**
|
||||
* Casts the expression to {@link org.apache.olingo.commons.api.edm.annotation.CsdlConstantExpression}
|
||||
* Casts the expression to {@link CsdlConstantExpression}.
|
||||
* @return Constant Expression
|
||||
*/
|
||||
public CsdlConstantExpression asConstant() {
|
||||
|
@ -41,7 +41,7 @@ public abstract class CsdlExpression extends CsdlAbstractEdmItem {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return true if the expression is dynamic
|
||||
* Returns true if the expression is dynamic.
|
||||
* @return true if the expression is dynamic
|
||||
*/
|
||||
public boolean isDynamic() {
|
||||
|
@ -49,7 +49,7 @@ public abstract class CsdlExpression extends CsdlAbstractEdmItem {
|
|||
}
|
||||
|
||||
/**
|
||||
* Cast the expression to {@link org.apache.olingo.commons.api.edm.annotation.CsdlDynamicExpression}
|
||||
* Cast the expression to {@link CsdlDynamicExpression}.
|
||||
* @return Dynamic Expression
|
||||
*/
|
||||
public CsdlDynamicExpression asDynamic() {
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.olingo.commons.api.edm.provider.annotation;
|
|||
|
||||
/**
|
||||
* The edm:LabeledElementReference expression returns the value of an
|
||||
* edm:LabeledElement (see {@link LabeledElement}) expression.
|
||||
* edm:LabeledElement (see {@link CsdlLabeledElement}) expression.
|
||||
*/
|
||||
public class CsdlLabeledElementReference extends CsdlDynamicExpression {
|
||||
private static final long serialVersionUID = -4793707024628773226L;
|
||||
|
|
|
@ -79,7 +79,7 @@ public class EdmRecordImplTest extends AbstractAnnotationTest {
|
|||
CsdlRecord csdlRecord = new CsdlRecord();
|
||||
csdlRecord.setType("ns.et");
|
||||
Edm mock = mock(Edm.class);
|
||||
when(mock.getEntityType(new FullQualifiedName("ns.et"))).thenReturn(mock(EdmEntityType.class));
|
||||
when(mock.getEntityType(new FullQualifiedName("ns", "et"))).thenReturn(mock(EdmEntityType.class));
|
||||
List<CsdlPropertyValue> propertyValues = new ArrayList<CsdlPropertyValue>();
|
||||
propertyValues.add(new CsdlPropertyValue());
|
||||
csdlRecord.setPropertyValues(propertyValues);
|
||||
|
@ -106,7 +106,7 @@ public class EdmRecordImplTest extends AbstractAnnotationTest {
|
|||
CsdlRecord csdlRecord = new CsdlRecord();
|
||||
csdlRecord.setType("ns.ct");
|
||||
Edm mock = mock(Edm.class);
|
||||
when(mock.getComplexType(new FullQualifiedName("ns.ct"))).thenReturn(mock(EdmComplexType.class));
|
||||
when(mock.getComplexType(new FullQualifiedName("ns", "ct"))).thenReturn(mock(EdmComplexType.class));
|
||||
EdmExpression record = AbstractEdmExpression.getExpression(mock, csdlRecord);
|
||||
|
||||
EdmDynamicExpression dynExp = assertDynamic(record);
|
||||
|
@ -137,7 +137,7 @@ public class EdmRecordImplTest extends AbstractAnnotationTest {
|
|||
}
|
||||
|
||||
// Enum
|
||||
when(edm.getEnumType(new FullQualifiedName("ns.enum"))).thenReturn(mock(EdmEnumType.class));
|
||||
when(edm.getEnumType(new FullQualifiedName("ns", "enum"))).thenReturn(mock(EdmEnumType.class));
|
||||
exp = AbstractEdmExpression.getExpression(edm, new CsdlRecord().setType("ns.enum"));
|
||||
record = exp.asDynamic().asRecord();
|
||||
try {
|
||||
|
@ -147,7 +147,7 @@ public class EdmRecordImplTest extends AbstractAnnotationTest {
|
|||
}
|
||||
|
||||
// Typedef
|
||||
when(edm.getTypeDefinition(new FullQualifiedName("ns.typedef"))).thenReturn(mock(EdmTypeDefinition.class));
|
||||
when(edm.getTypeDefinition(new FullQualifiedName("ns", "typedef"))).thenReturn(mock(EdmTypeDefinition.class));
|
||||
exp = AbstractEdmExpression.getExpression(edm, new CsdlRecord().setType("ns.typedef"));
|
||||
record = exp.asDynamic().asRecord();
|
||||
try {
|
||||
|
|
|
@ -631,7 +631,6 @@ public class MetadataParser {
|
|||
element = event.asStartElement();
|
||||
if (element.getName().getLocalPart().equals(name)) {
|
||||
reader.nextEvent(); // advance cursor
|
||||
// System.out.println("reading = "+names[i]);
|
||||
build(reader, element, t, name);
|
||||
hit = true;
|
||||
}
|
||||
|
@ -640,7 +639,6 @@ public class MetadataParser {
|
|||
EndElement e = event.asEndElement();
|
||||
if (e.getName().getLocalPart().equals(name)) {
|
||||
reader.nextEvent(); // advance cursor
|
||||
// System.out.println("done reading = "+names[i]);
|
||||
hit = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,8 +235,8 @@ public interface ServiceHandler extends Processor {
|
|||
/**
|
||||
* Delete references (relationships) in an Entity
|
||||
* @param request
|
||||
* @param deleteId; for collection valued navigation this will be non-null value; for single valued
|
||||
* navigation property, this will be null.
|
||||
* @param deleteId for collection valued navigation this will be non-null value;
|
||||
* for single valued navigation property, this will be null
|
||||
* @param entityETag
|
||||
* @param response - always should be 204
|
||||
* @throws ODataLibraryException
|
||||
|
|
|
@ -46,8 +46,6 @@ import org.apache.olingo.commons.api.edm.EdmProperty;
|
|||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmStream;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.ODataLibraryException;
|
||||
|
@ -165,7 +163,7 @@ public class DataRequest extends ServiceRequest {
|
|||
return false;
|
||||
}
|
||||
EdmProperty property = ((UriResourcePrimitiveProperty)this.uriResourceProperty).getProperty();
|
||||
return (property.getType() instanceof EdmStream);
|
||||
return property.getType() == odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Stream);
|
||||
}
|
||||
|
||||
public UriResourceProperty getUriResourceProperty() {
|
||||
|
@ -601,9 +599,10 @@ public class DataRequest extends ServiceRequest {
|
|||
|
||||
@Override
|
||||
public ContentType getResponseContentType() throws ContentNegotiatorException {
|
||||
RepresentationType valueRepresentationType = uriResourceProperty.getType() == EdmPrimitiveTypeFactory
|
||||
.getInstance(EdmPrimitiveTypeKind.Binary) ? RepresentationType.BINARY
|
||||
: RepresentationType.VALUE;
|
||||
RepresentationType valueRepresentationType =
|
||||
uriResourceProperty.getType() == odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Binary) ?
|
||||
RepresentationType.BINARY :
|
||||
RepresentationType.VALUE;
|
||||
return ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request,
|
||||
getCustomContentTypeSupport(), valueRepresentationType);
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ public class MetadataParserTest {
|
|||
CsdlProperty p = ct.getProperties().get(0);
|
||||
assertEquals("CountryRegion", p.getName());
|
||||
assertEquals("Edm.String", p.getType());
|
||||
assertEquals(false, p.isNullable());
|
||||
assertFalse(p.isNullable());
|
||||
|
||||
ct = provider.getComplexType(new FullQualifiedName(NS, "Location"));
|
||||
assertNotNull(ct);
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
package org.apache.olingo.server.core;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
@ -246,8 +248,8 @@ public class ServiceDispatcherTest {
|
|||
Mockito.verify(handler).read(arg1.capture(), arg2.capture());
|
||||
|
||||
DataRequest request = arg1.getValue();
|
||||
assertEquals(true, request.isPropertyRequest());
|
||||
assertEquals(false, request.isPropertyComplex());
|
||||
assertTrue(request.isPropertyRequest());
|
||||
assertFalse(request.isPropertyComplex());
|
||||
assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
|
||||
assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
|
||||
.toContentTypeString());
|
||||
|
@ -266,8 +268,8 @@ public class ServiceDispatcherTest {
|
|||
Mockito.verify(handler).read(arg1.capture(), arg2.capture());
|
||||
|
||||
DataRequest request = arg1.getValue();
|
||||
assertEquals(true, request.isPropertyRequest());
|
||||
assertEquals(true, request.isPropertyComplex());
|
||||
assertTrue(request.isPropertyRequest());
|
||||
assertTrue(request.isPropertyComplex());
|
||||
assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
|
||||
assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
|
||||
.toContentTypeString());
|
||||
|
@ -287,8 +289,8 @@ public class ServiceDispatcherTest {
|
|||
Mockito.verify(handler).read(arg1.capture(), arg2.capture());
|
||||
|
||||
DataRequest request = arg1.getValue();
|
||||
assertEquals(true, request.isPropertyRequest());
|
||||
assertEquals(false, request.isPropertyComplex());
|
||||
assertTrue(request.isPropertyRequest());
|
||||
assertFalse(request.isPropertyComplex());
|
||||
assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
|
||||
assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
|
||||
}
|
||||
|
@ -307,8 +309,8 @@ public class ServiceDispatcherTest {
|
|||
Mockito.verify(handler).read(arg1.capture(), arg2.capture());
|
||||
|
||||
DataRequest request = arg1.getValue();
|
||||
assertEquals(true, request.isPropertyRequest());
|
||||
assertEquals(false, request.isPropertyComplex());
|
||||
assertTrue(request.isPropertyRequest());
|
||||
assertFalse(request.isPropertyComplex());
|
||||
assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
|
||||
assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.apache.http.entity.ContentType;
|
|||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.olingo.commons.core.Encoder;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
|
@ -283,8 +282,8 @@ public class TripPinServiceTest {
|
|||
public void testLambdaAny() throws Exception {
|
||||
// this is just testing to see the lamda expressions are going through the
|
||||
// framework, none of the system options are not implemented in example service
|
||||
String query = "Friends/any(d:d/UserName eq 'foo')";
|
||||
HttpResponse response = httpGET(baseURL + "/People?$filter="+Encoder.encode(query), 200);
|
||||
String query = "Friends/any(d%3Ad/UserName%20eq%20'foo')";
|
||||
HttpResponse response = httpGET(baseURL + "/People?$filter=" + query, 200);
|
||||
EntityUtils.consumeQuietly(response.getEntity());
|
||||
}
|
||||
|
||||
|
@ -727,9 +726,9 @@ public class TripPinServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCrossJoin() throws Exception {
|
||||
String editUrl = baseURL + "/$crossjoin(People,Airlines)?$filter="+
|
||||
Encoder.encode("People/UserName eq Airlines/AirlineCode");
|
||||
public void crossJoin() throws Exception {
|
||||
String editUrl = baseURL + "/$crossjoin(People,Airlines)?$filter="
|
||||
+ "People/UserName%20eq%20Airlines/AirlineCode";
|
||||
HttpResponse response = httpGET(editUrl, 200);
|
||||
EntityUtils.consumeQuietly(response.getEntity());
|
||||
}
|
||||
|
|
|
@ -34,13 +34,14 @@ import org.apache.olingo.server.api.etag.ServiceMetadataETagSupport;
|
|||
*/
|
||||
public class ServiceMetadataImpl implements ServiceMetadata {
|
||||
|
||||
private final EdmProviderImpl edm;
|
||||
private final List<EdmxReference> references = new ArrayList<EdmxReference>();
|
||||
private final Edm edm;
|
||||
private final List<EdmxReference> references;
|
||||
private final ServiceMetadataETagSupport serviceMetadataETagSupport;
|
||||
|
||||
public ServiceMetadataImpl(CsdlEdmProvider edmProvider, List<EdmxReference> references,
|
||||
ServiceMetadataETagSupport serviceMetadataETagSupport) {
|
||||
edm = new EdmProviderImpl(edmProvider);
|
||||
this.references = new ArrayList<EdmxReference>();
|
||||
this.references.addAll(references);
|
||||
this.serviceMetadataETagSupport = serviceMetadataETagSupport;
|
||||
}
|
||||
|
|
|
@ -44,13 +44,14 @@ import org.apache.olingo.commons.api.edm.EdmEntityType;
|
|||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||
import org.apache.olingo.commons.api.ex.ODataErrorDetail;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.server.api.ODataServerError;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
|
||||
|
@ -729,7 +730,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
|||
final Boolean isUnicode, final XMLStreamWriter writer)
|
||||
throws EdmPrimitiveTypeException, XMLStreamException, SerializerException {
|
||||
if (property.isPrimitive()) {
|
||||
if (!(type instanceof EdmString)) {
|
||||
if (type != EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String)) {
|
||||
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
|
||||
type.getKind() == EdmTypeKind.DEFINITION ?
|
||||
"#" + type.getFullQualifiedName().getFullQualifiedNameAsString() :
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.olingo.server.core.uri;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
|
@ -33,7 +34,7 @@ import org.apache.olingo.server.api.uri.UriResourceKind;
|
|||
*/
|
||||
public class UriResourceFunctionImpl extends UriResourceWithKeysImpl implements UriResourceFunction {
|
||||
|
||||
protected List<UriParameterImpl> parameters;
|
||||
protected List<UriParameter> parameters;
|
||||
protected EdmFunction function;
|
||||
protected EdmFunctionImport functionImport;
|
||||
private boolean isParameterListFilled = false;
|
||||
|
@ -44,14 +45,12 @@ public class UriResourceFunctionImpl extends UriResourceWithKeysImpl implements
|
|||
|
||||
@Override
|
||||
public List<UriParameter> getParameters() {
|
||||
List<UriParameter> retList = new ArrayList<UriParameter>();
|
||||
for (UriParameterImpl item : parameters) {
|
||||
retList.add(item);
|
||||
}
|
||||
return retList;
|
||||
return parameters == null ?
|
||||
Collections.<UriParameter> emptyList() :
|
||||
new ArrayList<UriParameter>(parameters);
|
||||
}
|
||||
|
||||
public UriResourceFunctionImpl setParameters(final List<UriParameterImpl> parameters) {
|
||||
public UriResourceFunctionImpl setParameters(final List<UriParameter> parameters) {
|
||||
isParameterListFilled = true;
|
||||
this.parameters = parameters;
|
||||
return this;
|
||||
|
@ -73,11 +72,9 @@ public class UriResourceFunctionImpl extends UriResourceWithKeysImpl implements
|
|||
}
|
||||
|
||||
public UriResourceFunctionImpl setFunctionImport(final EdmFunctionImport edmFI,
|
||||
final List<UriParameterImpl> parameters) {
|
||||
final List<UriParameter> parameters) {
|
||||
functionImport = edmFI;
|
||||
|
||||
setParameters(parameters);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -88,14 +85,11 @@ public class UriResourceFunctionImpl extends UriResourceWithKeysImpl implements
|
|||
|
||||
@Override
|
||||
public boolean isCollection() {
|
||||
if (keyPredicates != null) {
|
||||
return false;
|
||||
}
|
||||
return function.getReturnType().isCollection();
|
||||
return keyPredicates == null && function.getReturnType().isCollection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSegmentValue(){
|
||||
public String getSegmentValue() {
|
||||
if (functionImport != null) {
|
||||
return functionImport.getName();
|
||||
} else if (function != null) {
|
||||
|
@ -103,7 +97,7 @@ public class UriResourceFunctionImpl extends UriResourceWithKeysImpl implements
|
|||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getSegmentValue();
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
package org.apache.olingo.server.core.uri;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.server.api.uri.UriParameter;
|
||||
import org.apache.olingo.server.api.uri.UriResourceKind;
|
||||
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
|
||||
|
@ -30,7 +30,7 @@ import org.apache.olingo.server.api.uri.UriResourcePartTyped;
|
|||
public abstract class UriResourceWithKeysImpl extends UriResourceImpl implements UriResourcePartTyped {
|
||||
|
||||
protected EdmType collectionTypeFilter = null;
|
||||
protected List<UriParameterImpl> keyPredicates = null;
|
||||
protected List<UriParameter> keyPredicates = null;
|
||||
protected EdmType entryTypeFilter = null;
|
||||
|
||||
public UriResourceWithKeysImpl(final UriResourceKind kind) {
|
||||
|
@ -46,16 +46,12 @@ public abstract class UriResourceWithKeysImpl extends UriResourceImpl implements
|
|||
}
|
||||
|
||||
public List<UriParameter> getKeyPredicates() {
|
||||
List<UriParameter> retList = new ArrayList<UriParameter>();
|
||||
if (keyPredicates != null) {
|
||||
for (UriParameterImpl item : keyPredicates) {
|
||||
retList.add(item);
|
||||
}
|
||||
}
|
||||
return retList;
|
||||
return keyPredicates == null ?
|
||||
Collections.<UriParameter> emptyList() :
|
||||
new ArrayList<UriParameter>(keyPredicates);
|
||||
}
|
||||
|
||||
public UriResourceWithKeysImpl setKeyPredicates(final List<UriParameterImpl> list) {
|
||||
public UriResourceWithKeysImpl setKeyPredicates(final List<UriParameter> list) {
|
||||
keyPredicates = list;
|
||||
return this;
|
||||
}
|
||||
|
@ -100,7 +96,7 @@ public abstract class UriResourceWithKeysImpl extends UriResourceImpl implements
|
|||
}
|
||||
|
||||
private String getFQN(final EdmType type) {
|
||||
return new FullQualifiedName(type.getNamespace(), type.getName()).getFullQualifiedNameAsString();
|
||||
return type.getFullQualifiedName().getFullQualifiedNameAsString();
|
||||
}
|
||||
|
||||
}
|
|
@ -50,12 +50,14 @@ import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
|||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.server.api.uri.UriInfoKind;
|
||||
import org.apache.olingo.server.api.uri.UriInfoResource;
|
||||
import org.apache.olingo.server.api.uri.UriParameter;
|
||||
import org.apache.olingo.server.api.uri.UriResource;
|
||||
import org.apache.olingo.server.api.uri.UriResourceEntitySet;
|
||||
import org.apache.olingo.server.api.uri.UriResourceFunction;
|
||||
import org.apache.olingo.server.api.uri.UriResourceNavigation;
|
||||
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
|
||||
import org.apache.olingo.server.api.uri.UriResourceRoot;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectItem;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind;
|
||||
|
@ -373,7 +375,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
|||
}
|
||||
context.contextReadingFunctionParameters = true;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<UriParameterImpl> parameters = (List<UriParameterImpl>) ctx.vlNVO.get(0).accept(this);
|
||||
List<UriParameter> parameters = (List<UriParameter>) ctx.vlNVO.get(0).accept(this);
|
||||
context.contextReadingFunctionParameters = false;
|
||||
|
||||
// mark parameters as consumed
|
||||
|
@ -384,7 +386,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
|||
|
||||
// collect parameter names
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (UriParameterImpl item : parameters) {
|
||||
for (UriParameter item : parameters) {
|
||||
names.add(item.getName());
|
||||
}
|
||||
|
||||
|
@ -672,12 +674,12 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
|||
|
||||
context.contextReadingFunctionParameters = true;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<UriParameterImpl> parameters = (List<UriParameterImpl>) ctx.vlNVO.get(0).accept(this);
|
||||
List<UriParameter> parameters = (List<UriParameter>) ctx.vlNVO.get(0).accept(this);
|
||||
context.contextReadingFunctionParameters = false;
|
||||
|
||||
// get names of function parameters
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (UriParameterImpl item : parameters) {
|
||||
for (UriParameter item : parameters) {
|
||||
names.add(item.getName());
|
||||
}
|
||||
|
||||
|
@ -1907,7 +1909,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<UriParameterImpl> list = (List<UriParameterImpl>) ctx.vlNVO.get(0).accept(this);
|
||||
List<UriParameter> list = (List<UriParameter>) ctx.vlNVO.get(0).accept(this);
|
||||
((UriResourceWithKeysImpl) pathInfoSegment)
|
||||
.setKeyPredicates(list);
|
||||
} else {
|
||||
|
@ -2110,10 +2112,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
|||
|
||||
@Override
|
||||
public Object visitSelect(final SelectContext ctx) {
|
||||
List<SelectItemImpl> selectItems = new ArrayList<SelectItemImpl>();
|
||||
|
||||
List<SelectItem> selectItems = new ArrayList<SelectItem>();
|
||||
for (SelectItemContext si : ctx.vlSI) {
|
||||
selectItems.add((SelectItemImpl) si.accept(this));
|
||||
selectItems.add((SelectItem) si.accept(this));
|
||||
}
|
||||
|
||||
return new SelectOptionImpl().setSelectItems(selectItems).setText(ctx.children.get(2).getText());
|
||||
|
@ -2121,10 +2122,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
|||
|
||||
@Override
|
||||
public Object visitSelectEOF(final SelectEOFContext ctx) {
|
||||
List<SelectItemImpl> selectItems = new ArrayList<SelectItemImpl>();
|
||||
|
||||
List<SelectItem> selectItems = new ArrayList<SelectItem>();
|
||||
for (SelectItemContext si : ctx.vlSI) {
|
||||
selectItems.add((SelectItemImpl) si.accept(this));
|
||||
selectItems.add((SelectItem) si.accept(this));
|
||||
}
|
||||
|
||||
return new SelectOptionImpl().setSelectItems(selectItems).setText(ctx.getText());
|
||||
|
@ -2345,7 +2345,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
|||
prevType = getTypeInformation(last).type;
|
||||
}
|
||||
|
||||
FullQualifiedName finalTypeName = new FullQualifiedName(prevType.getNamespace(), prevType.getName());
|
||||
final FullQualifiedName finalTypeName = prevType.getFullQualifiedName();
|
||||
|
||||
// check for action
|
||||
EdmAction action = edm.getBoundAction(fullName, finalTypeName, null);
|
||||
|
|
|
@ -19,18 +19,18 @@
|
|||
package org.apache.olingo.server.core.uri.queryoption;
|
||||
|
||||
import org.apache.olingo.server.api.uri.queryoption.AliasQueryOption;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.Expression;
|
||||
|
||||
public class AliasQueryOptionImpl extends QueryOptionImpl implements AliasQueryOption {
|
||||
|
||||
private ExpressionImpl aliasValue;
|
||||
private Expression aliasValue;
|
||||
|
||||
@Override
|
||||
public ExpressionImpl getValue() {
|
||||
public Expression getValue() {
|
||||
return aliasValue;
|
||||
}
|
||||
|
||||
public AliasQueryOptionImpl setAliasValue(final ExpressionImpl aliasValue) {
|
||||
public AliasQueryOption setAliasValue(final Expression aliasValue) {
|
||||
this.aliasValue = aliasValue;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -53,50 +53,49 @@ public class ExpandItemImpl implements ExpandItem {
|
|||
private boolean isRef;
|
||||
private EdmType startTypeFilter;
|
||||
|
||||
public ExpandItemImpl setSystemQueryOption(final SystemQueryOptionImpl sysItem) {
|
||||
public ExpandItemImpl setSystemQueryOption(final SystemQueryOption sysItem) {
|
||||
|
||||
if (sysItem instanceof ExpandOptionImpl) {
|
||||
if (sysItem instanceof ExpandOption) {
|
||||
validateDoubleSystemQueryOption(expandOption, sysItem);
|
||||
expandOption = (ExpandOptionImpl) sysItem;
|
||||
} else if (sysItem instanceof FilterOptionImpl) {
|
||||
expandOption = (ExpandOption) sysItem;
|
||||
} else if (sysItem instanceof FilterOption) {
|
||||
validateDoubleSystemQueryOption(filterOption, sysItem);
|
||||
filterOption = (FilterOptionImpl) sysItem;
|
||||
} else if (sysItem instanceof CountOptionImpl) {
|
||||
filterOption = (FilterOption) sysItem;
|
||||
} else if (sysItem instanceof CountOption) {
|
||||
validateDoubleSystemQueryOption(inlineCountOption, sysItem);
|
||||
inlineCountOption = (CountOptionImpl) sysItem;
|
||||
} else if (sysItem instanceof OrderByOptionImpl) {
|
||||
inlineCountOption = (CountOption) sysItem;
|
||||
} else if (sysItem instanceof OrderByOption) {
|
||||
validateDoubleSystemQueryOption(orderByOption, sysItem);
|
||||
orderByOption = (OrderByOptionImpl) sysItem;
|
||||
} else if (sysItem instanceof SearchOptionImpl) {
|
||||
orderByOption = (OrderByOption) sysItem;
|
||||
} else if (sysItem instanceof SearchOption) {
|
||||
validateDoubleSystemQueryOption(searchOption, sysItem);
|
||||
searchOption = (SearchOptionImpl) sysItem;
|
||||
} else if (sysItem instanceof SelectOptionImpl) {
|
||||
searchOption = (SearchOption) sysItem;
|
||||
} else if (sysItem instanceof SelectOption) {
|
||||
validateDoubleSystemQueryOption(selectOption, sysItem);
|
||||
selectOption = (SelectOptionImpl) sysItem;
|
||||
} else if (sysItem instanceof SkipOptionImpl) {
|
||||
selectOption = (SelectOption) sysItem;
|
||||
} else if (sysItem instanceof SkipOption) {
|
||||
validateDoubleSystemQueryOption(skipOption, sysItem);
|
||||
skipOption = (SkipOptionImpl) sysItem;
|
||||
} else if (sysItem instanceof TopOptionImpl) {
|
||||
skipOption = (SkipOption) sysItem;
|
||||
} else if (sysItem instanceof TopOption) {
|
||||
validateDoubleSystemQueryOption(topOption, sysItem);
|
||||
topOption = (TopOptionImpl) sysItem;
|
||||
topOption = (TopOption) sysItem;
|
||||
} else if (sysItem instanceof LevelsExpandOption) {
|
||||
if(levelsExpandOption != null) {
|
||||
if (levelsExpandOption != null) {
|
||||
throw new ODataRuntimeException("$levels");
|
||||
}
|
||||
levelsExpandOption = (LevelsExpandOption) sysItem;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
private void validateDoubleSystemQueryOption(final SystemQueryOption oldOption, final SystemQueryOption newOption) {
|
||||
if(oldOption != null) {
|
||||
if (oldOption != null) {
|
||||
throw new ODataRuntimeException(newOption.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public ExpandItemImpl setSystemQueryOptions(final List<SystemQueryOptionImpl> list) {
|
||||
|
||||
for (SystemQueryOptionImpl item : list) {
|
||||
public ExpandItemImpl setSystemQueryOptions(final List<SystemQueryOption> list) {
|
||||
for (SystemQueryOption item : list) {
|
||||
setSystemQueryOption(item);
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -27,20 +27,20 @@ import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
|
|||
|
||||
public class ExpandOptionImpl extends SystemQueryOptionImpl implements ExpandOption {
|
||||
|
||||
List<ExpandItemImpl> expandItems = new ArrayList<ExpandItemImpl>();
|
||||
List<ExpandItem> expandItems = new ArrayList<ExpandItem>();
|
||||
|
||||
public ExpandOptionImpl() {
|
||||
setKind(SystemQueryOptionKind.EXPAND);
|
||||
}
|
||||
|
||||
public void addExpandItem(final ExpandItemImpl expandItem) {
|
||||
public void addExpandItem(final ExpandItem expandItem) {
|
||||
expandItems.add(expandItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExpandItem> getExpandItems() {
|
||||
List<ExpandItem> retList = new ArrayList<ExpandItem>();
|
||||
for (ExpandItemImpl item : expandItems) {
|
||||
for (ExpandItem item : expandItems) {
|
||||
retList.add(item);
|
||||
}
|
||||
return retList;
|
||||
|
|
|
@ -20,23 +20,23 @@ package org.apache.olingo.server.core.uri.queryoption;
|
|||
|
||||
import org.apache.olingo.server.api.uri.queryoption.FilterOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.Expression;
|
||||
|
||||
public class FilterOptionImpl extends SystemQueryOptionImpl implements FilterOption {
|
||||
|
||||
private ExpressionImpl expression;
|
||||
private Expression expression;
|
||||
|
||||
public FilterOptionImpl() {
|
||||
setKind(SystemQueryOptionKind.FILTER);
|
||||
}
|
||||
|
||||
public FilterOptionImpl setExpression(final ExpressionImpl expression) {
|
||||
public FilterOptionImpl setExpression(final Expression expression) {
|
||||
this.expression = expression;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionImpl getExpression() {
|
||||
public Expression getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
|
|||
|
||||
public class OrderByOptionImpl extends SystemQueryOptionImpl implements OrderByOption {
|
||||
|
||||
private List<OrderByItemImpl> orders = new ArrayList<OrderByItemImpl>();
|
||||
private List<OrderByItem> orders = new ArrayList<OrderByItem>();
|
||||
|
||||
public OrderByOptionImpl() {
|
||||
setKind(SystemQueryOptionKind.ORDERBY);
|
||||
|
@ -36,13 +36,13 @@ public class OrderByOptionImpl extends SystemQueryOptionImpl implements OrderByO
|
|||
@Override
|
||||
public List<OrderByItem> getOrders() {
|
||||
List<OrderByItem> retList = new ArrayList<OrderByItem>();
|
||||
for (OrderByItemImpl item : orders) {
|
||||
for (OrderByItem item : orders) {
|
||||
retList.add(item);
|
||||
}
|
||||
return retList;
|
||||
}
|
||||
|
||||
public OrderByOptionImpl addOrder(final OrderByItemImpl order) {
|
||||
public OrderByOptionImpl addOrder(final OrderByItem order) {
|
||||
orders.add(order);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.olingo.server.core.uri.queryoption;
|
|||
|
||||
import org.apache.olingo.server.api.uri.queryoption.QueryOption;
|
||||
|
||||
public class QueryOptionImpl implements QueryOption {
|
||||
public abstract class QueryOptionImpl implements QueryOption {
|
||||
private String name;
|
||||
private String text;
|
||||
|
||||
|
|
|
@ -27,13 +27,13 @@ import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
|
|||
|
||||
public class SelectOptionImpl extends SystemQueryOptionImpl implements SelectOption {
|
||||
|
||||
private List<SelectItemImpl> selectItems;
|
||||
private List<SelectItem> selectItems;
|
||||
|
||||
public SelectOptionImpl() {
|
||||
setKind(SystemQueryOptionKind.SELECT);
|
||||
}
|
||||
|
||||
public SelectOptionImpl setSelectItems(final List<SelectItemImpl> selectItems) {
|
||||
public SelectOptionImpl setSelectItems(final List<SelectItem> selectItems) {
|
||||
this.selectItems = selectItems;
|
||||
return this;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class SelectOptionImpl extends SystemQueryOptionImpl implements SelectOpt
|
|||
@Override
|
||||
public List<SelectItem> getSelectItems() {
|
||||
List<SelectItem> retList = new ArrayList<SelectItem>();
|
||||
for (SelectItemImpl item : selectItems) {
|
||||
for (SelectItem item : selectItems) {
|
||||
retList.add(item);
|
||||
}
|
||||
return retList;
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.apache.olingo.server.core.uri.queryoption;
|
|||
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
|
||||
|
||||
public class SystemQueryOptionImpl extends QueryOptionImpl implements SystemQueryOption {
|
||||
public abstract class SystemQueryOptionImpl extends QueryOptionImpl implements SystemQueryOption {
|
||||
|
||||
private SystemQueryOptionKind kind;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import static org.junit.Assert.fail;
|
|||
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.server.api.ODataLibraryException.MessageKey;
|
||||
import org.apache.olingo.server.api.ODataLibraryException;
|
||||
import org.apache.olingo.server.api.ODataServerError;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.api.etag.PreconditionException;
|
||||
|
@ -36,102 +37,78 @@ public class ExceptionHelperTest {
|
|||
|
||||
@Test
|
||||
public void withRuntimeException() {
|
||||
try {
|
||||
throw new NullPointerException();
|
||||
} catch (NullPointerException e) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
|
||||
assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), serverError.getStatusCode());
|
||||
assertEquals("OData Library: An exception without message text was thrown.", serverError.getMessage());
|
||||
assertEquals(e, serverError.getException());
|
||||
}
|
||||
final Exception e = new NullPointerException();
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
|
||||
assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), serverError.getStatusCode());
|
||||
assertEquals("OData Library: An exception without message text was thrown.", serverError.getMessage());
|
||||
assertEquals(e, serverError.getException());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withRuntimeExceptionAndText() {
|
||||
try {
|
||||
throw new NullPointerException("Text");
|
||||
} catch (NullPointerException e) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
|
||||
assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), serverError.getStatusCode());
|
||||
assertEquals("Text", serverError.getMessage());
|
||||
assertEquals(e, serverError.getException());
|
||||
}
|
||||
final Exception e = new NullPointerException("Text");
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
|
||||
assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), serverError.getStatusCode());
|
||||
assertEquals("Text", serverError.getMessage());
|
||||
assertEquals(e, serverError.getException());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriValidatorExceptionMustLeadTo400() {
|
||||
public void uriValidatorExceptionMustLeadToBadRequest() {
|
||||
for (MessageKey key : UriValidationException.MessageKeys.values()) {
|
||||
try {
|
||||
throw new UriValidationException(DEV_MSG, key);
|
||||
} catch (UriValidationException e) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
assertEquals("FailedKey: " + e.getMessageKey().getKey(), HttpStatusCode.BAD_REQUEST.getStatusCode(),
|
||||
serverError.getStatusCode());
|
||||
}
|
||||
final UriValidationException e = new UriValidationException(DEV_MSG, key);
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
checkStatusCode(serverError, HttpStatusCode.BAD_REQUEST, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deserializerExceptionMustLeadTo400() {
|
||||
public void deserializerExceptionMustLeadToBadRequest() {
|
||||
for (MessageKey key : DeserializerException.MessageKeys.values()) {
|
||||
try {
|
||||
throw new DeserializerException(DEV_MSG, key);
|
||||
} catch (DeserializerException e) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
assertEquals("FailedKey: " + e.getMessageKey().getKey(), HttpStatusCode.BAD_REQUEST.getStatusCode(),
|
||||
serverError.getStatusCode());
|
||||
}
|
||||
final DeserializerException e = new DeserializerException(DEV_MSG, key);
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
checkStatusCode(serverError, HttpStatusCode.BAD_REQUEST, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializerExceptionMustLeadTo400() {
|
||||
public void serializerExceptionMustLeadToBadRequest() {
|
||||
for (MessageKey key : SerializerException.MessageKeys.values()) {
|
||||
try {
|
||||
throw new SerializerException(DEV_MSG, key);
|
||||
} catch (SerializerException e) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
assertEquals("FailedKey: " + e.getMessageKey().getKey(), HttpStatusCode.BAD_REQUEST.getStatusCode(),
|
||||
serverError.getStatusCode());
|
||||
}
|
||||
final SerializerException e = new SerializerException(DEV_MSG, key);
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
checkStatusCode(serverError, HttpStatusCode.BAD_REQUEST, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentNegotiatorExceptionMustLeadTo406() {
|
||||
public void contentNegotiatorExceptionMustLeadToNotAcceptable() {
|
||||
for (MessageKey key : ContentNegotiatorException.MessageKeys.values()) {
|
||||
try {
|
||||
throw new ContentNegotiatorException(DEV_MSG, key);
|
||||
} catch (ContentNegotiatorException e) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
assertEquals("FailedKey: " + e.getMessageKey().getKey(), HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(),
|
||||
serverError.getStatusCode());
|
||||
}
|
||||
final ContentNegotiatorException e = new ContentNegotiatorException(DEV_MSG, key);
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
checkStatusCode(serverError, HttpStatusCode.NOT_ACCEPTABLE, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preconditionRequiredTesting() {
|
||||
for (MessageKey key : PreconditionException.MessageKeys.values()) {
|
||||
try {
|
||||
throw new PreconditionException(DEV_MSG, key);
|
||||
} catch (PreconditionException e) {
|
||||
if (e.getMessageKey().equals(PreconditionException.MessageKeys.FAILED)) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
assertEquals("FailedKey: " + e.getMessageKey().getKey(), HttpStatusCode.PRECONDITION_FAILED.getStatusCode(),
|
||||
serverError.getStatusCode());
|
||||
} else if (e.getMessageKey().equals(PreconditionException.MessageKeys.MISSING_HEADER)) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
assertEquals("FailedKey: " + e.getMessageKey().getKey(), HttpStatusCode.PRECONDITION_REQUIRED.getStatusCode(),
|
||||
serverError.getStatusCode());
|
||||
} else if (e.getMessageKey().equals(PreconditionException.MessageKeys.INVALID_URI)) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
assertEquals("FailedKey: " + e.getMessageKey().getKey(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
serverError.getStatusCode());
|
||||
} else {
|
||||
fail("Unexpected message key for: " + e.getClass().getName());
|
||||
}
|
||||
final PreconditionException e = new PreconditionException(DEV_MSG, key);
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
if (e.getMessageKey().equals(PreconditionException.MessageKeys.FAILED)) {
|
||||
checkStatusCode(serverError, HttpStatusCode.PRECONDITION_FAILED, e);
|
||||
} else if (e.getMessageKey().equals(PreconditionException.MessageKeys.MISSING_HEADER)) {
|
||||
checkStatusCode(serverError, HttpStatusCode.PRECONDITION_REQUIRED, e);
|
||||
} else if (e.getMessageKey().equals(PreconditionException.MessageKeys.INVALID_URI)) {
|
||||
checkStatusCode(serverError, HttpStatusCode.INTERNAL_SERVER_ERROR, e);
|
||||
} else {
|
||||
fail("Unexpected message key for: " + e.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStatusCode(final ODataServerError serverError, final HttpStatusCode statusCode,
|
||||
final ODataLibraryException exception) {
|
||||
assertEquals("FailedKey: " + exception.getMessageKey().getKey(),
|
||||
serverError.getStatusCode(), statusCode.getStatusCode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,18 +26,13 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
|||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.deserializer.FixedFormatDeserializer;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public class FixedFormatDeserializerTest {
|
||||
|
||||
private static final OData oData = OData.newInstance();
|
||||
private final FixedFormatDeserializer deserializer;
|
||||
|
||||
public FixedFormatDeserializerTest() throws SerializerException {
|
||||
deserializer = oData.createFixedFormatDeserializer();
|
||||
}
|
||||
private final FixedFormatDeserializer deserializer = oData.createFixedFormatDeserializer();
|
||||
|
||||
@Test
|
||||
public void binary() throws Exception {
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.apache.olingo.server.core.deserializer.json;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
@ -34,23 +33,14 @@ import org.junit.Test;
|
|||
|
||||
public class ODataJsonDeserializerBasicTest {
|
||||
|
||||
@Test
|
||||
public void checkSupportedJsonFormats() throws Exception {
|
||||
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
|
||||
assertNotNull(deserializer);
|
||||
deserializer = null;
|
||||
private final ODataDeserializer deserializer;
|
||||
|
||||
deserializer = OData.newInstance().createDeserializer(ContentType.JSON_NO_METADATA);
|
||||
assertNotNull(deserializer);
|
||||
deserializer = null;
|
||||
|
||||
deserializer = OData.newInstance().createDeserializer(ContentType.JSON_FULL_METADATA);
|
||||
assertNotNull(deserializer);
|
||||
deserializer = null;
|
||||
public ODataJsonDeserializerBasicTest() throws DeserializerException {
|
||||
deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadingCollectionProperties() throws Exception {
|
||||
public void collectionProperties() throws Exception {
|
||||
String payload = "{\n" +
|
||||
" \"@odata.context\": \"http://host/service/$metadata#Collection($ref)\",\n" +
|
||||
" \"value\": [\n" +
|
||||
|
@ -58,7 +48,6 @@ public class ODataJsonDeserializerBasicTest {
|
|||
" { \"@odata.id\": \"Orders(10759)\" }\n" +
|
||||
" ]\n" +
|
||||
"}";
|
||||
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
|
||||
List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()))
|
||||
.getEntityReferences();
|
||||
assertEquals(2, values.size());
|
||||
|
@ -67,12 +56,11 @@ public class ODataJsonDeserializerBasicTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testReadingProperties() throws Exception {
|
||||
public void properties() throws Exception {
|
||||
String payload = "{\n" +
|
||||
" \"@odata.context\": \"http://host/service/$metadata#$ref\",\n" +
|
||||
" \"@odata.id\": \"Orders(10643)\"\n" +
|
||||
"}";
|
||||
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
|
||||
List<URI> values = deserializer.entityReferences(new ByteArrayInputStream(payload
|
||||
.getBytes())).getEntityReferences();
|
||||
assertEquals(1, values.size());
|
||||
|
@ -87,7 +75,6 @@ public class ODataJsonDeserializerBasicTest {
|
|||
+ "}";
|
||||
|
||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
||||
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
|
||||
final List<URI> entityReferences = deserializer.entityReferences(stream).getEntityReferences();
|
||||
|
||||
assertEquals(1, entityReferences.size());
|
||||
|
@ -105,7 +92,6 @@ public class ODataJsonDeserializerBasicTest {
|
|||
"}";
|
||||
|
||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
||||
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
|
||||
final List<URI> entityReferences = deserializer.entityReferences(stream).getEntityReferences();
|
||||
|
||||
assertEquals(2, entityReferences.size());
|
||||
|
@ -124,7 +110,6 @@ public class ODataJsonDeserializerBasicTest {
|
|||
"}";
|
||||
|
||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
||||
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
|
||||
final List<URI> entityReferences = deserializer.entityReferences(stream).getEntityReferences();
|
||||
|
||||
assertEquals(1, entityReferences.size());
|
||||
|
@ -142,7 +127,6 @@ public class ODataJsonDeserializerBasicTest {
|
|||
"}";
|
||||
|
||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
||||
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
|
||||
final List<URI> entityReferences = deserializer.entityReferences(stream).getEntityReferences();
|
||||
|
||||
assertEquals(1, entityReferences.size());
|
||||
|
@ -158,7 +142,6 @@ public class ODataJsonDeserializerBasicTest {
|
|||
"}";
|
||||
|
||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
||||
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
|
||||
final List<URI> entityReferences = deserializer.entityReferences(stream).getEntityReferences();
|
||||
|
||||
assertEquals(0, entityReferences.size());
|
||||
|
@ -167,20 +150,18 @@ public class ODataJsonDeserializerBasicTest {
|
|||
@Test(expected = DeserializerException.class)
|
||||
public void referencesEmpty() throws Exception {
|
||||
/*
|
||||
* See OData JSON Format chaper 13
|
||||
* See OData JSON Format chapter 13
|
||||
* ... the object that MUST contain the id of the referenced entity
|
||||
*/
|
||||
String entityString = "{ }";
|
||||
|
||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
||||
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
|
||||
deserializer.entityReferences(stream).getEntityReferences();
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
public void referencesNoContent() throws Exception {
|
||||
OData.newInstance().createDeserializer(ContentType.JSON).entityReferences(
|
||||
new ByteArrayInputStream(new byte[] {}));
|
||||
deserializer.entityReferences(new ByteArrayInputStream(new byte[] {}));
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
|
@ -191,7 +172,6 @@ public class ODataJsonDeserializerBasicTest {
|
|||
"}";
|
||||
|
||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
||||
ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
|
||||
deserializer.entityReferences(stream);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import static org.junit.Assert.assertEquals;
|
|||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.serializer.FixedFormatSerializer;
|
||||
import org.apache.olingo.server.api.serializer.PrimitiveValueSerializerOptions;
|
||||
|
@ -50,7 +49,7 @@ public class FixedFormatSerializerTest {
|
|||
|
||||
@Test
|
||||
public void primitiveValue() throws Exception {
|
||||
final EdmPrimitiveType type = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
|
||||
final EdmPrimitiveType type = OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int32);
|
||||
assertEquals("42", IOUtils.toString(serializer.primitiveValue(type, 42,
|
||||
PrimitiveValueSerializerOptions.with().nullable(true).build())));
|
||||
}
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core.serializer.json;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.ex.ODataException;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
|
||||
import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl;
|
||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
||||
|
||||
public class ComplexTypeHelper {
|
||||
|
||||
public static EdmComplexType createType() throws ODataException {
|
||||
CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
|
||||
EdmProviderImpl edm = new EdmProviderImpl(provider);
|
||||
|
||||
FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName");
|
||||
CsdlComplexType baseComplexType = new CsdlComplexType();
|
||||
List<CsdlProperty> baseProperties = new ArrayList<CsdlProperty>();
|
||||
baseProperties.add(new CsdlProperty().setName("prop1").setType(
|
||||
EdmPrimitiveTypeKind.String.getFullQualifiedName()));
|
||||
List<CsdlNavigationProperty> baseNavigationProperties = new ArrayList<CsdlNavigationProperty>();
|
||||
baseNavigationProperties.add(new CsdlNavigationProperty().setName("nav1"));
|
||||
baseComplexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(baseProperties)
|
||||
.setNavigationProperties(baseNavigationProperties);
|
||||
when(provider.getComplexType(baseName)).thenReturn(baseComplexType);
|
||||
|
||||
FullQualifiedName name = new FullQualifiedName("namespace", "typeName");
|
||||
CsdlComplexType complexType = new CsdlComplexType().setBaseType(baseName);
|
||||
List<CsdlProperty> properties = new ArrayList<CsdlProperty>();
|
||||
properties.add(new CsdlProperty().setName("prop2").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
|
||||
List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>();
|
||||
navigationProperties.add(new CsdlNavigationProperty().setName("nav2"));
|
||||
complexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(properties)
|
||||
.setNavigationProperties(navigationProperties);
|
||||
when(provider.getComplexType(name)).thenReturn(complexType);
|
||||
|
||||
return new EdmComplexTypeImpl(edm, name, complexType);
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core.serializer.json;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.ex.ODataException;
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ODataJsonSerializerTest {
|
||||
@Test
|
||||
public void testCollectionComplex() throws ODataException, IOException {
|
||||
final List<ComplexValue> col = new ArrayList<ComplexValue>();
|
||||
col.add(getValues(1));
|
||||
col.add(getValues(2));
|
||||
final Property complexCollection = new Property(null, "ComplexCol", ValueType.COLLECTION_COMPLEX, col);
|
||||
|
||||
final ODataJsonSerializer serializer = new ODataJsonSerializer(ContentType.APPLICATION_JSON);
|
||||
final ComplexSerializerOptions options = ComplexSerializerOptions.with()
|
||||
.contextURL(ContextURL.with().selectList("ComplexCollection").build()).build();
|
||||
final InputStream in = serializer.complexCollection(null, ComplexTypeHelper.createType(),
|
||||
complexCollection, options).getContent();
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.contains("value")) {
|
||||
assertEquals(
|
||||
"{\"@odata.context\":\"$metadata(ComplexCollection)\",\"value\":"
|
||||
+ "[{\"prop1\":\"test1\",\"prop2\":\"test11\"},{\"prop1\":\"test2\",\"prop2\":\"test22\"}]}",
|
||||
line);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ComplexValue getValues(final int i) {
|
||||
ComplexValue value = new ComplexValue();
|
||||
value.getValue().add(new Property(null, "prop1", ValueType.PRIMITIVE, "test" + i));
|
||||
value.getValue().add(new Property(null, "prop2", ValueType.PRIMITIVE, "test" + i + i));
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
@ -32,7 +33,6 @@ import org.apache.olingo.server.api.OData;
|
|||
import org.apache.olingo.server.api.ODataServerError;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
@ -41,10 +41,9 @@ import com.fasterxml.jackson.databind.node.JsonNodeType;
|
|||
|
||||
public class ServerErrorSerializerTest {
|
||||
|
||||
ODataSerializer ser;
|
||||
final ODataSerializer ser;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
public ServerErrorSerializerTest() throws SerializerException {
|
||||
ser = OData.newInstance().createSerializer(ContentType.JSON);
|
||||
}
|
||||
|
||||
|
@ -110,10 +109,10 @@ public class ServerErrorSerializerTest {
|
|||
|
||||
@Test
|
||||
public void verifiedWithJacksonParser() throws Exception {
|
||||
List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>();
|
||||
details.add(new ODataErrorDetail().setCode("detailCode").setMessage("detailMessage").setTarget("detailTarget"));
|
||||
ODataServerError error =
|
||||
new ODataServerError().setCode("Code").setMessage("Message").setTarget("Target").setDetails(details);
|
||||
new ODataServerError().setCode("Code").setMessage("Message").setTarget("Target")
|
||||
.setDetails(Collections.singletonList(
|
||||
new ODataErrorDetail().setCode("detailCode").setMessage("detailMessage").setTarget("detailTarget")));
|
||||
InputStream stream = ser.error(error).getContent();
|
||||
JsonNode tree = new ObjectMapper().readTree(stream);
|
||||
assertNotNull(tree);
|
||||
|
|
|
@ -23,8 +23,6 @@ import static org.mockito.Mockito.mock;
|
|||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
import org.apache.olingo.commons.api.data.ContextURL.Suffix;
|
||||
|
@ -33,23 +31,18 @@ import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
|||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
|
||||
import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl;
|
||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public class ContextURLBuilderTest {
|
||||
|
||||
private static final URI serviceRoot = URI.create("http://host/service/");
|
||||
|
||||
@Test
|
||||
public void buildServiceDocument() {
|
||||
final ContextURL contextURL = ContextURL.with()
|
||||
.serviceRoot(URI.create("http://host/service/")).build();
|
||||
assertEquals("http://host/service/$metadata", ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
final ContextURL contextURL = ContextURL.with().serviceRoot(serviceRoot).build();
|
||||
assertEquals(serviceRoot + "$metadata", ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -62,10 +55,10 @@ public class ContextURLBuilderTest {
|
|||
public void buildEntitySet() {
|
||||
EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class);
|
||||
Mockito.when(entitySet.getName()).thenReturn("Customers");
|
||||
final ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
final ContextURL contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.entitySet(entitySet)
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#Customers", ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
assertEquals(serviceRoot + "$metadata#Customers", ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -74,11 +67,11 @@ public class ContextURLBuilderTest {
|
|||
Mockito.when(entitySet.getName()).thenReturn("Customers");
|
||||
EdmEntityType derivedType = Mockito.mock(EdmEntityType.class);
|
||||
Mockito.when(derivedType.getFullQualifiedName()).thenReturn(new FullQualifiedName("Model", "VipCustomer"));
|
||||
final ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
final ContextURL contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.entitySet(entitySet)
|
||||
.derived(derivedType)
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#Customers/Model.VipCustomer",
|
||||
assertEquals(serviceRoot + "$metadata#Customers/Model.VipCustomer",
|
||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
||||
|
@ -86,30 +79,30 @@ public class ContextURLBuilderTest {
|
|||
public void buildEntitySetWithEntitySuffix() {
|
||||
EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class);
|
||||
Mockito.when(entitySet.getName()).thenReturn("Customers");
|
||||
final ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
final ContextURL contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.entitySet(entitySet)
|
||||
.suffix(Suffix.ENTITY)
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#Customers/$entity", ContextURLBuilder.create(contextURL)
|
||||
.toASCIIString());
|
||||
assertEquals(serviceRoot + "$metadata#Customers/$entity",
|
||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildEntity() {
|
||||
EdmEntityType entityType = mock(EdmEntityType.class);
|
||||
when(entityType.getFullQualifiedName()).thenReturn(new FullQualifiedName("namespace.entityType"));
|
||||
ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
when(entityType.getFullQualifiedName()).thenReturn(new FullQualifiedName("namespace", "entityType"));
|
||||
ContextURL contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.type(entityType)
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#namespace.entityType", ContextURLBuilder.create(contextURL)
|
||||
.toASCIIString());
|
||||
assertEquals(serviceRoot + "$metadata#namespace.entityType",
|
||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
|
||||
contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.type(entityType)
|
||||
.asCollection()
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#Collection(namespace.entityType)", ContextURLBuilder.create(contextURL)
|
||||
.toASCIIString());
|
||||
assertEquals(serviceRoot + "$metadata#Collection(namespace.entityType)",
|
||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
@ -125,12 +118,12 @@ public class ContextURLBuilderTest {
|
|||
Mockito.when(entitySet.getName()).thenReturn("Customers");
|
||||
EdmEntityType derivedType = Mockito.mock(EdmEntityType.class);
|
||||
Mockito.when(derivedType.getFullQualifiedName()).thenReturn(new FullQualifiedName("Model", "VipCustomer"));
|
||||
final ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
final ContextURL contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.entitySet(entitySet)
|
||||
.derived(derivedType)
|
||||
.suffix(Suffix.ENTITY)
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#Customers/Model.VipCustomer/$entity",
|
||||
assertEquals(serviceRoot + "$metadata#Customers/Model.VipCustomer/$entity",
|
||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
||||
|
@ -138,72 +131,55 @@ public class ContextURLBuilderTest {
|
|||
public void buildProperty() {
|
||||
EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class);
|
||||
Mockito.when(entitySet.getName()).thenReturn("Customers");
|
||||
ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
ContextURL contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.entitySet(entitySet)
|
||||
.keyPath("1")
|
||||
.navOrPropertyPath("Name")
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#Customers(1)/Name",
|
||||
assertEquals(serviceRoot + "$metadata#Customers(1)/Name",
|
||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
|
||||
contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.entitySet(entitySet)
|
||||
.keyPath("one=1,two='two'")
|
||||
.navOrPropertyPath("ComplexName")
|
||||
.selectList("Part1")
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#Customers(one=1,two='two')/ComplexName(Part1)",
|
||||
assertEquals(serviceRoot + "$metadata#Customers(one=1,two='two')/ComplexName(Part1)",
|
||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildPrimitiveType() {
|
||||
EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class);
|
||||
Mockito.when(entitySet.getName()).thenReturn("Customers");
|
||||
ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
.type(EdmString.getInstance())
|
||||
ContextURL contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.type(OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String))
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#Edm.String",
|
||||
assertEquals(serviceRoot + "$metadata#Edm.String",
|
||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
|
||||
contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
.type(EdmString.getInstance()).asCollection()
|
||||
contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.type(OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String)).asCollection()
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#Collection(Edm.String)",
|
||||
assertEquals(serviceRoot + "$metadata#Collection(Edm.String)",
|
||||
ContextURLBuilder.create(contextURL).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildComplexType() throws Exception {
|
||||
CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
|
||||
EdmProviderImpl edm = new EdmProviderImpl(provider);
|
||||
EdmComplexType baseType = mock(EdmComplexType.class);
|
||||
when(baseType.getFullQualifiedName()).thenReturn(new FullQualifiedName("namespace", "BaseTypeName"));
|
||||
|
||||
FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName");
|
||||
CsdlComplexType baseComplexType = new CsdlComplexType();
|
||||
List<CsdlProperty> baseProperties = new ArrayList<CsdlProperty>();
|
||||
baseProperties.add(new CsdlProperty().setName("prop1").setType(
|
||||
EdmPrimitiveTypeKind.String.getFullQualifiedName()));
|
||||
List<CsdlNavigationProperty> baseNavigationProperties = new ArrayList<CsdlNavigationProperty>();
|
||||
baseNavigationProperties.add(new CsdlNavigationProperty().setName("nav1"));
|
||||
baseComplexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(baseProperties)
|
||||
.setNavigationProperties(baseNavigationProperties);
|
||||
when(provider.getComplexType(baseName)).thenReturn(baseComplexType);
|
||||
|
||||
EdmComplexType baseType = new EdmComplexTypeImpl(edm, baseName, baseComplexType);
|
||||
|
||||
EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class);
|
||||
Mockito.when(entitySet.getName()).thenReturn("Customers");
|
||||
ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
ContextURL contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.type(baseType)
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#namespace.BaseTypeName",
|
||||
assertEquals(serviceRoot + "$metadata#namespace.BaseTypeName",
|
||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
|
||||
contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/"))
|
||||
contextURL = ContextURL.with().serviceRoot(serviceRoot)
|
||||
.type(baseType)
|
||||
.asCollection()
|
||||
.build();
|
||||
assertEquals("http://host/service/$metadata#Collection(namespace.BaseTypeName)",
|
||||
assertEquals(serviceRoot + "$metadata#Collection(namespace.BaseTypeName)",
|
||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
||||
|
@ -220,8 +196,8 @@ public class ContextURLBuilderTest {
|
|||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void buildReferenceWithEntitySet() {
|
||||
EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class);
|
||||
Mockito.when(entitySet.getName()).thenReturn("Customers");
|
||||
EdmEntitySet entitySet = mock(EdmEntitySet.class);
|
||||
when(entitySet.getName()).thenReturn("Customers");
|
||||
ContextURLBuilder.create(ContextURL.with().entitySet(entitySet).suffix(Suffix.REFERENCE).build());
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,9 @@ import java.util.List;
|
|||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmSchema;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlAction;
|
||||
|
@ -85,7 +87,6 @@ import org.apache.olingo.commons.api.edm.provider.annotation.CsdlUrlRef;
|
|||
//CHECKSTYLE:ON
|
||||
import org.apache.olingo.commons.api.ex.ODataException;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||
|
@ -130,33 +131,12 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
|
||||
InputStream metadata = serializer.metadataDocument(serviceMetadata).getContent();
|
||||
assertNotNull(metadata);
|
||||
assertEquals("<?xml version='1.0' encoding='UTF-8'?>" +
|
||||
"<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" +
|
||||
"<edmx:DataServices>" +
|
||||
"<Schema xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" Namespace=\"MyNamespace\"/>" +
|
||||
"</edmx:DataServices>" +
|
||||
"</edmx:Edmx>",
|
||||
IOUtils.toString(metadata));
|
||||
}
|
||||
|
||||
/** Writes simplest (empty) Schema. */
|
||||
@Test
|
||||
public void writeMetadataWithSimpleSchema() throws Exception {
|
||||
EdmSchema schema = mock(EdmSchema.class);
|
||||
when(schema.getNamespace()).thenReturn("MyNamespace");
|
||||
Edm edm = mock(Edm.class);
|
||||
when(edm.getSchemas()).thenReturn(Arrays.asList(schema));
|
||||
ServiceMetadata serviceMetadata = mock(ServiceMetadata.class);
|
||||
when(serviceMetadata.getEdm()).thenReturn(edm);
|
||||
|
||||
InputStream metadata = serializer.metadataDocument(serviceMetadata).getContent();
|
||||
assertNotNull(metadata);
|
||||
assertEquals("<?xml version='1.0' encoding='UTF-8'?>" +
|
||||
"<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" +
|
||||
"<edmx:DataServices>" +
|
||||
"<Schema xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" Namespace=\"MyNamespace\"/>" +
|
||||
"</edmx:DataServices>" +
|
||||
"</edmx:Edmx>",
|
||||
assertEquals("<?xml version='1.0' encoding='UTF-8'?>"
|
||||
+ "<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">"
|
||||
+ "<edmx:DataServices>"
|
||||
+ "<Schema xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" Namespace=\"MyNamespace\"/>"
|
||||
+ "</edmx:DataServices>"
|
||||
+ "</edmx:Edmx>",
|
||||
IOUtils.toString(metadata));
|
||||
}
|
||||
|
||||
|
@ -370,17 +350,38 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
List<EdmComplexType> complexTypes = new ArrayList<EdmComplexType>();
|
||||
|
||||
FullQualifiedName name = new FullQualifiedName("namespace", "ComplexType");
|
||||
CsdlComplexType complexType = new CsdlComplexType();
|
||||
complexType.setAbstract(true);
|
||||
complexType.setName(name.getName());
|
||||
complexType.setOpenType(true);
|
||||
List<CsdlProperty> properties = new ArrayList<CsdlProperty>();
|
||||
EdmComplexType complexType = mock(EdmComplexType.class);
|
||||
when(complexType.isAbstract()).thenReturn(true);
|
||||
when(complexType.getFullQualifiedName()).thenReturn(name);
|
||||
when(complexType.getName()).thenReturn(name.getName());
|
||||
when(complexType.isOpenType()).thenReturn(true);
|
||||
|
||||
properties.add(new CsdlProperty().setName("prop1").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
|
||||
properties.add(new CsdlProperty().setName("prop2").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
|
||||
final EdmPrimitiveType stringType = OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String);
|
||||
when(complexType.getPropertyNames()).thenReturn(Arrays.asList("prop1", "prop2"));
|
||||
EdmProperty prop1 = mock(EdmProperty.class);
|
||||
when(prop1.isPrimitive()).thenReturn(true);
|
||||
when(prop1.getType()).thenReturn(stringType);
|
||||
when(prop1.isNullable()).thenReturn(true);
|
||||
when(prop1.getMaxLength()).thenReturn(null);
|
||||
when(prop1.getPrecision()).thenReturn(null);
|
||||
when(prop1.getScale()).thenReturn(null);
|
||||
when(prop1.isUnicode()).thenReturn(true);
|
||||
when(complexType.getStructuralProperty("prop1")).thenReturn(prop1);
|
||||
EdmProperty prop2 = mock(EdmProperty.class);
|
||||
when(prop2.isPrimitive()).thenReturn(true);
|
||||
when(prop2.getType()).thenReturn(stringType);
|
||||
when(prop2.isNullable()).thenReturn(true);
|
||||
when(prop2.getMaxLength()).thenReturn(null);
|
||||
when(prop2.getPrecision()).thenReturn(null);
|
||||
when(prop2.getScale()).thenReturn(null);
|
||||
when(prop2.isUnicode()).thenReturn(true);
|
||||
when(complexType.getStructuralProperty("prop2")).thenReturn(prop2);
|
||||
complexTypes.add(complexType);
|
||||
|
||||
complexType.setProperties(properties);
|
||||
EdmComplexTypeImpl c1 = new EdmComplexTypeImpl(edm, name, complexType);
|
||||
EdmComplexType c1 = mock(EdmComplexType.class);
|
||||
when(c1.getFullQualifiedName()).thenReturn(new FullQualifiedName("namespace", "C1"));
|
||||
when(c1.getName()).thenReturn("C1");
|
||||
when(c1.getBaseType()).thenReturn(complexType);
|
||||
complexTypes.add(c1);
|
||||
|
||||
when(schema.getComplexTypes()).thenReturn(complexTypes);
|
||||
|
@ -418,20 +419,17 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
|
||||
@Override
|
||||
public List<CsdlAliasInfo> getAliasInfos() throws ODataException {
|
||||
return Arrays.asList(
|
||||
new CsdlAliasInfo().setAlias("Alias").setNamespace(nameSpace)
|
||||
);
|
||||
return Collections.singletonList(new CsdlAliasInfo().setAlias("Alias").setNamespace(nameSpace));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsdlEnumType getEnumType(final FullQualifiedName enumTypeName) throws ODataException {
|
||||
if ("ENString".equals(enumTypeName.getName())) {
|
||||
if (nameENString.equals(enumTypeName)) {
|
||||
return new CsdlEnumType()
|
||||
.setName("ENString")
|
||||
.setName(nameENString.getName())
|
||||
.setFlags(true)
|
||||
.setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName())
|
||||
.setMembers(Arrays.asList(
|
||||
new CsdlEnumMember().setName("String1").setValue("1")));
|
||||
.setMembers(Collections.singletonList(new CsdlEnumMember().setName("String1").setValue("1")));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -442,15 +440,14 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
return new CsdlEntityType()
|
||||
.setName("ETAbstract")
|
||||
.setAbstract(true)
|
||||
.setProperties(Arrays.asList(propertyString));
|
||||
.setProperties(Collections.singletonList(propertyString));
|
||||
|
||||
} else if (entityTypeName.equals(nameETAbstractBase)) {
|
||||
return new CsdlEntityType()
|
||||
.setName("ETAbstractBase")
|
||||
.setBaseType(nameETAbstract)
|
||||
.setKey(Arrays.asList(new CsdlPropertyRef().setName("PropertyInt16")))
|
||||
.setProperties(Arrays.asList(
|
||||
propertyInt16_NotNullable));
|
||||
.setKey(Collections.singletonList(new CsdlPropertyRef().setName("PropertyInt16")))
|
||||
.setProperties(Collections.singletonList(propertyInt16_NotNullable));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -468,7 +465,6 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
.setName("CTTwoPrimBase")
|
||||
.setBaseType(nameCTTwoPrim)
|
||||
.setProperties(Arrays.asList(propertyInt16_NotNullable, propertyString));
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
|
@ -477,14 +473,11 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
@Override
|
||||
public List<CsdlAction> getActions(final FullQualifiedName actionName) throws ODataException {
|
||||
if (actionName.equals(nameUARTPrimParam)) {
|
||||
return Arrays.asList(
|
||||
return Collections.singletonList(
|
||||
new CsdlAction().setName("UARTPrimParam")
|
||||
.setParameters(Arrays.asList(
|
||||
.setParameters(Collections.singletonList(
|
||||
new CsdlParameter().setName("ParameterInt16").setType(nameInt16)))
|
||||
|
||||
.setReturnType(new CsdlReturnType().setType(nameString))
|
||||
);
|
||||
|
||||
.setReturnType(new CsdlReturnType().setType(nameString)));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -492,14 +485,11 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
@Override
|
||||
public List<CsdlFunction> getFunctions(final FullQualifiedName functionName) throws ODataException {
|
||||
if (functionName.equals(nameUFNRTInt16)) {
|
||||
return Arrays.asList(
|
||||
return Collections.singletonList(
|
||||
new CsdlFunction()
|
||||
.setName("UFNRTInt16")
|
||||
.setParameters(new ArrayList<CsdlParameter>())
|
||||
.setReturnType(
|
||||
new CsdlReturnType().setType(nameInt16))
|
||||
);
|
||||
|
||||
.setParameters(Collections.<CsdlParameter> emptyList())
|
||||
.setReturnType(new CsdlReturnType().setType(nameInt16)));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -511,7 +501,6 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
return new CsdlEntitySet()
|
||||
.setName("ESAllPrim")
|
||||
.setType(nameETAbstractBase);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -523,7 +512,6 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
return new CsdlSingleton()
|
||||
.setName("SI")
|
||||
.setType(nameETAbstractBase);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -536,7 +524,6 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
return new CsdlActionImport()
|
||||
.setName("AIRTPrimParam")
|
||||
.setAction(nameUARTPrimParam);
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -552,7 +539,6 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
.setName("FINRTInt16")
|
||||
.setFunction(nameUFNRTInt16)
|
||||
.setIncludeInServiceDocument(true);
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -565,52 +551,42 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
schema.setNamespace(nameSpace);
|
||||
schema.setAlias("Alias");
|
||||
schemas.add(schema);
|
||||
// EnumTypes
|
||||
List<CsdlEnumType> enumTypes = new ArrayList<CsdlEnumType>();
|
||||
schema.setEnumTypes(enumTypes);
|
||||
enumTypes.add(getEnumType(nameENString));
|
||||
// EntityTypes
|
||||
List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
|
||||
schema.setEntityTypes(entityTypes);
|
||||
|
||||
entityTypes.add(getEntityType(nameETAbstract));
|
||||
entityTypes.add(getEntityType(nameETAbstractBase));
|
||||
// EnumTypes
|
||||
schema.setEnumTypes(Collections.singletonList(getEnumType(nameENString)));
|
||||
|
||||
// EntityTypes
|
||||
schema.setEntityTypes(Arrays.asList(
|
||||
getEntityType(nameETAbstract),
|
||||
getEntityType(nameETAbstractBase)));
|
||||
|
||||
// ComplexTypes
|
||||
List<CsdlComplexType> complexType = new ArrayList<CsdlComplexType>();
|
||||
schema.setComplexTypes(complexType);
|
||||
complexType.add(getComplexType(nameCTTwoPrim));
|
||||
complexType.add(getComplexType(nameCTTwoPrimBase));
|
||||
schema.setComplexTypes(Arrays.asList(
|
||||
getComplexType(nameCTTwoPrim),
|
||||
getComplexType(nameCTTwoPrimBase)));
|
||||
|
||||
// TypeDefinitions
|
||||
|
||||
// Actions
|
||||
List<CsdlAction> actions = new ArrayList<CsdlAction>();
|
||||
schema.setActions(actions);
|
||||
actions.addAll(getActions(nameUARTPrimParam));
|
||||
schema.setActions(getActions(nameUARTPrimParam));
|
||||
|
||||
// Functions
|
||||
List<CsdlFunction> functions = new ArrayList<CsdlFunction>();
|
||||
schema.setFunctions(functions);
|
||||
|
||||
functions.addAll(getFunctions(nameUFNRTInt16));
|
||||
schema.setFunctions(getFunctions(nameUFNRTInt16));
|
||||
|
||||
// EntityContainer
|
||||
schema.setEntityContainer(getEntityContainer());
|
||||
|
||||
//Terms
|
||||
List<CsdlTerm> terms = new ArrayList<CsdlTerm>();
|
||||
terms.add(getTerm(new FullQualifiedName("ns.term")));
|
||||
terms.add(getTerm(new FullQualifiedName("namespace.Term1")));
|
||||
terms.add(getTerm(new FullQualifiedName("ns.Term2")));
|
||||
terms.add(getTerm(new FullQualifiedName("ns.Term3")));
|
||||
terms.add(getTerm(new FullQualifiedName("ns.Term4")));
|
||||
schema.setTerms(terms);
|
||||
|
||||
schema.setTerms(Arrays.asList(
|
||||
getTerm(new FullQualifiedName("ns","term")),
|
||||
getTerm(new FullQualifiedName("namespace", "Term1")),
|
||||
getTerm(new FullQualifiedName("ns", "Term2")),
|
||||
getTerm(new FullQualifiedName("ns", "Term3")),
|
||||
getTerm(new FullQualifiedName("ns", "Term4"))));
|
||||
|
||||
// Annotationgroups
|
||||
List<CsdlAnnotations> annotationGroups = new ArrayList<CsdlAnnotations>();
|
||||
annotationGroups.add(getAnnotationsGroup(new FullQualifiedName("Alias.ETAbstract"), "Tablett"));
|
||||
schema.setAnnotationsGroup(annotationGroups);
|
||||
schema.setAnnotationsGroup(Collections.singletonList(
|
||||
getAnnotationsGroup(new FullQualifiedName("Alias", "ETAbstract"), "Tablett")));
|
||||
|
||||
return schemas;
|
||||
}
|
||||
|
@ -630,24 +606,16 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
container.setName("container");
|
||||
|
||||
// EntitySets
|
||||
List<CsdlEntitySet> entitySets = new ArrayList<CsdlEntitySet>();
|
||||
container.setEntitySets(entitySets);
|
||||
entitySets.add(getEntitySet(nameContainer, "ESAllPrim"));
|
||||
container.setEntitySets(Collections.singletonList(getEntitySet(nameContainer, "ESAllPrim")));
|
||||
|
||||
// Singletons
|
||||
List<CsdlSingleton> singletons = new ArrayList<CsdlSingleton>();
|
||||
container.setSingletons(singletons);
|
||||
singletons.add(getSingleton(nameContainer, "SI"));
|
||||
container.setSingletons(Collections.singletonList(getSingleton(nameContainer, "SI")));
|
||||
|
||||
// ActionImports
|
||||
List<CsdlActionImport> actionImports = new ArrayList<CsdlActionImport>();
|
||||
container.setActionImports(actionImports);
|
||||
actionImports.add(getActionImport(nameContainer, "AIRTPrimParam"));
|
||||
container.setActionImports(Collections.singletonList(getActionImport(nameContainer, "AIRTPrimParam")));
|
||||
|
||||
// FunctionImports
|
||||
List<CsdlFunctionImport> functionImports = new ArrayList<CsdlFunctionImport>();
|
||||
container.setFunctionImports(functionImports);
|
||||
functionImports.add(getFunctionImport(nameContainer, "FINRTInt16"));
|
||||
container.setFunctionImports(Collections.singletonList(getFunctionImport(nameContainer, "FINRTInt16")));
|
||||
|
||||
return container;
|
||||
}
|
||||
|
@ -659,36 +627,36 @@ public class MetadataDocumentXmlSerializerTest {
|
|||
|
||||
@Override
|
||||
public CsdlTerm getTerm(FullQualifiedName termName) throws ODataException {
|
||||
if (new FullQualifiedName("ns.term").equals(termName)) {
|
||||
if (new FullQualifiedName("ns", "term").equals(termName)) {
|
||||
return new CsdlTerm().setType("Edm.String").setName("term");
|
||||
|
||||
} else if(new FullQualifiedName("namespace.Term1").equals(termName)){
|
||||
|
||||
} else if(new FullQualifiedName("namespace", "Term1").equals(termName)){
|
||||
return new CsdlTerm().setType("Edm.String").setName("Term1");
|
||||
|
||||
} else if(new FullQualifiedName("ns.Term2").equals(termName)){
|
||||
|
||||
} else if(new FullQualifiedName("ns", "Term2").equals(termName)){
|
||||
return new CsdlTerm().setType("Edm.String").setName("Term2")
|
||||
.setNullable(false).setDefaultValue("default").setMaxLength(1).setPrecision(2).setScale(3);
|
||||
|
||||
} else if(new FullQualifiedName("ns.Term3").equals(termName)){
|
||||
|
||||
} else if(new FullQualifiedName("ns", "Term3").equals(termName)){
|
||||
return new CsdlTerm().setType("Edm.String").setName("Term3")
|
||||
.setAppliesTo(Arrays.asList("Property", "EntitySet", "Schema"));
|
||||
|
||||
} else if(new FullQualifiedName("ns.Term4").equals(termName)){
|
||||
|
||||
} else if(new FullQualifiedName("ns", "Term4").equals(termName)){
|
||||
return new CsdlTerm().setType("Edm.String").setName("Term4").setBaseTerm("namespace.Term1");
|
||||
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsdlAnnotations getAnnotationsGroup(FullQualifiedName targetName, String qualifier) throws ODataException {
|
||||
if (new FullQualifiedName("Alias.ETAbstract").equals(targetName) && "Tablett".equals(qualifier)) {
|
||||
if (new FullQualifiedName("Alias", "ETAbstract").equals(targetName) && "Tablett".equals(qualifier)) {
|
||||
CsdlAnnotations annoGroup = new CsdlAnnotations();
|
||||
annoGroup.setTarget("Alias.ETAbstract");
|
||||
annoGroup.setQualifier("Tablett");
|
||||
|
||||
List<CsdlAnnotation> innerAnnotations = new ArrayList<CsdlAnnotation>();
|
||||
innerAnnotations.add(new CsdlAnnotation().setTerm("ns.term"));
|
||||
List<CsdlAnnotation> innerAnnotations = Collections.singletonList(
|
||||
new CsdlAnnotation().setTerm("ns.term"));
|
||||
|
||||
List<CsdlAnnotation> annotationsList = new ArrayList<CsdlAnnotation>();
|
||||
annoGroup.setAnnotations(annotationsList);
|
||||
|
|
|
@ -21,8 +21,7 @@ package org.apache.olingo.server.core.serializer.xml;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.olingo.commons.api.ex.ODataErrorDetail;
|
||||
|
@ -31,15 +30,13 @@ import org.apache.olingo.server.api.OData;
|
|||
import org.apache.olingo.server.api.ODataServerError;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ServerErrorXmlSerializerTest {
|
||||
|
||||
ODataSerializer ser;
|
||||
final ODataSerializer ser;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
public ServerErrorXmlSerializerTest() throws SerializerException {
|
||||
ser = OData.newInstance().createSerializer(ContentType.APPLICATION_XML);
|
||||
}
|
||||
|
||||
|
@ -53,7 +50,7 @@ public class ServerErrorXmlSerializerTest {
|
|||
+ "<error xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
||||
+ "<code>0</code>"
|
||||
+ "<message>ErrorMessage</message>"
|
||||
+ "</error>",
|
||||
+ "</error>",
|
||||
jsonString);
|
||||
}
|
||||
|
||||
|
@ -64,18 +61,15 @@ public class ServerErrorXmlSerializerTest {
|
|||
|
||||
@Test
|
||||
public void singleDetailNothingSet() throws Exception {
|
||||
ODataErrorDetail detail = new ODataErrorDetail();
|
||||
detail.setCode("detail code");
|
||||
detail.setMessage("detail message");
|
||||
|
||||
List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>();
|
||||
details.add(detail);
|
||||
|
||||
ODataServerError error = new ODataServerError().setDetails(details);
|
||||
error.setCode("code");
|
||||
error.setMessage("err message");
|
||||
error.setTarget("target");
|
||||
|
||||
ODataServerError error = new ODataServerError()
|
||||
.setCode("code")
|
||||
.setMessage("err message")
|
||||
.setTarget("target")
|
||||
.setDetails(Collections.singletonList(
|
||||
new ODataErrorDetail()
|
||||
.setCode("detail code")
|
||||
.setMessage("detail message")));
|
||||
|
||||
InputStream stream = ser.error(error).getContent();
|
||||
String jsonString = IOUtils.toString(stream);
|
||||
assertEquals("<?xml version='1.0' encoding='UTF-8'?>"
|
||||
|
|
|
@ -25,11 +25,13 @@ import static org.mockito.Matchers.any;
|
|||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmBindingTarget;
|
||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||
import org.apache.olingo.server.api.etag.CustomETagSupport;
|
||||
import org.apache.olingo.server.api.etag.PreconditionException;
|
||||
import org.apache.olingo.server.api.uri.UriInfo;
|
||||
|
@ -47,7 +49,8 @@ import org.mockito.stubbing.Answer;
|
|||
|
||||
public class PreconditionsValidatorTest {
|
||||
|
||||
private static final Edm edm = new EdmProviderImpl(new EdmTechProvider());
|
||||
private static final Edm edm = OData.newInstance().createServiceMetadata(
|
||||
new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
|
||||
|
||||
// -------------- POSITIVE TESTS --------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -41,12 +41,11 @@ import org.apache.olingo.commons.api.data.Link;
|
|||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlMapping;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDate;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
|
||||
|
@ -571,13 +570,15 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
|
|||
EdmProperty propertyDate = mock(EdmProperty.class);
|
||||
when(propertyDate.getName()).thenReturn("PropertyDate");
|
||||
when(propertyDate.getMapping()).thenReturn(mapping);
|
||||
when(propertyDate.getType()).thenReturn(new EdmDate());
|
||||
when(propertyDate.getType()).thenReturn(
|
||||
OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Date));
|
||||
when(entityType.getProperty("PropertyDate")).thenReturn(propertyDate);
|
||||
|
||||
EdmProperty propertyDateTimeOffset = mock(EdmProperty.class);
|
||||
when(propertyDateTimeOffset.getName()).thenReturn("PropertyDateTimeOffset");
|
||||
when(propertyDateTimeOffset.getMapping()).thenReturn(mapping);
|
||||
when(propertyDateTimeOffset.getType()).thenReturn(new EdmDateTimeOffset());
|
||||
when(propertyDateTimeOffset.getType()).thenReturn(
|
||||
OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.DateTimeOffset));
|
||||
when(entityType.getProperty("PropertyDateTimeOffset")).thenReturn(propertyDateTimeOffset);
|
||||
|
||||
String entityString =
|
||||
|
|
|
@ -32,12 +32,11 @@ import org.apache.olingo.commons.api.data.Link;
|
|||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmBinary;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDate;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmTimeOfDay;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
|
||||
import org.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
|
@ -59,21 +58,9 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
|
|||
XMLUnit.setCompareUnmatched(false);
|
||||
}
|
||||
|
||||
protected byte[] edmBinary(String value) throws EdmPrimitiveTypeException {
|
||||
return EdmBinary.getInstance().valueOfString(value, true, null, null, null, true,
|
||||
byte[].class);
|
||||
}
|
||||
protected Object edmDate(String value) throws EdmPrimitiveTypeException {
|
||||
return EdmDate.getInstance().valueOfString(value, true, null, null, null, true,
|
||||
EdmDate.getInstance().getDefaultType());
|
||||
}
|
||||
protected Object edmDateTimeOffset(String value) throws EdmPrimitiveTypeException {
|
||||
return EdmDateTimeOffset.getInstance().valueOfString(value, true, null, null, null, true,
|
||||
EdmDateTimeOffset.getInstance().getDefaultType());
|
||||
}
|
||||
protected Object edmTimeOfDay(String value) throws EdmPrimitiveTypeException {
|
||||
return EdmTimeOfDay.getInstance().valueOfString(value, true, null, null, null, true,
|
||||
EdmTimeOfDay.getInstance().getDefaultType());
|
||||
protected Object valueOf(final String value, final EdmPrimitiveTypeKind kind) throws EdmPrimitiveTypeException {
|
||||
final EdmPrimitiveType type = OData.newInstance().createPrimitiveTypeInstance(kind);
|
||||
return type.valueOfString(value, true, null, null, null, true, type.getDefaultType());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -131,14 +118,17 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
|
|||
Assert.assertEquals(1.79E20F, result.getProperty("PropertySingle").asPrimitive());
|
||||
Assert.assertEquals(-1.79E19, result.getProperty("PropertyDouble").asPrimitive());
|
||||
Assert.assertEquals(BigDecimal.valueOf(34), result.getProperty("PropertyDecimal").asPrimitive());
|
||||
Assert.assertArrayEquals(edmBinary("ASNFZ4mrze8="), (byte[]) result.getProperty("PropertyBinary").asPrimitive());
|
||||
Assert.assertEquals(edmDate("2012-12-03"), result.getProperty("PropertyDate").asPrimitive());
|
||||
Assert.assertEquals(edmDateTimeOffset("2012-12-03T07:16:23Z"), result.getProperty("PropertyDateTimeOffset")
|
||||
.asPrimitive());
|
||||
Assert.assertArrayEquals((byte[]) valueOf("ASNFZ4mrze8=", EdmPrimitiveTypeKind.Binary),
|
||||
(byte[]) result.getProperty("PropertyBinary").asPrimitive());
|
||||
Assert.assertEquals(valueOf("2012-12-03", EdmPrimitiveTypeKind.Date),
|
||||
result.getProperty("PropertyDate").asPrimitive());
|
||||
Assert.assertEquals(valueOf("2012-12-03T07:16:23Z", EdmPrimitiveTypeKind.DateTimeOffset),
|
||||
result.getProperty("PropertyDateTimeOffset").asPrimitive());
|
||||
Assert.assertEquals(BigDecimal.valueOf(6), result.getProperty("PropertyDuration").asPrimitive());
|
||||
Assert.assertEquals(UUID.fromString("01234567-89ab-cdef-0123-456789abcdef"),
|
||||
result.getProperty("PropertyGuid").asPrimitive());
|
||||
Assert.assertEquals(edmTimeOfDay("03:26:05"), result.getProperty("PropertyTimeOfDay").asPrimitive());
|
||||
Assert.assertEquals(valueOf("03:26:05", EdmPrimitiveTypeKind.TimeOfDay),
|
||||
result.getProperty("PropertyTimeOfDay").asPrimitive());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -198,14 +188,17 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
|
|||
Assert.assertEquals(1.79E20F, result.getProperty("PropertySingle").asPrimitive());
|
||||
Assert.assertEquals(-1.79E19, result.getProperty("PropertyDouble").asPrimitive());
|
||||
Assert.assertEquals(BigDecimal.valueOf(34), result.getProperty("PropertyDecimal").asPrimitive());
|
||||
Assert.assertArrayEquals(edmBinary("ASNFZ4mrze8="), (byte[]) result.getProperty("PropertyBinary").asPrimitive());
|
||||
Assert.assertEquals(edmDate("2012-12-03"), result.getProperty("PropertyDate").asPrimitive());
|
||||
Assert.assertEquals(edmDateTimeOffset("2012-12-03T07:16:23Z"), result.getProperty("PropertyDateTimeOffset")
|
||||
.asPrimitive());
|
||||
Assert.assertArrayEquals((byte[]) valueOf("ASNFZ4mrze8=", EdmPrimitiveTypeKind.Binary),
|
||||
(byte[]) result.getProperty("PropertyBinary").asPrimitive());
|
||||
Assert.assertEquals(valueOf("2012-12-03", EdmPrimitiveTypeKind.Date),
|
||||
result.getProperty("PropertyDate").asPrimitive());
|
||||
Assert.assertEquals(valueOf("2012-12-03T07:16:23Z", EdmPrimitiveTypeKind.DateTimeOffset),
|
||||
result.getProperty("PropertyDateTimeOffset").asPrimitive());
|
||||
Assert.assertEquals(BigDecimal.valueOf(6), result.getProperty("PropertyDuration").asPrimitive());
|
||||
Assert.assertEquals(UUID.fromString("01234567-89ab-cdef-0123-456789abcdef"),
|
||||
result.getProperty("PropertyGuid").asPrimitive());
|
||||
Assert.assertEquals(edmTimeOfDay("03:26:05"), result.getProperty("PropertyTimeOfDay").asPrimitive());
|
||||
Assert.assertEquals(valueOf("03:26:05", EdmPrimitiveTypeKind.TimeOfDay),
|
||||
result.getProperty("PropertyTimeOfDay").asPrimitive());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -477,9 +470,10 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
|
|||
Entity inline = navLink.getInlineEntity();
|
||||
Assert.assertEquals(1, inline.getProperties().size());
|
||||
Assert.assertEquals(2, inline.getNavigationBindings().size());
|
||||
Assert.assertEquals(edmDate("2012-12-03"), inline.getProperty("PropertyDate").asPrimitive());
|
||||
Assert.assertEquals(valueOf("2012-12-03", EdmPrimitiveTypeKind.Date),
|
||||
inline.getProperty("PropertyDate").asPrimitive());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void primitiveProperty() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
|
|
|
@ -50,7 +50,6 @@ public class MetadataDocumentTest {
|
|||
|
||||
final String metadata = IOUtils.toString(
|
||||
odata.createSerializer(ContentType.APPLICATION_XML).metadataDocument(serviceMetadata).getContent());
|
||||
System.out.println(metadata);
|
||||
assertNotNull(metadata);
|
||||
assertThat(metadata, containsString("<edmx:Reference Uri=\"" + CORE_VOCABULARY + "\">"
|
||||
+ "<edmx:Include Namespace=\"Org.OData.Core.V1\" Alias=\"Core\"/>" + "</edmx:Reference>"));
|
||||
|
|
|
@ -22,12 +22,14 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
||||
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||
import org.apache.olingo.server.api.uri.UriInfoAll;
|
||||
import org.apache.olingo.server.api.uri.UriInfoBatch;
|
||||
import org.apache.olingo.server.api.uri.UriInfoCrossjoin;
|
||||
|
@ -51,13 +53,14 @@ import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
|
|||
import org.apache.olingo.server.core.uri.queryoption.SkipOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.SkipTokenOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.TopOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UriInfoImplTest {
|
||||
|
||||
Edm edm = new EdmProviderImpl(new EdmTechTestProvider());
|
||||
private static final Edm edm = OData.newInstance().createServiceMetadata(
|
||||
new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
|
||||
|
||||
@Test
|
||||
public void testKind() {
|
||||
|
@ -154,7 +157,7 @@ public class UriInfoImplTest {
|
|||
CustomQueryOptionImpl customOption1 = new CustomQueryOptionImpl();
|
||||
customOption1.setText("B");
|
||||
|
||||
QueryOptionImpl queryOption = new QueryOptionImpl();
|
||||
QueryOptionImpl queryOption = new CustomQueryOptionImpl();
|
||||
|
||||
queryOptions.add(expand.setName(""));
|
||||
queryOptions.add(filter.setName(""));
|
||||
|
|
|
@ -19,40 +19,42 @@
|
|||
package org.apache.olingo.server.core.uri;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.commons.api.edm.EdmActionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmComplexType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
|
||||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmSingleton;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl;
|
||||
import org.apache.olingo.commons.core.edm.EdmEntitySetImpl;
|
||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
||||
import org.apache.olingo.commons.core.edm.EdmSingletonImpl;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||
import org.apache.olingo.server.api.uri.UriParameter;
|
||||
import org.apache.olingo.server.api.uri.UriResourceKind;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl;
|
||||
import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.ActionProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UriResourceImplTest {
|
||||
|
||||
Edm edm = new EdmProviderImpl(new EdmTechTestProvider());
|
||||
private static final Edm edm = OData.newInstance().createServiceMetadata(
|
||||
new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
|
||||
|
||||
@Test
|
||||
public void testUriParameterImpl() {
|
||||
|
@ -88,13 +90,13 @@ public class UriResourceImplTest {
|
|||
impl.setActionImport(actionImport);
|
||||
assertEquals(actionImport, impl.getActionImport());
|
||||
assertEquals(actionImport.getUnboundAction(), impl.getAction());
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertFalse(impl.isCollection());
|
||||
assertEquals("AIRTCTTwoPrimParam", impl.toString());
|
||||
assertEquals(actionImport.getUnboundAction().getReturnType().getType(), impl.getType());
|
||||
|
||||
actionImport = edm.getEntityContainer(null).getActionImport("AIRT");
|
||||
impl.setActionImport(actionImport);
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertFalse(impl.isCollection());
|
||||
assertNull(impl.getType());
|
||||
}
|
||||
|
||||
|
@ -107,10 +109,10 @@ public class UriResourceImplTest {
|
|||
impl.setExpression(expression);
|
||||
impl.setLamdaVariable("A");
|
||||
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertFalse(impl.isCollection());
|
||||
assertEquals(expression, impl.getExpression());
|
||||
assertEquals("A", impl.getLambdaVariable());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean), impl.getType());
|
||||
assertEquals(OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean), impl.getType());
|
||||
assertEquals("all", impl.toString());
|
||||
}
|
||||
|
||||
|
@ -123,10 +125,10 @@ public class UriResourceImplTest {
|
|||
impl.setExpression(expression);
|
||||
impl.setLamdaVariable("A");
|
||||
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertFalse(impl.isCollection());
|
||||
assertEquals(expression, impl.getExpression());
|
||||
assertEquals("A", impl.getLambdaVariable());
|
||||
assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean), impl.getType());
|
||||
assertEquals(OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean), impl.getType());
|
||||
assertEquals("any", impl.toString());
|
||||
}
|
||||
|
||||
|
@ -141,13 +143,12 @@ public class UriResourceImplTest {
|
|||
|
||||
assertEquals(property, impl.getProperty());
|
||||
assertEquals(property.getName(), impl.toString());
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertFalse(impl.isCollection());
|
||||
assertEquals(property.getType(), impl.getType());
|
||||
assertEquals(property.getType(), impl.getComplexType());
|
||||
impl.getComplexType();
|
||||
|
||||
EdmComplexTypeImpl complexTypeImplType =
|
||||
(EdmComplexTypeImpl) edm.getComplexType(ComplexTypeProvider.nameCTBasePrimCompNav);
|
||||
EdmComplexType complexTypeImplType = edm.getComplexType(ComplexTypeProvider.nameCTBasePrimCompNav);
|
||||
|
||||
impl.setTypeFilter(complexTypeImplType);
|
||||
assertEquals(complexTypeImplType, impl.getTypeFilter());
|
||||
|
@ -167,7 +168,7 @@ public class UriResourceImplTest {
|
|||
|
||||
assertEquals(property, impl.getProperty());
|
||||
assertEquals(property.getName(), impl.toString());
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertFalse(impl.isCollection());
|
||||
assertEquals(property.getType(), impl.getType());
|
||||
}
|
||||
|
||||
|
@ -183,7 +184,7 @@ public class UriResourceImplTest {
|
|||
UriResourceEntitySetImpl impl = new UriResourceEntitySetImpl();
|
||||
assertEquals(UriResourceKind.entitySet, impl.getKind());
|
||||
|
||||
EdmEntitySetImpl entitySet = (EdmEntitySetImpl) edm.getEntityContainer(null).getEntitySet("ESAllPrim");
|
||||
EdmEntitySet entitySet = edm.getEntityContainer(null).getEntitySet("ESAllPrim");
|
||||
impl.setEntitSet(entitySet);
|
||||
|
||||
assertEquals("ESAllPrim", impl.toString());
|
||||
|
@ -194,9 +195,9 @@ public class UriResourceImplTest {
|
|||
impl.getEntityType();
|
||||
|
||||
// is Collection
|
||||
assertEquals(true, impl.isCollection());
|
||||
impl.setKeyPredicates(new ArrayList<UriParameterImpl>());
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertTrue(impl.isCollection());
|
||||
impl.setKeyPredicates(Collections.<UriParameter> emptyList());
|
||||
assertFalse(impl.isCollection());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -207,19 +208,19 @@ public class UriResourceImplTest {
|
|||
|
||||
// function
|
||||
EdmFunction function = edm.getEntityContainer(null).getFunctionImport("FINRTInt16")
|
||||
.getUnboundFunction(new ArrayList<String>());
|
||||
.getUnboundFunction(Collections.<String> emptyList());
|
||||
assertNotNull(function);
|
||||
impl.setFunction(function);
|
||||
|
||||
assertEquals(function, impl.getFunction());
|
||||
assertEquals("UFNRTInt16", impl.toString());
|
||||
assertEquals(function.getReturnType().getType(), impl.getType());
|
||||
assertEquals(false, impl.isParameterListFilled());
|
||||
assertFalse(impl.isParameterListFilled());
|
||||
|
||||
// function import
|
||||
impl = new UriResourceFunctionImpl();
|
||||
EdmFunctionImport functionImport = edm.getEntityContainer(null).getFunctionImport("FINRTInt16");
|
||||
impl.setFunctionImport(functionImport, new ArrayList<UriParameterImpl>());
|
||||
impl.setFunctionImport(functionImport, Collections.<UriParameter> emptyList());
|
||||
assertEquals(functionImport, impl.getFunctionImport());
|
||||
assertEquals("FINRTInt16", impl.toString());
|
||||
|
||||
|
@ -227,37 +228,31 @@ public class UriResourceImplTest {
|
|||
impl = new UriResourceFunctionImpl();
|
||||
functionImport = edm.getEntityContainer(null).getFunctionImport("FICRTCollESTwoKeyNavParam");
|
||||
assertNotNull(function);
|
||||
UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
|
||||
impl.setFunctionImport(functionImport, Arrays.asList(parameter));
|
||||
UriParameter parameter = new UriParameterImpl().setName("ParameterInt16");
|
||||
impl.setFunctionImport(functionImport, Collections.singletonList(parameter));
|
||||
assertEquals("FICRTCollESTwoKeyNavParam", impl.toString());
|
||||
|
||||
impl.setFunction(functionImport.getUnboundFunction(Arrays.asList("ParameterInt16")));
|
||||
assertEquals(true, impl.isCollection());
|
||||
impl.setKeyPredicates(new ArrayList<UriParameterImpl>());
|
||||
assertEquals(false, impl.isCollection());
|
||||
impl.setFunction(functionImport.getUnboundFunction(Collections.singletonList("ParameterInt16")));
|
||||
assertTrue(impl.isCollection());
|
||||
impl.setKeyPredicates(Collections.<UriParameter> emptyList());
|
||||
assertFalse(impl.isCollection());
|
||||
|
||||
assertEquals(parameter, impl.getParameters().get(0));
|
||||
assertEquals(true, impl.isParameterListFilled());
|
||||
assertTrue(impl.isParameterListFilled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUriResourceImplKeyPred() {
|
||||
final EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav);
|
||||
class Mock extends UriResourceWithKeysImpl {
|
||||
|
||||
EdmType type;
|
||||
|
||||
public Mock() {
|
||||
super(UriResourceKind.action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Mock setType(final EdmType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -265,11 +260,6 @@ public class UriResourceImplTest {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getSegmentValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSegmentValue() {
|
||||
return "mock";
|
||||
|
@ -277,11 +267,9 @@ public class UriResourceImplTest {
|
|||
}
|
||||
|
||||
Mock impl = new Mock();
|
||||
EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav);
|
||||
EdmEntityType entityTypeBaseColl = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav);
|
||||
EdmEntityType entityTypeBaseEntry = edm.getEntityType(EntityTypeProvider.nameETTwoBaseTwoKeyNav);
|
||||
|
||||
impl.setType(entityType);
|
||||
assertEquals(entityType, impl.getType());
|
||||
assertEquals("mock", impl.toString(false));
|
||||
assertEquals("mock", impl.toString(true));
|
||||
|
@ -299,7 +287,6 @@ public class UriResourceImplTest {
|
|||
|
||||
// set entry
|
||||
impl = new Mock();
|
||||
impl.setType(entityType);
|
||||
impl.setEntryTypeFilter(entityTypeBaseEntry);
|
||||
assertEquals(entityTypeBaseEntry, impl.getTypeFilterOnEntry());
|
||||
assertEquals("mock", impl.toString(false));
|
||||
|
@ -307,35 +294,29 @@ public class UriResourceImplTest {
|
|||
|
||||
// set collection
|
||||
impl = new Mock();
|
||||
impl.setType(entityType);
|
||||
impl.setCollectionTypeFilter(entityTypeBaseColl);
|
||||
assertEquals(entityTypeBaseColl, impl.getTypeFilterOnCollection());
|
||||
assertEquals("mock", impl.toString(false));
|
||||
assertEquals("mock/olingo.odata.test1.ETBaseTwoKeyNav", impl.toString(true));
|
||||
|
||||
impl = new Mock();
|
||||
UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
|
||||
List<UriParameterImpl> keyPredicates = new ArrayList<UriParameterImpl>();
|
||||
keyPredicates.add(parameter);
|
||||
|
||||
impl.setKeyPredicates(keyPredicates);
|
||||
impl.setKeyPredicates(
|
||||
Collections.singletonList(
|
||||
(UriParameter) new UriParameterImpl().setName("ParameterInt16")));
|
||||
assertNotNull(null, impl.getKeyPredicates());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUriResourceImplTyped() {
|
||||
final EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav);
|
||||
class Mock extends UriResourceTypedImpl {
|
||||
|
||||
EdmType type;
|
||||
|
||||
public Mock() {
|
||||
super(UriResourceKind.action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmType getType() {
|
||||
return type;
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -343,39 +324,23 @@ public class UriResourceImplTest {
|
|||
return false;
|
||||
}
|
||||
|
||||
public Mock setType(final EdmType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSegmentValue() {
|
||||
return "mock";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getSegmentValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Mock impl = new Mock();
|
||||
EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav);
|
||||
EdmEntityType entityTypeBaseColl = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav);
|
||||
edm.getEntityType(EntityTypeProvider.nameETTwoBaseTwoKeyNav);
|
||||
|
||||
impl.setType(entityType);
|
||||
assertEquals("mock", impl.toString());
|
||||
assertEquals("mock", impl.toString(true));
|
||||
assertEquals("mock", impl.toString(false));
|
||||
|
||||
impl.setTypeFilter(entityTypeBaseColl);
|
||||
assertEquals(entityTypeBaseColl, impl.getTypeFilter());
|
||||
assertEquals("mock", impl.toString());
|
||||
assertEquals("mock/olingo.odata.test1.ETBaseTwoKeyNav", impl.toString(true));
|
||||
assertEquals("mock", impl.toString(false));
|
||||
//
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -389,15 +354,12 @@ public class UriResourceImplTest {
|
|||
impl.setType(entityType);
|
||||
assertEquals(entityType, impl.getType());
|
||||
|
||||
UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
|
||||
List<UriParameterImpl> keyPredicates = new ArrayList<UriParameterImpl>();
|
||||
keyPredicates.add(parameter);
|
||||
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertFalse(impl.isCollection());
|
||||
impl.setCollection(true);
|
||||
assertEquals(true, impl.isCollection());
|
||||
impl.setKeyPredicates(keyPredicates);
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertTrue(impl.isCollection());
|
||||
impl.setKeyPredicates(Collections.singletonList(
|
||||
(UriParameter) new UriParameterImpl().setName("ParameterInt16")));
|
||||
assertFalse(impl.isCollection());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -415,13 +377,10 @@ public class UriResourceImplTest {
|
|||
assertEquals("NavPropertyETKeyNavMany", impl.toString());
|
||||
assertEquals(property.getType(), impl.getType());
|
||||
|
||||
UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
|
||||
List<UriParameterImpl> keyPredicates = new ArrayList<UriParameterImpl>();
|
||||
keyPredicates.add(parameter);
|
||||
|
||||
assertEquals(true, impl.isCollection());
|
||||
impl.setKeyPredicates(keyPredicates);
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertTrue(impl.isCollection());
|
||||
impl.setKeyPredicates(Collections.singletonList(
|
||||
(UriParameter) new UriParameterImpl().setName("ParameterInt16")));
|
||||
assertFalse(impl.isCollection());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -442,15 +401,12 @@ public class UriResourceImplTest {
|
|||
impl.setType(entityType);
|
||||
assertEquals(entityType, impl.getType());
|
||||
|
||||
UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
|
||||
List<UriParameterImpl> keyPredicates = new ArrayList<UriParameterImpl>();
|
||||
keyPredicates.add(parameter);
|
||||
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertFalse(impl.isCollection());
|
||||
impl.setCollection(true);
|
||||
assertEquals(true, impl.isCollection());
|
||||
impl.setKeyPredicates(keyPredicates);
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertTrue(impl.isCollection());
|
||||
impl.setKeyPredicates(Collections.singletonList(
|
||||
(UriParameter) new UriParameterImpl().setName("ParameterInt16")));
|
||||
assertFalse(impl.isCollection());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -458,7 +414,7 @@ public class UriResourceImplTest {
|
|||
UriResourceSingletonImpl impl = new UriResourceSingletonImpl();
|
||||
assertEquals(UriResourceKind.singleton, impl.getKind());
|
||||
|
||||
EdmSingletonImpl singleton = (EdmSingletonImpl) edm.getEntityContainer(null).getSingleton("SINav");
|
||||
EdmSingleton singleton = edm.getEntityContainer(null).getSingleton("SINav");
|
||||
EdmEntityType entityTypeBaseColl = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav);
|
||||
impl.setSingleton(singleton);
|
||||
|
||||
|
@ -473,7 +429,7 @@ public class UriResourceImplTest {
|
|||
assertEquals(entityTypeBaseColl, impl.getEntityTypeFilter());
|
||||
|
||||
// is Collection
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertFalse(impl.isCollection());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -495,9 +451,9 @@ public class UriResourceImplTest {
|
|||
assertEquals("A", impl.toString());
|
||||
assertEquals(entityType, impl.getType());
|
||||
assertEquals("A", impl.getVariableName());
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertFalse(impl.isCollection());
|
||||
impl.setCollection(true);
|
||||
assertEquals(true, impl.isCollection());
|
||||
assertTrue(impl.isCollection());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -510,15 +466,11 @@ public class UriResourceImplTest {
|
|||
assertEquals("olingo.odata.test1.ETTwoKeyNav", impl.toString());
|
||||
assertEquals(entityType, impl.getType());
|
||||
|
||||
UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
|
||||
List<UriParameterImpl> keyPredicates = new ArrayList<UriParameterImpl>();
|
||||
keyPredicates.add(parameter);
|
||||
|
||||
assertEquals(false, impl.isCollection());
|
||||
assertFalse(impl.isCollection());
|
||||
impl.setCollection(true);
|
||||
assertEquals(true, impl.isCollection());
|
||||
impl.setKeyPredicates(keyPredicates);
|
||||
assertEquals(false, impl.isCollection());
|
||||
|
||||
assertTrue(impl.isCollection());
|
||||
impl.setKeyPredicates(Collections.singletonList(
|
||||
(UriParameter) new UriParameterImpl().setName("ParameterInt16")));
|
||||
assertFalse(impl.isCollection());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,14 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef;
|
||||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
|
@ -36,17 +43,18 @@ import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
|
|||
import org.apache.olingo.server.core.uri.parser.UriParserException;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException.MessageKeys;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
|
||||
import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
|
||||
import org.apache.olingo.server.core.uri.testutil.FilterValidator;
|
||||
import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
|
||||
import org.apache.olingo.server.core.uri.validator.UriValidationException;
|
||||
import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EnumTypeProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.PropertyProvider;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public class TestFullResourcePath {
|
||||
|
||||
|
@ -55,7 +63,7 @@ public class TestFullResourcePath {
|
|||
private final FilterValidator testFilter;
|
||||
|
||||
public TestFullResourcePath() {
|
||||
final Edm edm = oData.createServiceMetadata(new EdmTechTestProvider(), Collections.<EdmxReference> emptyList())
|
||||
final Edm edm = oData.createServiceMetadata(new EdmTechProvider(), Collections.<EdmxReference> emptyList())
|
||||
.getEdm();
|
||||
testUri = new TestUriValidator().setEdm(edm);
|
||||
testFilter = new FilterValidator().setEdm(edm);
|
||||
|
@ -5542,15 +5550,42 @@ public class TestFullResourcePath {
|
|||
|
||||
@Test
|
||||
public void navPropertySameNameAsEntitySet() throws Exception {
|
||||
testUri.run("ESNavProp(1)/ESNavProp(2)/ESNavProp(3)/ESNavProp")
|
||||
final String namespace = "namespace";
|
||||
final String entityTypeName = "ETNavProp";
|
||||
final FullQualifiedName nameETNavProp = new FullQualifiedName(namespace, entityTypeName);
|
||||
final String entitySetName = "ESNavProp";
|
||||
final String keyPropertyName = "a";
|
||||
EdmProperty keyProperty = Mockito.mock(EdmProperty.class);
|
||||
Mockito.when(keyProperty.getType()).thenReturn(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Byte));
|
||||
EdmKeyPropertyRef keyPropertyRef = Mockito.mock(EdmKeyPropertyRef.class);
|
||||
Mockito.when(keyPropertyRef.getName()).thenReturn(keyPropertyName);
|
||||
Mockito.when(keyPropertyRef.getProperty()).thenReturn(keyProperty);
|
||||
EdmNavigationProperty navProperty = Mockito.mock(EdmNavigationProperty.class);
|
||||
Mockito.when(navProperty.getName()).thenReturn(entitySetName);
|
||||
Mockito.when(navProperty.isCollection()).thenReturn(true);
|
||||
EdmEntityType entityType = Mockito.mock(EdmEntityType.class);
|
||||
Mockito.when(entityType.getFullQualifiedName()).thenReturn(nameETNavProp);
|
||||
Mockito.when(entityType.getKeyPredicateNames()).thenReturn(Collections.singletonList(keyPropertyName));
|
||||
Mockito.when(entityType.getKeyPropertyRefs()).thenReturn(Collections.singletonList(keyPropertyRef));
|
||||
Mockito.when(entityType.getProperty(entitySetName)).thenReturn(navProperty);
|
||||
Mockito.when(navProperty.getType()).thenReturn(entityType);
|
||||
EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class);
|
||||
Mockito.when(entitySet.getName()).thenReturn(entitySetName);
|
||||
Mockito.when(entitySet.getEntityType()).thenReturn(entityType);
|
||||
EdmEntityContainer container = Mockito.mock(EdmEntityContainer.class);
|
||||
Mockito.when(container.getEntitySet(entitySetName)).thenReturn(entitySet);
|
||||
Edm mockedEdm = Mockito.mock(Edm.class);
|
||||
Mockito.when(mockedEdm.getEntityContainer(null)).thenReturn(container);
|
||||
new TestUriValidator().setEdm(mockedEdm)
|
||||
.run("ESNavProp(1)/ESNavProp(2)/ESNavProp(3)/ESNavProp")
|
||||
.goPath()
|
||||
.at(0).isEntitySet("ESNavProp")
|
||||
.at(0).isKeyPredicate(0, "a", "1")
|
||||
.at(1).isNavProperty("ESNavProp", EdmTechTestProvider.nameETNavProp, false)
|
||||
.at(1).isKeyPredicate(0, "a", "2")
|
||||
.at(2).isNavProperty("ESNavProp", EdmTechTestProvider.nameETNavProp, false)
|
||||
.at(2).isKeyPredicate(0, "a", "3")
|
||||
.at(3).isNavProperty("ESNavProp", EdmTechTestProvider.nameETNavProp, true);
|
||||
.at(0).isEntitySet(entitySetName)
|
||||
.at(0).isKeyPredicate(0, keyPropertyName, "1")
|
||||
.at(1).isNavProperty(entitySetName, nameETNavProp, false)
|
||||
.at(1).isKeyPredicate(0, keyPropertyName, "2")
|
||||
.at(2).isNavProperty(entitySetName, nameETNavProp, false)
|
||||
.at(2).isKeyPredicate(0, keyPropertyName, "3")
|
||||
.at(3).isNavProperty(entitySetName, nameETNavProp, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -5617,26 +5652,26 @@ public class TestFullResourcePath {
|
|||
|
||||
testUri.run("ESAllPrim", "$filter=" + Short.MIN_VALUE + " eq " + Short.MAX_VALUE)
|
||||
.goFilter().isBinary(BinaryOperatorKind.EQ)
|
||||
.left().isLiteral("" + Short.MIN_VALUE)
|
||||
.left().isLiteral(Short.toString(Short.MIN_VALUE))
|
||||
.isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int16))
|
||||
.root()
|
||||
.right().isLiteral("" + Short.MAX_VALUE)
|
||||
.right().isLiteral(Short.toString(Short.MAX_VALUE))
|
||||
.isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int16));
|
||||
|
||||
testUri.run("ESAllPrim", "$filter=" + Integer.MIN_VALUE + " eq " + Integer.MAX_VALUE)
|
||||
.goFilter().isBinary(BinaryOperatorKind.EQ)
|
||||
.left().isLiteral("" + Integer.MIN_VALUE)
|
||||
.left().isLiteral(Integer.toString(Integer.MIN_VALUE))
|
||||
.isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int32))
|
||||
.root()
|
||||
.right().isLiteral("" + Integer.MAX_VALUE)
|
||||
.right().isLiteral(Integer.toString(Integer.MAX_VALUE))
|
||||
.isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int32));
|
||||
|
||||
|
||||
testUri.run("ESAllPrim", "$filter=" + Long.MIN_VALUE + " eq " + Long.MAX_VALUE)
|
||||
.goFilter().isBinary(BinaryOperatorKind.EQ)
|
||||
.left().isLiteral("" + Long.MIN_VALUE)
|
||||
.left().isLiteral(Long.toString(Long.MIN_VALUE))
|
||||
.isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int64))
|
||||
.root()
|
||||
.right().isLiteral("" + Long.MAX_VALUE)
|
||||
.right().isLiteral(Long.toString(Long.MAX_VALUE))
|
||||
.isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int64));
|
||||
}
|
||||
|
||||
|
|
|
@ -19,18 +19,18 @@
|
|||
package org.apache.olingo.server.core.uri.antlr;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.core.Encoder;
|
||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||
import org.apache.olingo.server.api.uri.UriInfoKind;
|
||||
import org.apache.olingo.server.api.uri.UriResourceKind;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserException;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
|
||||
import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
|
||||
import org.apache.olingo.server.core.uri.testutil.FilterValidator;
|
||||
import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
|
||||
import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
|
||||
|
@ -38,15 +38,20 @@ import org.apache.olingo.server.core.uri.validator.UriValidationException;
|
|||
import org.apache.olingo.server.tecsvc.provider.ActionProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.PropertyProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestUriParserImpl {
|
||||
Edm edm = null;
|
||||
private final Edm edm = OData.newInstance().createServiceMetadata(
|
||||
new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
|
||||
private final TestUriValidator testUri = new TestUriValidator().setEdm(edm);
|
||||
private final ResourceValidator testRes = new ResourceValidator().setEdm(edm);
|
||||
private final FilterValidator testFilter = new FilterValidator().setEdm(edm);
|
||||
|
||||
private final String PropertyBoolean = "PropertyBoolean=true";
|
||||
private final String PropertyByte = "PropertyByte=1";
|
||||
|
||||
private final String PropertyDate = "PropertyDate=2013-09-25";
|
||||
private final String PropertyDateTimeOffset = "PropertyDateTimeOffset=2002-10-10T12:00:00-05:00";
|
||||
private final String PropertyDecimal = "PropertyDecimal=12";
|
||||
|
@ -63,17 +68,6 @@ public class TestUriParserImpl {
|
|||
+ "," + PropertySByte + "," + PropertyInt32 + "," + PropertyInt64 + "," + PropertyDecimal + "," + PropertyDate
|
||||
+ "," + PropertyDateTimeOffset + "," + PropertyDuration + "," + PropertyGuid + "," + PropertyTimeOfDay;
|
||||
|
||||
TestUriValidator testUri = null;
|
||||
ResourceValidator testRes = null;
|
||||
FilterValidator testFilter = null;
|
||||
|
||||
public TestUriParserImpl() {
|
||||
edm = new EdmProviderImpl(new EdmTechTestProvider());
|
||||
testUri = new TestUriValidator().setEdm(edm);
|
||||
testRes = new ResourceValidator().setEdm(edm);
|
||||
testFilter = new FilterValidator().setEdm(edm);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoundFunctionImport_VarParameters() {
|
||||
|
||||
|
@ -350,7 +344,7 @@ public class TestUriParserImpl {
|
|||
.isKeyPredicate(1, "PropertyString", "'ABC'");
|
||||
|
||||
// with all keys
|
||||
testRes.run("ESAllKey(" + Encoder.encode(allKeys) + ")")
|
||||
testRes.run("ESAllKey(" + encode(allKeys) + ")")
|
||||
.isEntitySet("ESAllKey")
|
||||
.isKeyPredicate(0, "PropertyString", "'ABC'")
|
||||
.isKeyPredicate(1, "PropertyInt16", "1")
|
||||
|
@ -569,34 +563,46 @@ public class TestUriParserImpl {
|
|||
|
||||
@Test
|
||||
public void testUnary() throws UriParserException {
|
||||
testFilter.runESabc("not a").isCompr("<not <a>>");
|
||||
testFilter.runESabc("- a eq a").isCompr("<<- <a>> eq <a>>");
|
||||
testFilter.runESabc("-a eq a").isCompr("<<- <a>> eq <a>>");
|
||||
testFilter.runOnETAllPrim("not PropertyBoolean").isCompr("<not <PropertyBoolean>>");
|
||||
testFilter.runOnETAllPrim("- PropertyInt16 eq PropertyInt16").isCompr("<<- <PropertyInt16>> eq <PropertyInt16>>");
|
||||
testFilter.runOnETAllPrim("-PropertyInt16 eq PropertyInt16").isCompr("<<- <PropertyInt16>> eq <PropertyInt16>>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterComplexMixedPriority() throws UriParserException {
|
||||
testFilter.runESabc("a or c and e ").isCompr("< <a> or < <c> and <e> >>");
|
||||
testFilter.runESabc("a or c and e eq f").isCompr("< <a> or < <c> and <<e> eq <f>>>>");
|
||||
testFilter.runESabc("a or c eq d and e ").isCompr("< <a> or <<<c> eq <d>> and <e> >>");
|
||||
testFilter.runESabc("a or c eq d and e eq f").isCompr("< <a> or <<<c> eq <d>> and <<e> eq <f>>>>");
|
||||
testFilter.runESabc("a eq b or c and e ").isCompr("<<<a> eq <b>> or < <c> and <e> >>");
|
||||
testFilter.runESabc("a eq b or c and e eq f").isCompr("<<<a> eq <b>> or < <c> and <<e> eq <f>>>>");
|
||||
testFilter.runESabc("a eq b or c eq d and e ").isCompr("<<<a> eq <b>> or <<<c> eq <d>> and <e> >>");
|
||||
testFilter.runESabc("a eq b or c eq d and e eq f").isCompr("<<<a> eq <b>> or <<<c> eq <d>> and <<e> eq <f>>>>");
|
||||
testFilter.runOnETAllPrim("PropertyInt16 or PropertyInt32 and PropertyInt64")
|
||||
.isCompr("<<PropertyInt16> or <<PropertyInt32> and <PropertyInt64>>>");
|
||||
testFilter.runOnETAllPrim("PropertyInt16 or PropertyInt32 and PropertyInt64 eq PropertyByte")
|
||||
.isCompr("<<PropertyInt16> or <<PropertyInt32> and <<PropertyInt64> eq <PropertyByte>>>>");
|
||||
testFilter.runOnETAllPrim("PropertyInt16 or PropertyInt32 eq PropertyInt64 and PropertyByte")
|
||||
.isCompr("<<PropertyInt16> or <<<PropertyInt32> eq <PropertyInt64>> and <PropertyByte>>>");
|
||||
testFilter.runOnETAllPrim("PropertyInt16 or PropertyInt32 eq PropertyInt64 and PropertyByte eq PropertySByte")
|
||||
.isCompr("<<PropertyInt16> or <<<PropertyInt32> eq <PropertyInt64>> "
|
||||
+ "and <<PropertyByte> eq <PropertySByte>>>>");
|
||||
testFilter.runOnETAllPrim("PropertyInt16 eq PropertyInt32 or PropertyInt64 and PropertyByte")
|
||||
.isCompr("<<<PropertyInt16> eq <PropertyInt32>> or <<PropertyInt64> and <PropertyByte>>>");
|
||||
testFilter.runOnETAllPrim("PropertyInt16 eq PropertyInt32 or PropertyInt64 and PropertyByte eq PropertySByte")
|
||||
.isCompr("<<<PropertyInt16> eq <PropertyInt32>> "
|
||||
+ "or <<PropertyInt64> and <<PropertyByte> eq <PropertySByte>>>>");
|
||||
testFilter.runOnETAllPrim("PropertyInt16 eq PropertyInt32 or PropertyInt64 eq PropertyByte and PropertySByte")
|
||||
.isCompr("<<<PropertyInt16> eq <PropertyInt32>> "
|
||||
+ "or <<<PropertyInt64> eq <PropertyByte>> and <PropertySByte>>>");
|
||||
testFilter.runOnETAllPrim("PropertyInt16 eq PropertyInt32 or PropertyInt64 eq PropertyByte "
|
||||
+ "and PropertySByte eq PropertyDecimal")
|
||||
.isCompr("<<<PropertyInt16> eq <PropertyInt32>> or <<<PropertyInt64> eq <PropertyByte>> "
|
||||
+ "and <<PropertySByte> eq <PropertyDecimal>>>>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterSimpleSameBinaryBinaryBinaryPriority() throws UriParserException {
|
||||
|
||||
testFilter.runESabc("1 add 2 add 3 add 4").isCompr("<<< <1> add <2>> add <3>> add <4>>");
|
||||
testFilter.runESabc("1 add 2 add 3 div 4").isCompr("<< <1> add <2>> add <<3> div <4>>>");
|
||||
testFilter.runESabc("1 add 2 div 3 add 4").isCompr("<< <1> add <<2> div <3>>> add <4>>");
|
||||
testFilter.runESabc("1 add 2 div 3 div 4").isCompr("< <1> add <<<2> div <3>> div <4>>>");
|
||||
testFilter.runESabc("1 div 2 add 3 add 4").isCompr("<<< <1> div <2>> add <3>> add <4>>");
|
||||
testFilter.runESabc("1 div 2 add 3 div 4").isCompr("<< <1> div <2>> add <<3> div <4>>>");
|
||||
testFilter.runESabc("1 div 2 div 3 add 4").isCompr("<<< <1> div <2>> div <3>> add <4>>");
|
||||
testFilter.runESabc("1 div 2 div 3 div 4").isCompr("<<< <1> div <2>> div <3>> div <4>>");
|
||||
testFilter.runOnETAllPrim("1 add 2 add 3 add 4").isCompr("<<< <1> add <2>> add <3>> add <4>>");
|
||||
testFilter.runOnETAllPrim("1 add 2 add 3 div 4").isCompr("<< <1> add <2>> add <<3> div <4>>>");
|
||||
testFilter.runOnETAllPrim("1 add 2 div 3 add 4").isCompr("<< <1> add <<2> div <3>>> add <4>>");
|
||||
testFilter.runOnETAllPrim("1 add 2 div 3 div 4").isCompr("< <1> add <<<2> div <3>> div <4>>>");
|
||||
testFilter.runOnETAllPrim("1 div 2 add 3 add 4").isCompr("<<< <1> div <2>> add <3>> add <4>>");
|
||||
testFilter.runOnETAllPrim("1 div 2 add 3 div 4").isCompr("<< <1> div <2>> add <<3> div <4>>>");
|
||||
testFilter.runOnETAllPrim("1 div 2 div 3 add 4").isCompr("<<< <1> div <2>> div <3>> add <4>>");
|
||||
testFilter.runOnETAllPrim("1 div 2 div 3 div 4").isCompr("<<< <1> div <2>> div <3>> div <4>>");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1164,4 +1170,8 @@ public class TestUriParserImpl {
|
|||
testUri.runEx("ESMixPrimCollComp", "$select=/PropertyInt16")
|
||||
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
|
||||
}
|
||||
|
||||
private final String encode(final String uriPart) {
|
||||
return uriPart.replaceAll(":", "%3A");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ public class ParserTest {
|
|||
EdmNavigationProperty productsNavigation = Mockito.mock(EdmNavigationProperty.class);
|
||||
EdmEntityType productsType = Mockito.mock(EdmEntityType.class);
|
||||
|
||||
final FullQualifiedName nameProducts = new FullQualifiedName("NS", "Products");
|
||||
Mockito.when(mockEdm.getEntityContainer(null)).thenReturn(container);
|
||||
Mockito.when(typeCategory.getName()).thenReturn("Category");
|
||||
Mockito.when(typeCategory.getNamespace()).thenReturn("NS");
|
||||
|
@ -62,7 +63,7 @@ public class ParserTest {
|
|||
Mockito.when(typeCategory.getProperty("Products")).thenReturn(productsNavigation);
|
||||
Mockito.when(container.getEntitySet("Category")).thenReturn(esCategory);
|
||||
Mockito.when(container.getEntitySet("Products")).thenReturn(esProduct);
|
||||
Mockito.when(productsType.getName()).thenReturn("Products");
|
||||
Mockito.when(productsType.getFullQualifiedName()).thenReturn(nameProducts);
|
||||
Mockito.when(productsType.getNamespace()).thenReturn("NS");
|
||||
Mockito.when(productsNavigation.getType()).thenReturn(productsType);
|
||||
|
||||
|
@ -72,13 +73,13 @@ public class ParserTest {
|
|||
.isKind(UriInfoKind.resource).goPath().goExpand()
|
||||
.first()
|
||||
.goPath().first()
|
||||
.isNavProperty("Products", new FullQualifiedName("NS", "Products"), false)
|
||||
.isType(new FullQualifiedName("NS", "Products"), false);
|
||||
.isNavProperty("Products", nameProducts, false)
|
||||
.isType(nameProducts, false);
|
||||
Mockito.verifyZeroInteractions(esProduct);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for EntitySet with navigation to an not existing NavigationProperty (name)
|
||||
* Test for EntitySet with navigation to a not existing NavigationProperty (name)
|
||||
* but with another EntitySet with this name defined in metadata.
|
||||
* (related to Olingo issue OLINGO-755)
|
||||
*/
|
||||
|
|
|
@ -19,32 +19,32 @@
|
|||
package org.apache.olingo.server.core.uri.queryoption;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
||||
import org.apache.olingo.server.api.uri.UriInfoResource;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectItem;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.Expression;
|
||||
import org.apache.olingo.server.core.uri.UriInfoImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.AliasImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl;
|
||||
import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
//TOOD add getKind check to all
|
||||
public class QueryOptionTest {
|
||||
|
||||
Edm edm = new EdmProviderImpl(new EdmTechTestProvider());
|
||||
|
||||
@Test
|
||||
public void testAliasQueryOption() {
|
||||
AliasQueryOptionImpl option = new AliasQueryOptionImpl();
|
||||
|
||||
ExpressionImpl expression = new LiteralImpl();
|
||||
Expression expression = new LiteralImpl();
|
||||
|
||||
option.setAliasValue(expression);
|
||||
assertEquals(expression, option.getValue());
|
||||
|
@ -90,7 +90,7 @@ public class QueryOptionTest {
|
|||
option.setSystemQueryOption(new IdOptionImpl());
|
||||
|
||||
option = new ExpandItemImpl();
|
||||
List<SystemQueryOptionImpl> list = new ArrayList<SystemQueryOptionImpl>();
|
||||
List<SystemQueryOption> list = new ArrayList<SystemQueryOption>();
|
||||
list.add(expand);
|
||||
list.add(filter);
|
||||
option.setSystemQueryOptions(list);
|
||||
|
@ -98,14 +98,14 @@ public class QueryOptionTest {
|
|||
assertEquals(filter, option.getFilterOption());
|
||||
|
||||
option = new ExpandItemImpl();
|
||||
assertEquals(false, option.isRef());
|
||||
assertFalse(option.isRef());
|
||||
option.setIsRef(true);
|
||||
assertEquals(true, option.isRef());
|
||||
assertTrue(option.isRef());
|
||||
|
||||
option = new ExpandItemImpl();
|
||||
assertEquals(false, option.isStar());
|
||||
assertFalse(option.isStar());
|
||||
option.setIsStar(true);
|
||||
assertEquals(true, option.isStar());
|
||||
assertTrue(option.isStar());
|
||||
|
||||
option = new ExpandItemImpl();
|
||||
UriInfoResource resource = new UriInfoImpl().asUriInfoResource();
|
||||
|
@ -144,7 +144,6 @@ public class QueryOptionTest {
|
|||
assertEquals(SystemQueryOptionKind.FORMAT, option.getKind());
|
||||
|
||||
option.setFormat("A");
|
||||
|
||||
assertEquals("A", option.getFormat());
|
||||
}
|
||||
|
||||
|
@ -154,7 +153,6 @@ public class QueryOptionTest {
|
|||
assertEquals(SystemQueryOptionKind.ID, option.getKind());
|
||||
|
||||
option.setValue("A");
|
||||
|
||||
assertEquals("A", option.getValue());
|
||||
}
|
||||
|
||||
|
@ -163,9 +161,9 @@ public class QueryOptionTest {
|
|||
CountOptionImpl option = new CountOptionImpl();
|
||||
assertEquals(SystemQueryOptionKind.COUNT, option.getKind());
|
||||
|
||||
assertEquals(false, option.getValue());
|
||||
assertFalse(option.getValue());
|
||||
option.setValue(true);
|
||||
assertEquals(true, option.getValue());
|
||||
assertTrue(option.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -179,7 +177,7 @@ public class QueryOptionTest {
|
|||
|
||||
option = new LevelsOptionImpl();
|
||||
option.setMax();
|
||||
assertEquals(true, option.isMax());
|
||||
assertTrue(option.isMax());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -190,9 +188,9 @@ public class QueryOptionTest {
|
|||
option.setExpression(expression);
|
||||
assertEquals(expression, option.getExpression());
|
||||
|
||||
assertEquals(false, option.isDescending());
|
||||
assertFalse(option.isDescending());
|
||||
option.setDescending(true);
|
||||
assertEquals(true, option.isDescending());
|
||||
assertTrue(option.isDescending());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -233,17 +231,16 @@ public class QueryOptionTest {
|
|||
option = new SelectItemImpl();
|
||||
|
||||
option = new SelectItemImpl();
|
||||
assertEquals(false, option.isStar());
|
||||
assertFalse(option.isStar());
|
||||
option.setStar(true);
|
||||
assertEquals(true, option.isStar());
|
||||
assertTrue(option.isStar());
|
||||
|
||||
option = new SelectItemImpl();
|
||||
assertEquals(false, option.isAllOperationsInSchema());
|
||||
assertFalse(option.isAllOperationsInSchema());
|
||||
FullQualifiedName fqName = new FullQualifiedName("Namespace", "Name");
|
||||
option.addAllOperationsInSchema(fqName);
|
||||
assertEquals(true, option.isAllOperationsInSchema());
|
||||
assertTrue(option.isAllOperationsInSchema());
|
||||
assertEquals(fqName, option.getAllOperationsInSchemaNameSpace());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -251,17 +248,12 @@ public class QueryOptionTest {
|
|||
SelectOptionImpl option = new SelectOptionImpl();
|
||||
assertEquals(SystemQueryOptionKind.SELECT, option.getKind());
|
||||
|
||||
SelectItemImpl item0 = new SelectItemImpl();
|
||||
SelectItemImpl item1 = new SelectItemImpl();
|
||||
|
||||
ArrayList<SelectItemImpl> list = new ArrayList<SelectItemImpl>();
|
||||
list.add(item0);
|
||||
list.add(item1);
|
||||
option.setSelectItems(list);
|
||||
SelectItem item0 = new SelectItemImpl();
|
||||
SelectItem item1 = new SelectItemImpl();
|
||||
option.setSelectItems(Arrays.asList(item0, item1));
|
||||
|
||||
assertEquals(item0, option.getSelectItems().get(0));
|
||||
assertEquals(item1, option.getSelectItems().get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -284,11 +276,8 @@ public class QueryOptionTest {
|
|||
|
||||
@Test
|
||||
public void testSystemQueryOptionImpl() {
|
||||
SystemQueryOptionImpl option = new SystemQueryOptionImpl();
|
||||
|
||||
option.setKind(SystemQueryOptionKind.EXPAND);
|
||||
SystemQueryOptionImpl option = new ExpandOptionImpl();
|
||||
assertEquals(SystemQueryOptionKind.EXPAND, option.getKind());
|
||||
|
||||
assertEquals("$expand", option.getName());
|
||||
}
|
||||
|
||||
|
|
|
@ -24,14 +24,16 @@ import static org.junit.Assert.assertNotNull;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.EdmFunction;
|
||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||
import org.apache.olingo.server.api.uri.UriInfoKind;
|
||||
import org.apache.olingo.server.api.uri.UriInfoResource;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind;
|
||||
|
@ -41,16 +43,17 @@ import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind
|
|||
import org.apache.olingo.server.core.uri.UriInfoImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourceActionImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourceFunctionImpl;
|
||||
import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
|
||||
import org.apache.olingo.server.core.uri.testutil.FilterTreeToText;
|
||||
import org.apache.olingo.server.tecsvc.provider.ActionProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EnumTypeProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.FunctionProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExpressionTest {
|
||||
Edm edm = new EdmProviderImpl(new EdmTechTestProvider());
|
||||
private static final Edm edm = OData.newInstance().createServiceMetadata(
|
||||
new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
|
||||
|
||||
@Test
|
||||
public void testSupportedOperators() {
|
||||
|
|
|
@ -1,119 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core.uri.testutil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.ex.ODataException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlEntityType;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
|
||||
/**
|
||||
* Implement the EdmTechProvider and
|
||||
* <li>adds a entity type <b>ETabc with</b> properties a,b,c,d,e,f</li>
|
||||
* <li>adds a entity type <b>ETNavProp with</b> with a navigation property ESNavProp (named like the entity set)</li>
|
||||
* <li>adds a complex type <b>CTabc</b> with properties a,b,c,d,e,f</li>
|
||||
* <li>adds a <b>abc</b> entity set of type <b>ETabc</b></li>
|
||||
* <li>adds a <b>ESNavProp</b> entity set of type <b>ETNavProp</b></li>
|
||||
*/
|
||||
public class EdmTechTestProvider extends EdmTechProvider {
|
||||
|
||||
private static final FullQualifiedName nameInt16 = EdmPrimitiveTypeKind.Int16.getFullQualifiedName();
|
||||
public static final String NAMESPACE = "olingo.odata.test1";
|
||||
public static final FullQualifiedName nameContainer = new FullQualifiedName(NAMESPACE, "Container");
|
||||
|
||||
CsdlProperty propertyAInt16 = new CsdlProperty().setName("a").setType(nameInt16);
|
||||
CsdlProperty propertyBInt16 = new CsdlProperty().setName("b").setType(nameInt16);
|
||||
CsdlProperty propertyCInt16 = new CsdlProperty().setName("c").setType(nameInt16);
|
||||
CsdlProperty propertyDInt16 = new CsdlProperty().setName("d").setType(nameInt16);
|
||||
CsdlProperty propertyEInt16 = new CsdlProperty().setName("e").setType(nameInt16);
|
||||
CsdlProperty propertyFInt16 = new CsdlProperty().setName("f").setType(nameInt16);
|
||||
|
||||
public static final FullQualifiedName nameETNavProp = new FullQualifiedName(NAMESPACE, "ETNavProp");
|
||||
public static final FullQualifiedName nameCTabc = new FullQualifiedName(NAMESPACE, "CTabc");
|
||||
public static final FullQualifiedName nameETabc = new FullQualifiedName(NAMESPACE, "ETabc");
|
||||
|
||||
@Override
|
||||
public CsdlComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
|
||||
if (complexTypeName.equals(nameCTabc)) {
|
||||
return new CsdlComplexType()
|
||||
.setName("CTabc")
|
||||
.setProperties(Arrays.asList(
|
||||
propertyAInt16, propertyBInt16, propertyCInt16,
|
||||
propertyDInt16, propertyEInt16, propertyFInt16
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
return super.getComplexType(complexTypeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsdlEntitySet getEntitySet(final FullQualifiedName entityContainer, final String name) throws ODataException {
|
||||
if (nameContainer.equals(entityContainer)) {
|
||||
if (name.equals("ESabc")) {
|
||||
return new CsdlEntitySet()
|
||||
.setName("ESabc")
|
||||
.setType(nameETabc);
|
||||
} else if(name.equals("ESNavProp")) {
|
||||
return new CsdlEntitySet()
|
||||
.setName("ESNavProp")
|
||||
.setType(nameETNavProp);
|
||||
}
|
||||
}
|
||||
|
||||
return super.getEntitySet(entityContainer, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsdlEntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException {
|
||||
List<CsdlPropertyRef> oneKeyPropertyInt16 = Arrays.asList(new CsdlPropertyRef().setName("a"));
|
||||
|
||||
if (entityTypeName.equals(nameETabc)) {
|
||||
return new CsdlEntityType()
|
||||
.setName("ETabc")
|
||||
.setProperties(Arrays.asList(
|
||||
propertyAInt16, propertyBInt16, propertyCInt16,
|
||||
propertyDInt16, propertyEInt16, propertyFInt16))
|
||||
.setKey(oneKeyPropertyInt16);
|
||||
} else if(entityTypeName.equals(nameETNavProp)) {
|
||||
return new CsdlEntityType()
|
||||
.setName("ETNavProp")
|
||||
.setProperties(Arrays.asList(propertyAInt16))
|
||||
.setKey(oneKeyPropertyInt16)
|
||||
.setNavigationProperties(Arrays.asList(new CsdlNavigationProperty[] {
|
||||
new CsdlNavigationProperty()
|
||||
.setCollection(true)
|
||||
.setName("ESNavProp")
|
||||
.setType(nameETNavProp)
|
||||
}));
|
||||
}
|
||||
|
||||
return super.getEntityType(entityTypeName);
|
||||
}
|
||||
|
||||
}
|
|
@ -23,28 +23,23 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.uri.UriInfoKind;
|
||||
import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
|
||||
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.FilterOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.OrderByOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.QueryOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectItem;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
|
||||
import org.apache.olingo.server.core.uri.UriInfoImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.OrderByOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.QueryOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
|
||||
|
||||
public class ExpandValidator implements TestValidator {
|
||||
private Edm edm;
|
||||
private TestValidator invokedByValidator;
|
||||
|
||||
private int expandItemIndex;
|
||||
private ExpandOptionImpl expandOption;
|
||||
private ExpandOption expandOption;
|
||||
private ExpandItem expandItem;
|
||||
|
||||
// --- Setup ---
|
||||
|
@ -54,7 +49,7 @@ public class ExpandValidator implements TestValidator {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ExpandValidator setExpand(final ExpandOptionImpl expand) {
|
||||
public ExpandValidator setExpand(final ExpandOption expand) {
|
||||
expandOption = expand;
|
||||
first();
|
||||
return this;
|
||||
|
@ -76,45 +71,33 @@ public class ExpandValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public ResourceValidator goPath() {
|
||||
UriInfoImpl uriInfo = (UriInfoImpl) expandItem.getResourcePath();
|
||||
|
||||
if (uriInfo.getKind() != UriInfoKind.resource) {
|
||||
fail("goPath() can only be used on UriInfoKind.resource");
|
||||
}
|
||||
|
||||
return new ResourceValidator()
|
||||
.setUpValidator(this)
|
||||
.setEdm(edm)
|
||||
.setUriInfoImplPath(uriInfo);
|
||||
|
||||
.setUpValidator(this)
|
||||
.setEdm(edm)
|
||||
.setUriInfoPath(expandItem.getResourcePath());
|
||||
}
|
||||
|
||||
public FilterValidator goOrder(final int index) {
|
||||
OrderByOptionImpl orderBy = (OrderByOptionImpl) expandItem.getOrderByOption();
|
||||
|
||||
final OrderByOption orderBy = expandItem.getOrderByOption();
|
||||
return new FilterValidator()
|
||||
.setValidator(this)
|
||||
.setEdm(edm)
|
||||
.setExpression(orderBy.getOrders().get(index).getExpression());
|
||||
.setValidator(this)
|
||||
.setEdm(edm)
|
||||
.setExpression(orderBy.getOrders().get(index).getExpression());
|
||||
}
|
||||
|
||||
public ResourceValidator goSelectItem(final int index) {
|
||||
SelectOptionImpl select = (SelectOptionImpl) expandItem.getSelectOption();
|
||||
|
||||
final SelectOption select = expandItem.getSelectOption();
|
||||
SelectItem item = select.getSelectItems().get(index);
|
||||
UriInfoImpl uriInfo = (UriInfoImpl) item.getResourcePath();
|
||||
|
||||
return new ResourceValidator()
|
||||
.setUpValidator(this)
|
||||
.setEdm(edm)
|
||||
.setUriInfoImplPath(uriInfo);
|
||||
|
||||
.setUpValidator(this)
|
||||
.setEdm(edm)
|
||||
.setUriInfoPath(item.getResourcePath());
|
||||
}
|
||||
|
||||
public ExpandValidator goExpand() {
|
||||
return new ExpandValidator()
|
||||
.setExpand((ExpandOptionImpl) expandItem.getExpandOption())
|
||||
.setUpValidator(this);
|
||||
.setExpand(expandItem.getExpandOption())
|
||||
.setUpValidator(this);
|
||||
}
|
||||
|
||||
public ExpandValidator first() {
|
||||
|
@ -132,7 +115,6 @@ public class ExpandValidator implements TestValidator {
|
|||
fail("not enough segments");
|
||||
}
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public ExpandValidator isSegmentStar() {
|
||||
|
@ -146,31 +128,31 @@ public class ExpandValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public ExpandValidator isLevelText(final String text) {
|
||||
QueryOptionImpl option = (QueryOptionImpl) expandItem.getLevelsOption();
|
||||
final QueryOption option = (QueryOption) expandItem.getLevelsOption();
|
||||
assertEquals(text, option.getText());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpandValidator isSkipText(final String text) {
|
||||
QueryOptionImpl option = (QueryOptionImpl) expandItem.getSkipOption();
|
||||
final QueryOption option = expandItem.getSkipOption();
|
||||
assertEquals(text, option.getText());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpandValidator isTopText(final String text) {
|
||||
QueryOptionImpl option = (QueryOptionImpl) expandItem.getTopOption();
|
||||
final QueryOption option = expandItem.getTopOption();
|
||||
assertEquals(text, option.getText());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpandValidator isInlineCountText(final String text) {
|
||||
QueryOptionImpl option = (QueryOptionImpl) expandItem.getCountOption();
|
||||
final QueryOption option = expandItem.getCountOption();
|
||||
assertEquals(text, option.getText());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpandValidator isSelectText(final String text) {
|
||||
QueryOptionImpl option = (QueryOptionImpl) expandItem.getSelectOption();
|
||||
final QueryOption option = expandItem.getSelectOption();
|
||||
assertEquals(text, option.getText());
|
||||
return this;
|
||||
}
|
||||
|
@ -213,18 +195,13 @@ public class ExpandValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public ExpandValidator isSortOrder(final int index, final boolean descending) {
|
||||
OrderByOptionImpl orderBy = (OrderByOptionImpl) expandItem.getOrderByOption();
|
||||
OrderByOption orderBy = expandItem.getOrderByOption();
|
||||
assertEquals(descending, orderBy.getOrders().get(index).isDescending());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExpandValidator isExpandStartType(final FullQualifiedName fullName) {
|
||||
EdmType actualType = expandItem.getStartTypeFilter();
|
||||
|
||||
FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
|
||||
assertEquals(fullName, actualName);
|
||||
assertEquals(fullName, expandItem.getStartTypeFilter().getFullQualifiedName());
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ public class FilterTreeToText implements ExpressionVisitor<String> {
|
|||
|
||||
@Override
|
||||
public String visitTypeLiteral(final EdmType type) {
|
||||
return "<" + type.getNamespace() + "." + type.getName() + ">";
|
||||
return "<" + type.getFullQualifiedName().getFullQualifiedNameAsString() + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -147,7 +147,7 @@ public class FilterTreeToText implements ExpressionVisitor<String> {
|
|||
tmp += item;
|
||||
}
|
||||
|
||||
return "<" + type.getNamespace() + "." + type.getName() + "<" + tmp + ">>";
|
||||
return "<" + type.getFullQualifiedName().getFullQualifiedNameAsString() + "<" + tmp + ">>";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,36 +31,33 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
|||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.uri.UriInfo;
|
||||
import org.apache.olingo.server.api.uri.UriInfoKind;
|
||||
import org.apache.olingo.server.api.uri.queryoption.FilterOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.OrderByOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.Binary;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.Enumeration;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.Expression;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.Literal;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.Member;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.Method;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
|
||||
import org.apache.olingo.server.core.uri.UriInfoImpl;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.TypeLiteral;
|
||||
import org.apache.olingo.server.core.uri.parser.Parser;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserException;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
|
||||
import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.OrderByOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.BinaryImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.EnumerationImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.MemberImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.MethodImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.TypeLiteralImpl;
|
||||
|
||||
public class FilterValidator implements TestValidator {
|
||||
private Edm edm;
|
||||
|
||||
private TestValidator invokedByValidator;
|
||||
private FilterOptionImpl filter;
|
||||
private FilterOption filter;
|
||||
private OrderByOption orderBy;
|
||||
|
||||
private Expression curExpression;
|
||||
private Expression rootExpression;
|
||||
|
||||
private OrderByOptionImpl orderBy;
|
||||
|
||||
private UriParserException exception;
|
||||
|
||||
// --- Setup ---
|
||||
|
@ -84,7 +81,7 @@ public class FilterValidator implements TestValidator {
|
|||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator setFilter(final FilterOptionImpl filter) {
|
||||
public FilterValidator setFilter(final FilterOption filter) {
|
||||
this.filter = filter;
|
||||
|
||||
if (filter.getExpression() == null) {
|
||||
|
@ -94,9 +91,8 @@ public class FilterValidator implements TestValidator {
|
|||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator setOrderBy(final OrderByOptionImpl orderBy) {
|
||||
public FilterValidator setOrderBy(final OrderByOption orderBy) {
|
||||
this.orderBy = orderBy;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -175,10 +171,6 @@ public class FilterValidator implements TestValidator {
|
|||
return runUri("ESCollAllPrim(1)/CollPropertyTimeOfDay", "$filter=" + filter.trim());
|
||||
}
|
||||
|
||||
public FilterValidator runESabc(final String filter) throws UriParserException {
|
||||
return runUri("ESabc", "$filter=" + filter.trim());
|
||||
}
|
||||
|
||||
public FilterValidator runUri(final String path, final String query) throws UriParserException {
|
||||
Parser parser = new Parser();
|
||||
UriInfo uriInfo = null;
|
||||
|
@ -189,7 +181,7 @@ public class FilterValidator implements TestValidator {
|
|||
fail("Filtervalidator can only be used on resourcePaths");
|
||||
}
|
||||
|
||||
setFilter((FilterOptionImpl) uriInfo.getFilterOption());
|
||||
setFilter(uriInfo.getFilterOption());
|
||||
curExpression = filter.getExpression();
|
||||
return this;
|
||||
}
|
||||
|
@ -215,7 +207,7 @@ public class FilterValidator implements TestValidator {
|
|||
fail("Filtervalidator can only be used on resourcePaths");
|
||||
}
|
||||
|
||||
setOrderBy((OrderByOptionImpl) uriInfo.getOrderByOption());
|
||||
setOrderBy(uriInfo.getOrderByOption());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -241,22 +233,21 @@ public class FilterValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public ResourceValidator goPath() {
|
||||
if (!(curExpression instanceof MemberImpl)) {
|
||||
if (!(curExpression instanceof Member)) {
|
||||
fail("Current expression not a member");
|
||||
}
|
||||
|
||||
MemberImpl member = (MemberImpl) curExpression;
|
||||
Member member = (Member) curExpression;
|
||||
|
||||
return new ResourceValidator()
|
||||
.setEdm(edm)
|
||||
.setUriInfoImplPath((UriInfoImpl) member.getResourcePath())
|
||||
.setUpValidator(this);
|
||||
|
||||
.setEdm(edm)
|
||||
.setUriInfoPath(member.getResourcePath())
|
||||
.setUpValidator(this);
|
||||
}
|
||||
|
||||
public FilterValidator goParameter(final int parameterIndex) {
|
||||
if (curExpression instanceof MethodImpl) {
|
||||
MethodImpl methodCall = (MethodImpl) curExpression;
|
||||
if (curExpression instanceof Method) {
|
||||
Method methodCall = (Method) curExpression;
|
||||
curExpression = methodCall.getParameters().get(parameterIndex);
|
||||
} else {
|
||||
fail("Current expression not a methodCall");
|
||||
|
@ -281,13 +272,12 @@ public class FilterValidator implements TestValidator {
|
|||
String actualFilterAsText = FilterTreeToText.Serialize(filter);
|
||||
assertEquals(expectedFilterAsString, actualFilterAsText);
|
||||
} catch (ExpressionVisitException e) {
|
||||
fail("Exception occured while converting the filterTree into text" + "\n"
|
||||
fail("Exception occurred while converting the filterTree into text" + "\n"
|
||||
+ " Exception: " + e.getMessage());
|
||||
} catch (ODataApplicationException e) {
|
||||
fail("Exception occured while converting the filterTree into text" + "\n"
|
||||
fail("Exception occurred while converting the filterTree into text" + "\n"
|
||||
+ " Exception: " + e.getMessage());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -303,14 +293,14 @@ public class FilterValidator implements TestValidator {
|
|||
public FilterValidator isType(final FullQualifiedName fullName) {
|
||||
EdmType actualType = null;
|
||||
|
||||
if (curExpression instanceof MemberImpl) {
|
||||
if (curExpression instanceof Member) {
|
||||
Member member = (Member) curExpression;
|
||||
actualType = member.getType();
|
||||
} else if (curExpression instanceof TypeLiteralImpl) {
|
||||
TypeLiteralImpl typeLiteral = (TypeLiteralImpl) curExpression;
|
||||
} else if (curExpression instanceof TypeLiteral) {
|
||||
TypeLiteral typeLiteral = (TypeLiteral) curExpression;
|
||||
actualType = typeLiteral.getType();
|
||||
} else if (curExpression instanceof LiteralImpl) {
|
||||
LiteralImpl typeLiteral = (LiteralImpl) curExpression;
|
||||
} else if (curExpression instanceof Literal) {
|
||||
Literal typeLiteral = (Literal) curExpression;
|
||||
actualType = typeLiteral.getType();
|
||||
}
|
||||
|
||||
|
@ -318,158 +308,134 @@ public class FilterValidator implements TestValidator {
|
|||
fail("Current expression not typed");
|
||||
}
|
||||
|
||||
FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
|
||||
assertEquals(fullName, actualName);
|
||||
assertEquals(fullName, actualType.getFullQualifiedName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator left() {
|
||||
if (!(curExpression instanceof BinaryImpl)) {
|
||||
if (!(curExpression instanceof Binary)) {
|
||||
fail("Current expression not a binary operator");
|
||||
}
|
||||
|
||||
curExpression = ((BinaryImpl) curExpression).getLeftOperand();
|
||||
|
||||
curExpression = ((Binary) curExpression).getLeftOperand();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator root() {
|
||||
if (filter != null) {
|
||||
curExpression = filter.getExpression();
|
||||
} else {
|
||||
curExpression = rootExpression;
|
||||
}
|
||||
|
||||
curExpression = filter == null ? rootExpression : filter.getExpression();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator right() {
|
||||
if (!(curExpression instanceof BinaryImpl)) {
|
||||
if (!(curExpression instanceof Binary)) {
|
||||
fail("Current expression is not a binary operator");
|
||||
}
|
||||
|
||||
curExpression = ((BinaryImpl) curExpression).getRightOperand();
|
||||
|
||||
curExpression = ((Binary) curExpression).getRightOperand();
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public FilterValidator isLiteral(final String literalText) {
|
||||
if (!(curExpression instanceof LiteralImpl)) {
|
||||
if (!(curExpression instanceof Literal)) {
|
||||
fail("Current expression is not a literal");
|
||||
}
|
||||
|
||||
String actualLiteralText = ((LiteralImpl) curExpression).getText();
|
||||
String actualLiteralText = ((Literal) curExpression).getText();
|
||||
assertEquals(literalText, actualLiteralText);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator isLiteralType(EdmType edmType) {
|
||||
if(!(curExpression instanceof LiteralImpl)) {
|
||||
fail("Current expression is nit a literal");
|
||||
if(!(curExpression instanceof Literal)) {
|
||||
fail("Current expression is not a literal");
|
||||
}
|
||||
|
||||
final EdmType type = ((LiteralImpl) curExpression).getType();
|
||||
final EdmType type = ((Literal) curExpression).getType();
|
||||
assertNotNull(type);
|
||||
assertEquals(edmType.getClass(), type.getClass());
|
||||
|
||||
assertEquals(edmType, type);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public FilterValidator isNullLiteralType() {
|
||||
if(!(curExpression instanceof LiteralImpl)) {
|
||||
fail("Current expression is nit a literal");
|
||||
if(!(curExpression instanceof Literal)) {
|
||||
fail("Current expression is not a literal");
|
||||
}
|
||||
|
||||
final EdmType type = ((LiteralImpl) curExpression).getType();
|
||||
|
||||
final EdmType type = ((Literal) curExpression).getType();
|
||||
assertNull(type);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public FilterValidator isMethod(final MethodKind methodKind, final int parameterCount) {
|
||||
if (!(curExpression instanceof MethodImpl)) {
|
||||
if (!(curExpression instanceof Method)) {
|
||||
fail("Current expression is not a methodCall");
|
||||
}
|
||||
|
||||
MethodImpl methodCall = (MethodImpl) curExpression;
|
||||
Method methodCall = (Method) curExpression;
|
||||
assertEquals(methodKind, methodCall.getMethod());
|
||||
assertEquals(parameterCount, methodCall.getParameters().size());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator isParameterText(final int parameterIndex, final String parameterText)
|
||||
throws ExpressionVisitException, ODataApplicationException {
|
||||
|
||||
if (!(curExpression instanceof MethodImpl)) {
|
||||
if (!(curExpression instanceof Method)) {
|
||||
fail("Current expression is not a method");
|
||||
}
|
||||
|
||||
MethodImpl methodCall = (MethodImpl) curExpression;
|
||||
Method methodCall = (Method) curExpression;
|
||||
|
||||
Expression parameter = methodCall.getParameters().get(parameterIndex);
|
||||
String actualParameterText = FilterTreeToText.Serialize(parameter);
|
||||
assertEquals(parameterText, actualParameterText);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator isBinary(final BinaryOperatorKind binaryOperator) {
|
||||
if (!(curExpression instanceof BinaryImpl)) {
|
||||
if (!(curExpression instanceof Binary)) {
|
||||
fail("Current expression is not a binary operator");
|
||||
}
|
||||
|
||||
BinaryImpl binary = (BinaryImpl) curExpression;
|
||||
Binary binary = (Binary) curExpression;
|
||||
assertEquals(binaryOperator, binary.getOperator());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator isTypedLiteral(final FullQualifiedName fullName) {
|
||||
if (!(curExpression instanceof TypeLiteralImpl)) {
|
||||
if (!(curExpression instanceof TypeLiteral)) {
|
||||
fail("Current expression not a typeLiteral");
|
||||
}
|
||||
|
||||
isType(fullName);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator isMember() {
|
||||
if (!(curExpression instanceof MemberImpl)) {
|
||||
if (!(curExpression instanceof Member)) {
|
||||
fail("Current expression not a member");
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator isMemberStartType(final FullQualifiedName fullName) {
|
||||
if (!(curExpression instanceof MemberImpl)) {
|
||||
fail("Current expression not a member");
|
||||
}
|
||||
|
||||
MemberImpl member = (MemberImpl) curExpression;
|
||||
isMember();
|
||||
Member member = (Member) curExpression;
|
||||
EdmType actualType = member.getStartTypeFilter();
|
||||
|
||||
FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
|
||||
assertEquals(fullName, actualName);
|
||||
assertEquals(fullName, actualType.getFullQualifiedName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilterValidator isEnum(final FullQualifiedName nameenstring, final List<String> enumValues) {
|
||||
if (!(curExpression instanceof EnumerationImpl)) {
|
||||
if (!(curExpression instanceof Enumeration)) {
|
||||
fail("Current expression not a enumeration");
|
||||
}
|
||||
|
||||
EnumerationImpl enumeration = (EnumerationImpl) curExpression;
|
||||
|
||||
FullQualifiedName actualName =
|
||||
new FullQualifiedName(enumeration.getType().getNamespace(), enumeration.getType().getName());
|
||||
Enumeration enumeration = (Enumeration) curExpression;
|
||||
|
||||
// check name
|
||||
assertEquals(nameenstring.toString(), actualName.toString());
|
||||
assertEquals(nameenstring, enumeration.getType().getFullQualifiedName());
|
||||
|
||||
// check values
|
||||
int i = 0;
|
||||
|
@ -504,33 +470,10 @@ public class FilterValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public FilterValidator isNull() {
|
||||
if (!(curExpression instanceof LiteralImpl)) {
|
||||
fail("Current expression is not a literal");
|
||||
}
|
||||
|
||||
String actualLiteralText = ((LiteralImpl) curExpression).getText();
|
||||
assertEquals("null", actualLiteralText);
|
||||
return this;
|
||||
return isLiteral("null");
|
||||
}
|
||||
|
||||
public FilterValidator isTrue() {
|
||||
if (!(curExpression instanceof LiteralImpl)) {
|
||||
fail("Current expression is not a literal");
|
||||
}
|
||||
|
||||
String actualLiteralText = ((LiteralImpl) curExpression).getText();
|
||||
assertEquals("true", actualLiteralText);
|
||||
return this;
|
||||
return isLiteral("true");
|
||||
}
|
||||
|
||||
public FilterValidator isFalse() {
|
||||
if (!(curExpression instanceof LiteralImpl)) {
|
||||
fail("Current expression is not a literal");
|
||||
}
|
||||
|
||||
String actualLiteralText = ((LiteralImpl) curExpression).getText();
|
||||
assertEquals("false", actualLiteralText);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core.uri.testutil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.misc.NotNull;
|
||||
import org.antlr.v4.runtime.misc.Nullable;
|
||||
import org.antlr.v4.runtime.misc.Utils;
|
||||
import org.antlr.v4.runtime.tree.ErrorNode;
|
||||
import org.antlr.v4.runtime.tree.RuleNode;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
import org.antlr.v4.runtime.tree.Tree;
|
||||
|
||||
public class ParseTreeToText {
|
||||
|
||||
public static String getTreeAsText(final Tree contextTree, final String[] ruleNames) {
|
||||
return toStringTree(contextTree, Arrays.asList(ruleNames));
|
||||
}
|
||||
|
||||
private static String toStringTree(final Tree t, @Nullable final List<String> ruleNames) {
|
||||
|
||||
if (t.getChildCount() == 0) {
|
||||
return Utils.escapeWhitespace(getNodeText(t, ruleNames), false);
|
||||
}
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
String s = Utils.escapeWhitespace(getNodeText(t, ruleNames), false);
|
||||
buf.append(s);
|
||||
buf.append("(");
|
||||
|
||||
for (int i = 0; i < t.getChildCount(); i++) {
|
||||
if (i > 0) {
|
||||
buf.append(' ');
|
||||
}
|
||||
buf.append(toStringTree(t.getChild(i), ruleNames));
|
||||
}
|
||||
buf.append(")");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static String getNodeText(@NotNull final Tree t, @Nullable final List<String> ruleNames) {
|
||||
if (ruleNames != null) {
|
||||
if (t instanceof RuleNode) {
|
||||
int ruleIndex = ((RuleNode) t).getRuleContext().getRuleIndex();
|
||||
return ruleNames.get(ruleIndex);
|
||||
} else if (t instanceof ErrorNode) {
|
||||
return t.toString();
|
||||
} else if (t instanceof TerminalNode) {
|
||||
Token symbol = ((TerminalNode) t).getSymbol();
|
||||
if (symbol != null) {
|
||||
return symbol.getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
// no recog for rule names
|
||||
Object payload = t.getPayload();
|
||||
if (payload instanceof Token) {
|
||||
return ((Token) payload).getText();
|
||||
}
|
||||
return t.getPayload().toString();
|
||||
}
|
||||
}
|
|
@ -1,162 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.core.uri.testutil;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
import org.apache.olingo.server.core.uri.antlr.UriParserParser;
|
||||
|
||||
public class ParserValidator {
|
||||
|
||||
private String input = null;
|
||||
private ParserRuleContext root;
|
||||
|
||||
int logLevel = 0;
|
||||
private int lexerLogLevel = 0;
|
||||
|
||||
boolean allowFullContext;
|
||||
boolean allowContextSensitifity;
|
||||
boolean allowAmbiguity;
|
||||
|
||||
List<Exception> exceptions = new ArrayList<Exception>();
|
||||
private Exception curException = null;
|
||||
|
||||
// --- Setup ---
|
||||
|
||||
public ParserValidator log(final int logLevel) {
|
||||
this.logLevel = logLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParserValidator lexerLog(final int logLevel) {
|
||||
lexerLogLevel = logLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in fast LL Parsing:
|
||||
* Don't stop the parsing process when the slower full context parsing (with prediction mode SLL) is
|
||||
* required
|
||||
* @return {@link ParserValidator}
|
||||
*/
|
||||
public ParserValidator aFC() {
|
||||
allowFullContext = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in fast LL Parsing:
|
||||
* Allows ContextSensitifity Errors which occur often when using the slower full context parsing
|
||||
* and indicate that there is a context sensitivity ( which may not be an error).
|
||||
* @return {@link ParserValidator}
|
||||
*/
|
||||
public ParserValidator aCS() {
|
||||
allowContextSensitifity = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in fast LL Parsing:
|
||||
* Allows ambiguities
|
||||
* @return {@link ParserValidator}
|
||||
*/
|
||||
public ParserValidator aAM() {
|
||||
allowAmbiguity = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
// --- Execution ---
|
||||
|
||||
public ParserValidator run(final String uri) {
|
||||
input = uri;
|
||||
|
||||
// just run a short lexer step. E.g. to print the tokens
|
||||
if (lexerLogLevel > 0) {
|
||||
(new TokenValidator()).log(lexerLogLevel).run(input);
|
||||
}
|
||||
|
||||
/**/// root = parseInput(uri);
|
||||
|
||||
// if LOG > 0 - Write serialized tree
|
||||
if (logLevel > 0) {
|
||||
if (root != null) {
|
||||
System.out.println(ParseTreeToText.getTreeAsText(root, new UriParserParser(null).getRuleNames()));
|
||||
} else {
|
||||
System.out.println("root == null");
|
||||
}
|
||||
}
|
||||
|
||||
// reset for next test
|
||||
allowFullContext = false;
|
||||
allowContextSensitifity = false;
|
||||
allowAmbiguity = false;
|
||||
logLevel = 0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// --- Navigation ---
|
||||
|
||||
public ParserValidator exFirst() {
|
||||
try {
|
||||
// curWeakException = exceptions.get(0);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
// curWeakException = null;
|
||||
}
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public ParserValidator exLast() {
|
||||
// curWeakException = exceptions.get(exceptions.size() - 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParserValidator exAt(final int index) {
|
||||
try {
|
||||
// curWeakException = exceptions.get(index);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
// curWeakException = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// --- Validation ---
|
||||
|
||||
public ParserValidator isText(final String expected) {
|
||||
|
||||
assertEquals(null, curException);
|
||||
assertEquals(0, exceptions.size());
|
||||
|
||||
String actualTreeAsText = ParseTreeToText.getTreeAsText(root, new UriParserParser(null).getRuleNames());
|
||||
|
||||
assertEquals(expected, actualTreeAsText);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParserValidator isExeptionType(final Class<?> exClass) {
|
||||
assertEquals(exClass, curException.getClass());
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@ package org.apache.olingo.server.core.uri.testutil;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -29,32 +30,27 @@ import org.apache.olingo.commons.api.edm.EdmElement;
|
|||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.uri.UriInfo;
|
||||
import org.apache.olingo.server.api.uri.UriInfoKind;
|
||||
import org.apache.olingo.server.api.uri.UriInfoResource;
|
||||
import org.apache.olingo.server.api.uri.UriParameter;
|
||||
import org.apache.olingo.server.api.uri.UriResource;
|
||||
import org.apache.olingo.server.api.uri.UriResourceAction;
|
||||
import org.apache.olingo.server.api.uri.UriResourceComplexProperty;
|
||||
import org.apache.olingo.server.api.uri.UriResourceEntitySet;
|
||||
import org.apache.olingo.server.api.uri.UriResourceFunction;
|
||||
import org.apache.olingo.server.api.uri.UriResourceKind;
|
||||
import org.apache.olingo.server.api.uri.UriResourceLambdaAll;
|
||||
import org.apache.olingo.server.api.uri.UriResourceLambdaAny;
|
||||
import org.apache.olingo.server.api.uri.UriResourceNavigation;
|
||||
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
|
||||
import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption;
|
||||
import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
|
||||
import org.apache.olingo.server.api.uri.UriResourceSingleton;
|
||||
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectItem;
|
||||
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
|
||||
import org.apache.olingo.server.core.uri.UriInfoImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourceActionImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourceComplexPropertyImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourceEntitySetImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourceFunctionImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourceImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourceLambdaAllImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourceLambdaAnyImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourceNavigationPropertyImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourcePrimitivePropertyImpl;
|
||||
import org.apache.olingo.server.core.uri.UriResourceSingletonImpl;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
||||
import org.apache.olingo.server.core.uri.UriResourceWithKeysImpl;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserException;
|
||||
import org.apache.olingo.server.core.uri.queryoption.CustomQueryOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl;
|
||||
import org.apache.olingo.server.core.uri.validator.UriValidationException;
|
||||
import org.apache.olingo.server.core.uri.validator.UriValidator;
|
||||
|
||||
|
@ -63,7 +59,7 @@ public class ResourceValidator implements TestValidator {
|
|||
private TestValidator invokedBy;
|
||||
private UriInfo uriInfo = null;
|
||||
|
||||
private UriResourceImpl uriPathInfo = null;
|
||||
private UriResource uriPathInfo = null;
|
||||
private int uriResourceIndex;
|
||||
|
||||
// --- Setup ---
|
||||
|
@ -78,8 +74,8 @@ public class ResourceValidator implements TestValidator {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator setUriInfoImplPath(final UriInfo uriInfoPath) {
|
||||
uriInfo = uriInfoPath;
|
||||
public ResourceValidator setUriInfoPath(final UriInfoResource uriInfoPath) {
|
||||
uriInfo = (UriInfo) uriInfoPath;
|
||||
last();
|
||||
return this;
|
||||
}
|
||||
|
@ -130,7 +126,7 @@ public class ResourceValidator implements TestValidator {
|
|||
|
||||
public FilterValidator goParameter(final int index) {
|
||||
assertEquals(UriResourceKind.function, uriPathInfo.getKind());
|
||||
UriResourceFunctionImpl function = (UriResourceFunctionImpl) uriPathInfo;
|
||||
UriResourceFunction function = (UriResourceFunction) uriPathInfo;
|
||||
|
||||
return new FilterValidator()
|
||||
.setEdm(edm)
|
||||
|
@ -142,12 +138,12 @@ public class ResourceValidator implements TestValidator {
|
|||
if (uriPathInfo.getKind() == UriResourceKind.lambdaAll) {
|
||||
return new FilterValidator()
|
||||
.setEdm(edm)
|
||||
.setExpression(((UriResourceLambdaAllImpl) uriPathInfo).getExpression());
|
||||
.setExpression(((UriResourceLambdaAll) uriPathInfo).getExpression());
|
||||
|
||||
} else if (uriPathInfo.getKind() == UriResourceKind.lambdaAny) {
|
||||
return new FilterValidator()
|
||||
.setEdm(edm)
|
||||
.setExpression(((UriResourceLambdaAnyImpl) uriPathInfo).getExpression());
|
||||
.setExpression(((UriResourceLambdaAny) uriPathInfo).getExpression());
|
||||
} else {
|
||||
fail("invalid resource kind: " + uriPathInfo.getKind().toString());
|
||||
}
|
||||
|
@ -155,20 +151,16 @@ public class ResourceValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public ResourceValidator goSelectItem(final int index) {
|
||||
SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
|
||||
|
||||
final SelectOption select = uriInfo.getSelectOption();
|
||||
SelectItem item = select.getSelectItems().get(index);
|
||||
UriInfoImpl uriInfo1 = (UriInfoImpl) item.getResourcePath();
|
||||
|
||||
return new ResourceValidator()
|
||||
.setUpValidator(this)
|
||||
.setEdm(edm)
|
||||
.setUriInfoImplPath(uriInfo1);
|
||||
|
||||
.setUpValidator(this)
|
||||
.setEdm(edm)
|
||||
.setUriInfoPath(item.getResourcePath());
|
||||
}
|
||||
|
||||
public ExpandValidator goExpand() {
|
||||
ExpandOptionImpl expand = (ExpandOptionImpl) uriInfo.getExpandOption();
|
||||
final ExpandOption expand = uriInfo.getExpandOption();
|
||||
if (expand == null) {
|
||||
fail("invalid resource kind: " + uriPathInfo.getKind().toString());
|
||||
}
|
||||
|
@ -177,41 +169,30 @@ public class ResourceValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public ResourceValidator first() {
|
||||
uriResourceIndex = 0;
|
||||
uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(0);
|
||||
return this;
|
||||
return at(0);
|
||||
}
|
||||
|
||||
public ResourceValidator last() {
|
||||
uriResourceIndex = 0;
|
||||
|
||||
try {
|
||||
uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(uriInfo.getUriResourceParts().size() - 1);
|
||||
uriResourceIndex = uriInfo.getUriResourceParts().size() - 1;
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
final List<UriResource> parts = uriInfo.getUriResourceParts();
|
||||
if (parts.isEmpty()) {
|
||||
uriResourceIndex = 0;
|
||||
fail("not enough segments");
|
||||
} else {
|
||||
uriResourceIndex = parts.size() - 1;
|
||||
uriPathInfo = parts.get(uriResourceIndex);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator n() {
|
||||
uriResourceIndex++;
|
||||
|
||||
try {
|
||||
uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(uriResourceIndex);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
fail("not enough segments");
|
||||
}
|
||||
|
||||
return this;
|
||||
return at(uriResourceIndex + 1);
|
||||
}
|
||||
|
||||
public ResourceValidator at(final int index) {
|
||||
uriResourceIndex = index;
|
||||
try {
|
||||
uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(index);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
if (index < uriInfo.getUriResourceParts().size()) {
|
||||
uriPathInfo = uriInfo.getUriResourceParts().get(index);
|
||||
} else {
|
||||
fail("not enough segments");
|
||||
}
|
||||
return this;
|
||||
|
@ -222,9 +203,9 @@ public class ResourceValidator implements TestValidator {
|
|||
public ResourceValidator isLambdaVar(final String var) {
|
||||
String actualVar = null;
|
||||
if (uriPathInfo.getKind() == UriResourceKind.lambdaAll) {
|
||||
actualVar = ((UriResourceLambdaAllImpl) uriPathInfo).getLambdaVariable();
|
||||
actualVar = ((UriResourceLambdaAll) uriPathInfo).getLambdaVariable();
|
||||
} else if (uriPathInfo.getKind() == UriResourceKind.lambdaAny) {
|
||||
actualVar = ((UriResourceLambdaAnyImpl) uriPathInfo).getLambdaVariable();
|
||||
actualVar = ((UriResourceLambdaAny) uriPathInfo).getLambdaVariable();
|
||||
} else {
|
||||
fail("invalid resource kind: " + uriPathInfo.getKind().toString());
|
||||
}
|
||||
|
@ -241,19 +222,17 @@ public class ResourceValidator implements TestValidator {
|
|||
}
|
||||
|
||||
EdmType actualType = null;
|
||||
if (uriPathInfo instanceof UriResourceComplexPropertyImpl) {
|
||||
actualType = ((UriResourceComplexPropertyImpl) uriPathInfo).getComplexTypeFilter();
|
||||
} else if (uriPathInfo instanceof UriResourceSingletonImpl) {
|
||||
actualType = ((UriResourceSingletonImpl) uriPathInfo).getEntityTypeFilter();
|
||||
if (uriPathInfo instanceof UriResourceComplexProperty) {
|
||||
actualType = ((UriResourceComplexProperty) uriPathInfo).getComplexTypeFilter();
|
||||
} else if (uriPathInfo instanceof UriResourceSingleton) {
|
||||
actualType = ((UriResourceSingleton) uriPathInfo).getEntityTypeFilter();
|
||||
}
|
||||
|
||||
if (actualType == null) {
|
||||
fail("type information not set");
|
||||
}
|
||||
|
||||
FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
|
||||
|
||||
assertEquals(expectedType.toString(), actualName.toString());
|
||||
assertEquals(expectedType, actualType.getFullQualifiedName());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -267,10 +246,7 @@ public class ResourceValidator implements TestValidator {
|
|||
if (actualType == null) {
|
||||
fail("type information not set");
|
||||
}
|
||||
|
||||
FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
|
||||
|
||||
assertEquals(type.toString(), actualName.toString());
|
||||
assertEquals(type, actualType.getFullQualifiedName());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -290,11 +266,7 @@ public class ResourceValidator implements TestValidator {
|
|||
|
||||
// input parameter type may be null in order to assert that the singleTypeFilter is not set
|
||||
EdmType actualType = uriPathInfoKeyPred.getTypeFilterOnEntry();
|
||||
if (type == null) {
|
||||
assertEquals(type, actualType);
|
||||
} else {
|
||||
assertEquals(type.toString(), new FullQualifiedName(actualType.getNamespace(), actualType.getName()).toString());
|
||||
}
|
||||
assertEquals(type, type == null ? actualType : actualType.getFullQualifiedName());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -307,48 +279,12 @@ public class ResourceValidator implements TestValidator {
|
|||
|
||||
// input parameter type may be null in order to assert that the collectionTypeFilter is not set
|
||||
EdmType actualType = uriPathInfoKeyPred.getTypeFilterOnCollection();
|
||||
if (expectedType == null) {
|
||||
assertEquals(expectedType, actualType);
|
||||
} else {
|
||||
FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
|
||||
assertEquals(expectedType.toString(), actualName.toString());
|
||||
}
|
||||
assertEquals(expectedType, expectedType == null ? actualType : actualType.getFullQualifiedName());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// other functions
|
||||
public ResourceValidator checkCustomParameter(final int index, final String name, final String value) {
|
||||
if (uriInfo == null) {
|
||||
fail("hasQueryParameter: uriInfo == null");
|
||||
}
|
||||
|
||||
List<CustomQueryOption> list = uriInfo.getCustomQueryOptions();
|
||||
if (list.size() <= index) {
|
||||
fail("not enough queryParameters");
|
||||
}
|
||||
|
||||
CustomQueryOptionImpl option = (CustomQueryOptionImpl) list.get(index);
|
||||
assertEquals(name, option.getName());
|
||||
assertEquals(value, option.getText());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isFilterString(final String expectedFilterTreeAsString) {
|
||||
|
||||
ExpressionImpl filterTree = (ExpressionImpl) uriInfo.getFilterOption().getExpression();
|
||||
try {
|
||||
String filterTreeAsString = filterTree.accept(new FilterTreeToText());
|
||||
assertEquals(expectedFilterTreeAsString, filterTreeAsString);
|
||||
} catch (ExpressionVisitException e) {
|
||||
fail("isFilterString: Exception " + e.getMessage() + " occured");
|
||||
} catch (ODataApplicationException e) {
|
||||
fail("isFilterString: Exception " + e.getMessage() + " occured");
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isKeyPredicateRef(final int index, final String name, final String refencedProperty) {
|
||||
if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) {
|
||||
fail("invalid resource kind: " + uriPathInfo.getKind().toString());
|
||||
|
@ -359,7 +295,6 @@ public class ResourceValidator implements TestValidator {
|
|||
assertEquals(name, keyPredicates.get(index).getName());
|
||||
assertEquals(refencedProperty, keyPredicates.get(index).getReferencedProperty());
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public ResourceValidator isKeyPredicateAlias(final int index, final String name, final String alias) {
|
||||
|
@ -389,11 +324,11 @@ public class ResourceValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public ResourceValidator isParameter(final int index, final String name, final String text) {
|
||||
if (!(uriPathInfo instanceof UriResourceFunctionImpl)) {
|
||||
if (!(uriPathInfo instanceof UriResourceFunction)) {
|
||||
fail("invalid resource kind: " + uriPathInfo.getKind().toString());
|
||||
}
|
||||
|
||||
UriResourceFunctionImpl info = (UriResourceFunctionImpl) uriPathInfo;
|
||||
UriResourceFunction info = (UriResourceFunction) uriPathInfo;
|
||||
List<UriParameter> keyPredicates = info.getParameters();
|
||||
assertEquals(name, keyPredicates.get(index).getName());
|
||||
assertEquals(text, keyPredicates.get(index).getText());
|
||||
|
@ -402,11 +337,11 @@ public class ResourceValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public ResourceValidator isParameterAlias(final int index, final String name, final String alias) {
|
||||
if (!(uriPathInfo instanceof UriResourceFunctionImpl)) {
|
||||
if (!(uriPathInfo instanceof UriResourceFunction)) {
|
||||
fail("invalid resource kind: " + uriPathInfo.getKind().toString());
|
||||
}
|
||||
|
||||
UriResourceFunctionImpl info = (UriResourceFunctionImpl) uriPathInfo;
|
||||
UriResourceFunction info = (UriResourceFunction) uriPathInfo;
|
||||
List<UriParameter> keyPredicates = info.getParameters();
|
||||
assertEquals(name, keyPredicates.get(index).getName());
|
||||
assertEquals(alias, keyPredicates.get(index).getAlias());
|
||||
|
@ -421,47 +356,47 @@ public class ResourceValidator implements TestValidator {
|
|||
|
||||
public ResourceValidator isPrimitiveProperty(final String name,
|
||||
final FullQualifiedName type, final boolean isCollection) {
|
||||
if (!(uriPathInfo instanceof UriResourcePrimitivePropertyImpl)) {
|
||||
if (!(uriPathInfo instanceof UriResourcePrimitiveProperty)) {
|
||||
fail("invalid resource kind: " + uriPathInfo.getKind().toString());
|
||||
}
|
||||
|
||||
UriResourcePrimitivePropertyImpl uriPathInfoProp = (UriResourcePrimitivePropertyImpl) uriPathInfo;
|
||||
UriResourcePrimitiveProperty uriPathInfoProp = (UriResourcePrimitiveProperty) uriPathInfo;
|
||||
|
||||
EdmElement property = uriPathInfoProp.getProperty();
|
||||
|
||||
assertEquals(name, property.getName());
|
||||
assertEquals(type, new FullQualifiedName(property.getType().getNamespace(), property.getType().getName()));
|
||||
assertEquals(type, property.getType().getFullQualifiedName());
|
||||
assertEquals(isCollection, property.isCollection());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator
|
||||
isComplexProperty(final String name, final FullQualifiedName type, final boolean isCollection) {
|
||||
if (!(uriPathInfo instanceof UriResourceComplexPropertyImpl)) {
|
||||
public ResourceValidator isComplexProperty(final String name, final FullQualifiedName type,
|
||||
final boolean isCollection) {
|
||||
if (!(uriPathInfo instanceof UriResourceComplexProperty)) {
|
||||
fail("invalid resource kind: " + uriPathInfo.getKind().toString());
|
||||
}
|
||||
|
||||
UriResourceComplexPropertyImpl uriPathInfoProp = (UriResourceComplexPropertyImpl) uriPathInfo;
|
||||
UriResourceComplexProperty uriPathInfoProp = (UriResourceComplexProperty) uriPathInfo;
|
||||
|
||||
EdmElement property = uriPathInfoProp.getProperty();
|
||||
|
||||
assertEquals(name, property.getName());
|
||||
assertEquals(type, new FullQualifiedName(property.getType().getNamespace(), property.getType().getName()));
|
||||
assertEquals(type, property.getType().getFullQualifiedName());
|
||||
assertEquals(isCollection, property.isCollection());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isNavProperty(final String name, final FullQualifiedName type, final boolean isCollection) {
|
||||
if (!(uriPathInfo instanceof UriResourceNavigationPropertyImpl)) {
|
||||
if (!(uriPathInfo instanceof UriResourceNavigation)) {
|
||||
fail("invalid resource kind: " + uriPathInfo.getKind().toString());
|
||||
}
|
||||
|
||||
UriResourceNavigationPropertyImpl uriPathInfoProp = (UriResourceNavigationPropertyImpl) uriPathInfo;
|
||||
UriResourceNavigation uriPathInfoProp = (UriResourceNavigation) uriPathInfo;
|
||||
|
||||
EdmElement property = uriPathInfoProp.getProperty();
|
||||
|
||||
assertEquals(name, property.getName());
|
||||
assertEquals(type, new FullQualifiedName(property.getType().getNamespace(), property.getType().getName()));
|
||||
assertEquals(type, property.getType().getFullQualifiedName());
|
||||
assertEquals(isCollection, uriPathInfoProp.isCollection());
|
||||
return this;
|
||||
}
|
||||
|
@ -473,65 +408,61 @@ public class ResourceValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public ResourceValidator isAction(final String name) {
|
||||
assertEquals(UriResourceKind.action, uriPathInfo.getKind());
|
||||
assertEquals(name, ((UriResourceActionImpl) uriPathInfo).getAction().getName());
|
||||
isUriPathInfoKind(UriResourceKind.action);
|
||||
assertEquals(name, ((UriResourceAction) uriPathInfo).getAction().getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isFunction(final String name) {
|
||||
assertEquals(UriResourceKind.function, uriPathInfo.getKind());
|
||||
assertEquals(name, ((UriResourceFunctionImpl) uriPathInfo).getFunction().getName());
|
||||
isUriPathInfoKind(UriResourceKind.function);
|
||||
assertEquals(name, ((UriResourceFunction) uriPathInfo).getFunction().getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isFunctionImport(final String name) {
|
||||
assertEquals(UriResourceKind.function, uriPathInfo.getKind());
|
||||
assertEquals(name, ((UriResourceFunctionImpl) uriPathInfo).getFunctionImport().getName());
|
||||
isUriPathInfoKind(UriResourceKind.function);
|
||||
assertEquals(name, ((UriResourceFunction) uriPathInfo).getFunctionImport().getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isEntitySet(final String name) {
|
||||
assertEquals(UriResourceKind.entitySet, uriPathInfo.getKind());
|
||||
assertEquals(name, ((UriResourceEntitySetImpl) uriPathInfo).getEntitySet().getName());
|
||||
isUriPathInfoKind(UriResourceKind.entitySet);
|
||||
assertEquals(name, ((UriResourceEntitySet) uriPathInfo).getEntitySet().getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isComplex(final String name) {
|
||||
assertEquals(UriResourceKind.complexProperty, uriPathInfo.getKind());
|
||||
assertEquals(name, ((UriResourceComplexPropertyImpl) uriPathInfo).getProperty().getName());
|
||||
isUriPathInfoKind(UriResourceKind.complexProperty);
|
||||
assertEquals(name, ((UriResourceComplexProperty) uriPathInfo).getProperty().getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isSingleton(final String name) {
|
||||
assertEquals(UriResourceKind.singleton, uriPathInfo.getKind());
|
||||
assertEquals(name, ((UriResourceSingletonImpl) uriPathInfo).getSingleton().getName());
|
||||
isUriPathInfoKind(UriResourceKind.singleton);
|
||||
assertEquals(name, ((UriResourceSingleton) uriPathInfo).getSingleton().getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isValue() {
|
||||
assertEquals(UriResourceKind.value, uriPathInfo.getKind());
|
||||
return this;
|
||||
return isUriPathInfoKind(UriResourceKind.value);
|
||||
}
|
||||
|
||||
public ResourceValidator isCount() {
|
||||
assertEquals(UriResourceKind.count, uriPathInfo.getKind());
|
||||
return this;
|
||||
return isUriPathInfoKind(UriResourceKind.count);
|
||||
}
|
||||
|
||||
public ResourceValidator isRef() {
|
||||
assertEquals(UriResourceKind.ref, uriPathInfo.getKind());
|
||||
return this;
|
||||
return isUriPathInfoKind(UriResourceKind.ref);
|
||||
}
|
||||
|
||||
public ResourceValidator isActionImport(final String actionName) {
|
||||
assertEquals(UriResourceKind.action, uriPathInfo.getKind());
|
||||
assertEquals(actionName, ((UriResourceActionImpl) uriPathInfo).getActionImport().getName());
|
||||
isUriPathInfoKind(UriResourceKind.action);
|
||||
assertEquals(actionName, ((UriResourceAction) uriPathInfo).getActionImport().getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isIt() {
|
||||
assertEquals(UriResourceKind.it, uriPathInfo.getKind());
|
||||
return this;
|
||||
return isUriPathInfoKind(UriResourceKind.it);
|
||||
}
|
||||
|
||||
public ResourceValidator isTopText(final String topText) {
|
||||
|
@ -560,29 +491,24 @@ public class ResourceValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public ResourceValidator isSelectItemStar(final int index) {
|
||||
SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
|
||||
|
||||
final SelectOption select = uriInfo.getSelectOption();
|
||||
SelectItem item = select.getSelectItems().get(index);
|
||||
assertEquals(true, item.isStar());
|
||||
assertTrue(item.isStar());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isSelectItemAllOp(final int index, final FullQualifiedName fqn) {
|
||||
SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
|
||||
|
||||
final SelectOption select = uriInfo.getSelectOption();
|
||||
SelectItem item = select.getSelectItems().get(index);
|
||||
assertEquals(fqn.toString(), item.getAllOperationsInSchemaNameSpace().toString());
|
||||
assertEquals(fqn, item.getAllOperationsInSchemaNameSpace());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceValidator isSelectStartType(final int index, final FullQualifiedName fullName) {
|
||||
SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
|
||||
final SelectOption select = uriInfo.getSelectOption();
|
||||
SelectItem item = select.getSelectItems().get(index);
|
||||
|
||||
EdmType actualType = item.getStartTypeFilter();
|
||||
|
||||
FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
|
||||
assertEquals(fullName, actualName);
|
||||
assertEquals(fullName, actualType.getFullQualifiedName());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -591,5 +517,4 @@ public class ResourceValidator implements TestValidator {
|
|||
assertEquals(value, valueForAlias);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
package org.apache.olingo.server.core.uri.testutil;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.EdmType;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
|
@ -32,16 +32,14 @@ import org.apache.olingo.server.api.ODataLibraryException;
|
|||
import org.apache.olingo.server.api.uri.UriInfo;
|
||||
import org.apache.olingo.server.api.uri.UriInfoKind;
|
||||
import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.FilterOption;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectItem;
|
||||
import org.apache.olingo.server.core.uri.UriInfoImpl;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
||||
import org.apache.olingo.server.core.uri.parser.Parser;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserException;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
|
||||
import org.apache.olingo.server.core.uri.queryoption.CustomQueryOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
|
||||
import org.apache.olingo.server.core.uri.validator.UriValidationException;
|
||||
import org.apache.olingo.server.core.uri.validator.UriValidator;
|
||||
|
||||
|
@ -95,7 +93,6 @@ public class TestUriValidator implements TestValidator {
|
|||
} catch (UriValidationException e) {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -106,22 +103,21 @@ public class TestUriValidator implements TestValidator {
|
|||
}
|
||||
|
||||
return new ResourceValidator()
|
||||
.setUpValidator(this)
|
||||
.setEdm(edm)
|
||||
.setUriInfoImplPath(uriInfo);
|
||||
.setUpValidator(this)
|
||||
.setEdm(edm)
|
||||
.setUriInfoPath(uriInfo);
|
||||
}
|
||||
|
||||
public FilterValidator goFilter() {
|
||||
FilterOptionImpl filter = (FilterOptionImpl) uriInfo.getFilterOption();
|
||||
final FilterOption filter = uriInfo.getFilterOption();
|
||||
if (filter == null) {
|
||||
fail("no filter found");
|
||||
}
|
||||
return new FilterValidator().setUriValidator(this).setFilter(filter);
|
||||
|
||||
}
|
||||
|
||||
public ExpandValidator goExpand() {
|
||||
ExpandOptionImpl expand = (ExpandOptionImpl) uriInfo.getExpandOption();
|
||||
final ExpandOption expand = uriInfo.getExpandOption();
|
||||
if (expand == null) {
|
||||
fail("invalid resource kind: " + uriInfo.getKind().toString());
|
||||
}
|
||||
|
@ -130,27 +126,20 @@ public class TestUriValidator implements TestValidator {
|
|||
}
|
||||
|
||||
public ResourceValidator goSelectItemPath(final int index) {
|
||||
SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
|
||||
|
||||
final SelectOption select = uriInfo.getSelectOption();
|
||||
SelectItem item = select.getSelectItems().get(index);
|
||||
UriInfoImpl uriInfo1 = (UriInfoImpl) item.getResourcePath();
|
||||
|
||||
return new ResourceValidator()
|
||||
.setUpValidator(this)
|
||||
.setEdm(edm)
|
||||
.setUriInfoImplPath(uriInfo1);
|
||||
|
||||
.setUpValidator(this)
|
||||
.setEdm(edm)
|
||||
.setUriInfoPath(item.getResourcePath());
|
||||
}
|
||||
|
||||
public TestUriValidator isSelectStartType(final int index, final FullQualifiedName fullName) {
|
||||
SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
|
||||
final SelectOption select = uriInfo.getSelectOption();
|
||||
SelectItem item = select.getSelectItems().get(index);
|
||||
EdmType actualType = item.getStartTypeFilter();
|
||||
|
||||
FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
|
||||
assertEquals(fullName, actualName);
|
||||
assertEquals(fullName, actualType.getFullQualifiedName());
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
// Validation
|
||||
|
@ -169,7 +158,7 @@ public class TestUriValidator implements TestValidator {
|
|||
fail("not enough queryParameters");
|
||||
}
|
||||
|
||||
CustomQueryOptionImpl option = (CustomQueryOptionImpl) list.get(index);
|
||||
CustomQueryOption option = list.get(index);
|
||||
assertEquals(name, option.getName());
|
||||
assertEquals(value, option.getText());
|
||||
return this;
|
||||
|
@ -185,7 +174,6 @@ public class TestUriValidator implements TestValidator {
|
|||
assertEquals(entitySet, uriInfo.getEntitySetNames().get(i));
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TestUriValidator isExSyntax(final UriParserSyntaxException.MessageKeys messageKey) {
|
||||
|
@ -232,7 +220,6 @@ public class TestUriValidator implements TestValidator {
|
|||
}
|
||||
|
||||
assertEquals(text, uriInfo.getFragment());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -241,27 +228,21 @@ public class TestUriValidator implements TestValidator {
|
|||
fail("invalid resource kind: " + uriInfo.getKind().toString());
|
||||
}
|
||||
|
||||
assertEquals(fullName.toString(), fullName(uriInfo.getEntityTypeCast()));
|
||||
assertEquals(fullName, uriInfo.getEntityTypeCast().getFullQualifiedName());
|
||||
return this;
|
||||
}
|
||||
|
||||
private String fullName(final EdmEntityType type) {
|
||||
return type.getNamespace() + "." + type.getName();
|
||||
}
|
||||
|
||||
public TestUriValidator isSelectItemStar(final int index) {
|
||||
SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
|
||||
|
||||
final SelectOption select = uriInfo.getSelectOption();
|
||||
SelectItem item = select.getSelectItems().get(index);
|
||||
assertEquals(true, item.isStar());
|
||||
assertTrue(item.isStar());
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestUriValidator isSelectItemAllOp(final int index, final FullQualifiedName fqn) {
|
||||
SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
|
||||
|
||||
final SelectOption select = uriInfo.getSelectOption();
|
||||
SelectItem item = select.getSelectItems().get(index);
|
||||
assertEquals(fqn.toString(), item.getAllOperationsInSchemaNameSpace().toString());
|
||||
assertEquals(fqn, item.getAllOperationsInSchemaNameSpace());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,12 @@ package org.apache.olingo.server.core.uri.validator;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||
import org.apache.olingo.server.api.uri.UriInfo;
|
||||
import org.apache.olingo.server.core.uri.parser.Parser;
|
||||
import org.apache.olingo.server.core.uri.parser.UriParserException;
|
||||
|
@ -327,7 +330,8 @@ public class UriValidatorTest {
|
|||
{ URI_ACTION_ES, QO_ID },
|
||||
};
|
||||
|
||||
private static final Edm edm = new EdmProviderImpl(new EdmTechProvider());
|
||||
private static final Edm edm = OData.newInstance().createServiceMetadata(
|
||||
new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
|
||||
|
||||
@Test
|
||||
public void validatePostOnActionSystemQueryOptions() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue