org.apache.olingo.odata2.api.uri.expression.OrderByExpression Java Examples
The following examples show how to use
org.apache.olingo.odata2.api.uri.expression.OrderByExpression.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OlingoManager.java From DataHubSystem with GNU Affero General Public License v3.0 | 8 votes |
public List<Product> getProducts(User user, String uuid, FilterExpression filter_expr, OrderByExpression order_expr, int skip, int top) throws ExceptionVisitExpression, ODataApplicationException { ProductSQLVisitor expV = new ProductSQLVisitor(); Object visit_result = null; if (filter_expr != null) { visit_result = filter_expr.accept(expV); } if (order_expr != null) { visit_result = order_expr.accept(expV); } return productService.getProducts((DetachedCriteria) visit_result, uuid, skip, top); }
Example #2
Source File: VisitorTool.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public Object visitOrderByExpression(final OrderByExpression orderByExpression, final String expressionString, final List<Object> orders) { StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("oc"); sb.append("("); for (int i = 0; i < orders.size(); i++) { if (i != 0) { sb.append(","); } sb.append(orders.get(i)); } sb.append(")}"); return sb.toString(); }
Example #3
Source File: JsonVisitor.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public Object visitOrderByExpression(final OrderByExpression orderByExpression, final String expressionString, final List<Object> orders) { try { StringWriter writer = new StringWriter(); JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer); jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", "order collection").separator().name("orders") .beginArray(); boolean first = true; for (final Object order : orders) { if (first) { first = false; } else { jsonStreamWriter.separator(); } jsonStreamWriter.unquotedValue(order.toString()); } jsonStreamWriter.endArray().endObject(); writer.flush(); return writer.toString(); } catch (final IOException e) { return null; } }
Example #4
Source File: JPAQueryBuilderTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private UriInfo mockURIInfoForEntitySetCount(EdmMapping mapping) throws EdmException { UriInfo uriInfo = EasyMock.createMock(UriInfo.class); List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>(); EasyMock.expect(uriInfo.getNavigationSegments()).andStubReturn(navSegments); EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class); EasyMock.expect(edmEntityType.getMapping()).andStubReturn(mapping); EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class); EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType); EasyMock.expect(uriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet); List<KeyPredicate> keyPreds =EasyMock.createMock(ArrayList.class); EasyMock.expect(uriInfo.getKeyPredicates()).andStubReturn(keyPreds); OrderByExpression orderbyExpression = mockOrderByExpressions(uriInfo); EasyMock.expect(uriInfo.getTop()).andStubReturn(null); EasyMock.expect(uriInfo.getSkip()).andStubReturn(null); EasyMock.replay(edmEntityType, edmEntitySet, uriInfo, keyPreds,orderbyExpression); return uriInfo; }
Example #5
Source File: OlingoManager.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
public List<User> getUsers( FilterExpression filter_expr, OrderByExpression order_expr, int skip, int top) throws ExceptionVisitExpression, ODataApplicationException { UserSQLVisitor expV = new UserSQLVisitor(); Object visit = null; if (filter_expr != null) { visit = filter_expr.accept(expV); } if (order_expr != null) { visit = order_expr.accept(expV); } return userService.getUsers((DetachedCriteria) visit, skip, top); }
Example #6
Source File: SQLVisitor.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
@Override public Object visitOrderByExpression(OrderByExpression order_expression, String expression_string, List<Object> orders) { for (Object object: orders) { Order order = Order.class.cast(object); criteria.addOrder(order); } return criteria; }
Example #7
Source File: UserMap.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
/** Private constructor used by {@link ProductsMap#getSubMapBuilder()}. */ private UserMap (FilterExpression filter, OrderByExpression order, int skip, int top) { this.filter = filter; this.orderBy = order; this.skip = skip; this.top = top; hasRole = Security.currentUserHasRole(Role.SYSTEM_MANAGER, Role.USER_MANAGER); }
Example #8
Source File: JPAQueryBuilderTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
/** * @param uriInfo * @return */ private OrderByExpression mockOrderByExpressions(UriInfo uriInfo) { OrderByExpression orderbyExpression = EasyMock.createMock(OrderByExpression.class); EasyMock.expect(orderbyExpression.getOrders()).andStubReturn(new ArrayList<OrderExpression>()); EasyMock.expect(uriInfo.getOrderBy()).andStubReturn(orderbyExpression); EasyMock.expect(uriInfo.getFilter()).andStubReturn(null); return orderbyExpression; }
Example #9
Source File: JPAQueryBuilderTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private UriInfo mockURIInfoForEntityCount(EdmMapping mapping) throws EdmException { EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class); UriInfo uriInfo = EasyMock.createMock(UriInfo.class); EdmEntitySet navEntitySet = EasyMock.createMock(EdmEntitySet.class); EdmEntityType navEntityType = EasyMock.createMock(EdmEntityType.class); List<NavigationSegment> navSegments = mockNavigationSegments(edmEntityType, uriInfo, navEntitySet, navEntityType); EasyMock.expect(uriInfo.getNavigationSegments()).andStubReturn(navSegments); EasyMock.expect(edmEntityType.getMapping()).andStubReturn(mapping); EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class); EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType); EasyMock.expect(uriInfo.getStartEntitySet()).andStubReturn(edmEntitySet); EasyMock.expect(uriInfo.getTargetEntitySet()).andStubReturn(navEntitySet); EasyMock.expect(navEntitySet.getEntityType()).andStubReturn(navEntityType); EasyMock.expect(navEntityType.getMapping()).andStubReturn((EdmMapping) mockNavEdmMappingForProperty()); List<KeyPredicate> keyPreds = new ArrayList<KeyPredicate>(); EdmProperty edmProperty = mockEdmProperty(mapping, "String"); keyPreds.add(mockKeyPredicate(edmProperty, "Id")); EasyMock.expect(uriInfo.getKeyPredicates()).andStubReturn(keyPreds); EasyMock.expect(uriInfo.getTop()).andStubReturn(null); EasyMock.expect(uriInfo.getSkip()).andStubReturn(null); OrderByExpression orderbyExpression = mockOrderByExpressions(uriInfo); EasyMock.replay(edmEntityType, edmEntitySet, uriInfo, navEntitySet, orderbyExpression); return uriInfo; }
Example #10
Source File: JPQLSelectStatementBuilderTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void testBuildQueryWithFilter() throws EdmException, ODataJPARuntimeException { OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class); FilterExpression filterExpression = null;// getFilterExpressionMockedObj(); JPQLSelectContext jpqlSelectContextImpl = createSelectContext(orderByExpression, filterExpression); jpqlSelectContextImpl.setWhereExpression("E1.soID >= 1234"); jpqlSelectStatementBuilder = new JPQLSelectStatementBuilder(jpqlSelectContextImpl); assertEquals("SELECT E1 FROM SalesOrderHeader E1 WHERE E1.soID >= 1234", jpqlSelectStatementBuilder.build() .toString()); }
Example #11
Source File: JPQLSelectStatementBuilderTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void testBuildQueryWithOrderBy() throws EdmException, ODataJPARuntimeException { OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class); JPQLSelectContext jpqlSelectContextImpl = createSelectContext(orderByExpression, null); jpqlSelectContextImpl.setOrderByCollection("E1.soID ASC , E1.buyerId DESC"); jpqlSelectStatementBuilder = new JPQLSelectStatementBuilder(jpqlSelectContextImpl); assertEquals("SELECT E1 FROM SalesOrderHeader E1 ORDER BY E1.soID ASC , E1.buyerId DESC", jpqlSelectStatementBuilder.build().toString()); }
Example #12
Source File: JPQLSelectStatementBuilderTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
/** * Test method for {@link org.apache.olingo.odata2.processor.jpa.jpql.JPQLSelectStatementBuilder#build)}. * @throws EdmException * @throws ODataJPARuntimeException */ @Test public void testBuildSimpleQuery() throws EdmException, ODataJPARuntimeException { OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class); JPQLSelectContext jpqlSelectContextImpl = createSelectContext(orderByExpression, null); jpqlSelectStatementBuilder = new JPQLSelectStatementBuilder(jpqlSelectContextImpl); assertEquals("SELECT E1 FROM SalesOrderHeader E1", jpqlSelectStatementBuilder.build().toString()); }
Example #13
Source File: JPQLSelectStatementBuilderTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private JPQLSelectContext createSelectContext(final OrderByExpression orderByExpression, final FilterExpression filterExpression) throws ODataJPARuntimeException, EdmException { // Object Instantiation JPQLSelectContext jpqlSelectContextImpl = null; GetEntitySetUriInfo getEntitySetView = EasyMock.createMock(GetEntitySetUriInfo.class); EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class); EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class); List<SelectItem> selectItemList = null; // Setting up the expected value EasyMock.expect(getEntitySetView.getTargetEntitySet()).andStubReturn(edmEntitySet); EasyMock.expect(getEntitySetView.getOrderBy()).andStubReturn(orderByExpression); EasyMock.expect(getEntitySetView.getSelect()).andStubReturn(selectItemList); EasyMock.expect(getEntitySetView.getFilter()).andStubReturn(filterExpression); EasyMock.replay(getEntitySetView); EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType); EasyMock.replay(edmEntitySet); EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null); EasyMock.expect(edmEntityType.getName()).andStubReturn("SalesOrderHeader"); EasyMock.replay(edmEntityType); JPQLContextBuilder contextBuilder1 = JPQLContext.createBuilder(JPQLContextType.SELECT, getEntitySetView); try { jpqlSelectContextImpl = (JPQLSelectContext) contextBuilder1.build(); } catch (ODataJPAModelException e) { fail("Model Exception thrown"); } return jpqlSelectContextImpl; }
Example #14
Source File: ListsProcessor.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private <T> void sort(final List<T> data, final OrderByExpression orderBy) { Collections.sort(data, new Comparator<T>() { @Override public int compare(final T entity1, final T entity2) { try { int result = 0; for (final OrderExpression expression : orderBy.getOrders()) { String first = evaluateExpression(entity1, expression.getExpression()); String second = evaluateExpression(entity2, expression.getExpression()); if (first != null && second != null) { result = first.compareTo(second); } else if (first == null && second != null) { result = 1; } else if (first != null && second == null) { result = -1; } if (expression.getSortOrder() == SortOrder.desc) { result = -result; } if (result != 0) { break; } } return result; } catch (final ODataException e) { return 0; } } }); }
Example #15
Source File: FunctionalVisitor.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
@Override public Object visitOrderByExpression(OrderByExpression orderby, String exp, List<Object> orders) { final ExecutableExpressionTree.Node node = (ExecutableExpressionTree.Node) (orders.get(0)); return new Comparator() { @Override public int compare(Object o1, Object o2) { return (Integer) node.exec(new Duo<>(o1, o2)); } }; }
Example #16
Source File: CollectionProductsMap.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
/** * Private constructor used by * {@link CollectionProductsMap#getSubMapBuilder()} */ public CollectionProductsMap (String collection_uuid, FilterExpression filter, OrderByExpression order, int skip, int top) { this.collectionUUID = collection_uuid; this.filter = filter; this.orderBy = order; this.skip = skip; this.top = top; }
Example #17
Source File: ProductsMap.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
/** Private constructor used by {@link ProductsMap#getSubMapBuilder()}. */ private ProductsMap (FilterExpression filter, OrderByExpression order, int skip, int top) { this.filter = filter; this.orderBy = order; this.skip = skip; this.top = top; }
Example #18
Source File: ListsProcessor.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private <T> void sort(final EdmEntitySet entitySet, final List<T> data, final OrderByExpression orderBy) { Collections.sort(data, new Comparator<T>() { @Override public int compare(final T entity1, final T entity2) { try { int result = 0; for (final OrderExpression expression : orderBy.getOrders()) { String first = evaluateExpression(entitySet, entity1, expression.getExpression()); String second = evaluateExpression(entitySet, entity2, expression.getExpression()); if (first != null && second != null) { result = first.compareTo(second); } else if (first == null && second != null) { result = 1; } else if (first != null && second == null) { result = -1; } if (expression.getSortOrder() == SortOrder.desc) { result = -result; } if (result != 0) { break; } } return result; } catch (final ODataException e) { return 0; } } }); }
Example #19
Source File: CollectionMap.java From DataHubSystem with GNU Affero General Public License v3.0 | 5 votes |
private CollectionMap (FilterExpression filter, OrderByExpression order, int skip, int top, String parent_id) { this.filter = filter; this.orderBy = order; this.skip = skip; this.top = top; this.parentId = parent_id; }
Example #20
Source File: ODataParser.java From cxf with Apache License 2.0 | 4 votes |
@Override public Object visitOrderByExpression(OrderByExpression orderByExpression, String expressionString, List<Object> orders) { throw new SearchParseException("Unsupported operation visitOrderByExpression: " + orderByExpression + "," + expressionString + "," + orders); }
Example #21
Source File: ODataDebugResponseWrapperTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Test public void uri() throws Exception { final ODataContext context = mockContext(ODataHttpMethod.GET); final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, null); UriInfo uriInfo = mock(UriInfo.class); final FilterExpression filter = UriParser.parseFilter(null, null, "true"); when(uriInfo.getFilter()).thenReturn(filter); final OrderByExpression orderBy = UriParser.parseOrderBy(null, null, "true"); when(uriInfo.getOrderBy()).thenReturn(orderBy); List<ArrayList<NavigationPropertySegment>> expand = new ArrayList<ArrayList<NavigationPropertySegment>>(); NavigationPropertySegment segment = mock(NavigationPropertySegment.class); EdmNavigationProperty navigationProperty = mock(EdmNavigationProperty.class); when(navigationProperty.getName()).thenReturn("nav"); when(segment.getNavigationProperty()).thenReturn(navigationProperty); ArrayList<NavigationPropertySegment> segments = new ArrayList<NavigationPropertySegment>(); segments.add(segment); expand.add(segments); when(uriInfo.getExpand()).thenReturn(expand); SelectItem select1 = mock(SelectItem.class); SelectItem select2 = mock(SelectItem.class); EdmProperty property = mock(EdmProperty.class); when(property.getName()).thenReturn("property"); when(select1.getProperty()).thenReturn(property); when(select2.getProperty()).thenReturn(property); when(select2.getNavigationPropertySegments()).thenReturn(segments); when(uriInfo.getSelect()).thenReturn(Arrays.asList(select1, select2)); ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, uriInfo, null, ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse(); String entity = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertEquals(EXPECTED.replace("null}}", "null," + "\"uri\":{\"filter\":{\"nodeType\":\"LITERAL\",\"type\":\"Edm.Boolean\",\"value\":\"true\"}," + "\"orderby\":{\"nodeType\":\"order collection\"," + "\"orders\":[{\"nodeType\":\"ORDER\",\"sortorder\":\"asc\"," + "\"expression\":{\"nodeType\":\"LITERAL\",\"type\":\"Edm.Boolean\",\"value\":\"true\"}}]}," + "\"expandSelect\":{\"all\":false,\"properties\":[\"property\"]," + "\"links\":[{\"nav\":{\"all\":false,\"properties\":[\"property\"],\"links\":[]}}]}}}}"), entity); response = new ODataDebugResponseWrapper(context, wrappedResponse, uriInfo, null, ODataDebugResponseWrapper.ODATA_DEBUG_HTML).wrapResponse(); entity = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertTrue(entity.contains("Edm.Boolean")); assertTrue(entity.contains("asc")); }
Example #22
Source File: ListsProcessor.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private <T> Integer applySystemQueryOptions(final EdmEntitySet entitySet, final List<T> data, final FilterExpression filter, final InlineCount inlineCount, final OrderByExpression orderBy, final String skipToken, final Integer skip, final Integer top) throws ODataException { ODataContext context = getContext(); final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "applySystemQueryOptions"); if (filter != null) { // Remove all elements the filter does not apply for. // A for-each loop would not work with "remove", see Java documentation. for (Iterator<T> iterator = data.iterator(); iterator.hasNext();) { if (!appliesFilter(entitySet, iterator.next(), filter)) { iterator.remove(); } } } final Integer count = inlineCount == InlineCount.ALLPAGES ? data.size() : null; if (orderBy != null) { sort(entitySet, data, orderBy); } else if (skipToken != null || skip != null || top != null) { sortInDefaultOrder(entitySet, data); } if (skipToken != null) { while (!data.isEmpty() && !getSkipToken(entitySet, data.get(0)).equals(skipToken)) { data.remove(0); } } if (skip != null) { if (skip >= data.size()) { data.clear(); } else { for (int i = 0; i < skip; i++) { data.remove(0); } } } if (top != null) { while (data.size() > top) { data.remove(top.intValue()); } } context.stopRuntimeMeasurement(timingHandle); return count; }
Example #23
Source File: UriInfoImpl.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public OrderByExpression getOrderBy() { return orderBy; }
Example #24
Source File: UriInfoImpl.java From olingo-odata2 with Apache License 2.0 | 4 votes |
public void setOrderBy(final OrderByExpression orderBy) { this.orderBy = orderBy; }
Example #25
Source File: UriParserImpl.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public OrderByExpression parseOrderByString(final EdmEntityType entityType, final String expression) throws ODataMessageException { return new OrderByParserImpl(entityType).parseOrderByString(expression); }
Example #26
Source File: AdaptableUriInfo.java From DataHubSystem with GNU Affero General Public License v3.0 | 4 votes |
@Override public OrderByExpression getOrderBy() { return OrderByExpression.class.cast(get("getOrderBy")); }
Example #27
Source File: OrderByParserImpl.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public OrderByExpression parseOrderByString(final String orderByExpression) throws ExpressionParserException, ExpressionParserInternalError { curExpression = orderByExpression; OrderByExpressionImpl orderCollection = new OrderByExpressionImpl(curExpression); try { tokenList = new Tokenizer(orderByExpression).tokenize(); // throws TokenizerMessage } catch (TokenizerException tokenizerException) { throw FilterParserExceptionImpl.createERROR_IN_TOKENIZER(tokenizerException, curExpression); } while (true) { CommonExpression node = null; try { CommonExpression nodeLeft = readElement(null); node = readElements(nodeLeft, 0); } catch (ExpressionParserException expressionException) { expressionException.setFilterTree(orderCollection); throw expressionException; } OrderExpressionImpl orderNode = new OrderExpressionImpl(node); // read the sort order Token token = tokenList.lookToken(); if (token == null) { orderNode.setSortOrder(SortOrder.asc); } else if ((token.getKind() == TokenKind.LITERAL) && ("asc".equals(token.getUriLiteral()))) { orderNode.setSortOrder(SortOrder.asc); tokenList.next(); token = tokenList.lookToken(); } else if ((token.getKind() == TokenKind.LITERAL) && ("desc".equals(token.getUriLiteral()))) { orderNode.setSortOrder(SortOrder.desc); tokenList.next(); token = tokenList.lookToken(); } else if (token.getKind() == TokenKind.COMMA) { orderNode.setSortOrder(SortOrder.asc); } else { // Tested with TestParserExceptions.TestOPMparseOrderByString CASE 1 throw FilterParserExceptionImpl.createINVALID_SORT_ORDER(token, curExpression); } orderCollection.addOrder(orderNode); // ls_token may be a ',' or empty. if (token == null) { break; } else if (token.getKind() == TokenKind.COMMA) { Token oldToken = token; tokenList.next(); token = tokenList.lookToken(); if (token == null) { // Tested with TestParserExceptions.TestOPMparseOrderByString CASE 2 throw FilterParserExceptionImpl.createEXPRESSION_EXPECTED_AFTER_POS(oldToken, curExpression); } } else { // e.g. in case $orderby=String asc a throw FilterParserExceptionImpl.createCOMMA_OR_END_EXPECTED_AT_POS(token, curExpression); } } return orderCollection; }
Example #28
Source File: JPAQueryBuilderTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private UriInfo mockURIInfoForEntitySetWithBinaryFilterExpression (EdmMapping mapping, String methodName) throws EdmException { UriInfo uriInfo = EasyMock.createMock(UriInfo.class); List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>(); EasyMock.expect(uriInfo.getNavigationSegments()).andStubReturn(navSegments); EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class); EasyMock.expect(edmEntityType.getMapping()).andStubReturn(mapping); EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class); EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType); EasyMock.expect(uriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet); EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class); EasyMock.expect(edmProperty.getMapping()).andStubReturn((EdmMapping)mockEdmMappingForProperty()); OrderByExpression orderbyExpression = EasyMock.createMock(OrderByExpression.class); List<OrderExpression> orders = new ArrayList<OrderExpression>(); EasyMock.expect(orderbyExpression.getOrders()).andStubReturn(orders); EasyMock.expect(uriInfo.getOrderBy()).andStubReturn(orderbyExpression); FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class); BinaryExpression commonExpression = EasyMock.createMock(BinaryExpression.class); EasyMock.expect(commonExpression.getOperator()).andStubReturn(BinaryOperator.EQ); EasyMock.expect(commonExpression.getKind()).andStubReturn(ExpressionKind.BINARY); MethodExpression methodExp = EasyMock.createMock(MethodExpression.class); EasyMock.expect(commonExpression.getLeftOperand()).andStubReturn(methodExp); EdmSimpleType type = EasyMock.createMock(EdmSimpleType.class);; EasyMock.expect(methodExp.getEdmType()).andStubReturn(type ); LiteralExpression literalValueExp = EasyMock.createMock(LiteralExpression.class); EasyMock.expect(commonExpression.getRightOperand()).andStubReturn(literalValueExp); EasyMock.expect(literalValueExp.getUriLiteral()).andStubReturn("'a%.b*.c'"); EasyMock.expect(literalValueExp.getKind()).andStubReturn(ExpressionKind.LITERAL); EasyMock.expect(literalValueExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()); PropertyExpression propExp = EasyMock.createMock(PropertyExpression.class); LiteralExpression literalExp1 = EasyMock.createMock(LiteralExpression.class); LiteralExpression literalExp2 = EasyMock.createMock(LiteralExpression.class); List<CommonExpression> parameterList = new ArrayList<CommonExpression>(); if ("substring".equals(methodName)) { EasyMock.expect(methodExp.getMethod()).andStubReturn(MethodOperator.SUBSTRING); EasyMock.expect(methodExp.getKind()).andStubReturn(ExpressionKind.METHOD); EasyMock.expect(methodExp.getParameterCount()).andStubReturn(3); EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty); EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY); parameterList.add(propExp); EasyMock.expect(literalExp1.getUriLiteral()).andStubReturn("1"); EasyMock.expect(literalExp1.getKind()).andStubReturn(ExpressionKind.LITERAL); EasyMock.expect(literalExp1.getEdmType()).andStubReturn(EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance()); parameterList.add(literalExp1); EasyMock.expect(literalExp2.getUriLiteral()).andStubReturn("2"); EasyMock.expect(literalExp2.getKind()).andStubReturn(ExpressionKind.LITERAL); EasyMock.expect(literalExp2.getEdmType()).andStubReturn(EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance()); parameterList.add(literalExp2); EasyMock.expect(methodExp.getParameters()).andStubReturn(parameterList); } else if ("toLower".equals(methodName)) { EasyMock.expect(methodExp.getMethod()).andStubReturn(MethodOperator.TOLOWER); EasyMock.expect(methodExp.getKind()).andStubReturn(ExpressionKind.METHOD); EasyMock.expect(methodExp.getParameterCount()).andStubReturn(1); EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty); EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY); parameterList.add(propExp); EasyMock.expect(methodExp.getParameters()).andStubReturn(parameterList); } else if ("toUpper".equals(methodName)) { EasyMock.expect(methodExp.getMethod()).andStubReturn(MethodOperator.TOUPPER); EasyMock.expect(methodExp.getKind()).andStubReturn(ExpressionKind.METHOD); EasyMock.expect(methodExp.getParameterCount()).andStubReturn(1); EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty); EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY); parameterList.add(propExp); EasyMock.expect(methodExp.getParameters()).andStubReturn(parameterList); } EasyMock.expect(filterExpression.getExpression()).andStubReturn(commonExpression); EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER); EasyMock.expect(filterExpression.getExpressionString()).andStubReturn("substring(CompanyName,1,2) eq 'a.b.c'"); EasyMock.expect(uriInfo.getFilter()).andStubReturn(filterExpression); EasyMock.replay(edmEntityType, edmEntitySet, orderbyExpression, filterExpression, commonExpression, literalExp1, literalExp2, propExp, uriInfo, edmProperty, methodExp, literalValueExp); return uriInfo; }
Example #29
Source File: JPAQueryBuilderTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private UriInfo mockURIInfoForEntitySet(EdmMapping mapping, String methodName) throws EdmException { UriInfo uriInfo = EasyMock.createMock(UriInfo.class); List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>(); EasyMock.expect(uriInfo.getNavigationSegments()).andStubReturn(navSegments); EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class); EasyMock.expect(edmEntityType.getMapping()).andStubReturn(mapping); EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class); EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType); EasyMock.expect(uriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet); EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class); EasyMock.expect(edmProperty.getMapping()).andStubReturn((EdmMapping)mockEdmMappingForProperty()); EdmProperty edmProperty1 = EasyMock.createMock(EdmProperty.class); EasyMock.expect(edmProperty1.getMapping()).andStubReturn((EdmMapping)mockEdmMappingForProperty1()); EdmNavigationProperty navEdmProperty = EasyMock.createMock(EdmNavigationProperty.class); EasyMock.expect(navEdmProperty.getMapping()).andStubReturn((EdmMapping)mockNavEdmMappingForProperty()); OrderByExpression orderbyExpression = EasyMock.createMock(OrderByExpression.class); List<OrderExpression> orders = new ArrayList<OrderExpression>(); EasyMock.expect(orderbyExpression.getOrders()).andStubReturn(orders); EasyMock.expect(uriInfo.getOrderBy()).andStubReturn(orderbyExpression); FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class); MethodExpression commonExpression = EasyMock.createMock(MethodExpression.class); EasyMock.expect(commonExpression.getKind()).andStubReturn(ExpressionKind.METHOD); PropertyExpression propExp = EasyMock.createMock(PropertyExpression.class); LiteralExpression literalExp = EasyMock.createMock(LiteralExpression.class); MemberExpression memberExp = EasyMock.createMock(MemberExpression.class); List<CommonExpression> parameterList = new ArrayList<CommonExpression>(); PropertyExpression navPropExp = EasyMock.createMock(PropertyExpression.class); if ("substringof".equals(methodName)) { EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.SUBSTRINGOF); EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2); EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'"); EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL); EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()); parameterList.add(literalExp); EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty); EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY); parameterList.add(propExp); } else if ("startsWith".equals(methodName)) { EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.STARTSWITH); EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2); EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty); EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY); parameterList.add(propExp); EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'"); EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL); EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()); parameterList.add(literalExp); } else if ("endsWith".equals(methodName)) { EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.ENDSWITH); EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2); EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty); EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY); parameterList.add(propExp); EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'"); EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL); EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()); parameterList.add(literalExp); } else if ("substringof_1".equals(methodName)) { EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.SUBSTRINGOF); EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2); EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'"); EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL); EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()); parameterList.add(literalExp); EasyMock.expect(memberExp.getKind()).andStubReturn(ExpressionKind.MEMBER); EasyMock.expect(memberExp.getProperty()).andStubReturn(propExp); EasyMock.expect(memberExp.getPath()).andStubReturn(navPropExp); EasyMock.expect(navPropExp.getKind()).andStubReturn(ExpressionKind.PROPERTY); EasyMock.expect(navPropExp.getEdmProperty()).andStubReturn(navEdmProperty); EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY); EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty1); parameterList.add(propExp); } EasyMock.expect(commonExpression.getParameters()).andStubReturn(parameterList); EasyMock.expect(filterExpression.getExpression()).andStubReturn(commonExpression); EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER); EasyMock.expect(filterExpression.getExpressionString()).andStubReturn("substringof('a.b.c',Id)"); EasyMock.expect(uriInfo.getFilter()).andStubReturn(filterExpression); EasyMock.replay(edmEntityType, edmEntitySet, orderbyExpression, filterExpression, commonExpression, literalExp, propExp, uriInfo, edmProperty, memberExp, edmProperty1, navEdmProperty); return uriInfo; }
Example #30
Source File: JPAProcessorImplTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private OrderByExpression getOrderByExpression() { return null; }