org.apache.olingo.odata2.api.processor.ODataContext Java Examples

The following examples show how to use org.apache.olingo.odata2.api.processor.ODataContext. 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: CarsODataJPAServiceFactory.java    From tutorials with MIT License 6 votes vote down vote up
/**
 * This method will be called by Olingo on every request to
 * initialize the ODataJPAContext that will be used. 
 */
@Override
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {

    log.info("[I32] >>> initializeODataJPAContext()");
    ODataJPAContext ctx = getODataJPAContext();
    ODataContext octx = ctx.getODataContext();
    HttpServletRequest request = (HttpServletRequest)octx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT);
    EntityManager em = (EntityManager)request.getAttribute(JerseyConfig.EntityManagerFilter.EM_REQUEST_ATTRIBUTE);
            
    // Here we're passing the EM that was created by the EntityManagerFilter (see JerseyConfig)
    ctx.setEntityManager(new EntityManagerWrapper(em));
    ctx.setPersistenceUnitName("default");
    
    // We're managing the EM's lifecycle, so we must inform Olingo that it should not
    // try to manage transactions and/or persistence sessions
    ctx.setContainerManaged(true);                
    return ctx;
}
 
Example #2
Source File: ServiceResolutionTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testMetadataUriWithMatrixParameter() throws IOException, ODataException,
    URISyntaxException {
  server.setPathSplit(3);
  startServer();

  final String endpoint = server.getEndpoint().toString();
  final HttpGet get = new HttpGet(URI.create(endpoint + "aaa/bbb;n=2,3;m=1/ccc/$metadata"));
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext ctx = service.getProcessor().getContext();
  assertNotNull(ctx);
  validateServiceRoot(ctx.getPathInfo().getServiceRoot().toASCIIString(),
      endpoint + "aaa/bbb;", "/ccc/", "n=2,3", "m=1");
  assertEquals("$metadata", ctx.getPathInfo().getODataSegments().get(0).getPath());
}
 
Example #3
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> parseLinkUri(final EdmEntitySet targetEntitySet, final String uriString)
    throws EdmException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("UriParser", "getKeyPredicatesFromEntityLink");

  List<KeyPredicate> key = null;
  try {
    key = UriParser.getKeyPredicatesFromEntityLink(targetEntitySet, uriString,
        context.getPathInfo().getServiceRoot());
  } catch (ODataException e) {
    // We don't understand the link target. This could also be seen as an error.
  }

  context.stopRuntimeMeasurement(timingHandle);

  return key == null ? null : mapKey(key);
}
 
Example #4
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private ODataEntry parseEntry(final EdmEntitySet entitySet, final InputStream content,
    final String requestContentType, final EntityProviderReadProperties properties) throws ODataBadRequestException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readEntry");

  ODataEntry entryValues;
  try {
    entryValues = EntityProvider.readEntry(requestContentType, entitySet, content, properties);
  } catch (final EntityProviderException e) {
    throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
  }

  context.stopRuntimeMeasurement(timingHandle);

  return entryValues;
}
 
Example #5
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private <T> ODataResponse writeEntry(final EdmEntitySet entitySet, final ExpandSelectTreeNode expandSelectTree,
    final T data, final String contentType) throws ODataException, EntityProviderException {
  final EdmEntityType entityType = entitySet.getEntityType();
  final Map<String, Object> values = getStructuralTypeValueMap(data, entityType);

  ODataContext context = getContext();
  EntityProviderWriteProperties writeProperties = EntityProviderWriteProperties
      .serviceRoot(context.getPathInfo().getServiceRoot())
      .expandSelectTree(expandSelectTree)
      .callbacks(getCallbacks(data, entityType))
      .build();

  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeEntry");

  final ODataResponse response = EntityProvider.writeEntry(contentType, entitySet, values, writeProperties);

  context.stopRuntimeMeasurement(timingHandle);

  return response;
}
 
Example #6
Source File: ODataEntityParser.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public final UriInfo parseLink(final EdmEntitySet entitySet, final InputStream content, final String contentType)
    throws ODataJPARuntimeException {

  String uriString = null;
  UriInfo uri = null;
  try {
    uriString = EntityProvider.readLink(contentType, entitySet, content);
    ODataContext odataContext = context.getODataContext();
    final String svcRoot = odataContext.getPathInfo().getServiceRoot().toString();
    final String path =
        uriString.startsWith(svcRoot.toString()) ? uriString.substring(svcRoot.length()) : uriString;
    final List<PathSegment> pathSegment = getPathSegment(path);
    edm = getEdm();
    uri = UriParser.parse(edm, pathSegment, Collections.<String, String> emptyMap());
  } catch (ODataException e) {
    throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
  }
  return uri;
}
 
