org.apache.olingo.odata2.api.ep.EntityProviderException Java Examples

The following examples show how to use org.apache.olingo.odata2.api.ep.EntityProviderException. 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: AtomEntrySerializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityWithInvalidInlineEntryType() throws Exception {
  expectedEx.expect(EntityProviderException.class);
  expectedEx.expectMessage("Navigation has to be either an Entity or a Map");
  Entity roomData = new Entity();
  roomData.addProperty("Id", "1");
  roomData.addProperty("Name", "Neu Schwanstein");
  roomData.addProperty("Seats", new Integer(20));

  EntitySerializerProperties properties =
      EntitySerializerProperties.serviceRoot(BASE_URI)
          .includeMetadata(true).build();
  roomData.setWriteProperties(properties);
  roomData.addNavigation("nr_Building", new ArrayList<String>());
  AtomSerializerDeserializer provider = createAtomEntityProvider();
      provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), roomData);

}
 
Example #2
Source File: ServiceDocumentConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testJsonServiceDocument() throws EntityProviderException {
  InputStream in = ClassLoader.class.getResourceAsStream("/svcDocJson.json");
  ServiceDocument serviceDoc = EntityProvider.readServiceDocument(in, "application/json");
  assertNotNull(serviceDoc);
  assertNull(serviceDoc.getAtomInfo());
  List<EdmEntitySetInfo> entitySetsInfo = serviceDoc.getEntitySetsInfo();
  assertEquals(7, entitySetsInfo.size());
  for (EdmEntitySetInfo entitySetInfo : entitySetsInfo) {
    if (!entitySetInfo.isDefaultEntityContainer()) {
      if ("Container2".equals(entitySetInfo.getEntityContainerName())) {
        assertEquals("Photos", entitySetInfo.getEntitySetName());
      } else if ("Container.Nr1".equals(entitySetInfo.getEntityContainerName())) {
        assertEquals("Employees", entitySetInfo.getEntitySetName());
      }
    }
  }
}
 
Example #3
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBaseType() throws XMLStreamException, EntityProviderException {
  int i = 0;
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmlWithBaseType);
  DataServices result = parser.readMetadata(reader, true);
  assertEquals("2.0", result.getDataServiceVersion());
  for (Schema schema : result.getSchemas()) {
    assertEquals(NAMESPACE, schema.getNamespace());
    assertEquals(2, schema.getEntityTypes().size());
    assertEquals("Employee", schema.getEntityTypes().get(0).getName());
    for (PropertyRef propertyRef : schema.getEntityTypes().get(0).getKey().getKeys()) {
      assertEquals("EmployeeId", propertyRef.getName());
    }
    for (Property property : schema.getEntityTypes().get(0).getProperties()) {
      assertEquals(propertyNames[i], property.getName());
      i++;
    }

  }
}
 
Example #4
Source File: XmlMetadataAssociationTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testAssociation() throws XMLStreamException, EntityProviderException,
EdmException, UnsupportedEncodingException {
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmlWithAssociation);
  EdmDataServices result = parser.readMetadata(reader, true);
  assertEquals("2.0", result.getDataServiceVersion());
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmAssociation association : schema.getAssociations()) {
      EdmAssociationEnd end;
      assertEquals(ASSOCIATION, association.getName());
      if ("Employee".equals(association.getEnd1().getEntityType().getName())) {
        end = association.getEnd1();
      } else {
        end = association.getEnd2();
      }
      assertEquals(EdmMultiplicity.MANY, end.getMultiplicity());
      assertEquals("r_Employees", end.getRole());
    }
  }
}
 
Example #5
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoSchemas() throws XMLStreamException, EntityProviderException {
  int i = 0;
  String schemasNs[] = { NAMESPACE, NAMESPACE2 };
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmlWithTwoSchemas);
  DataServices result = parser.readMetadata(reader, true);
  assertEquals("2.0", result.getDataServiceVersion());
  assertEquals(2, result.getSchemas().size());
  for (Schema schema : result.getSchemas()) {
    assertEquals(schemasNs[i], schema.getNamespace());
    assertEquals(1, schema.getEntityTypes().size());
    i++;

  }
}
 
