Java Code Examples for org.apache.olingo.odata2.api.edm.Edm#NAMESPACE_EDM_2008_09

The following examples show how to use org.apache.olingo.odata2.api.edm.Edm#NAMESPACE_EDM_2008_09 . 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: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testMissingRelationship() throws Exception {
  final String xmlWithInvalidAssociation =
      "<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\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\""
          + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<NavigationProperty Name=\"ne_Manager\" />" + "</EntityType>"
          + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">" + "</EntityType>"
          + "<Association Name=\"ManagerEmployees\">"
          + "<End Type=\"RefScenario.Employee\" Multiplicity=\"*\" Role=\"r_Employees\"/>"
          + "<End Type=\"RefScenario.Manager\" Multiplicity=\"1\" Role=\"r_Manager\"/>"
          + "</Association></Schema></edmx:DataServices></edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmlWithInvalidAssociation);
  try {
    parser.readMetadata(reader, true);
  } catch (EntityProviderException e) {
    assertEquals(EntityProviderException.MISSING_ATTRIBUTE.getKey(), e.getMessageReference().getKey());
    assertEquals(2, e.getMessageReference().getContent().size());
    assertEquals("Relationship", e.getMessageReference().getContent().get(0));
    assertEquals("NavigationProperty", e.getMessageReference().getContent().get(1));
    throw e;
  }
}
 
Example 2
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void ODATAJAVA_77_ExceptionScenario() throws Exception {
  final String metadata = ""
      + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
      + "           <EntityType Name= \"ConfigParameter\" BaseType= \"RefScenario2.Parameter\" />"
      + "           <EntityType Name= \"DataConfigParameter\" BaseType= \"RefScenario2.ConfigParameter\" />"
      + "           <EntityType Name= \"StringDataConfigParameter\" BaseType= \"RefScenario2.DataConfigParameter\" />"
      + "         <EntityType Name= \"Parameter\">"
      + "            <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />"
      + "           </EntityType>"
      + "       </Schema>"
      + "  </edmx:DataServices>"
      + "</edmx:Edmx>";

  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(metadata);
  parser.readMetadata(reader, true);
}
 
Example 3
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testComplexTypeWithInvalidBaseType() 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=\"RefScenario.Employee\">" + "</ComplexType>" + "</Schema>"
          + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xml);
  parser.readMetadata(reader, true);
}
 
Example 4
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testMissingEdmxCloseTag() throws XMLStreamException, 
EntityProviderException, EdmException, UnsupportedEncodingException {
  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[1] + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>" + "<Property Name=\""
      + propertyNames[2] + "\" Type=\"RefScenario.c_Location\" Nullable=\"false\"/>" + "</EntityType>"
      + "<ComplexType Name=\"c_Location\">" + "<Property Name=\"Country\" Type=\"Edm.String\"/>" + "</ComplexType>"
      + "</Schema>" + "</edmx:DataServices>";

  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xml);
  parser.readMetadata(reader, true);
}
 
Example 5
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testInvalidAssociationEnd() throws XMLStreamException, EntityProviderException {
  final String employees = "r_Employees";
  final String manager = "r_Manager";
  final String xmlWithInvalidAssociationSetEnd =
      "<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\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\""
          + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<NavigationProperty Name=\"ne_Manager\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + employees + "\" ToRole=\"" + manager + "\" />" + "</EntityType>"
          + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">"
          + "<NavigationProperty Name=\"nm_Employees\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + manager + "\" ToRole=\"" + employees + "\" />" + "</EntityType>" + "<Association Name=\"" + ASSOCIATION
          + "\">"
          + "<End Type=\"RefScenario.Employee\" Multiplicity=\"*\" Role=\"" + employees + "1" + "\"/>"
          + "<End Type=\"RefScenario.Manager\" Multiplicity=\"1\" Role=\"" + manager + "\"/>" + "</Association>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<EntitySet Name=\"Managers\" EntityType=\"RefScenario.Manager\"/>" + "<AssociationSet Name=\""
          + ASSOCIATION + "\" Association=\"RefScenario2." + ASSOCIATION + "\">"
          + "<End EntitySet=\"Managers\" Role=\"" + manager + "\"/>" + "<End EntitySet=\"Employees\" Role=\""
          + employees + "\"/>" + "</AssociationSet>" + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>"
          + "</edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmlWithInvalidAssociationSetEnd);
  parser.readMetadata(reader, true);

}
 