Example #7
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private List<Locale> getLanguages(final ODataContext context) {
  try {
    if (context.getAcceptableLanguages().isEmpty()) {
      return Arrays.asList(DEFAULT_RESPONSE_LOCALE);
    }
    return context.getAcceptableLanguages();
  } catch (WebApplicationException e) {
    if (e.getCause() != null && e.getCause().getClass() == ParseException.class) {
      // invalid accept-language string in http header
      // compensate exception with using default locale
      return Arrays.asList(DEFAULT_RESPONSE_LOCALE);
    }
    // not able to compensate exception -> re-throw
    throw e;
  }
}
 
Example #8
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private <T> Map<String, Object> getStructuralTypeTypeMap(final T data, final EdmStructuralType type)
    throws ODataException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeTypeMap");

  Map<String, Object> typeMap = new HashMap<String, Object>();
  for (final String propertyName : type.getPropertyNames()) {
    final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
    if (property.isSimple()) {
      typeMap.put(propertyName, valueAccess.getPropertyType(data, property));
    } else {
      typeMap.put(propertyName, getStructuralTypeTypeMap(valueAccess.getPropertyValue(data, property),
          (EdmStructuralType) property.getType()));
    }
  }

  context.stopRuntimeMeasurement(timingHandle);

  return typeMap;
}
 
Example #9
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private ODataEntry parseEntry(final EdmEntitySet entitySet, final InputStream content,
    final String requestContentType, final EntityProviderReadProperties properties) throws ODataBadRequestException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readEntry");

  ODataEntry entryValues;
  try {
    entryValues = EntityProvider.readEntry(requestContentType, entitySet, content, properties);
  } catch (final EntityProviderException e) {
    throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
  }

  context.stopRuntimeMeasurement(timingHandle);

  return entryValues;
}
 
Example #10
Source File: ServiceResolutionTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplit1() throws IOException, ODataException {
  server.setPathSplit(1);
  startServer();

  final HttpGet get = new HttpGet(URI.create(server.getEndpoint().toString() + "/aaa/$metadata"));
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext ctx = service.getProcessor().getContext();
  assertNotNull(ctx);

  assertEquals("aaa", ctx.getPathInfo().getPrecedingSegments().get(0).getPath());
  assertEquals("$metadata", ctx.getPathInfo().getODataSegments().get(0).getPath());
}
 
Example #11
Source File: ODataDebugResponseWrapperTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void minimal() throws Exception {
  final ODataContext context = mockContext(ODataHttpMethod.PUT);
  final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.NO_CONTENT, null, null);

  ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
      ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse();
  final String actualJson = StringHelper.inputStreamToString((InputStream) response.getEntity());
  assertEquals(EXPECTED.replace(ODataHttpMethod.GET.name(), ODataHttpMethod.PUT.name())
      .replace(Integer.toString(HttpStatusCodes.OK.getStatusCode()),
          Integer.toString(HttpStatusCodes.NO_CONTENT.getStatusCode()))
      .replace(HttpStatusCodes.OK.getInfo(), HttpStatusCodes.NO_CONTENT.getInfo()),
      actualJson);

  response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
      ODataDebugResponseWrapper.ODATA_DEBUG_HTML).wrapResponse();
  final String html = StringHelper.inputStreamToString((InputStream) response.getEntity());
  assertTrue(html.contains(HttpStatusCodes.NO_CONTENT.getInfo()));
}
 
Example #12
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse updateEntityMedia(final PutMergePatchUriInfo uriInfo, final InputStream content,
    final String requestContentType, final String contentType) throws ODataException {
  final Object data = retrieveData(
      uriInfo.getStartEntitySet(),
      uriInfo.getKeyPredicates(),
      uriInfo.getFunctionImport(),
      mapFunctionParameters(uriInfo.getFunctionImportParameters()),
      uriInfo.getNavigationSegments());

  final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
  if (!appliesFilter(entitySet, data, uriInfo.getFilter())) {
    throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
  }

  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readBinary");

  final byte[] value = EntityProvider.readBinary(content);

  context.stopRuntimeMeasurement(timingHandle);

  dataSource.writeBinaryData(entitySet, data, new BinaryData(value, requestContentType));

  return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
}
 
Example #13
Source File: ServiceResolutionTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testMatrixParameterInNonODataPath() throws IOException, ODataException {
  server.setPathSplit(1);
  startServer();

  final HttpGet get = new HttpGet(URI.create(server.getEndpoint().toString() + "aaa;n=2/"));
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext ctx = service.getProcessor().getContext();
  assertNotNull(ctx);

  assertEquals("", ctx.getPathInfo().getODataSegments().get(0).getPath());
  assertEquals("aaa", ctx.getPathInfo().getPrecedingSegments().get(0).getPath());

  assertNotNull(ctx.getPathInfo().getPrecedingSegments().get(0).getMatrixParameters());

  String key, value;
  key = ctx.getPathInfo().getPrecedingSegments().get(0).getMatrixParameters().keySet().iterator().next();
  assertEquals("n", key);
  value = ctx.getPathInfo().getPrecedingSegments().get(0).getMatrixParameters().get(key).get(0);
  assertEquals("2", value);
}
 
Example #14
Source File: ServiceResolutionTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplit0() throws IOException, ODataException {
  server.setPathSplit(0);
  startServer();

  final HttpGet get = new HttpGet(URI.create(server.getEndpoint().toString() + "/$metadata"));
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext ctx = service.getProcessor().getContext();
  assertNotNull(ctx);

  assertTrue(ctx.getPathInfo().getPrecedingSegments().isEmpty());
  assertEquals("$metadata", ctx.getPathInfo().getODataSegments().get(0).getPath());
}
 
Example #15
Source File: ServiceResolutionTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplit2() throws IOException, ODataException {
  server.setPathSplit(2);
  startServer();

  final HttpGet get = new HttpGet(URI.create(server.getEndpoint().toString() + "/aaa/bbb/$metadata"));
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext ctx = service.getProcessor().getContext();
  assertNotNull(ctx);

  assertEquals("aaa", ctx.getPathInfo().getPrecedingSegments().get(0).getPath());
  assertEquals("bbb", ctx.getPathInfo().getPrecedingSegments().get(1).getPath());
  assertEquals("$metadata", ctx.getPathInfo().getODataSegments().get(0).getPath());
}
 
Example #16
Source File: ODataServletTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void serviceInstance() throws Exception {
  ODataServlet servlet = new ODataServlet();
  prepareServlet(servlet);
  prepareRequest(reqMock, "", "/servlet-path");
  Mockito.when(reqMock.getPathInfo()).thenReturn("/request-path-info");
  Mockito.when(reqMock.getRequestURI()).thenReturn("http://localhost:8080/servlet-path/request-path-info");
  ODataServiceFactory factory = Mockito.mock(ODataServiceFactory.class);
  ODataService service = Mockito.mock(ODataService.class);
  Mockito.when(factory.createService(Mockito.any(ODataContext.class))).thenReturn(service);
  ODataProcessor processor = Mockito.mock(ODataProcessor.class);
  Mockito.when(service.getProcessor()).thenReturn(processor);
  Mockito.when(reqMock.getAttribute(ODataServiceFactory.FACTORY_INSTANCE_LABEL)).thenReturn(factory);
  Mockito.when(respMock.getOutputStream()).thenReturn(Mockito.mock(ServletOutputStream.class));

  servlet.service(reqMock, respMock);

  Mockito.verify(factory).createService(Mockito.any(ODataContext.class));
}
 
Example #17
Source File: ServiceResolutionTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBaseUriWithEncoding() throws IOException, ODataException,
    URISyntaxException {
  server.setPathSplit(3);
  startServer();

  final URI uri =
      new URI(server.getEndpoint().getScheme(), null, server.getEndpoint().getHost(), server.getEndpoint().getPort(),
          server.getEndpoint().getPath() + "/aaa/äдержb;n=2, 3;m=1/c c/", null, null);

  final HttpGet get = new HttpGet(uri);
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext context = service.getProcessor().getContext();
  assertNotNull(context);
  validateServiceRoot(context.getPathInfo().getServiceRoot().toASCIIString(),
      server.getEndpoint() + "aaa/%C3%A4%D0%B4%D0%B5%D1%80%D0%B6b;", "/c%20c/", "n=2,%203", "m=1");
}
 
Example #18
Source File: ServiceResolutionTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBaseUriWithMatrixParameter() throws IOException, ODataException,
    URISyntaxException {
  server.setPathSplit(3);
  startServer();

  final String endpoint = server.getEndpoint().toString();
  final HttpGet get = new HttpGet(URI.create(endpoint + "aaa/bbb;n=2,3;m=1/ccc/"));
  final HttpResponse response = httpClient.execute(get);

  assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());

  final ODataContext ctx = service.getProcessor().getContext();
  assertNotNull(ctx);
  validateServiceRoot(ctx.getPathInfo().getServiceRoot().toASCIIString(),
      endpoint + "aaa/bbb;", "/ccc/", "n=2,3", "m=1");
}
 
Example #19
Source File: FitStaticServiceFactory.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
  public ODataService createService(final ODataContext ctx) throws ODataException {

    assertNotNull(ctx);
    assertNotNull(ctx.getAcceptableLanguages());
    assertNotNull(ctx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT));

    final Map<String, List<String>> requestHeaders = ctx.getRequestHeaders();
    final String host = requestHeaders.get("Host").get(0);

    String tmp[] = host.split(":", 2);
    String port = (tmp.length == 2 && tmp[1] != null) ? tmp[1] : "80";

    // access and validation in synchronized block
    synchronized (PORT_2_SERVICE) {
      final ODataService service = PORT_2_SERVICE.get(port);
//      if (service == null) {
//        throw new IllegalArgumentException("no static service set for JUnit test");
//      }
      return service;
    }
  }
 
Example #20
Source File: AbstractProviderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
protected ODataContext createContextMock() throws ODataException {
  PathInfo pathInfo = mock(PathInfo.class);
  when(pathInfo.getServiceRoot()).thenReturn(BASE_URI);
  ODataContext ctx = mock(ODataContext.class);
  when(ctx.getPathInfo()).thenReturn(pathInfo);
  return ctx;
}
 
Example #21
Source File: ODataDebugResponseWrapperTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void runtime() throws Exception {
  ODataContext context = mockContext(ODataHttpMethod.GET);
  List<RuntimeMeasurement> runtimeMeasurements = new ArrayList<RuntimeMeasurement>();
  runtimeMeasurements.add(mockRuntimeMeasurement("method", 1000, 42000));
  runtimeMeasurements.add(mockRuntimeMeasurement("inner", 2000, 5000));
  runtimeMeasurements.add(mockRuntimeMeasurement("inner", 7000, 12000));
  runtimeMeasurements.add(mockRuntimeMeasurement("inner", 13000, 16000));
  runtimeMeasurements.add(mockRuntimeMeasurement("inner2", 14000, 15000));
  runtimeMeasurements.add(mockRuntimeMeasurement("child", 17000, 21000));
  runtimeMeasurements.add(mockRuntimeMeasurement("second", 45000, 99000));
  when(context.getRuntimeMeasurements()).thenReturn(runtimeMeasurements);

  final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, null);

  ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
      ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse();
  String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
  assertEquals(EXPECTED.replace("null}}", "null,"
      + "\"runtime\":[{\"class\":\"class\",\"method\":\"method\",\"duration\":{\"value\":41,\"unit\":\"µs\"},"
      + "\"children\":[{\"class\":\"class\",\"method\":\"inner\",\"duration\":{\"value\":8,\"unit\":\"µs\"}},"
      + "{\"class\":\"class\",\"method\":\"inner\",\"duration\":{\"value\":3,\"unit\":\"µs\"},\"children\":["
      + "{\"class\":\"class\",\"method\":\"inner2\",\"duration\":{\"value\":1,\"unit\":\"µs\"}}]},"
      + "{\"class\":\"class\",\"method\":\"child\",\"duration\":{\"value\":4,\"unit\":\"µs\"}}]},"
      + "{\"class\":\"class\",\"method\":\"second\",\"duration\":{\"value\":54,\"unit\":\"µs\"}}]}}"),
      entity);

  response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
      ODataDebugResponseWrapper.ODATA_DEBUG_HTML).wrapResponse();
  entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
  assertTrue(entity.contains("54&nbsp;&micro;s"));
}
 
Example #22
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Map<String, Object> parseLink(final EdmEntitySet entitySet, final InputStream content,
    final String contentType) throws ODataException {
  ODataContext context = getContext();
  final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readLink");

  final String uriString = EntityProvider.readLink(contentType, entitySet, content);

  context.stopRuntimeMeasurement(timingHandle);

  final Map<String, Object> targetKeys = parseLinkUri(entitySet, uriString);
  if (targetKeys == null) {
    throw new ODataBadRequestException(ODataBadRequestException.BODY);
  }
  return targetKeys;
}
 
Example #23
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataErrorCallback getErrorHandlerCallbackFromContext(final ODataContext context)
    throws ClassNotFoundException, InstantiationException, IllegalAccessException {
  ODataErrorCallback cback = null;
  ODataServiceFactory serviceFactory = context.getServiceFactory();
  cback = serviceFactory.getCallback(ODataErrorCallback.class);
  return cback;
}
 
