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

The following examples show how to use org.apache.olingo.odata2.api.edm.Edm#NAMESPACE_EDMX_2007_06 . 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: XmlMetadataConsumerTest.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>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader 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: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testInvalidEntitySet() 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.Mitarbeiter\"/>" + "</EntityContainer>"
          + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmWithEntityContainer);
  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 testMissingEdmxCloseTag() 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[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>";

  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xml);
  parser.readMetadata(reader, true);
}
 
Example 4
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 5
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testInvalidEntitySet() 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\"/>"
          + "<Property Name=\"" + propertyNames[1] + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>"
          + "</EntityType>" + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Mitarbeiter\"/>" + "</EntityContainer>"
          + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  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 ODATAJAVA_77_testMetadataDokumentWithMultiLevelEntityType() 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\" />"
      + "       </Schema>"
      + "  </edmx:DataServices>"
      + "</edmx:Edmx>";

  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(metadata);
  EdmDataServices result = parser.readMetadata(reader, true);

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

}
 
Example 7
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 8
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testInvalidRelationship() throws XMLStreamException, EntityProviderException {
  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.ManagerEmployee\" " +
          "FromRole=\"r_Employees\" ToRole=\"r_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>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmlWithInvalidAssociation);
  parser.readMetadata(reader, true);
}
 
Example 9
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 10
Source File: XmlMetadataAssociationTest.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 11
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testMissingEntityType() 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>" + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" />" + "</EntityContainer>" + "<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("EntityType", e.getMessageReference().getContent().get(0));
    assertEquals("EntitySet", e.getMessageReference().getContent().get(1));
    throw e;
  }
}
 
Example 12
Source File: XMLMetadataFunctionImportDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testFunctionImportError() 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=\"NoReturn\" " +
          "EntitySet=\"Rooms\" m:HttpMethod=\"GET\"/>"
          + "<FunctionImport Name=\"SingleRoomReturnType\" ReturnType=\"RefScenario.Room\" " +
          "EntitySet=\"Rooms\" m:HttpMethod=\"GET\">"
          + "</FunctionImport>"
          + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  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 testMissingEntityType() 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>" + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" />" + "</EntityContainer>" + "<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>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader 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("EntityType", e.getMessageReference().getContent().get(0));
    assertEquals("EntitySet", e.getMessageReference().getContent().get(1));
    throw e;
  }
}
 
Example 14
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void ODATAJAVA_77_testBaseTypeKey() 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\" >"
      + "               <Key> "
      + "                 <PropertyRef Name=\"Name\" />"
      + "               </Key>"
      + "               <Property Name=\"Name\" Type=\"Edm.String\" Nullable=\"false\" />"
      + "           </EntityType>"
      + "           <EntityType Name= \"StringDataConfigParameter\" BaseType= \"RefScenario2.DataConfigParameter\" />"
      + "       </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 15
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMetadataDokumentWithWhitepacesMultiline() 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\n"
      + "                 long long long multiline attribute</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\n" +
      "                 long long long multiline attribute", childElements.get(0).getText());
  assertEquals("value2", childElements.get(1).getText());
}
 
Example 16
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testFunctionImportEntity() 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=\"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>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xmWithEntityContainer);
  DataServices result = parser.readMetadata(reader, true);
  for (Schema schema : result.getSchemas()) {
    for (EntityContainer container : schema.getEntityContainers()) {
      assertEquals("Container1", container.getName());
      assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());

      FunctionImport functionImport1 = container.getFunctionImports().get(0);

      assertEquals("EmployeeSearch", functionImport1.getName());
      assertEquals("Employees", functionImport1.getEntitySet());
      assertEquals(NAMESPACE, functionImport1.getReturnType().getTypeName().getNamespace());
      assertEquals("Employee", functionImport1.getReturnType().getTypeName().getName());
      assertEquals(EdmMultiplicity.ONE, functionImport1.getReturnType().getMultiplicity());
      assertEquals("GET", functionImport1.getHttpMethod());
      assertEquals(2, functionImport1.getParameters().size());
      assertEquals("q1", functionImport1.getParameters().get(0).getName());
      assertEquals(EdmSimpleTypeKind.String, functionImport1.getParameters().get(0).getType());
      assertEquals(Boolean.TRUE, functionImport1.getParameters().get(0).getFacets().isNullable());
      assertEquals("q2", functionImport1.getParameters().get(1).getName());
      assertEquals(EdmSimpleTypeKind.Int32, functionImport1.getParameters().get(1).getType());
      assertEquals(Boolean.FALSE, functionImport1.getParameters().get(1).getFacets().isNullable());
    }
  }
}
 
Example 17
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test(expected = EdmException.class)
public void testInvalidAssociation() throws XMLStreamException, 
EntityProviderException, EdmException, UnsupportedEncodingException {
  final String xmlWithInvalidAssociationSet =
      "<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\">"
          + "<NavigationProperty Name=\"nm_Employees\" Relationship=\"RefScenario.ManagerEmployees\" " +
          "FromRole=\"r_Manager\" ToRole=\"r_Employees\" />"
          + "</EntityType>" + "<Association Name=\"" + ASSOCIATION + "\">"
          + "<End Type=\"RefScenario.Employee\" Multiplicity=\"*\" Role=\"r_Employees\">"
          + "<OnDelete Action=\"Cascade\"/>" + "</End>"
          + "<End Type=\"RefScenario.Manager\" Multiplicity=\"1\" Role=\"r_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=\"r_Manager\"/>"
          + "<End EntitySet=\"Employees\" Role=\"r_Employees\"/>" + "</AssociationSet>" + "</EntityContainer>"
          + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmlWithInvalidAssociationSet);
  parser.readMetadata(reader, true);

}
 
Example 18
Source File: XMLMetadataFunctionImportDeserializerTest.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;
  }
}
 
Example 19
Source File: XMLMetadataFunctionImportDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testFunctionImportEntityWithoutEntitySet() 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\" " +
          " 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());
      EdmFunctionImport functionImport1 = container.getFunctionImport("EmployeeSearch");

      assertEquals("EmployeeSearch", functionImport1.getName());
      assertNull(functionImport1.getEntitySet());
      assertEquals("GET", functionImport1.getHttpMethod());
    }
  }
}
 
Example 20
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++;
        }
      }
    }
  }
  
}