[OLINGO-704] Small fix TecSvc
This commit is contained in:
parent
b51117477b
commit
b3dcaa25b3
|
@ -24,6 +24,7 @@ import static org.junit.Assert.assertNull;
|
|||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -37,7 +38,9 @@ import org.apache.olingo.client.api.communication.response.ODataReferenceAddingR
|
|||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
import org.apache.olingo.client.api.domain.ClientEntity;
|
||||
import org.apache.olingo.client.api.domain.ClientEntitySet;
|
||||
import org.apache.olingo.client.api.domain.ClientObjectFactory;
|
||||
import org.apache.olingo.client.api.uri.QueryOption;
|
||||
import org.apache.olingo.client.api.uri.URIBuilder;
|
||||
import org.apache.olingo.client.core.ODataClientFactory;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
|
@ -984,6 +987,49 @@ public class EntityReferencesITCase extends AbstractBaseTestITCase {
|
|||
assertNull(responseGetESTwoKeyNav.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMissingNavigationProperty() throws Exception {
|
||||
final ODataClient client = getClient();
|
||||
final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendRefSegment().build();
|
||||
final URI ref = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build();
|
||||
|
||||
try {
|
||||
client.getCUDRequestFactory().getReferenceAddingRequest(new URI(SERVICE_URI), uri, ref).execute();
|
||||
} catch (ODataClientErrorException e) {
|
||||
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMissingNavigationProperty() throws Exception {
|
||||
final ODataClient client = getClient();
|
||||
final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
|
||||
.appendKeySegment(1)
|
||||
.appendRefSegment()
|
||||
.build();
|
||||
final URI ref = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build();
|
||||
|
||||
try {
|
||||
client.getCUDRequestFactory().getReferenceSingleChangeRequest(new URI(SERVICE_URI), uri, ref).execute();
|
||||
} catch (ODataClientErrorException e) {
|
||||
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMissingNavigationProperty() {
|
||||
final ODataClient client = getClient();
|
||||
final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
|
||||
.appendRefSegment()
|
||||
.build();
|
||||
|
||||
try {
|
||||
client.getCUDRequestFactory().getDeleteRequest(uri);
|
||||
} catch (ODataClientErrorException e) {
|
||||
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
private void sendRequest(final URI uri, final int count, final String... expected) {
|
||||
final ODataClient client = getClient();
|
||||
final ODataRetrieveResponse<ClientEntitySet> response = client.getRetrieveRequestFactory()
|
||||
|
|
|
@ -318,6 +318,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
|
|||
|
||||
final Entity entity = readEntity(uriInfo, true);
|
||||
final UriResourceNavigation navigationProperty = getLastNavigation(uriInfo);
|
||||
ensureNavigationPropertyNotNull(navigationProperty);
|
||||
dataProvider.createReference(entity, navigationProperty.getProperty(), references.getEntityReferences().get(0),
|
||||
request.getRawBaseUri());
|
||||
|
||||
|
@ -338,6 +339,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
|
|||
|
||||
final Entity entity = readEntity(uriInfo, true);
|
||||
final UriResourceNavigation navigationProperty = getLastNavigation(uriInfo);
|
||||
ensureNavigationPropertyNotNull(navigationProperty);
|
||||
dataProvider.createReference(entity, navigationProperty.getProperty(), references.getEntityReferences().get(0),
|
||||
request.getRawBaseUri());
|
||||
|
||||
|
@ -350,7 +352,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
|
|||
|
||||
final UriResourceNavigation lastNavigation = getLastNavigation(uriInfo);
|
||||
final IdOption idOption = uriInfo.getIdOption();
|
||||
|
||||
|
||||
ensureNavigationPropertyNotNull(lastNavigation);
|
||||
if (lastNavigation.isCollection() && idOption == null) {
|
||||
throw new ODataApplicationException("Id system query option must be provided",
|
||||
HttpStatusCode.BAD_REQUEST.getStatusCode(),
|
||||
|
@ -537,4 +540,12 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
|
|||
.suffix(isSingleEntity && entitySet != null ? Suffix.ENTITY : null);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private void ensureNavigationPropertyNotNull(final UriResourceNavigation navigationProperty)
|
||||
throws ODataApplicationException {
|
||||
if(navigationProperty == null) {
|
||||
throw new ODataApplicationException("Missing navigation segment", HttpStatusCode.BAD_REQUEST.getStatusCode(),
|
||||
Locale.ROOT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,8 +213,9 @@ public abstract class TechnicalProcessor implements Processor {
|
|||
&& resourcePaths.get(navigationCount) instanceof UriResourceNavigation) {
|
||||
navigationCount++;
|
||||
}
|
||||
|
||||
return (UriResourceNavigation) resourcePaths.get(--navigationCount);
|
||||
|
||||
final UriResource lastSegment = resourcePaths.get(--navigationCount);
|
||||
return (lastSegment instanceof UriResourceNavigation) ? (UriResourceNavigation) lastSegment : null;
|
||||
}
|
||||
|
||||
private void blockTypeFilters(final UriResource uriResource) throws ODataApplicationException {
|
||||
|
|
Loading…
Reference in New Issue