Example 6
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntityTypeInOtherSchema() throws XMLStreamException, 
EntityProviderException, EdmException, UnsupportedEncodingException {
  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\"/>" + "</EntityType>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Photos\" EntityType=\"" + NAMESPACE2 + ".Photo\"/>" + "</EntityContainer>"
          + "</Schema>" + "<Schema Namespace=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
          + "<EntityType Name= \"Photo\">" + "<Key><PropertyRef Name=\"Id\"/></Key>"
          + "<Property Name=\"Id\" Type=\"Edm.Int32\" Nullable=\"false\"/>" + "</EntityType>" + "</Schema>"
          + "</edmx:DataServices>"
          + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  EdmDataServices result = parser.readMetadata(reader, true);
  assertEquals("2.0", result.getDataServiceVersion());
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      assertEquals("Container1", container.getName());
      for (EdmEntitySet entitySet : container.getEntitySets()) {
        assertEquals(NAMESPACE2, entitySet.getEntityType().getNamespace());
        assertEquals("Photo", entitySet.getEntityType().getName());
      }
    }
  }
}
 
Example 7
Source File: XMLMetadataFunctionImportDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testFunctionImportProperty() throws Exception {
  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=\"GetId\" ReturnType=\"Edm.String\""
          + " m:HttpMethod=\"GET\"/>"
          + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  EdmDataServices result = parser.readMetadata(reader, true);
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      EdmFunctionImport functionImport4 = container.getFunctionImport("GetId");
      assertEquals("GetId", functionImport4.getName());
      assertNull(functionImport4.getEntitySet());
    }
  }
}
 
Example 8
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void ODATAJAVA_77_testEntityTypeKey() throws Exception {
  final String metadata = ""
      + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
      + "         <EntityType Name= \"Parameter\">"
      + "               <Key> "
      + "                 <PropertyRef Name=\"Id\" />"
      + "               </Key>"
      + "               <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />"
      + "           </EntityType>"
      + "           <EntityType Name= \"ConfigParameter\" BaseType= \"RefScenario2.Parameter\" />"
      + "           <EntityType Name= \"DataConfigParameter\" BaseType= \"RefScenario2.ConfigParameter\" />"
      + "           <EntityType Name= \"StringDataConfigParameter\" BaseType= \"RefScenario2.DataConfigParameter\" >"
      + "               <Key> "
      + "                 <PropertyRef Name=\"Name\" />"
      + "               </Key>"
      + "               <Property Name=\"Name\" Type=\"Edm.String\" Nullable=\"false\" />"
      + "           </EntityType>"
      + "       </Schema>"
      + "  </edmx:DataServices>"
      + "</edmx:Edmx>";

  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(metadata);
  DataServices result = parser.readMetadata(reader, true);

  assertEquals(1, result.getSchemas().size());
  List<EntityType> entityTypes = result.getSchemas().get(0).getEntityTypes();
  assertEquals(4, entityTypes.size());

}
 
Example 9
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testMissingTypeAtAssociation() throws Exception {
  final String xmlWithInvalidAssociation =
      "<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\">"
          + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\""
          + propertyNames[0]
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<NavigationProperty Name=\"ne_Manager\" Relationship=\"RefScenario.ManagerEmployees\" " +
          "FromRole=\"r_Employees\" ToRole=\"r_Manager\" />"
          + "</EntityType>" + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">"
          + "</EntityType>" + "<Association Name=\"ManagerEmployees\">"
          + "<End Multiplicity=\"*\" Role=\"r_Employees\"/>"
          + "<End Type=\"RefScenario.Manager\" Multiplicity=\"1\" Role=\"r_Manager\"/>"
          + "</Association></Schema></edmx:DataServices></edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmlWithInvalidAssociation);
  try {
    parser.readMetadata(reader, true);
  } catch (EntityProviderException e) {
    assertEquals(EntityProviderException.MISSING_ATTRIBUTE.getKey(), e.getMessageReference().getKey());
    assertEquals(2, e.getMessageReference().getContent().size());
    assertEquals("Type", e.getMessageReference().getContent().get(0));
    assertEquals("End", e.getMessageReference().getContent().get(1));
    throw e;
  }
}
 
Example 10
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testMissingAssociation() throws Exception {
  final String xmlWithAssociation =
      "<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\">"
          + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\""
          + propertyNames[0]
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<NavigationProperty Name=\"ne_Manager\" Relationship=\"RefScenario.ManagerEmployees\" " +
          "FromRole=\"r_Employees\" ToRole=\"r_Manager\" />"
          + "</EntityType>" + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>" + "<AssociationSet Name=\""
          + ASSOCIATION
          // + "\" Association=\"RefScenario." + ASSOCIATION
          + "\">" + "<End EntitySet=\"Employees\" Role=\"r_Employees\"/>" + "</AssociationSet>"
          + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices></edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmlWithAssociation);
  try {
    parser.readMetadata(reader, true);
  } catch (EntityProviderException e) {
    assertEquals(EntityProviderException.MISSING_ATTRIBUTE.getKey(), e.getMessageReference().getKey());
    assertEquals(2, e.getMessageReference().getContent().size());
    assertEquals("Association", e.getMessageReference().getContent().get(0));
    assertEquals("AssociationSet", e.getMessageReference().getContent().get(1));
    throw e;
  }
}
 
Example 11
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMetadataDokumentWithWhitepaces() throws Exception {
  final String metadata = ""
      + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
      + "           <EntityType Name= \"Photo\">"
      + "               <Key> "
      + "                 <PropertyRef Name=\"Id\" />"
      + "               </Key>"
      + "               <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />"
      + "               <MyAnnotation xmlns=\"http://company.com/odata\">   "
      + "                 <child> value1</child>"
      + "                 <child>value2</child>"
      + "               </MyAnnotation>"
      + "           </EntityType>"
      + "       </Schema>"
      + "  </edmx:DataServices>"
      + "</edmx:Edmx>";

  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(metadata);
  DataServices result = parser.readMetadata(reader, true);

  assertEquals(1, result.getSchemas().size());
  List<EntityType> entityTypes = result.getSchemas().get(0).getEntityTypes();
  assertEquals(1, entityTypes.size());
  EntityType entityType = entityTypes.get(0);
  List<AnnotationElement> annotationElements = entityType.getAnnotationElements();
  assertEquals(1, annotationElements.size());
  AnnotationElement annotationElement = annotationElements.get(0);
  List<AnnotationElement> childElements = annotationElement.getChildElements();
  assertEquals(2, childElements.size());

  assertEquals(" value1", childElements.get(0).getText());
  assertEquals("value2", childElements.get(1).getText());
}
 
Example 12
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EdmException.class)
public void testInvalidAssociationEnd() throws XMLStreamException, 
EntityProviderException, EdmException, UnsupportedEncodingException {
  final String employees = "r_Employees";
  final String manager = "r_Manager";
  final String xmlWithInvalidAssociationSetEnd =
      "<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\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\""
          + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<NavigationProperty Name=\"ne_Manager\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + employees + "\" ToRole=\"" + manager + "\" />" + "</EntityType>"
          + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">"
          + "<NavigationProperty Name=\"nm_Employees\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + manager + "\" ToRole=\"" + employees + "\" />" + "</EntityType>" + "<Association Name=\"" + ASSOCIATION
          + "\">"
          + "<End Type=\"RefScenario.Employee\" Multiplicity=\"*\" Role=\"" + employees + "1" + "\"/>"
          + "<End Type=\"RefScenario.Manager\" Multiplicity=\"1\" Role=\"" + manager + "\"/>" + "</Association>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<EntitySet Name=\"Managers\" EntityType=\"RefScenario.Manager\"/>" + "<AssociationSet Name=\""
          + ASSOCIATION + "\" Association=\"RefScenario2." + ASSOCIATION + "\">"
          + "<End EntitySet=\"Managers\" Role=\"" + manager + "\"/>" + "<End EntitySet=\"Employees\" Role=\""
          + employees + "\"/>" + "</AssociationSet>" + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>"
          + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmlWithInvalidAssociationSetEnd);
  parser.readMetadata(reader, true);

}
 
Example 13
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testFunctionImportError() 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=\"NoReturn\" " +
          "EntitySet=\"Rooms\" m:HttpMethod=\"GET\"/>"
          + "<FunctionImport Name=\"SingleRoomReturnType\" ReturnType=\"RefScenario.Room\" " +
          "EntitySet=\"Rooms\" m:HttpMethod=\"GET\">"
          + "</FunctionImport>"
          + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmWithEntityContainer);
  parser.readMetadata(reader, true);
}
 