Example #6
Source File: JsonEntryEntitySerializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void addNullToNavigation() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  Entity employeeData = new Entity();
  employeeData.addProperty("EmployeeId", "1");
  employeeData.addNavigation("ne_Manager", null); 

  EntitySerializerProperties properties =
      EntitySerializerProperties.fromProperties(DEFAULT_PROPERTIES).build();
  employeeData.setWriteProperties(properties);
  try {
    new JsonSerializerDeserializer().writeEntry(entitySet, employeeData);
  } catch (EntityProviderException e) {
    assertEquals(ERROR_MSG, e.getMessage());
  }
}
 
Example #7
Source File: AtomFeedSerializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void entityWithNullFeed() throws Exception {
  Entity roomData = new Entity();
  roomData.addProperty("Id", "1");
  roomData.addProperty("Name", "Neu Schwanstein");
  roomData.addProperty("Seats", new Integer(20));

  EntitySerializerProperties properties =
      EntitySerializerProperties.serviceRoot(BASE_URI).build();

  AtomSerializerDeserializer provider = createAtomEntityProvider();
  roomData.addNavigation("nr_Employees", null);
  roomData.setWriteProperties(properties);
  ODataResponse response =
      provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), roomData);

  String xmlString = verifyResponse(response);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  assertXpathExists("/a:entry/a:link", xmlString);
}
 
Example #8
Source File: JsonEntityProvider.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataResponse writeFunctionImport(final EdmFunctionImport functionImport, final Object data,
    final EntityProviderWriteProperties properties) throws EntityProviderException {
  try {
    if(functionImport.getReturnType() !=null){
      if (functionImport.getReturnType().getType().getKind() == EdmTypeKind.ENTITY) {
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>) data;
        return writeEntry(functionImport.getEntitySet(), map, properties);
      }

      final EntityPropertyInfo info = EntityInfoAggregator.create(functionImport);
      if (functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY) {
        return writeCollection(info, (List<?>) data);
      } else {
        return writeSingleTypedElement(info, data);
      }
    }else{
      return ODataResponse.newBuilder().status(HttpStatusCodes.ACCEPTED).build();
    }
  } catch (final EdmException e) {
    throw new EntityProviderProducerException(e.getMessageReference(), e);
  }
}
 
Example #9
Source File: JsonServiceDocumentConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws EntityProviderException {
  JsonServiceDocumentConsumer parser = new JsonServiceDocumentConsumer();
  InputStream in = ClassLoader.class.getResourceAsStream("/svcDocJson.json");
  ServiceDocument serviceDoc = parser.parseJson(in);
  List<EdmEntitySetInfo> entitySetsInfo = serviceDoc.getEntitySetsInfo();
  assertNotNull(entitySetsInfo);
  assertEquals(7, entitySetsInfo.size());
  for (EdmEntitySetInfo entitySetInfo : entitySetsInfo) {
    if (!entitySetInfo.isDefaultEntityContainer()) {
      if ("Container2".equals(entitySetInfo.getEntityContainerName())) {
        assertEquals("Photos", entitySetInfo.getEntitySetName());
      } else if ("Container.Nr1".equals(entitySetInfo.getEntityContainerName())) {
        assertEquals("Employees", entitySetInfo.getEntitySetName());
      } else {
        fail();
      }
    }
  }
}
 
Example #10
Source File: ODataClientImpl.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private ContentTypeBasedDeserializer createDeserializer(ContentType contentType)
    throws EntityProviderException {
  try {
    switch (contentType.getODataFormat()) {
    case ATOM:
    case XML:
      return new AtomSerializerDeserializer(contentType.getODataFormat());
    case JSON:
      return new JsonSerializerDeserializer();
    default:
      throw new ODataNotAcceptableException(ODataNotAcceptableException.NOT_SUPPORTED_CONTENT_TYPE
          .addContent(contentType));
    }
  } catch (final ODataNotAcceptableException e) {
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}
 
Example #11
Source File: XmlMetadataDeserializer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private EdmProperty readPropertyRef(final XMLStreamReader reader) throws XMLStreamException, 
EntityProviderException, EdmException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_PROPERTY_REF);
  EdmPropertyImpl propertyRef = new EdmPropertyRefImpl();
  propertyRef.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  EdmAnnotations annotations = new EdmAnnotationsImpl();
  List<EdmAnnotationElement> annotationElements = new ArrayList<EdmAnnotationElement>();
  ((EdmAnnotationsImpl) annotations).setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_PROPERTY_REF.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    ((EdmAnnotationsImpl) annotations).setAnnotationElements(annotationElements);
  }
  propertyRef.setAnnotations(annotations);
  return propertyRef;
}
 
Example #12
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testComplexTypeWithInvalidBaseType2() throws XMLStreamException, EntityProviderException {
  final String xml =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">"
          + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">"
          + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
          + "<EntityType Name= \"Employee\" m:HasStream=\"true\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\"" + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<Property Name=\"" + propertyNames[2] + "\" Type=\"RefScenario.c_Location\" Nullable=\"false\"/>"
          + "</EntityType>" + "<ComplexType Name=\"c_BaseType_for_Location\" Abstract=\"true\">"
          + "<Property Name=\"Country\" Type=\"Edm.String\"/>" + "</ComplexType>"
          + "<ComplexType Name=\"c_Location\" BaseType=\"c_BaseType_for_Location\">" + "</ComplexType>" + "</Schema>"
          + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xml);
  parser.readMetadata(reader, true);
}
 
Example #13
Source File: AtomEntryEntityProducer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void appendAdditinalLinks(final XMLStreamWriter writer, final EntityInfoAggregator eia,
    final Map<String, Object> data)
    throws EntityProviderException, EdmException, URISyntaxException {
  final Map<String, Map<String, Object>> links = properties.getAdditionalLinks();
  if (links != null && !links.isEmpty()) {
    for (Entry<String, Map<String, Object>> entry : links.entrySet()) {
      Map<String, Object> navigationKeyMap = entry.getValue();
      final boolean isFeed =
          (eia.getNavigationPropertyInfo(entry.getKey()).getMultiplicity() == EdmMultiplicity.MANY);
      if (navigationKeyMap != null && !navigationKeyMap.isEmpty()) {
        final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create(
            eia.getEntitySet().getRelatedEntitySet(
                (EdmNavigationProperty) eia.getEntityType().getProperty(entry.getKey())));
        appendAtomNavigationLink(writer, createSelfLink(targetEntityInfo, navigationKeyMap, null), entry.getKey(),
            isFeed, eia, data);
      }
    }
  }
}
 
Example #14
Source File: XmlLinkConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Reads multiple links with format
 * <pre> {@code
 * <links>
 *  <uri>http://somelink</uri>
 *  <uri>http://anotherLink</uri>
 *  <uri>http://somelink/yetAnotherLink</uri>
 * </links>
 * } </pre>
 * @param reader
 * @param entitySet
 * @return list of string based links
 * @throws EntityProviderException
 */
public List<String> readLinks(final XMLStreamReader reader, final EdmEntitySet entitySet)
    throws EntityProviderException {
  try {
    List<String> links = new ArrayList<String>();
    reader.nextTag();
    reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_D_2007_08, FormatXml.D_LINKS);
    reader.nextTag();
    while (!reader.isEndElement()) {
      if (reader.getLocalName().equals(FormatXml.M_COUNT)) {
        readTag(reader, Edm.NAMESPACE_M_2007_08, FormatXml.M_COUNT);
      } else {
        final String link = readLink(reader);
        links.add(link);
      }
      reader.nextTag();
    }

    reader.require(XMLStreamConstants.END_ELEMENT, Edm.NAMESPACE_D_2007_08, FormatXml.D_LINKS);
    return links;
  } catch (final XMLStreamException e) {
    throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
        .getSimpleName()), e);
  }
}
 
