[OLINGO-422] Minor code refactorings and fixes
This commit is contained in:
parent
a1d9f747b8
commit
588ae2a70c
|
@ -47,8 +47,7 @@ public final class ContextURLHelper {
|
|||
public static String buildSelectList(final EdmEntityType entityType,
|
||||
final ExpandOption expand, final SelectOption select) throws ODataSerializerException {
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean isSelected = select != null && select.getSelectItems() != null && !select.getSelectItems().isEmpty();
|
||||
if(isSelected) {
|
||||
if (ExpandSelectHelper.hasSelect(select)) {
|
||||
handleSelect(entityType, select, result);
|
||||
}
|
||||
|
||||
|
@ -58,7 +57,7 @@ public final class ContextURLHelper {
|
|||
return result.length() == 0 ? null : result.toString();
|
||||
}
|
||||
|
||||
private static void handleSelect(EdmEntityType entityType, SelectOption select, StringBuilder result) {
|
||||
private static void handleSelect(final EdmEntityType entityType, final SelectOption select, StringBuilder result) {
|
||||
if (ExpandSelectHelper.isAll(select)) {
|
||||
result.append('*');
|
||||
} else {
|
||||
|
@ -98,7 +97,7 @@ public final class ContextURLHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private static void handleExpand(EdmEntityType entityType, ExpandOption expand, StringBuilder result)
|
||||
private static void handleExpand(final EdmEntityType entityType, final ExpandOption expand, StringBuilder result)
|
||||
throws ODataSerializerException {
|
||||
final Set<String> expandedPropertyNames = ExpandSelectHelper.getExpandedPropertyNames(expand.getExpandItems());
|
||||
for (final String propertyName : entityType.getNavigationPropertyNames()) {
|
||||
|
@ -109,10 +108,12 @@ public final class ContextURLHelper {
|
|||
|| ExpandSelectHelper.hasSelect(expandItem.getSelectOption())) {
|
||||
final String innerSelectList = buildSelectList(entityType.getNavigationProperty(propertyName).getType(),
|
||||
expandItem.getExpandOption(), expandItem.getSelectOption());
|
||||
if (result.length() > 0) {
|
||||
result.append(',');
|
||||
if (innerSelectList != null) {
|
||||
if (result.length() > 0) {
|
||||
result.append(',');
|
||||
}
|
||||
result.append(Encoder.encode(propertyName)).append('(').append(innerSelectList).append(')');
|
||||
}
|
||||
result.append(Encoder.encode(propertyName)).append('(').append(innerSelectList).append(')');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmElement;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
||||
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||
import org.apache.olingo.server.api.uri.UriInfoResource;
|
||||
import org.apache.olingo.server.api.uri.UriResource;
|
||||
import org.apache.olingo.server.api.uri.UriResourceNavigation;
|
||||
import org.apache.olingo.server.api.uri.UriResourceProperty;
|
||||
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.SelectItem;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public final class ExpandSelectMock {
|
||||
|
||||
private static UriInfoResource mockResource(final EdmEntitySet edmEntitySet, final String... names) {
|
||||
EdmStructuredType type = edmEntitySet.getEntityType();
|
||||
List<UriResource> elements = new ArrayList<UriResource>();
|
||||
for (final String name : Arrays.asList(names)) {
|
||||
final EdmElement edmElement = type.getProperty(name);
|
||||
if (edmElement.getType().getKind() == EdmTypeKind.ENTITY) {
|
||||
UriResourceNavigation element = Mockito.mock(UriResourceNavigation.class);
|
||||
Mockito.when(element.getProperty()).thenReturn((EdmNavigationProperty) edmElement);
|
||||
elements.add(element);
|
||||
} else {
|
||||
final EdmProperty property = (EdmProperty) edmElement;
|
||||
UriResourceProperty element = Mockito.mock(UriResourceProperty.class);
|
||||
Mockito.when(element.getProperty()).thenReturn(property);
|
||||
elements.add(element);
|
||||
type = property.isPrimitive() ? null : (EdmStructuredType) property.getType();
|
||||
}
|
||||
}
|
||||
UriInfoResource resource = Mockito.mock(UriInfoResource.class);
|
||||
Mockito.when(resource.getUriResourceParts()).thenReturn(elements);
|
||||
return resource;
|
||||
}
|
||||
|
||||
public static SelectItem mockSelectItem(final EdmEntitySet edmEntitySet, final String... names) {
|
||||
final UriInfoResource resource = mockResource(edmEntitySet, names);
|
||||
SelectItem selectItem = Mockito.mock(SelectItem.class);
|
||||
Mockito.when(selectItem.getResourcePath()).thenReturn(resource);
|
||||
return selectItem;
|
||||
}
|
||||
|
||||
public static SelectOption mockSelectOption(final List<SelectItem> selectItems) {
|
||||
SelectOption select = Mockito.mock(SelectOption.class);
|
||||
Mockito.when(select.getSelectItems()).thenReturn(selectItems);
|
||||
return select;
|
||||
}
|
||||
|
||||
public static ExpandItem mockExpandItem(final EdmEntitySet edmEntitySet, final String... names) {
|
||||
final UriInfoResource resource = mockResource(edmEntitySet, names);
|
||||
ExpandItem expandItem = Mockito.mock(ExpandItem.class);
|
||||
Mockito.when(expandItem.getResourcePath()).thenReturn(resource);
|
||||
return expandItem;
|
||||
}
|
||||
|
||||
public static ExpandOption mockExpandOption(final List<ExpandItem> expandItems) {
|
||||
ExpandOption expand = Mockito.mock(ExpandOption.class);
|
||||
Mockito.when(expand.getExpandItems()).thenReturn(expandItems);
|
||||
return expand;
|
||||
}
|
||||
}
|
|
@ -20,9 +20,7 @@ package org.apache.olingo.server.core.serializer.json;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
|
@ -31,28 +29,20 @@ import org.apache.olingo.commons.api.data.Entity;
|
|||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.ValueType;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmElement;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.edm.EdmStructuredType;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializerException;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializerOptions;
|
||||
import org.apache.olingo.server.api.uri.UriInfoResource;
|
||||
import org.apache.olingo.server.api.uri.UriResource;
|
||||
import org.apache.olingo.server.api.uri.UriResourceNavigation;
|
||||
import org.apache.olingo.server.api.uri.UriResourceProperty;
|
||||
import org.apache.olingo.server.api.uri.queryoption.CountOption;
|
||||
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.SelectItem;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
||||
import org.apache.olingo.server.core.serializer.ExpandSelectMock;
|
||||
import org.apache.olingo.server.tecsvc.data.DataProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
|
@ -347,9 +337,10 @@ public class ODataJsonSerializerTest {
|
|||
public void select() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
|
||||
final SelectItem selectItem1 = mockSelectItem(edmEntitySet, "PropertyDate");
|
||||
final SelectItem selectItem2 = mockSelectItem(edmEntitySet, "PropertyBoolean");
|
||||
final SelectOption select = mockSelectOption(Arrays.asList(selectItem1, selectItem2, selectItem2));
|
||||
final SelectItem selectItem1 = ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyDate");
|
||||
final SelectItem selectItem2 = ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyBoolean");
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
|
||||
selectItem1, selectItem2, selectItem2));
|
||||
InputStream result = serializer
|
||||
.entity(edmEntitySet, entity,
|
||||
ODataSerializerOptions.with()
|
||||
|
@ -369,10 +360,10 @@ public class ODataJsonSerializerTest {
|
|||
public void selectAll() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
|
||||
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
|
||||
final SelectItem selectItem1 = mockSelectItem(edmEntitySet, "PropertyString");
|
||||
final SelectItem selectItem1 = ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyString");
|
||||
SelectItem selectItem2 = Mockito.mock(SelectItem.class);
|
||||
Mockito.when(selectItem2.isStar()).thenReturn(true);
|
||||
final SelectOption select = mockSelectOption(Arrays.asList(selectItem1, selectItem2));
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem1, selectItem2));
|
||||
InputStream result = serializer.entity(edmEntitySet, entity,
|
||||
ODataSerializerOptions.with()
|
||||
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
|
||||
|
@ -388,8 +379,8 @@ public class ODataJsonSerializerTest {
|
|||
public void selectComplex() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompComp");
|
||||
final EntitySet entitySet = data.readAll(edmEntitySet);
|
||||
final SelectOption select = mockSelectOption(Arrays.asList(
|
||||
mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString")));
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
|
||||
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString")));
|
||||
InputStream result = serializer
|
||||
.entitySet(edmEntitySet, entitySet,
|
||||
ODataSerializerOptions.with()
|
||||
|
@ -411,9 +402,9 @@ public class ODataJsonSerializerTest {
|
|||
public void selectComplexTwice() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompComp");
|
||||
final EntitySet entitySet = data.readAll(edmEntitySet);
|
||||
final SelectOption select = mockSelectOption(Arrays.asList(
|
||||
mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString"),
|
||||
mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp")));
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
|
||||
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString"),
|
||||
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp")));
|
||||
final String resultString = IOUtils.toString(serializer
|
||||
.entitySet(edmEntitySet, entitySet,
|
||||
ODataSerializerOptions.with()
|
||||
|
@ -434,8 +425,8 @@ public class ODataJsonSerializerTest {
|
|||
public void expand() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
|
||||
final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
|
||||
final ExpandOption expand = mockExpandOption(Arrays.asList(
|
||||
mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne")));
|
||||
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
|
||||
ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne")));
|
||||
InputStream result = serializer.entity(edmEntitySet, entity,
|
||||
ODataSerializerOptions.with()
|
||||
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
|
||||
|
@ -468,11 +459,11 @@ public class ODataJsonSerializerTest {
|
|||
public void expandSelect() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
|
||||
final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
|
||||
final SelectOption select = mockSelectOption(Arrays.asList(
|
||||
mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyDate")));
|
||||
ExpandItem expandItem = mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne");
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
|
||||
ExpandSelectMock.mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyDate")));
|
||||
ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne");
|
||||
Mockito.when(expandItem.getSelectOption()).thenReturn(select);
|
||||
final ExpandOption expand = mockExpandOption(Arrays.asList(expandItem));
|
||||
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem));
|
||||
final String resultString = IOUtils.toString(serializer
|
||||
.entity(edmEntitySet, entity,
|
||||
ODataSerializerOptions.with()
|
||||
|
@ -492,11 +483,13 @@ public class ODataJsonSerializerTest {
|
|||
public void expandAll() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
|
||||
final ExpandItem expandItem = mockExpandItem(edmEntitySet, "NavPropertyETTwoPrimOne");
|
||||
final ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETTwoPrimOne");
|
||||
ExpandItem expandItemAll = Mockito.mock(ExpandItem.class);
|
||||
Mockito.when(expandItemAll.isStar()).thenReturn(true);
|
||||
final ExpandOption expand = mockExpandOption(Arrays.asList(expandItem, expandItem, expandItemAll));
|
||||
final SelectOption select = mockSelectOption(Arrays.asList(mockSelectItem(edmEntitySet, "PropertySByte")));
|
||||
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
|
||||
expandItem, expandItem, expandItemAll));
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
|
||||
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertySByte")));
|
||||
final String resultString = IOUtils.toString(serializer
|
||||
.entity(edmEntitySet, entity,
|
||||
ODataSerializerOptions.with()
|
||||
|
@ -520,8 +513,9 @@ public class ODataJsonSerializerTest {
|
|||
final Entity entity = data.readAll(edmEntitySet).getEntities().get(1);
|
||||
ExpandItem expandItemAll = Mockito.mock(ExpandItem.class);
|
||||
Mockito.when(expandItemAll.isStar()).thenReturn(true);
|
||||
final ExpandOption expand = mockExpandOption(Arrays.asList(expandItemAll));
|
||||
final SelectOption select = mockSelectOption(Arrays.asList(mockSelectItem(edmEntitySet, "PropertyTimeOfDay")));
|
||||
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemAll));
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
|
||||
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyTimeOfDay")));
|
||||
final String resultString = IOUtils.toString(serializer
|
||||
.entity(edmEntitySet, entity,
|
||||
ODataSerializerOptions.with()
|
||||
|
@ -545,13 +539,13 @@ public class ODataJsonSerializerTest {
|
|||
final Entity entity = data.readAll(edmEntitySet).getEntities().get(1);
|
||||
ExpandItem expandItemSecond = Mockito.mock(ExpandItem.class);
|
||||
Mockito.when(expandItemSecond.isStar()).thenReturn(true);
|
||||
final ExpandOption expandInner = mockExpandOption(Arrays.asList(expandItemSecond));
|
||||
ExpandItem expandItemFirst = mockExpandItem(edmEntitySet, "NavPropertyETAllPrimMany");
|
||||
final ExpandOption expandInner = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemSecond));
|
||||
ExpandItem expandItemFirst = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimMany");
|
||||
Mockito.when(expandItemFirst.getExpandOption()).thenReturn(expandInner);
|
||||
final SelectOption select = mockSelectOption(Arrays.asList(
|
||||
mockSelectItem(innerEntitySet, "PropertyInt32")));
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
|
||||
ExpandSelectMock.mockSelectItem(innerEntitySet, "PropertyInt32")));
|
||||
Mockito.when(expandItemFirst.getSelectOption()).thenReturn(select);
|
||||
final ExpandOption expand = mockExpandOption(Arrays.asList(expandItemFirst));
|
||||
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemFirst));
|
||||
final String resultString = IOUtils.toString(serializer
|
||||
.entity(edmEntitySet, entity,
|
||||
ODataSerializerOptions.with()
|
||||
|
@ -572,52 +566,4 @@ public class ODataJsonSerializerTest {
|
|||
+ "{\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"}]}]}",
|
||||
resultString);
|
||||
}
|
||||
|
||||
private static UriInfoResource mockResource(final EdmEntitySet edmEntitySet, final String... names) {
|
||||
EdmStructuredType type = edmEntitySet.getEntityType();
|
||||
List<UriResource> elements = new ArrayList<UriResource>();
|
||||
for (final String name : Arrays.asList(names)) {
|
||||
final EdmElement edmElement = type.getProperty(name);
|
||||
if (edmElement.getType().getKind() == EdmTypeKind.ENTITY) {
|
||||
UriResourceNavigation element = Mockito.mock(UriResourceNavigation.class);
|
||||
Mockito.when(element.getProperty()).thenReturn((EdmNavigationProperty) edmElement);
|
||||
elements.add(element);
|
||||
} else {
|
||||
final EdmProperty property = (EdmProperty) edmElement;
|
||||
UriResourceProperty element = Mockito.mock(UriResourceProperty.class);
|
||||
Mockito.when(element.getProperty()).thenReturn(property);
|
||||
elements.add(element);
|
||||
type = property.isPrimitive() ? null : (EdmStructuredType) property.getType();
|
||||
}
|
||||
}
|
||||
UriInfoResource resource = Mockito.mock(UriInfoResource.class);
|
||||
Mockito.when(resource.getUriResourceParts()).thenReturn(elements);
|
||||
return resource;
|
||||
}
|
||||
|
||||
public static SelectItem mockSelectItem(final EdmEntitySet edmEntitySet, final String... names) {
|
||||
final UriInfoResource resource = mockResource(edmEntitySet, names);
|
||||
SelectItem selectItem = Mockito.mock(SelectItem.class);
|
||||
Mockito.when(selectItem.getResourcePath()).thenReturn(resource);
|
||||
return selectItem;
|
||||
}
|
||||
|
||||
public static SelectOption mockSelectOption(final List<SelectItem> selectItems) {
|
||||
SelectOption select = Mockito.mock(SelectOption.class);
|
||||
Mockito.when(select.getSelectItems()).thenReturn(selectItems);
|
||||
return select;
|
||||
}
|
||||
|
||||
public static ExpandItem mockExpandItem(final EdmEntitySet edmEntitySet, final String... names) {
|
||||
final UriInfoResource resource = mockResource(edmEntitySet, names);
|
||||
ExpandItem expandItem = Mockito.mock(ExpandItem.class);
|
||||
Mockito.when(expandItem.getResourcePath()).thenReturn(resource);
|
||||
return expandItem;
|
||||
}
|
||||
|
||||
public static ExpandOption mockExpandOption(final List<ExpandItem> expandItems) {
|
||||
ExpandOption expand = Mockito.mock(ExpandOption.class);
|
||||
Mockito.when(expand.getExpandItems()).thenReturn(expandItems);
|
||||
return expand;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ 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.SelectItem;
|
||||
import org.apache.olingo.server.api.uri.queryoption.SelectOption;
|
||||
import org.apache.olingo.server.core.serializer.json.ODataJsonSerializerTest;
|
||||
import org.apache.olingo.server.core.serializer.ExpandSelectMock;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
@ -46,9 +46,9 @@ public class ContextURLHelperTest {
|
|||
@Test
|
||||
public void buildSelect() throws Exception {
|
||||
final EdmEntitySet entitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
final SelectItem selectItem1 = ODataJsonSerializerTest.mockSelectItem(entitySet, "PropertyString");
|
||||
final SelectItem selectItem2 = ODataJsonSerializerTest.mockSelectItem(entitySet, "PropertyInt16");
|
||||
final SelectOption select = ODataJsonSerializerTest.mockSelectOption(Arrays.asList(
|
||||
final SelectItem selectItem1 = ExpandSelectMock.mockSelectItem(entitySet, "PropertyString");
|
||||
final SelectItem selectItem2 = ExpandSelectMock.mockSelectItem(entitySet, "PropertyInt16");
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
|
||||
selectItem1, selectItem2, selectItem2));
|
||||
final ContextURL contextURL = ContextURL.with().entitySet(entitySet)
|
||||
.selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build();
|
||||
|
@ -59,10 +59,10 @@ public class ContextURLHelperTest {
|
|||
@Test
|
||||
public void buildSelectAll() throws Exception {
|
||||
final EdmEntitySet entitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
final SelectItem selectItem1 = ODataJsonSerializerTest.mockSelectItem(entitySet, "PropertyGuid");
|
||||
final SelectItem selectItem1 = ExpandSelectMock.mockSelectItem(entitySet, "PropertyGuid");
|
||||
SelectItem selectItem2 = Mockito.mock(SelectItem.class);
|
||||
Mockito.when(selectItem2.isStar()).thenReturn(true);
|
||||
final SelectOption select = ODataJsonSerializerTest.mockSelectOption(Arrays.asList(selectItem1, selectItem2));
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem1, selectItem2));
|
||||
final ContextURL contextURL = ContextURL.with().entitySet(entitySet)
|
||||
.selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build();
|
||||
assertEquals("$metadata#ESAllPrim(*)", ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
|
@ -71,14 +71,14 @@ public class ContextURLHelperTest {
|
|||
@Test
|
||||
public void buildSelectComplex() throws Exception {
|
||||
final EdmEntitySet entitySet = entityContainer.getEntitySet("ESCompMixPrimCollComp");
|
||||
final SelectOption select = ODataJsonSerializerTest.mockSelectOption(Arrays.asList(
|
||||
ODataJsonSerializerTest.mockSelectItem(entitySet,
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
|
||||
ExpandSelectMock.mockSelectItem(entitySet,
|
||||
"PropertyMixedPrimCollComp", "PropertyComp", "PropertyString"),
|
||||
ODataJsonSerializerTest.mockSelectItem(entitySet,
|
||||
ExpandSelectMock.mockSelectItem(entitySet,
|
||||
"PropertyMixedPrimCollComp", "PropertyComp", "PropertyInt16"),
|
||||
ODataJsonSerializerTest.mockSelectItem(entitySet, "PropertyMixedPrimCollComp", "CollPropertyString"),
|
||||
ODataJsonSerializerTest.mockSelectItem(entitySet, "PropertyMixedPrimCollComp", "CollPropertyComp"),
|
||||
ODataJsonSerializerTest.mockSelectItem(entitySet, "PropertyInt16")));
|
||||
ExpandSelectMock.mockSelectItem(entitySet, "PropertyMixedPrimCollComp", "CollPropertyString"),
|
||||
ExpandSelectMock.mockSelectItem(entitySet, "PropertyMixedPrimCollComp", "CollPropertyComp"),
|
||||
ExpandSelectMock.mockSelectItem(entitySet, "PropertyInt16")));
|
||||
final ContextURL contextURL = ContextURL.with().entitySet(entitySet)
|
||||
.selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build();
|
||||
assertEquals("$metadata#ESCompMixPrimCollComp("
|
||||
|
@ -95,7 +95,7 @@ public class ContextURLHelperTest {
|
|||
final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim");
|
||||
ExpandItem expandItem = Mockito.mock(ExpandItem.class);
|
||||
Mockito.when(expandItem.isStar()).thenReturn(true);
|
||||
final ExpandOption expand = ODataJsonSerializerTest.mockExpandOption(Arrays.asList(expandItem));
|
||||
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem));
|
||||
final ContextURL contextURL = ContextURL.with().entitySet(entitySet)
|
||||
.selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build();
|
||||
assertEquals("$metadata#ESTwoPrim", ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
|
@ -104,8 +104,8 @@ public class ContextURLHelperTest {
|
|||
@Test
|
||||
public void buildExpandNoSelect() throws Exception {
|
||||
final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim");
|
||||
final ExpandOption expand = ODataJsonSerializerTest.mockExpandOption(Arrays.asList(
|
||||
ODataJsonSerializerTest.mockExpandItem(entitySet, "NavPropertyETAllPrimOne")));
|
||||
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
|
||||
ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne")));
|
||||
final ContextURL contextURL = ContextURL.with().entitySet(entitySet)
|
||||
.selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build();
|
||||
assertEquals("$metadata#ESTwoPrim", ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
|
@ -114,35 +114,63 @@ public class ContextURLHelperTest {
|
|||
@Test
|
||||
public void buildExpandSelect() throws Exception {
|
||||
final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim");
|
||||
final ExpandItem expandItem1 = ODataJsonSerializerTest.mockExpandItem(entitySet, "NavPropertyETAllPrimOne");
|
||||
final ExpandItem expandItem1 = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne");
|
||||
final EdmEntitySet innerEntitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
ExpandItem expandItem2 = ODataJsonSerializerTest.mockExpandItem(entitySet, "NavPropertyETAllPrimMany");
|
||||
final SelectOption innerSelect = ODataJsonSerializerTest.mockSelectOption(Arrays.asList(
|
||||
ODataJsonSerializerTest.mockSelectItem(innerEntitySet, "PropertyInt32")));
|
||||
ExpandItem expandItem2 = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimMany");
|
||||
final SelectOption innerSelect = ExpandSelectMock.mockSelectOption(Arrays.asList(
|
||||
ExpandSelectMock.mockSelectItem(innerEntitySet, "PropertyInt32")));
|
||||
Mockito.when(expandItem2.getSelectOption()).thenReturn(innerSelect);
|
||||
final ExpandOption expand = ODataJsonSerializerTest.mockExpandOption(Arrays.asList(
|
||||
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
|
||||
expandItem1, expandItem2));
|
||||
final SelectItem selectItem = ODataJsonSerializerTest.mockSelectItem(entitySet, "PropertyString");
|
||||
final SelectOption select = ODataJsonSerializerTest.mockSelectOption(Arrays.asList(selectItem));
|
||||
final SelectItem selectItem = ExpandSelectMock.mockSelectItem(entitySet, "PropertyString");
|
||||
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem));
|
||||
final ContextURL contextURL = ContextURL.with().entitySet(entitySet)
|
||||
.selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, select)).build();
|
||||
assertEquals("$metadata#ESTwoPrim(PropertyString,NavPropertyETAllPrimMany(PropertyInt32))",
|
||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildExpandTwoLevels() throws Exception {
|
||||
final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim");
|
||||
final EdmEntitySet innerEntitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
final ExpandOption innerExpand = ExpandSelectMock.mockExpandOption(Arrays.asList(
|
||||
ExpandSelectMock.mockExpandItem(innerEntitySet, "NavPropertyETTwoPrimOne")));
|
||||
ExpandItem expandItem = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne");
|
||||
Mockito.when(expandItem.getExpandOption()).thenReturn(innerExpand);
|
||||
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem));
|
||||
final ContextURL contextURL = ContextURL.with().entitySet(entitySet)
|
||||
.selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build();
|
||||
assertEquals("$metadata#ESTwoPrim", ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildExpandTwoLevelsInnerAll() throws Exception {
|
||||
final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim");
|
||||
ExpandItem expandItemInner = Mockito.mock(ExpandItem.class);
|
||||
Mockito.when(expandItemInner.isStar()).thenReturn(true);
|
||||
final ExpandOption innerExpand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemInner));
|
||||
ExpandItem expandItem = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne");
|
||||
Mockito.when(expandItem.getExpandOption()).thenReturn(innerExpand);
|
||||
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem));
|
||||
final ContextURL contextURL = ContextURL.with().entitySet(entitySet)
|
||||
.selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build();
|
||||
assertEquals("$metadata#ESTwoPrim", ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildExpandSelectTwoLevels() throws Exception {
|
||||
final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim");
|
||||
final EdmEntitySet innerEntitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
ExpandItem expandItemInner = ODataJsonSerializerTest.mockExpandItem(innerEntitySet, "NavPropertyETTwoPrimOne");
|
||||
ExpandItem expandItemInner = ExpandSelectMock.mockExpandItem(innerEntitySet, "NavPropertyETTwoPrimOne");
|
||||
SelectItem innerSelectItem = Mockito.mock(SelectItem.class);
|
||||
Mockito.when(innerSelectItem.isStar()).thenReturn(true);
|
||||
final SelectOption innerSelect = ODataJsonSerializerTest.mockSelectOption(Arrays.asList(innerSelectItem));
|
||||
final SelectOption innerSelect = ExpandSelectMock.mockSelectOption(Arrays.asList(innerSelectItem));
|
||||
Mockito.when(expandItemInner.getSelectOption()).thenReturn(innerSelect);
|
||||
final ExpandOption innerExpand = ODataJsonSerializerTest.mockExpandOption(Arrays.asList(expandItemInner));
|
||||
ExpandItem expandItem = ODataJsonSerializerTest.mockExpandItem(entitySet, "NavPropertyETAllPrimOne");
|
||||
final ExpandOption innerExpand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemInner));
|
||||
ExpandItem expandItem = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne");
|
||||
Mockito.when(expandItem.getExpandOption()).thenReturn(innerExpand);
|
||||
final ExpandOption expand = ODataJsonSerializerTest.mockExpandOption(Arrays.asList(expandItem));
|
||||
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem));
|
||||
final ContextURL contextURL = ContextURL.with().entitySet(entitySet)
|
||||
.selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build();
|
||||
assertEquals("$metadata#ESTwoPrim(NavPropertyETAllPrimOne(NavPropertyETTwoPrimOne(*)))",
|
||||
|
|
Loading…
Reference in New Issue