Example #24
Source File: ODataJPAContextImplTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {

  edmProvider = new ODataJPAEdmProvider();
  emf = EasyMock.createMock(EntityManagerFactory.class);
  em = EasyMock.createMock(EntityManager.class);
  EasyMock.expect(em.isOpen()).andReturn(false);
  EasyMock.replay(em);

  EasyMock.expect(emf.createEntityManager()).andStubReturn(em);
  EasyMock.replay(emf);

  odataContext = EasyMock.createMock(ODataContext.class);
  List<Locale> listLocale = new ArrayList<Locale>();
  listLocale.add(Locale.ENGLISH);
  listLocale.add(Locale.GERMAN);

  EasyMock.expect(odataContext.getAcceptableLanguages()).andStubReturn(listLocale);
  EasyMock.replay(odataContext);

  processor = EasyMock.createMock(ODataProcessor.class);
  EasyMock.replay(processor);

  odataJPAContext = new ODataJPAContextImpl();
  odataJPAContext.setEdmProvider(edmProvider);
  odataJPAContext.setEntityManagerFactory(emf);
  odataJPAContext.setODataContext(odataContext);
  odataJPAContext.setODataProcessor(processor);
  odataJPAContext.setPersistenceUnitName(ODataJPAContextMock.PERSISTENCE_UNIT_NAME);
  odataJPAContext.setJPAEdmMappingModel(ODataJPAContextMock.MAPPING_MODEL);
}
 
Example #25
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  ODataContextMock odataContextMock = new ODataContextMock();
  ODataContext context;
  try {
    context = odataContextMock.mock();
    ODataJPAContext odataJPAContext = ODataJPAContextMock.mockODataJPAContext(context);
    builder = new JPAQueryBuilder(odataJPAContext);
  } catch (ODataException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
Example #26
Source File: ODataJPAContextMock.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public static ODataJPAContext mockODataJPAContext(final ODataContext context) {
  ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
  EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn(NAMESPACE);
  EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andReturn(mockEntityManagerFactory());
  EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(mockEntityManager());
  EasyMock.expect(odataJPAContext.getJPAEdmMappingModel()).andReturn(MAPPING_MODEL);
  EasyMock.expect(odataJPAContext.getJPAEdmExtension()).andReturn(null);
  EasyMock.expect(odataJPAContext.getDefaultNaming()).andReturn(true);
  EasyMock.expect(odataJPAContext.getODataContext()).andReturn(context).anyTimes();
  EasyMock.expect(odataJPAContext.getPageSize()).andReturn(0);

  EasyMock.replay(odataJPAContext);
  return odataJPAContext;
}
 
Example #27
Source File: JPAProcessorImplTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataContext getLocalODataContext() {
  ODataContext objODataContext = EasyMock.createMock(ODataContext.class);
  try {
    EasyMock.expect(objODataContext.getPathInfo()).andStubReturn(getLocalPathInfo());
  } catch (ODataException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
  EasyMock.replay(objODataContext);
  return objODataContext;
}
 
Example #28
Source File: ODataJPAProcessor.java    From lemonaid with MIT License 5 votes vote down vote up
@Override
public ODataResponse executeBatch(BatchHandler handler, String contentType, InputStream content)
		throws ODataException {
	ODataContext ctx = ODataJPAContextImpl.getContextInThreadLocal();
	authorization.setContext((HttpServletRequest) ctx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT));
	return super.executeBatch(handler, contentType, content);
}
 
Example #29
Source File: ODataContextMock.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public ODataContext mockWithoutOnJPAWriteContent() throws ODataException {
  ODataContext context = EasyMock.createMock(ODataContext.class);
  EasyMock.expect(context.getService()).andReturn(odataService).anyTimes();
  EasyMock.expect(context.getPathInfo()).andReturn(pathInfo).anyTimes();
  EasyMock.expect(context.isInBatchMode()).andReturn(this.isInBatchMode).anyTimes();
  ODataJPAServiceFactoryMock mockServiceFactory = new ODataJPAServiceFactoryMock(context);
  mockServiceFactory.initializeODataJPAContextX();
  EasyMock.expect(context.getServiceFactory()).andReturn(mockServiceFactory).anyTimes();
  EasyMock.replay(context);
  return context;
}
 
Example #30
Source File: JPAEntityTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataJPAContext mockODataJPAContext() throws ODataException {
  PathInfoMock pathInfoMock = new PathInfoMock();
  try {
    pathInfoMock.setServiceRootURI("http://olingo.apache.org/service.svc");
  } catch (URISyntaxException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
        + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
  ODataContextMock contextMock = new ODataContextMock();
  contextMock.setPathInfo(pathInfoMock.mock());
  ODataContext context = contextMock.mock();
  ODataJPAContext jpaContext = ODataJPAContextMock.mockODataJPAContext(context);
  return jpaContext;
}