Example 14
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testInvalidAssociationEnd2() throws XMLStreamException, EntityProviderException {
  final String employees = "r_Employees";
  final String manager = "r_Manager";
  final String xmlWithInvalidAssociationSetEnd =
      "<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\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\""
          + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<NavigationProperty Name=\"ne_Manager\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + employees + "\" ToRole=\"" + manager + "\" />" + "</EntityType>"
          + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">"
          + "<NavigationProperty Name=\"nm_Employees\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + manager + "\" ToRole=\"" + employees + "\" />" + "</EntityType>" + "<Association Name=\"" + ASSOCIATION
          + "\">"
          + "<End Type=\"RefScenario.Employee\" Multiplicity=\"*\" Role=\"" + employees + "\"/>"
          + "<End Type=\"RefScenario.Manager\" Multiplicity=\"1\" Role=\"" + manager + "\"/>" + "</Association>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<EntitySet Name=\"Managers\" EntityType=\"RefScenario.Manager\"/>" + "<AssociationSet Name=\""
          + ASSOCIATION + "\" Association=\"RefScenario2." + ASSOCIATION + "\">"
          + "<End EntitySet=\"Managers\" Role=\"" + manager + "\"/>" + "<End EntitySet=\"Managers\" Role=\""
          + manager + "\"/>" + "</AssociationSet>" + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>"
          + "</edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmlWithInvalidAssociationSetEnd);
  parser.readMetadata(reader, true);

}
 
Example 15
Source File: XmlMetadataAssociationTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EdmException.class)
public void testInvalidAssociationEnd2() throws XMLStreamException, 
EntityProviderException, EdmException, UnsupportedEncodingException {
  final String employees = "r_Employees";
  final String manager = "r_Manager";
  final String xmlWithInvalidAssociationSetEnd =
      "<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\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\""
          + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<NavigationProperty Name=\"ne_Manager\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + employees + "\" ToRole=\"" + manager + "\" />" + "</EntityType>"
          + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">"
          + "<NavigationProperty Name=\"nm_Employees\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + manager + "\" ToRole=\"" + employees + "\" />" + "</EntityType>" + "<Association Name=\"" + ASSOCIATION
          + "\">"
          + "<End Type=\"RefScenario.Employee\" Multiplicity=\"*\" Role=\"" + employees + "\"/>"
          + "<End Type=\"RefScenario.Manager\" Multiplicity=\"1\" Role=\"" + manager + "\"/>" + "</Association>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<EntitySet Name=\"Managers\" EntityType=\"RefScenario.Manager\"/>" + "<AssociationSet Name=\""
          + ASSOCIATION + "\" Association=\"RefScenario2." + ASSOCIATION + "\">"
          + "<End EntitySet=\"Managers\" Role=\"" + manager + "\"/>" + "<End EntitySet=\"Managers\" Role=\""
          + manager + "\"/>" + "</AssociationSet>" + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>"
          + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmlWithInvalidAssociationSetEnd);
  parser.readMetadata(reader, true);

}
 
Example 16
Source File: XmlMetadataAssociationTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testRelatedEntitySetWithCyclicAssociation() throws Exception {
  final String employees = "r_Employees";
  final String manager = "r_Manager";
  final String xmlWithInvalidAssociationSetEnd =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\" "
          + "xmlns:sap=\"http://www.sap.com/Protocols/SAPData\">"
          + "<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\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\""
          + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<NavigationProperty Name=\"ne_Manager\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + employees + "\" ToRole=\"" + manager + "\" />" + "</EntityType>"
          + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">"
          + "<NavigationProperty Name=\"nm_Employees\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + manager + "\" ToRole=\"" + employees + "\" />" + "</EntityType>" + "<Association Name=\"" + ASSOCIATION
          + "\">"
          + "<End Type=\"RefScenario.Employee\" Multiplicity=\"*\" Role=\"" + employees + "\"/>"
          + "<End Type=\"RefScenario.Manager\" Multiplicity=\"1\" Role=\"" + manager + "\"/>" + "</Association>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<EntitySet Name=\"Managers\" EntityType=\"RefScenario.Manager\"/>" + "<AssociationSet Name=\""
          + ASSOCIATION + "\" Association=\"RefScenario." + ASSOCIATION + "\" "
          + "sap:creatable=\"true\" sap:updatable=\"true\" "
          + "sap:deletable=\"false\">"
          + "<End EntitySet=\"Managers\" Role=\"" + manager + "\"/>" + "<End EntitySet=\"Employees\" Role=\""
          + employees + "\"/>" + "</AssociationSet>" + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>"
          + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmlWithInvalidAssociationSetEnd);
  EdmDataServices result = parser.readMetadata(reader, true);
  List<String> annotationList = new ArrayList<String>();
  annotationList.add("creatable");
  annotationList.add("updatable");
  annotationList.add("deletable");
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      for (EdmEntitySet entitySet : container.getEntitySets()) {
        for(EdmEntityType entityType:schema.getEntityTypes()){
          List<String> navigationPropertyNames = entityType.getNavigationPropertyNames();
          for (String navigationPropertyName : navigationPropertyNames) {
            EdmNavigationProperty navigationProperty = (EdmNavigationProperty) entityType
                .getProperty(navigationPropertyName);
            if((entitySet.getName().equals("Managers") && navigationProperty.getName().equals("nm_Employees")) || 
                entitySet.getName().equals("Employees") && navigationProperty.getName().equals("ne_Manager") ){
              assertNotNull(entitySet.getRelatedEntitySet(navigationProperty));
            }else{
              assertNull(entitySet.getRelatedEntitySet(navigationProperty));
            }
          }
        }
      }
    }
  }
  
}
 
Example 17
Source File: XMLMetadataFunctionImportDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testFunctionImportEntityOrderChange() throws Exception {
  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=\"RefScenario.Employee\" " +
          "EntitySet=\"Employees\" 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>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  EdmDataServices result = parser.readMetadata(reader, true);
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      assertEquals("Container1", container.getName());
      assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());

      EdmFunctionImport functionImport1 = container.getFunctionImport("EmployeeSearch");

      assertEquals("EmployeeSearch", functionImport1.getName());
      assertEquals("Employees", functionImport1.getEntitySet().getName());
      assertEquals(EdmMultiplicity.ONE, functionImport1.getReturnType().getMultiplicity());
      assertEquals("GET", functionImport1.getHttpMethod());
    }
  }
}
 
Example 18
Source File: XmlMetadataAssociationTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testAnnoationsOnAssociationSet() throws Exception {
  final String employees = "r_Employees";
  final String manager = "r_Manager";
  final String xmlWithInvalidAssociationSetEnd =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\" "
          + "xmlns:sap=\"http://www.sap.com/Protocols/SAPData\">"
          + "<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\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\""
          + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<NavigationProperty Name=\"ne_Manager\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + employees + "\" ToRole=\"" + manager + "\" />" + "</EntityType>"
          + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">"
          + "<NavigationProperty Name=\"nm_Employees\" Relationship=\"RefScenario.ManagerEmployees\" FromRole=\""
          + manager + "\" ToRole=\"" + employees + "\" />" + "</EntityType>" + "<Association Name=\"" + ASSOCIATION
          + "\">"
          + "<End Type=\"RefScenario.Employee\" Multiplicity=\"*\" Role=\"" + employees + "\"/>"
          + "<End Type=\"RefScenario.Manager\" Multiplicity=\"1\" Role=\"" + manager + "\"/>" + "</Association>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<EntitySet Name=\"Managers\" EntityType=\"RefScenario.Manager\"/>" + "<AssociationSet Name=\""
          + ASSOCIATION + "\" Association=\"RefScenario." + ASSOCIATION + "\" "
          + "sap:creatable=\"true\" sap:updatable=\"true\" "
          + "sap:deletable=\"false\">"
          + "<End EntitySet=\"Managers\" Role=\"" + manager + "\"/>" + "<End EntitySet=\"Employees\" Role=\""
          + employees + "\"/>" + "</AssociationSet>" + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>"
          + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmlWithInvalidAssociationSetEnd);
  EdmDataServices result = parser.readMetadata(reader, true);
  List<String> annotationList = new ArrayList<String>();
  annotationList.add("creatable");
  annotationList.add("updatable");
  annotationList.add("deletable");
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      for (EdmAssociationSet associationSet : container.getAssociationSets()) {
        assertEquals("ManagerEmployees", associationSet.getName());
        int i = 0;
        for (EdmAnnotationAttribute annotationAttr : associationSet.getAnnotations().getAnnotationAttributes()) {
          assertEquals(annotationList.get(i), annotationAttr.getName());
          assertEquals("sap", annotationAttr.getPrefix());
          assertEquals("http://www.sap.com/Protocols/SAPData", annotationAttr.getNamespace());
          i++;
        }
      }
    }
  }
  
}
 
Example 19
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testAnnotations() throws XMLStreamException,
EntityProviderException, EdmException, UnsupportedEncodingException {
  final String xmlWithAnnotations =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\""
          + Edm.NAMESPACE_EDMX_2007_06
          + "\" xmlns:annoPrefix=\"http://annoNamespace\">"
          + "<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\" prefix1:href=\"http://foo\" xmlns:prefix1=\"namespaceForAnno\">"
          + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\"EmployeeId\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<Property Name=\"EmployeeName\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\" " +
          "annoPrefix:annoName=\"annoText\">"
          + "<annoPrefix:propertyAnnoElement>text</annoPrefix:propertyAnnoElement>"
          + "<annoPrefix:propertyAnnoElement2 />"
          + "</Property>"
          + "</EntityType>"
          + "<annoPrefix:schemaElementTest1>"
          + "<prefix:schemaElementTest2 xmlns:prefix=\"namespace\">text3"
          + "</prefix:schemaElementTest2>"
          + "<annoPrefix:schemaElementTest3 rel=\"self\" pre:href=\"http://foo\" " +
          "xmlns:pre=\"namespaceForAnno\">text4</annoPrefix:schemaElementTest3>"
          + " </annoPrefix:schemaElementTest1>" + "</Schema>"
          + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmlWithAnnotations);
  EdmDataServices result = parser.readMetadata(reader, false);
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    assertEquals(1, schema.getAnnotationElements().size());
    for (EdmAnnotationElement annoElement : schema.getAnnotationElements()) {
      for (EdmAnnotationElement childAnnoElement : annoElement.getChildElements()) {
        if ("schemaElementTest2".equals(childAnnoElement.getName())) {
          assertEquals("prefix", childAnnoElement.getPrefix());
          assertEquals("namespace", childAnnoElement.getNamespace());
          assertEquals("text3", childAnnoElement.getText());
        } else if ("schemaElementTest3".equals(childAnnoElement.getName())) {
          assertEquals("text4", childAnnoElement.getText());
          assertEquals("rel", childAnnoElement.getAttributes().get(0).getName());
          assertEquals("self", childAnnoElement.getAttributes().get(0).getText());
          assertEquals("", childAnnoElement.getAttributes().get(0).getPrefix());
          assertNull(childAnnoElement.getAttributes().get(0).getNamespace());
          assertEquals("href", childAnnoElement.getAttributes().get(1).getName());
          assertEquals("pre", childAnnoElement.getAttributes().get(1).getPrefix());
          assertEquals("namespaceForAnno", childAnnoElement.getAttributes().get(1).getNamespace());
          assertEquals("http://foo", childAnnoElement.getAttributes().get(1).getText());
        } else {
          throw new EntityProviderException(null, "xmlWithAnnotations");
        }
      }
    }
    for (EdmEntityType entityType : schema.getEntityTypes()) {
      assertEquals(1, entityType.getAnnotations().getAnnotationAttributes().size());
      EdmAnnotationAttribute attr = entityType.getAnnotations().getAnnotationAttributes().get(0);
      assertEquals("href", attr.getName());
      assertEquals("prefix1", attr.getPrefix());
      assertEquals("namespaceForAnno", attr.getNamespace());
      assertEquals("http://foo", attr.getText());
      for (String name : entityType.getPropertyNames()) {
        if ("EmployeeName".equals(name)) {
          EdmProperty property = (EdmProperty) entityType.getProperty(name);
          assertEquals(2, property.getAnnotations().getAnnotationElements().size());
          for (EdmAnnotationElement anElement : property.getAnnotations().getAnnotationElements()) {
            if ("propertyAnnoElement".equals(anElement.getName())) {
              assertEquals("text", anElement.getText());
            }
          }
          for (EdmAnnotationAttribute anAttribute : property.getAnnotations().getAnnotationAttributes()) {
            assertEquals("annoName", anAttribute.getName());
            assertEquals("annoPrefix", anAttribute.getPrefix());
            assertEquals("annoText", anAttribute.getText());
            assertEquals("http://annoNamespace", anAttribute.getNamespace());
          }
        }
      }
    }
  }
}
 
Example 20
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testMissingTypeAtFunctionImport() throws Exception {
  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[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)\" " +
          "EntitySet=\"Employees\" m:HttpMethod=\"GET\">"
          + "<Parameter Name=\"q\" Nullable=\"true\" />" + "</FunctionImport>"
          + "</EntityContainer></Schema></edmx:DataServices></edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xml);
  try {
    parser.readMetadata(reader, true);
  } catch (EntityProviderException e) {
    assertEquals(EntityProviderException.MISSING_ATTRIBUTE.getKey(), e.getMessageReference().getKey());
    assertEquals(2, e.getMessageReference().getContent().size());
    assertEquals("Type", e.getMessageReference().getContent().get(0));
    assertEquals("Parameter", e.getMessageReference().getContent().get(1));
    throw e;
  }
}