This commit is contained in:
parent
b5ff47837f
commit
717d69b979
|
@ -94,13 +94,14 @@ public class UriHelperImpl implements UriHelper {
|
|||
result.append(Encoder.encode(value));
|
||||
} catch (final EdmPrimitiveTypeException e) {
|
||||
throw new SerializerException("Wrong key value!", e,
|
||||
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, edmProperty.getName(), propertyValue.toString());
|
||||
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, edmProperty.getName(),
|
||||
propertyValue != null ? propertyValue.toString(): null);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private Object findPropertyRefValue(Entity entity, EdmKeyPropertyRef refType) {
|
||||
private Object findPropertyRefValue(Entity entity, EdmKeyPropertyRef refType) throws SerializerException {
|
||||
final int INDEX_ERROR_CODE = -1;
|
||||
final String propertyPath = refType.getName();
|
||||
String tmpPropertyName;
|
||||
|
@ -122,6 +123,10 @@ public class UriHelperImpl implements UriHelper {
|
|||
tmpPropertyName = propertyPath.substring(lastIndex, index);
|
||||
prop = findProperty(tmpPropertyName, prop.asComplex().getValue());
|
||||
}
|
||||
if (prop == null) {
|
||||
throw new SerializerException("Key Value Cannot be null for property: " + propertyPath,
|
||||
SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, propertyPath);
|
||||
}
|
||||
return prop.getValue();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,13 @@
|
|||
*/
|
||||
package org.apache.olingo.server.core.uri;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.Property;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
|
@ -32,7 +36,9 @@ import org.apache.olingo.server.api.uri.UriHelper;
|
|||
import org.apache.olingo.server.tecsvc.data.DataProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
public class UriHelperTest {
|
||||
|
||||
|
@ -78,4 +84,29 @@ public class UriHelperTest {
|
|||
entity.getProperty("PropertyInt16").setValue(ValueType.PRIMITIVE, "wrong");
|
||||
helper.buildCanonicalURL(entitySet, entity);
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedEx = ExpectedException.none();
|
||||
|
||||
@Test(expected = SerializerException.class)
|
||||
public void canonicalURLWithoutKeys() throws Exception {
|
||||
final EdmEntitySet entitySet = container.getEntitySet("ESAllPrim");
|
||||
Entity entity = data.readAll(entitySet).getEntities().get(0);
|
||||
List<Property> properties = entity.getProperties();
|
||||
properties.remove(0);
|
||||
helper.buildCanonicalURL(entitySet, entity);
|
||||
expectedEx.expect(SerializerException.class);
|
||||
expectedEx.expectMessage("Key Value Cannot be null for property: PropertyInt16");
|
||||
}
|
||||
|
||||
@Test(expected = SerializerException.class)
|
||||
public void canonicalURLWithKeyHavingNullValue() throws Exception {
|
||||
final EdmEntitySet entitySet = container.getEntitySet("ESAllPrim");
|
||||
Entity entity = data.readAll(entitySet).getEntities().get(0);
|
||||
Property property = entity.getProperties().get(0);
|
||||
property.setValue(property.getValueType(), null);
|
||||
helper.buildCanonicalURL(entitySet, entity);
|
||||
expectedEx.expect(SerializerException.class);
|
||||
expectedEx.expectMessage("Wrong key value!");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue