Package org.apache.olingo.odata2.api.uri.info

Examples of org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo


  private void buildSelectContext(final boolean orderByIsNull, final boolean selectFieldsIsNull,
      final boolean filterIsNull, final boolean isTopNull, final boolean isSkipNull) {
    builder = null;
    selectContext = null;
    keyPredicates = new ArrayList<KeyPredicate>();
    GetEntitySetUriInfo resultsView = EasyMock.createMock(GetEntitySetUriInfo.class);

    EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
    EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
    KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
    EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
    EdmType edmType1 = EasyMock.createMock(EdmType.class);
    EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
    EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
    try {
      EasyMock.expect(mapping.getInternalName()).andStubReturn("Field1");
      EasyMock.expect(kpProperty.getMapping()).andStubReturn(mapping);
      EasyMock.expect(kpProperty.getType()).andStubReturn(edmType1);

    } catch (EdmException e2) {
      fail("this should not happen");
    }
    EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
    EasyMock.replay(mapping, edmType1, kpProperty, keyPredicate);
    keyPredicates.add(keyPredicate);
    int i = 0;
    List<OrderExpression> orderList = new ArrayList<OrderExpression>(2);
    do {

      EdmType edmType = EasyMock.createMock(EdmType.class);
      try {
        EasyMock.expect(edmType.getName()).andStubReturn(fields[i]);
        EasyMock.replay(edmType);
      } catch (EdmException e2) {
        fail("Exception not Expected");
      }

      PropertyExpression commonExpression = EasyMock.createMock(PropertyExpression.class);
      EasyMock.expect(commonExpression.getEdmType()).andStubReturn(edmType);

      EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);
      EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
      EasyMock.expect(edmMapping.getInternalName()).andStubReturn(fields[i]);
      try {
        EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
      } catch (EdmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      EasyMock.expect(commonExpression.getEdmProperty()).andStubReturn(edmTyped);
      OrderExpression order = EasyMock.createMock(OrderExpression.class);
      EasyMock.expect(order.getExpression()).andStubReturn(commonExpression);
      EasyMock.expect(order.getSortOrder()).andStubReturn(orderType[i]);
      EasyMock.replay(edmMapping, edmTyped, commonExpression);
      EasyMock.replay(order);

      orderList.add(order);

    } while (++i < 2);

    OrderByExpression orderBy = EasyMock.createMock(OrderByExpression.class);
    EasyMock.expect(orderBy.getOrders()).andStubReturn(orderList);
    EasyMock.replay(orderBy);

    try {
      i = 0;
      List<SelectItem> selectItemList = new ArrayList<SelectItem>(2);
      do {
        EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
        EasyMock.expect(edmMapping.getInternalName()).andStubReturn(fields[i]);
        EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
        EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
        EasyMock.replay(edmMapping, edmProperty);

        SelectItem selectItem = EasyMock.createMock(SelectItem.class);
        EasyMock.expect(selectItem.getProperty()).andStubReturn(edmProperty);
        EasyMock.replay(selectItem);

        selectItemList.add(selectItem);

      } while (++i < 2);
      EasyMock.expect(entityType.getMapping()).andStubReturn(null);
      EasyMock.expect(entityType.getName()).andStubReturn(entityTypeName);
      EasyMock.expect(entityType.getKeyProperties()).andStubReturn(getLocalKeyProperties());

      EasyMock.replay(entityType);
      EasyMock.expect(entitySet.getEntityType()).andStubReturn(entityType);
      EasyMock.replay(entitySet);

      EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);
      if (orderByIsNull) {
        EasyMock.expect(resultsView.getOrderBy()).andStubReturn(null);
      } else {
        EasyMock.expect(resultsView.getOrderBy()).andStubReturn(orderBy);
      }
      if (selectFieldsIsNull) {
        EasyMock.expect(resultsView.getSelect()).andStubReturn(null);
      } else {
        EasyMock.expect(resultsView.getSelect()).andStubReturn(selectItemList);
      }
      // FilterExpression filterExpression =
      // EasyMock.createMock(FilterExpression.class);
      // EasyMock.expect(filterExpression.g)
      if (filterIsNull) {
        EasyMock.expect(resultsView.getFilter()).andStubReturn(null);
      } else {
        EasyMock.expect(resultsView.getFilter()).andStubReturn(
            getFilterExpressionMockedObj(ExpressionKind.PROPERTY, "SalesOrder"));
      }
      if (isTopNull) {
        EasyMock.expect(resultsView.getTop()).andStubReturn(null);
      } else {
        EasyMock.expect(resultsView.getTop()).andStubReturn(10);
      }
      if (isSkipNull) {
        EasyMock.expect(resultsView.getSkip()).andStubReturn(null);
      } else {
        EasyMock.expect(resultsView.getSkip()).andStubReturn(0);
      }
      EasyMock.expect(resultsView.getKeyPredicates()).andStubReturn(keyPredicates);
      EasyMock.replay(resultsView);

    } catch (EdmException e1) {
      fail("Exception not Expected");
    }