Example #15
Source File: XmlFeedDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void readEmployeesFeedWithInlineCountLetters() throws Exception {
  // prepare
  String content = readFile("feed_employees_full.xml").replace("<m:count>6</m:count>", "<m:count>AAA</m:count>");
  assertNotNull(content);

  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
  InputStream reqContent = createContentAsStream(content);

  // execute
  XmlEntityDeserializer xec = new XmlEntityDeserializer();
  DeserializerProperties consumerProperties = DeserializerProperties.init()
      .build();

  EntityStream es = new EntityStream();
  es.setContent(reqContent);
  es.setReadProperties(consumerProperties);
  try {
    xec.readFeed(entitySet, es);
  } catch (EntityProviderException e) {
    assertEquals(EntityProviderException.INLINECOUNT_INVALID, e.getMessageReference());
    throw e;
  }

  Assert.fail("Exception expected");
}
 
Example #16
Source File: AtomEntryEntitySerializer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void appendAtomContentLink(final XMLStreamWriter writer, final EntityInfoAggregator eia,
    final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException {
  try {
    String mediaResourceMimeType = null;
    EdmMapping entityTypeMapping = eia.getEntityType().getMapping();
    if (entityTypeMapping != null) {
      String mediaResourceMimeTypeKey = entityTypeMapping.getMediaResourceMimeTypeKey();
      if (mediaResourceMimeTypeKey != null) {
        mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey);
      }
    }
    if (mediaResourceMimeType == null) {
      mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString();
    }

    writer.writeStartElement(FormatXml.ATOM_LINK);
    writer.writeAttribute(FormatXml.ATOM_HREF, selfLink + VALUE);
    writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT_MEDIA);
    writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType);
    writer.writeEndElement();
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example #17
Source File: XmlLinksEntityProducer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public void append(final XMLStreamWriter writer, final EntityInfoAggregator entityInfo,
    final List<Map<String, Object>> data) throws EntityProviderException {
  try {
    writer.writeStartElement(FormatXml.D_LINKS);
    writer.writeDefaultNamespace(Edm.NAMESPACE_D_2007_08);
    if (properties.getInlineCount() != null) {
      writer.writeStartElement(Edm.PREFIX_M, FormatXml.M_COUNT, Edm.NAMESPACE_M_2007_08);
      writer.writeNamespace(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08);
      writer.writeCharacters(properties.getInlineCount().toString());
      writer.writeEndElement();
    }
    XmlLinkEntityProducer provider = new XmlLinkEntityProducer(properties);
    for (final Map<String, Object> entityData : data) {
      provider.append(writer, entityInfo, entityData, false);
    }
    writer.writeEndElement();
    writer.flush();
  } catch (final XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example #18
Source File: JsonEntryDeserializer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @throws IOException
 * @throws EntityProviderException
 */
private void readODataContext() throws IOException, EntityProviderException {
  String contextValue = reader.nextString();
  if (contextValue == null) {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE.addContent(FormatJson.ODATA_CONTEXT)
        .addContent(FormatJson.RESULTS));
  }

  if (contextValue.startsWith(FormatJson.DELTA_CONTEXT_PREFIX)
      && contextValue.endsWith(FormatJson.DELTA_CONTEXT_POSTFIX)) {
    while (reader.hasNext()) {
      ensureDeletedEntryMetadataExists();
      String name = reader.nextName();
      String value = reader.nextString();
      if (FormatJson.ID.equals(name)) {
        resultDeletedEntry.setUri(value);
      } else if (FormatJson.DELTA_WHEN.equals(name)) {
        Date when = parseWhen(value);
        resultDeletedEntry.setWhen(when);
      }
    }
  }
}
 
Example #19
Source File: XmlMetadataDeserializer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void validateFunctionImport() throws EntityProviderException, EdmException {
  for (EdmFunctionImport functionImport : edmFunctionImportList) {
    EdmTyped returnType = functionImport.getReturnType();
    if (returnType != null) {
      FullQualifiedName fqn = extractFQName(returnType.toString());
      String entitySet = ((EdmFunctionImportImpl)functionImport).getEntitySetName();
      if (returnType.getMultiplicity() == EdmMultiplicity.MANY && entitySet == null && entityTypesMap.get(
          fqn) != null) {
        throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE.addContent("EntitySet = "
            + entitySet, XmlMetadataConstants.EDM_FUNCTION_IMPORT + " = " + functionImport.getName()));
      } else if (returnType.getMultiplicity() != EdmMultiplicity.MANY && entitySet != null && entityTypesMap.get(
          fqn) == null) {
        throw new EntityProviderException(EntityProviderException.INVALID_ATTRIBUTE.addContent("EntitySet = "
            + entitySet, XmlMetadataConstants.EDM_FUNCTION_IMPORT
                + " = " + functionImport.getName()));
      }
    }
  }
}
 
