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

The following examples show how to use org.apache.olingo.odata2.api.edm.Edm#NAMESPACE_M_2007_08 . 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()
public void testAlias() 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 + "\" Alias=\"RS\"  xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
          + "<EntityType Name= \"Employee\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\""
          + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "</EntityType>"
          + "<EntityType Name=\"Manager\" BaseType=\"RS.Employee\" m:HasStream=\"true\">" + "</EntityType>"
          + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xml);
  EdmDataServices result = parser.readMetadata(reader, true);
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    assertEquals("RS", schema.getAlias());
    for (EdmEntityType entityType : schema.getEntityTypes()) {
      if ("Manager".equals(entityType.getName())) {
        assertEquals("Employee", entityType.getBaseType().getName());
        assertEquals("RefScenario", entityType.getBaseType()
            .getNamespace());
      }
    }

  }
}
 
Example 2
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void complexPropertyNullValueNotAllowedButNotValidated() throws Exception {
  final String xml = "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08
      + "\" m:null=\"true\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" />";
  EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee")
      .getProperty("Location");
  EdmFacets facets = mock(EdmFacets.class);
  when(facets.isNullable()).thenReturn(false);
  when(property.getFacets()).thenReturn(facets);
  final EntityProviderReadProperties readProperties = mock(EntityProviderReadProperties.class);

  final Map<String, Object> resultMap = new XmlPropertyConsumer()
      .readProperty(createReaderForTest(xml, true), property, readProperties);
  assertFalse(resultMap.isEmpty());
  assertNull(resultMap.get("Location"));
}
 
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 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>";

  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(metadata);
  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 testComplexTypeWithInvalidBaseType() 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[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>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xml);
  parser.readMetadata(reader, true);
}
 
Example 5
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void readComplexPropertyWithoutTypeAttribute() throws Exception {
  String xml =
      "<Location xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\""
          + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" +
          "<Country>Germany</Country>" +
          "<City m:type=\"RefScenario.c_City\">" +
          "<PostalCode>69124</PostalCode>" +
          "<CityName>Heidelberg</CityName>" +
          "</City>" +
          "</Location>";
  XMLStreamReader reader = createReaderForTest(xml, true);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Location");

  Map<String, Object> resultMap = new XmlPropertyConsumer().readProperty(reader, property, null);

  Map<String, Object> locationMap = (Map<String, Object>) resultMap.get("Location");
  assertEquals("Germany", locationMap.get("Country"));
  Map<String, Object> cityMap = (Map<String, Object>) locationMap.get("City");
  assertEquals("69124", cityMap.get("PostalCode"));
  assertEquals("Heidelberg", cityMap.get("CityName"));
}
 
Example 6
Source File: BasicHttpTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void postMethodNotAllowedWithContent() throws Exception {
  final HttpPost post = new HttpPost(URI.create(getEndpoint().toString()));
  final String xml =
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
          "<entry xmlns=\"" + Edm.NAMESPACE_ATOM_2005 + "\"" +
          " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\"" +
          " xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\"" +
          " xml:base=\"https://server.at.some.domain.com/path.to.some.service/ReferenceScenario.svc/\">" +
          "</entry>";
  final HttpEntity entity = new StringEntity(xml);
  post.setEntity(entity);
  final HttpResponse response = getHttpClient().execute(post);

  assertEquals(HttpStatusCodes.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusLine().getStatusCode());
  final String payload = StringHelper.inputStreamToString(response.getEntity().getContent());
  assertTrue(payload.contains("error"));
}
 
Example 7
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 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: XmlMetadataDeserializerTest.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: XmlMetadataDeserializerTest.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, EdmException, UnsupportedEncodingException {
  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>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmlWithInvalidAssociation);
  parser.readMetadata(reader, true);
}
 
Example 11
Source File: EntryXmlChangeTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void createMinimal() throws Exception {
  final String requestBody = "<entry xmlns=\"" + Edm.NAMESPACE_ATOM_2005 + "\"" + "\n"
      + "       xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + "\n"
      + "       xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "\n"
      + "  <content><m:properties><d:Id>99</d:Id></m:properties></content>" + "\n"
      + "</entry>";

  final HttpResponse response =
      postUri("Teams()", requestBody, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry");
  assertEquals(getEndpoint() + "Teams('4')", response.getFirstHeader(HttpHeaders.LOCATION).getValue());
}
 
Example 12
Source File: XmlMetadataConsumerTest.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>";

  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 13
Source File: XmlMetadataAssociationTest.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>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream 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 14
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void testMissingType() 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]
          + "\" 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 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("Type", e.getMessageReference().getContent().get(0));
    assertEquals("Property", e.getMessageReference().getContent().get(1));
    throw e;
  }
}
 