View Full Code Here


  }

  @Test
  public void testEntityNameThrowingException() {
    // buildSelectContext(false, false, false);
    GetEntitySetUriInfo resultsView = EasyMock.createMock(GetEntitySetUriInfo.class);

    EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
    EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);

    try {
      EasyMock.expect(entityType.getName()).andStubThrow(new EdmException(null));
      EasyMock.expect(entitySet.getEntityType()).andStubThrow(new EdmException(null));
    } catch (EdmException e1) {
      // throw new ODataException();
    }

    EasyMock.replay(entityType);
    EasyMock.replay(entitySet);

    EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);
    EasyMock.expect(resultsView.getOrderBy()).andStubReturn(null);
    EasyMock.expect(resultsView.getSelect()).andStubReturn(null);
    EasyMock.expect(resultsView.getFilter()).andStubReturn(null);
    EasyMock.replay(resultsView);
    try {
      JPQLSelectContextBuilder builder1 =
          (JPQLSelectContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT, resultsView);
View Full Code Here

  /*
   * This Unit is supposed to test the building of Entity Provider Properties for query with $expand
   */
  @Test
  public void testGetEntityProviderPropertiesQuery() {
    GetEntitySetUriInfo getEntitySetUriInfo = mockEntitySetUriInfoForExpand();
    ODataJPAContext oDataJPAContext = getODataJPAContext();
    // Building the edm entity
    List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
    Map<String, Object> edmEntity = new HashMap<String, Object>();
    edmEntity.put("ID", 1);
View Full Code Here

    }
    return uri;
  }

  private GetEntitySetUriInfo getResultsView() {
    GetEntitySetUriInfo objGetEntitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
    EasyMock.expect(objGetEntitySetUriInfo.getInlineCount()).andStubReturn(getLocalInlineCount());
    EasyMock.expect(objGetEntitySetUriInfo.getTargetEntitySet()).andStubReturn(getLocalTargetEntitySet());
    EasyMock.expect(objGetEntitySetUriInfo.getSelect()).andStubReturn(getSelectItemList());
    EasyMock.expect(objGetEntitySetUriInfo.getExpand()).andStubReturn(getExpandList());
    EasyMock.expect(objGetEntitySetUriInfo.getSkip()).andStubReturn(new Integer(1));
    EasyMock.replay(objGetEntitySetUriInfo);
    return objGetEntitySetUriInfo;
  }