Example #20
Source File: JsonFeedEntityProducer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void appendDeletedEntries(final Writer writer, final EntityInfoAggregator entityInfo,
    final List<Map<String, Object>> data, TombstoneCallback callback) throws EntityProviderException {
  JsonDeletedEntryEntityProducer deletedEntryProducer = new JsonDeletedEntryEntityProducer(properties);
  TombstoneCallbackResult callbackResult = callback.getTombstoneCallbackResult();
  List<Map<String, Object>> deletedEntries = callbackResult.getDeletedEntriesData();
  if (deletedEntries != null) {
    deletedEntryProducer.append(writer, entityInfo, deletedEntries, data.isEmpty());
  }
}
 
Example #21
Source File: JsonFeedDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void doubleNext() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Teams");
  InputStream contentBody = createContentAsStream("{\"d\":{\"results\":[],\"__next\":\"a\",\"__next\":\"b\"}}");
  EntityStream entityStream = new EntityStream();
  entityStream.setContent(contentBody);
  entityStream.setReadProperties(DEFAULT_PROPERTIES);
  new JsonEntityDeserializer().readFeed(entitySet, entityStream);
}
 
Example #22
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testFunctionImportCollError() throws XMLStreamException, EntityProviderException {
  final String xmWithEntityContainer =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\""
          + Edm.NAMESPACE_EDMX_2007_06
          + "\">"
          + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\""
          + Edm.NAMESPACE_M_2007_08
          + "\">"
          + "<Schema Namespace=\""
          + NAMESPACE
          + "\" xmlns=\""
          + Edm.NAMESPACE_EDM_2008_09
          + "\">"
          + "<EntityType Name= \"Employee\" m:HasStream=\"true\">"
          + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\""
          + propertyNames[0]
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<Property Name=\""
          + propertyNames[1]
          + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>"
          + "</EntityType>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<FunctionImport Name=\"EmployeeSearch\" ReturnType=\"Collection(RefScenario.Employee)\" " +
          " m:HttpMethod=\"GET\">"
          + "<Parameter Name=\"q1\" Type=\"Edm.String\" Nullable=\"true\" />"
          + "<Parameter Name=\"q2\" Type=\"Edm.Int32\" Nullable=\"false\" />"
          + "</FunctionImport>"
          + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmWithEntityContainer);
  parser.readMetadata(reader, true);
}
 
Example #23
Source File: XmlEntityDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void readCustomizableFeedMappingsBadRequest() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos");
  InputStream reqContent = createContentAsStream(PHOTO_XML_INVALID_MAPPING);

  readAndExpectException(entitySet, reqContent, false,
      EntityProviderException.INVALID_PROPERTY.addContent("ignore"));
}
 
Example #24
Source File: JsonDeletedEntryEntityProducer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public void append(final Writer writer, final EntityInfoAggregator entityInfo,
    final List<Map<String, Object>> deletedEntries, boolean noPreviousEntries)
    throws EntityProviderException {
  JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
  try {
    if (!deletedEntries.isEmpty()) {
      if(!noPreviousEntries){
        jsonStreamWriter.separator();
      }
      int counter = 0;
      for (Map<String, Object> deletedEntry : deletedEntries) {
        jsonStreamWriter.beginObject();

        String odataContextValue = JsonUtils.createODataContextValueForTombstone(entityInfo.getEntitySetName());
        String selfLink = AtomEntryEntityProducer.createSelfLink(entityInfo, deletedEntry, null);
        String idValue = properties.getServiceRoot().toASCIIString() + selfLink;

        jsonStreamWriter.namedStringValue(FormatJson.ODATA_CONTEXT, odataContextValue);
        jsonStreamWriter.separator();
        jsonStreamWriter.namedStringValue(FormatJson.ID, idValue);
        jsonStreamWriter.endObject();

        if (counter < deletedEntries.size() - 1) {
          jsonStreamWriter.separator();
        }

        counter++;
      }
    }
  } catch (final IOException e) {
    throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
        .getSimpleName()), e);
  }

}
 