Example 15
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 16
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 17
Source File: XmlPropertyConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void collectionSimpleTypeWrong() throws Exception {
  final String xml = "<AllUsedRoomIds xmlns=\"" + Edm.NAMESPACE_D_2007_08 + "\">"
      + "<m:element xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\" />"
      + "</AllUsedRoomIds>";
  new XmlPropertyConsumer().readCollection(createReaderForTest(xml, true),
      EntityInfoAggregator.create(MockFacade.getMockEdm().getDefaultEntityContainer()
          .getFunctionImport("AllUsedRoomIds")), null);
}
 
Example 18
Source File: XmlEntityConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void readPropertyWrongClosingNamespace() throws Exception {
  String xml =
      "<d:Age xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">1</m:Age>";
  InputStream content = createContentAsStream(xml);
  final EdmProperty property =
      (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("Age");

  new XmlEntityConsumer().readPropertyValue(property, content, Integer.class);
}
 
Example 19
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void scenarioTest() throws XMLStreamException, 
EntityProviderException, EdmException, UnsupportedEncodingException {
  final String ASSOCIATION2 = "TeamEmployees";
  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
          + "\" Alias=\"RS\" xmlns=\""
          + Edm.NAMESPACE_EDM_2008_09
          + "\">"
          + "<EntityType Name= \"Employee\">"
          + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\""
          + propertyNames[0]
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<Property Name=\""
          + propertyNames[2]
          + "\" Type=\"RefScenario.c_Location\" Nullable=\"false\"/>"
          + "<NavigationProperty Name=\"ne_Manager\" Relationship=\"RefScenario.ManagerEmployees\" " +
          "FromRole=\"r_Employees\" ToRole=\"r_Manager\" />"
          + "<NavigationProperty Name=\"ne_Team\" Relationship=\"RefScenario.TeamEmployees\" " +
          "FromRole=\"r_Employees\" ToRole=\"r_Team\" />"
          + "</EntityType>"
          + "<EntityType Name=\"Manager\" BaseType=\"RefScenario.Employee\" m:HasStream=\"true\">"
          + "<NavigationProperty Name=\"nm_Employees\" Relationship=\"RefScenario.ManagerEmployees\" " +
          "FromRole=\"r_Manager\" ToRole=\"r_Employees\" />"
          + "</EntityType>"
          + "<EntityType Name=\"Team\">"
          + "<Key>"
          + "<PropertyRef Name=\"Id\"/>"
          + "</Key>"
          + "<Property Name=\""
          + "Id"
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<NavigationProperty Name=\"nt_Employees\" Relationship=\"RefScenario.TeamEmployees\"" +
          " FromRole=\"r_Team\" ToRole=\"r_Employees\" />"
          + "</EntityType>" + "<ComplexType Name=\"c_Location\">"
          + "<Property Name=\"Country\" Type=\"Edm.String\"/>" + "</ComplexType>" + "<Association Name=\""
          + ASSOCIATION + "\">" + "<End Type=\"RS.Employee\" Multiplicity=\"*\" Role=\"r_Employees\">"
          + "<OnDelete Action=\"Cascade\"/>" + "</End>"
          + "<End Type=\"RefScenario.Manager\" Multiplicity=\"1\" Role=\"r_Manager\"/>" + "</Association>"
          + "<Association Name=\"" + ASSOCIATION2 + "\">"
          + "<End Type=\"RefScenario.Employee\" Multiplicity=\"*\" Role=\"r_Employees\"/>"
          + "<End Type=\"RefScenario.Team\" Multiplicity=\"1\" Role=\"r_Team\"/>" + "</Association>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RS.Employee\"/>"
          + "<EntitySet Name=\"Managers\" EntityType=\"RefScenario.Manager\"/>"
          + "<EntitySet Name=\"Teams\" EntityType=\"RefScenario.Team\"/>" + "<AssociationSet Name=\"" + ASSOCIATION
          + "\" Association=\"RefScenario." + ASSOCIATION + "\">"
          + "<End EntitySet=\"Managers\" Role=\"r_Manager\"/>"
          + "<End EntitySet=\"Employees\" Role=\"r_Employees\"/>" + "</AssociationSet>" + "<AssociationSet Name=\""
          + ASSOCIATION2 + "\" Association=\"RefScenario." + ASSOCIATION2 + "\">"
          + "<End EntitySet=\"Teams\" Role=\"r_Team\"/>" + "<End EntitySet=\"Employees\" Role=\"r_Employees\"/>"
          + "</AssociationSet>" + "</EntityContainer>" + "</Schema>" + "<Schema Namespace=\"" + NAMESPACE2
          + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Photo\">" + "<Key>"
          + "<PropertyRef Name=\"Id\"/>" + "<PropertyRef Name=\"Name\"/>" + "</Key>"
          + "<Property Name=\"Id\" Type=\"Edm.Int32\" Nullable=\"false\" ConcurrencyMode=\"Fixed\" MaxLength=\""
          + MAX_LENGTH + "\"/>" + "<Property Name=\"Name\" Type=\"Edm.String\" Unicode=\"true\" DefaultValue=\""
          + DEFAULT_VALUE + "\" FixedLength=\"false\"/>"
          + "<Property Name=\"BinaryData\" Type=\"Edm.Binary\" m:MimeType=\"" + MIME_TYPE + "\"/>"
          + "<Property Name=\"Содержание\" Type=\"Edm.String\" m:FC_TargetPath=\"" + FC_TARGET_PATH
          + "\" m:FC_NsUri=\"" + FC_NS_URI + "\"" + " m:FC_NsPrefix=\"" + FC_NS_PREFIX + "\" m:FC_KeepInContent=\""
          + FC_KEEP_IN_CONTENT + "\" m:FC_ContentKind=\"text\" >" + "</Property>" + "</EntityType>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Photos\" EntityType=\"RefScenario2.Photo\"/>" + "</EntityContainer>" + "</Schema>"
          + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xml);
  EdmDataServices result = parser.readMetadata(reader, true);
  assertEquals(2, result.getEdm().getSchemas().size());
  ClientEdm edm = result.getEdm();
  assertEquals(4, edm.getEntitySets().size());
  assertEquals(0, edm.getFunctionImports().size());
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    if (NAMESPACE.equals(schema.getNamespace())) {
      assertEquals(3, schema.getEntityTypes().size());
      assertEquals(1, schema.getComplexTypes().size());
      assertEquals(2, schema.getAssociations().size());
      assertEquals(1, schema.getEntityContainers().size());
    } else if (NAMESPACE2.equals(schema.getNamespace())) {
      assertEquals(1, schema.getEntityTypes().size());
      assertEquals(0, schema.getComplexTypes().size());
      assertEquals(0, schema.getAssociations().size());
      assertEquals(1, schema.getEntityContainers().size());
      for (EdmEntityType entityType : schema.getEntityTypes()) {
        assertEquals(2, entityType.getKeyProperties().size());
      }
    }
  }
}
 