View Full Code Here

    List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
    return expandList;
  }

  private GetEntitySetUriInfo getResultsViewWithNullSelects() {
    GetEntitySetUriInfo objGetEntitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
    EasyMock.expect(objGetEntitySetUriInfo.getInlineCount()).andStubReturn(getLocalInlineCount());
    EasyMock.expect(objGetEntitySetUriInfo.getTargetEntitySet()).andStubReturn(getLocalTargetEntitySet());
    EasyMock.expect(objGetEntitySetUriInfo.getSelect()).andStubReturn(null);
    EasyMock.expect(objGetEntitySetUriInfo.getExpand()).andStubReturn(null);
    EasyMock.expect(objGetEntitySetUriInfo.getSkip()).andStubReturn(new Integer(1));

    EasyMock.replay(objGetEntitySetUriInfo);
    return objGetEntitySetUriInfo;
  }
View Full Code Here

    EasyMock.expect(navigationPropertySegment.getTargetEntitySet()).andStubReturn(getTargetEntitySetForExpand());
    EasyMock.replay(navigationPropertySegment);
    navigationPropertyList.add(navigationPropertySegment);
    expandList.add(navigationPropertyList);
    // Mocking EntityUriInfo
    GetEntitySetUriInfo entitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
    EasyMock.expect(entitySetUriInfo.getSelect()).andStubReturn(selectItemList);
    EasyMock.expect(entitySetUriInfo.getExpand()).andStubReturn(expandList);
    EasyMock.expect(entitySetUriInfo.getInlineCount()).andStubReturn(InlineCount.ALLPAGES);
    EasyMock.expect(entitySetUriInfo.getSkip()).andStubReturn(new Integer(1));
    EasyMock.expect(entitySetUriInfo.getTop()).andStubReturn(new Integer(2));
    EasyMock.replay(entitySetUriInfo);
    return entitySetUriInfo;
  }
View Full Code Here

                queryParams = Collections.emptyMap();
            }
            for (String segment : segments) {
                if (segment.indexOf(';') == -1) {

                    pathSegments.add(new ODataPathSegmentImpl(segment, null));
                } else {

                    // handle matrix params in path segment
                    final String[] splitSegment = segment.split(";");
                    segment = splitSegment[0];

                    Map<String, List<String>> matrixParams = new HashMap<String, List<String>>();
                    for (int i = 1; i < splitSegment.length; i++) {
                        final String[] param = splitSegment[i].split("=");
                        List<String> values = matrixParams.get(param[0]);
                        if (values == null) {
                            values = new ArrayList<String>();
                            matrixParams.put(param[0], values);
                        }
                        if (param[1].indexOf(',') == -1) {
                            values.add(param[1]);
                        } else {
                            values.addAll(Arrays.asList(param[1].split(",")));
                        }
                    }
                    pathSegments.add(new ODataPathSegmentImpl(segment, matrixParams));
                }
            }
            result = (UriInfoImpl) UriParser.parse(edm, pathSegments, queryParams);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("resourcePath: " + e.getMessage(), e);
View Full Code Here

            });
    }

    private ContentType getResourceContentType(UriInfoImpl uriInfo) {
        ContentType resourceContentType;
        switch (uriInfo.getUriType()) {
        case URI0:
            // service document
            resourceContentType = SERVICE_DOCUMENT_CONTENT_TYPE;
            break;
View Full Code Here

        }

        ByteArrayInputStream content = null;
        try {
            if (response.getBody() != null) {
                final ContentType partContentType = ContentType.create(
                    headers.get(HttpHeaders.CONTENT_TYPE)).receiveWithCharsetParameter(ContentType.CHARSET_UTF_8);
                final String charset = partContentType.getParameters().get(ContentType.PARAMETER_CHARSET);

                final String body = response.getBody();
                content = body != null ? new ByteArrayInputStream(body.getBytes(charset)) : null;

                httpResponse.setEntity(new StringEntity(body, charset));
View Full Code Here

  public void before() {
    try {
      final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);
      final EdmProvider provider = mock(EdmProvider.class);

      service = new ODataSingleProcessorService(provider, processor) {};
      // FitStaticServiceFactory.setService(service);

      // science fiction (return context after setContext)
      // see http://www.planetgeek.ch/2010/07/20/mockito-answer-vs-return/
View Full Code Here

TOP

Related Classes of org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.