Example #25
Source File: ProviderFacadeImplTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readErrorDocumentJson() throws EntityProviderException {
  ProviderFacadeImpl providerFacade = new ProviderFacadeImpl();
  String errorDoc = "{\"error\":{\"code\":\"ErrorCode\",\"message\":{\"lang\":\"en-US\",\"value\":\"Message\"}}}";
  ODataErrorContext errorContext = providerFacade.readErrorDocument(StringHelper.encapsulate(errorDoc),
      ContentType.APPLICATION_JSON.toContentTypeString());
  //
  assertEquals("Wrong content type", "application/json", errorContext.getContentType());
  assertEquals("Wrong message", "Message", errorContext.getMessage());
  assertEquals("Wrong error code", "ErrorCode", errorContext.getErrorCode());
  assertEquals("Wrong locale for lang", Locale.US, errorContext.getLocale());
}
 
Example #26
Source File: JsonEntryConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void doubleClosingBracketsAtTheEnd() throws Exception {
  String invalidJson = "{ \"Id\" : \"1\", \"Seats\" : 1, \"Version\" : 1}}";
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  InputStream contentBody = createContentAsStream(invalidJson);

  // execute
  JsonEntityConsumer xec = new JsonEntityConsumer();
  xec.readEntry(entitySet, contentBody, DEFAULT_PROPERTIES);
}
 
Example #27
Source File: XmlErrorDocumentTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void invalidErrorDocumentMissingMessage() throws EntityProviderException {
  InputStream in = StringHelper.encapsulate(XML_ERROR_DOCUMENT_MISSING_MESSAGE);
  try {
    xedc.readError(in);
    fail("Expected exception was not thrown");
  } catch (EntityProviderException e) {
    assertEquals("Got wrong exception: " + e.getMessageReference().getKey(),
        EntityProviderException.MISSING_PROPERTY, e.getMessageReference());
    assertTrue(e.getMessage().contains("message"));
    throw e;
  }
}
 
Example #28
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void nullValueNotAllowed() throws Exception {
  final String xml = "<Age xmlns=\"" + Edm.NAMESPACE_D_2007_08
      + "\" m:null=\"true\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" />";
  XMLStreamReader reader = createReaderForTest(xml, true);
  EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age");
  EdmFacets facets = mock(EdmFacets.class);
  when(facets.isNullable()).thenReturn(false);
  when(property.getFacets()).thenReturn(facets);

  new XmlPropertyConsumer().readProperty(reader, property, null);
}
 
Example #29
Source File: JsonEntryEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void entryWithExpandedFeedWithRegisteredNullCallback() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Buildings");
  Map<String, Object> buildingData = new HashMap<String, Object>();
  buildingData.put("Id", "1");

  ExpandSelectTreeNode node1 = createBuildingNode();

  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nb_Rooms", null);

  new JsonEntityProvider().writeEntry(entitySet, buildingData,
      EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1).callbacks(callbacks)
          .build());
}
 
Example #30
Source File: XmlMetadataDeserializer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private FullQualifiedName validateComplexTypeWithAlias(final FullQualifiedName aliasName)
    throws EntityProviderException {
  String namespace = aliasNamespaceMap.get(aliasName.getNamespace());
  FullQualifiedName fqName = new FullQualifiedName(namespace, aliasName.getName());
  if (!complexTypesMap.containsKey(fqName)) {
    throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT.addContent("Invalid BaseType")
        .addContent(fqName));
  }
  return fqName;
}