Example 20
Source File: XmlMetadataDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testEntityType() 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>"
          + "<EntityContainer Name=\"Container2\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Sign\" EntityType=\"" + NAMESPACE3 + ".Sign\"/>" + "</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>"
          + "<EntityType Name= \"Name\">" + "<Key><PropertyRef Name=\"NameId\"/></Key>"
          + "<Property Name=\"NameId\" Type=\"Edm.Int32\" Nullable=\"false\"/>" + "</EntityType>"
          + "<EntityContainer Name=\"Container2\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Name\" EntityType=\"" + NAMESPACE2 + ".Name\"/>"
          + "<EntitySet Name=\"Photo\" EntityType=\"" + NAMESPACE2 + ".Photo\"/>"
          + "</EntityContainer>"
          + "</Schema>"

          + "<Schema Namespace=\"" + NAMESPACE3 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
          + "<EntityType Name= \"Sign\">" + "<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());
  assertEquals(NAMESPACE, result.getEdm().getSchemas().get(0).getNamespace());
  assertEquals(NAMESPACE2, result.getEdm().getSchemas().get(1).getNamespace());
  assertEquals(NAMESPACE3, result.getEdm().getSchemas().get(2).getNamespace());
  
  assertEquals("Employee", result.getEdm().getSchemas().get(0).getEntityTypes().get(0).getName());
  assertNotNull(result.getEdm().getSchemas().get(0).getEntityTypes().get(0).getProperty("EmployeeId"));

  assertEquals("Photo", result.getEdm().getSchemas().get(1).getEntityTypes().get(0).getName());
  assertNotNull(result.getEdm().getSchemas().get(1).getEntityTypes().get(0).getProperty("Id"));   
  assertEquals("Name", result.getEdm().getSchemas().get(1).getEntityTypes().get(1).getName());
  assertEquals("NameId", result.getEdm().getSchemas().get(1).getEntityTypes()
      .get(1).getKeyProperties().get(0).getName());  

  assertEquals("Sign", result.getEdm().getSchemas().get(2).getEntityTypes().get(0).getName());
  assertNotNull(result.getEdm().getSchemas().get(2).getEntityTypes().get(0).getProperty("Id"));
  
}