org.apache.olingo.commons.api.edm.Edm Java Examples

The following examples show how to use org.apache.olingo.commons.api.edm.Edm. 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: MetadataTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void testOLINGO1100() {
  final Edm edm = client.getReader().readMetadata(getClass().getResourceAsStream("olingo1100.xml"));
  assertNotNull(edm);
  final EdmEntityContainer container = edm.getEntityContainer(
      new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "EntityContainer"));
  assertNotNull(container);
  final EdmEntitySet providers = container.getEntitySet("Provider");
  assertNotNull(providers);
  assertEquals(edm.getEntityType(new FullQualifiedName(container.getNamespace(), "Provider")),
      providers.getEntityType());
  assertEquals(container.getEntitySet("ProviderLicense"), providers.getRelatedBindingTarget("ProviderLicense"));
  assertNull(providers.getRelatedBindingTarget("ProviderLicensePractice"));
  assertNull(providers.getRelatedBindingTarget("Provider"));
  final EdmEntitySet providerLicenses = container.getEntitySet("ProviderLicense");
  assertEquals(edm.getEntityType(new FullQualifiedName(container.getNamespace(), "ProviderLicense")),
      providerLicenses.getEntityType());
  assertEquals(container.getEntitySet("ProviderLicensePractice"), 
      providerLicenses.getRelatedBindingTarget("ProviderLicensePractice"));
  assertNull(providerLicenses.getRelatedBindingTarget("ProviderLicense"));
  assertNull(providerLicenses.getRelatedBindingTarget("Provider"));
  final EdmEntitySet providerLicensePractices = container.getEntitySet("ProviderLicensePractice");
  assertNull(providerLicensePractices.getRelatedBindingTarget("ProviderLicensePractice"));
  assertNull(providerLicensePractices.getRelatedBindingTarget("Provider"));
  assertNull(providerLicenses.getRelatedBindingTarget("ProviderLicense"));
}
 
Example #2
Source File: EdmTermImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void termWithComplexType() {
  CsdlTerm csdlTerm = new CsdlTerm();
  FullQualifiedName csdlTerm1Name = new FullQualifiedName("namespace", "name1");
  csdlTerm.setName(csdlTerm1Name.getName());
  String namespaceAndName = "mySchema.Complex";
  String name = "Complex";
  csdlTerm.setType(namespaceAndName);
  Edm edm = mock(Edm.class);
  EdmComplexType typeMock = mock(EdmComplexType.class);
  when(typeMock.getName()).thenReturn(name);
  when(edm.getComplexType(new FullQualifiedName(namespaceAndName))).thenReturn(typeMock);
  EdmTerm localTerm = new EdmTermImpl(edm, "namespace", csdlTerm);
  assertNotNull(localTerm.getType());
  assertEquals(name, localTerm.getType().getName());
}
 
Example #3
Source File: MetadataTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void readAnnotationWithAliasOnEntitySetProperties() {
  final Edm edm = fetchEdm();
  assertNotNull(edm);
  EdmEntityContainer container = edm.getEntityContainer();
  EdmEntitySet entitySet = container.getEntitySet("I_DraftAdministrativeData");
  EdmEntityType entityType = entitySet.getEntityTypeWithAnnotations();
  List<EdmAnnotation> annotations = ((EdmProperty)entityType.getProperty("DraftUUID")).getAnnotations();
  assertEquals(3, annotations.size());
  
  FullQualifiedName termName =
      new FullQualifiedName("Integration", "Extractable");
  EdmTerm term = edm.getTerm(termName);
  EdmAnnotation annotation = ((EdmProperty)entityType.getProperty("DraftUUID")).getAnnotation(term, null);
  assertNotNull(annotation);
  
}
 
Example #4
Source File: ExpressionParserTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void parseMethodWithParametersWithAlias(TokenKind kind, 
    String... parameters) throws UriParserException, UriValidationException {
  final String methodName = kind.name().substring(0, kind.name().indexOf("Method")).toLowerCase(Locale.ROOT)
      .replace("geo", "geo.");
  String expressionString = methodName + '(';
  expressionString += "@word";
  expressionString += ',';
  expressionString += parameters[1];
  expressionString += ')';
  expressionString += "&@word=" + parameters[0];

  Map<String, AliasQueryOption> alias = new HashMap<String, AliasQueryOption>();
  AliasQueryOptionImpl aliasQueryOption = new AliasQueryOptionImpl();
  aliasQueryOption.setName("@word");
  aliasQueryOption.setText("\'a\'");
  alias.put("@word", aliasQueryOption);
  UriTokenizer tokenizer = new UriTokenizer(expressionString);
  final Expression expression = new ExpressionParser(mock(Edm.class), odata).parse(tokenizer, null, null, alias);
  assertNotNull(expression);
  
  assertEquals('{' + methodName + ' ' + "[@word, " + parameters[1] + ']' + '}',
      expression.toString());
  
}
 
Example #5
Source File: MetadataTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void readAnnotationOnBoundActions() {
  final Edm edm = fetchEdm();
  assertNotNull(edm);
  EdmAction action = edm.getBoundAction(new FullQualifiedName("SEPMRA_SO_MAN2", "BA_RTCountryVHType"),
      new FullQualifiedName("SEPMRA_SO_MAN2", "I_DraftAdministrativeDataType"), false);
  assertEquals(1, action.getAnnotations().size());
  assertEquals("HeaderInfo", action.getAnnotations().get(0).getTerm().getName());

  // Annotations on Bound Action parameter
  assertEquals(2, action.getParameter("ParameterCTPrim").getAnnotations().size());
  assertEquals("HeaderInfo", action.getParameter("ParameterCTPrim")
      .getAnnotations().get(0).getTerm().getName());
  
  FullQualifiedName termName = new FullQualifiedName("UI", "AdditionalInfo");
  EdmTerm term = edm.getTerm(termName);
  EdmAnnotation annotation = action.getParameter("ParameterCTPrim").getAnnotation(term, null);
  assertNotNull(annotation);
}
 
Example #6
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private EntityCollection createESTwoPrim(final Edm edm, final OData odata) {
  EntityCollection entityCollection = new EntityCollection();

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 32766))
      .addProperty(createPrimitive("PropertyString", "Test String1")));

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) -365))
      .addProperty(createPrimitive("PropertyString", "Test String2")));

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) -32766))
      .addProperty(createPrimitive("PropertyString", null)));

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
      .addProperty(createPrimitive("PropertyString", "Test String4")));

  setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETTwoPrim));
  createEntityId(edm, odata, "ESTwoPrim", entityCollection);
  createOperations("ESTwoPrim", entityCollection, EntityTypeProvider.nameETTwoPrim);
  return entityCollection;
}
 
Example #7
Source File: EdmEnumTypeImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName enumName, final CsdlEnumType enumType) {
  super(edm, enumName, EdmTypeKind.ENUM, enumType);

  if (enumType.getUnderlyingType() == null) {
    underlyingType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
  } else {
    final EdmPrimitiveTypeKind underlyingTypeKind = EdmPrimitiveTypeKind.valueOfFQN(enumType.getUnderlyingType());
    if (underlyingTypeKind == EdmPrimitiveTypeKind.Byte
        || underlyingTypeKind == EdmPrimitiveTypeKind.SByte
        || underlyingTypeKind == EdmPrimitiveTypeKind.Int16
        || underlyingTypeKind == EdmPrimitiveTypeKind.Int32
        || underlyingTypeKind == EdmPrimitiveTypeKind.Int64) {
      underlyingType = EdmPrimitiveTypeFactory.getInstance(underlyingTypeKind);
    } else {
      throw new EdmException("Not allowed as underlying type: " + underlyingTypeKind);
    }
  }

  this.enumType = enumType;
  this.enumName = enumName;
}
 
Example #8
Source File: ParserTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void keyPropertyGuidStartsWithNumber() throws Exception {
  final String entitySetName = "ESGuid";
  final String keyPropertyName = "a";
  EdmProperty keyProperty = Mockito.mock(EdmProperty.class);
  Mockito.when(keyProperty.getType())
      .thenReturn(OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Guid));
  EdmKeyPropertyRef keyPropertyRef = Mockito.mock(EdmKeyPropertyRef.class);
  Mockito.when(keyPropertyRef.getName()).thenReturn(keyPropertyName);
  Mockito.when(keyPropertyRef.getProperty()).thenReturn(keyProperty);
  EdmEntityType entityType = Mockito.mock(EdmEntityType.class);
  Mockito.when(entityType.getKeyPredicateNames()).thenReturn(Collections.singletonList(keyPropertyName));
  Mockito.when(entityType.getKeyPropertyRefs()).thenReturn(Collections.singletonList(keyPropertyRef));
  Mockito.when(entityType.getPropertyNames()).thenReturn(Collections.singletonList(keyPropertyName));
  Mockito.when(entityType.getProperty(keyPropertyName)).thenReturn(keyProperty);
  EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class);
  Mockito.when(entitySet.getName()).thenReturn(entitySetName);
  Mockito.when(entitySet.getEntityType()).thenReturn(entityType);
  EdmEntityContainer container = Mockito.mock(EdmEntityContainer.class);
  Mockito.when(container.getEntitySet(entitySetName)).thenReturn(entitySet);
  Edm mockedEdm = Mockito.mock(Edm.class);
  Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container);
  new TestUriValidator().setEdm(mockedEdm)
      .run("ESGuid", "$filter=a eq 889e3e73-af9f-4cd4-b330-db93c25ff3c7");
}
 
Example #9
Source File: EdmIfImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void withAllExpressions() {
  CsdlIf csdlIf = new CsdlIf();
  csdlIf.setGuard(new CsdlConstantExpression(ConstantExpressionType.Bool));
  csdlIf.setThen(new CsdlConstantExpression(ConstantExpressionType.String));
  csdlIf.setElse(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.And));
  List<CsdlAnnotation> csdlAnnotations = new ArrayList<CsdlAnnotation>();
  csdlAnnotations.add(new CsdlAnnotation().setTerm("ns.term"));
  csdlIf.setAnnotations(csdlAnnotations);
  EdmExpression exp = AbstractEdmExpression.getExpression(mock(Edm.class), csdlIf);
  EdmIf asIf = exp.asDynamic().asIf();

  assertNotNull(asIf.getGuard());
  assertTrue(asIf.getGuard().isConstant());
  assertNotNull(asIf.getThen());
  assertTrue(asIf.getThen().isConstant());
  assertNotNull(asIf.getElse());
  assertTrue(asIf.getElse().isDynamic());

  assertNotNull(asIf.getAnnotations());
  assertEquals(1, asIf.getAnnotations().size());
}
 
Example #10
Source File: BasicITCase.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void test3Olingo1064() throws ODataDeserializerException {
  EdmMetadataRequest request = getClient().getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI);
  assertNotNull(request);
  setCookieHeader(request);    
  
  ODataRetrieveResponse<Edm> response = request.execute();
  saveCookieHeader(response);
  assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());

  Edm edm = response.getBody();
  
  EdmEnabledODataClient odataClient = ODataClientFactory.getEdmEnabledClient(SERVICE_URI, edm, null);
  final InputStream input = Thread.currentThread().getContextClassLoader().
      getResourceAsStream("ESCompAllPrimWithEmptyValueForComplexProperty.json");
  ClientEntity entity = odataClient.getReader().readEntity(input, ContentType.JSON);
  assertEquals("olingo.odata.test1.CTAllPrim", entity.getProperty(PROPERTY_COMP).getComplexValue().getTypeName());
  assertEquals(PROPERTY_COMP, entity.getProperty(PROPERTY_COMP).getName());
  assertTrue(entity.getProperty(PROPERTY_COMP).hasNullValue());
}
 
Example #11
Source File: EdmTermImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void invalidAppliesToContent() {
  CsdlTerm csdlTerm = new CsdlTerm();
  FullQualifiedName csdlTerm1Name = new FullQualifiedName("namespace", "name1");
  csdlTerm.setName(csdlTerm1Name.getName());
  csdlTerm.setType("Edm.String");
  csdlTerm.setAppliesTo(Arrays.asList("Invalid"));
  EdmTerm localTerm = new EdmTermImpl(mock(Edm.class), "namespace", csdlTerm);

  try {
    localTerm.getAppliesTo();
    fail("Expected an EdmException");
  } catch (EdmException e) {
    assertEquals("Invalid AppliesTo value: Invalid", e.getMessage());
  }
}
 
Example #12
Source File: EdmProviderImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void nothingSpecifiedMustNotResultInExceptions() throws Exception {
  CsdlEdmProvider localProvider = mock(CsdlEdmProvider.class);
  when(localProvider.getActions(FQN)).thenReturn(null);
  when(localProvider.getFunctions(FQN)).thenReturn(null);
  Edm localEdm = new EdmProviderImpl(localProvider);
  localEdm.getUnboundAction(FQN);
  localEdm.getUnboundFunction(FQN, null);
  localEdm.getBoundAction(FQN, FQN, true);
  localEdm.getBoundFunction(FQN, FQN, true, null);
  localEdm.getComplexType(FQN);
  localEdm.getEntityContainer(FQN);
  localEdm.getEntityType(FQN);
  localEdm.getEnumType(FQN);
  localEdm.getTypeDefinition(FQN);
}
 
Example #13
Source File: EdmLogicalOrComparisonImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void logicalOrOperationsClassesWithExpressions() {
  for (LogicalOrComparisonExpressionType type : LogicalOrComparisonExpressionType.values()) {
    EdmExpression path = AbstractEdmExpression.getExpression(
        mock(Edm.class),
        new CsdlLogicalOrComparisonExpression(type)
            .setLeft(new CsdlConstantExpression(ConstantExpressionType.String))
            .setRight(new CsdlLogicalOrComparisonExpression(type)));

    EdmDynamicExpression dynExp = assertDynamic(path);
    assertEquals(type.toString(), dynExp.getExpressionName());
    assertSingleKindDynamicExpression(dynExp);

    EdmLogicalOrComparisonExpression logicOrComparisonExp = (EdmLogicalOrComparisonExpression) dynExp;
    assertNotNull(logicOrComparisonExp.getLeftExpression());
    assertNotNull(logicOrComparisonExp.getRightExpression());
    if (type == LogicalOrComparisonExpressionType.Not) {
      assertTrue(logicOrComparisonExp.getLeftExpression() == logicOrComparisonExp.getRightExpression());
    } else {
      assertTrue(logicOrComparisonExp.getLeftExpression() instanceof EdmConstantExpression);
      assertTrue(logicOrComparisonExp.getRightExpression() instanceof EdmDynamicExpression);
    }
  }
}
 
Example #14
Source File: MetadataTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void readAnnotationOnFunction() {
  final Edm edm = fetchEdm();
  assertNotNull(edm);
  List<EdmFunction> function = edm.getUnboundFunctions(new FullQualifiedName("SEPMRA_SO_MAN2", "UFCRTCollString"));
  assertEquals(1, function.size());
  List<EdmAnnotation> annotations = function.get(0).getAnnotations();
  assertEquals(2, annotations.size());

  FullQualifiedName termName =
      new FullQualifiedName("Integration", "Extractable");
  EdmTerm term = edm.getTerm(termName);
  EdmAnnotation annotation = function.get(0).getAnnotation(term, null);
  assertNotNull(annotation);
  
}
 
Example #15
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private EntityCollection createESFourKeyAlias(final Edm edm, final OData odata) {
  final EntityCollection entityCollection = new EntityCollection();

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 1))
      .addProperty(createComplex("PropertyComp",
          ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(),
          createPrimitive("PropertyInt16", (short) 11),
          createPrimitive("PropertyString", "Num11")
          ))
      .addProperty(createComplex("PropertyCompComp",
          ComplexTypeProvider.nameCTCompComp.getFullQualifiedNameAsString(),
          createComplex("PropertyComp",
              ComplexTypeProvider.nameCTBase.getFullQualifiedNameAsString(),
              createPrimitive("PropertyInt16", (short) 111),
              createPrimitive("PropertyString", "Num111"),
              createPrimitive("AdditionalPropString", "Test123")
          )
          ))
      );

  setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETFourKeyAlias));
  createEntityId(edm, odata, "ESFourKeyAlias", entityCollection);
  createOperations("ESFourKeyAlias", entityCollection, EntityTypeProvider.nameETFourKeyAlias);
  return entityCollection;
}
 
Example #16
Source File: EdmTermImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void termWithEnumType() {
  CsdlTerm csdlTerm = new CsdlTerm();
  FullQualifiedName csdlTerm1Name = new FullQualifiedName("namespace", "name1");
  csdlTerm.setName(csdlTerm1Name.getName());
  String namespaceAndName = "mySchema.Enum";
  String name = "Enum";
  csdlTerm.setType(namespaceAndName);
  Edm edm = mock(Edm.class);
  EdmEnumType typeMock = mock(EdmEnumType.class);
  when(typeMock.getName()).thenReturn(name);
  when(edm.getEnumType(new FullQualifiedName(namespaceAndName))).thenReturn(typeMock);
  EdmTerm localTerm = new EdmTermImpl(edm, "namespace", csdlTerm);
  assertNotNull(localTerm.getType());
  assertEquals(name, localTerm.getType().getName());
}
 
Example #17
Source File: TestExample.java    From teiid-spring-boot with Apache License 2.0 6 votes vote down vote up
static void olingoClient(String serviceRoot) throws Exception {
    EdmEnabledODataClient client = ODataClientFactory
            .getEdmEnabledClient(serviceRoot);
    ODataServiceVersion version = client.getServiceVersion();
    assertThat(ODataServiceVersion.V40, equalTo(version));
    Edm edm = client.getCachedEdm();
    EdmEntitySet es = edm.getEntityContainer().getEntitySet("CUSTOMER");
    assertThat("CUSTOMER", equalTo(es.getName()));

    URI customersUri = client.newURIBuilder(serviceRoot)
            .appendEntitySetSegment("CUSTOMER").filter("LASTNAME eq 'Smith'").build();

    ODataRetrieveResponse<ClientEntitySetIterator<ClientEntitySet, ClientEntity>> response = client
            .getRetrieveRequestFactory().getEntitySetIteratorRequest(customersUri).execute();

    ClientEntitySetIterator<ClientEntitySet, ClientEntity> iterator = response.getBody();
    assertTrue(iterator.hasNext());
    ClientEntity entity = iterator.next();
    assertNotNull(entity);
    assertThat(entity.getProperty("FIRSTNAME").getValue().asPrimitive().toValue(), equalTo("Joseph"));
}
 
Example #18
Source File: MetadataTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void readAnnotationOnASingleton() {
  final Edm edm = fetchEdm();
  assertNotNull(edm);
  EdmEntityContainer container = edm.getEntityContainer();
  EdmSingleton singleton = container.getSingleton("SINav");
  assertEquals(2, singleton.getAnnotations().size());
  FullQualifiedName termName = new FullQualifiedName("UI", "HeaderInfo");
  EdmTerm term = edm.getTerm(termName);
  EdmAnnotation annotation = singleton.getAnnotation(term, null);
  assertNotNull(annotation);

  EdmEntityType singletonET = singleton.getEntityType();
  EdmProperty singlComplexProp = (EdmProperty) singletonET.getProperty("ComplexProperty");
  EdmComplexType singlCompType = (EdmComplexType) singlComplexProp.getTypeWithAnnotations();
  EdmNavigationProperty singlNavProp = (EdmNavigationProperty) singlCompType.getNavigationProperty(
      "NavPropertyDraftAdministrativeDataType");
  assertEquals(2, singlNavProp.getAnnotations().size());
  assertEquals("AdditionalInfo", singlNavProp.getAnnotations().get(0).getTerm().getName());
}
 
Example #19
Source File: ODataMetaDataExtension.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private static void extractEdmNames(ODataMetadata odataMetadata, Edm edm) {
        Set<EdmNamed> namedList = new HashSet<>();
        EdmEntityContainer container = edm.getEntityContainer();
        namedList.addAll(container.getEntitySets());

//
// TODO
// Consider whether we need these in the future.
//
//            namedList.addAll(container.getFunctionImports());
//            namedList.addAll(container.getSingletons());
//            namedList.addAll(container.getActionImports());
//
        Set<String> names = new TreeSet<>();
        namedList.stream().distinct().forEach((entity) -> {
            names.add(entity.getName());
        });

        odataMetadata.setEntityNames(names);
    }
 
Example #20
Source File: ParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void keyPropertyGuid() throws Exception {
  final String entitySetName = "ESGuid";
  final String keyPropertyName = "a";
  EdmProperty keyProperty = Mockito.mock(EdmProperty.class);
  Mockito.when(keyProperty.getType())
      .thenReturn(OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Guid));
  EdmKeyPropertyRef keyPropertyRef = Mockito.mock(EdmKeyPropertyRef.class);
  Mockito.when(keyPropertyRef.getName()).thenReturn(keyPropertyName);
  Mockito.when(keyPropertyRef.getProperty()).thenReturn(keyProperty);
  EdmEntityType entityType = Mockito.mock(EdmEntityType.class);
  Mockito.when(entityType.getKeyPredicateNames()).thenReturn(Collections.singletonList(keyPropertyName));
  Mockito.when(entityType.getKeyPropertyRefs()).thenReturn(Collections.singletonList(keyPropertyRef));
  EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class);
  Mockito.when(entitySet.getName()).thenReturn(entitySetName);
  Mockito.when(entitySet.getEntityType()).thenReturn(entityType);
  EdmEntityContainer container = Mockito.mock(EdmEntityContainer.class);
  Mockito.when(container.getEntitySet(entitySetName)).thenReturn(entitySet);
  Edm mockedEdm = Mockito.mock(Edm.class);
  Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container);
  new TestUriValidator().setEdm(mockedEdm)
      .run("ESGuid(f89dee73-af9f-4cd4-b330-db93c25ff3c7)")
      .goPath()
      .at(0).isEntitySet(entitySetName)
      .at(0).isKeyPredicate(0, keyPropertyName, "f89dee73-af9f-4cd4-b330-db93c25ff3c7");

  new TestUriValidator().setEdm(mockedEdm)
      .run("ESGuid(889e3e73-af9f-4cd4-b330-db93c25ff3c7)")
      .goPath()
      .at(0).isEntitySet(entitySetName)
      .at(0).isKeyPredicate(0, keyPropertyName, "889e3e73-af9f-4cd4-b330-db93c25ff3c7");
}
 
Example #21
Source File: ExpandSystemQueryOptionHandler.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public void applyExpandQueryOptions(final EntityCollection entitySet, final EdmEntitySet edmEntitySet,
    final ExpandOption expandOption, final UriInfoResource uriInfo, final Edm edm) throws ODataApplicationException {
  if (expandOption == null) {
    return;
  }

  for (final Entity entity : entitySet.getEntities()) {
    applyExpandOptionToEntity(entity, edmEntitySet, expandOption, uriInfo, edm);
  }
}
 
Example #22
Source File: MetadataTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void readAnnotationOnFunctionImport() {
  final Edm edm = fetchEdm();
  assertNotNull(edm);
  EdmEntityContainer container = edm.getEntityContainer();
  EdmFunctionImport functionImport = container.getFunctionImport("FIC_RTTimeOfDay_");
  assertEquals(3, functionImport.getAnnotations().size());
  
  FullQualifiedName termName = new FullQualifiedName("UI", "Identification");
  EdmTerm term = edm.getTerm(termName);
  EdmAnnotation annotation = functionImport.getAnnotation(term, null);
  assertNotNull(annotation);
  
}
 
Example #23
Source File: AbstractEdmExpression.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static EdmExpression getExpression(Edm edm, final CsdlExpression exp) {
  EdmExpression _expression = null;

  if (exp.isConstant()) {
    _expression = new EdmConstantExpressionImpl(edm, exp.asConstant());
  } else if (exp.isDynamic()) {
    _expression = getDynamicExpression(edm, exp.asDynamic());
  }

  return _expression;
}
 
Example #24
Source File: EdmAnnotationImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void simpleAnnotationNoExpression() {
  Edm mock = mock(Edm.class);
  EdmTerm termMock = mock(EdmTerm.class);
  when(mock.getTerm(new FullQualifiedName("ns", "termName"))).thenReturn(termMock);
  EdmAnnotation anno =
      new EdmAnnotationImpl(mock, new CsdlAnnotation().setQualifier("Qualifier").setTerm("ns.termName"));

  assertEquals("Qualifier", anno.getQualifier());
  assertNotNull(anno.getAnnotations());
  assertTrue(anno.getAnnotations().isEmpty());
  assertNotNull(anno.getTerm());
  assertEquals(termMock, anno.getTerm());
}
 
Example #25
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private EntityCollection createESTwoPrimDerived(final Edm edm, final OData odata) {
  EntityCollection entityCollection = new EntityCollection();

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) -365))
      .addProperty(createPrimitive("PropertyString", "Test String2")));

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) -32766))
      .addProperty(createPrimitive("PropertyString", null)));

  entityCollection.getEntities().add(new Entity()
      .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
      .addProperty(createPrimitive("PropertyString", "Test String4")));

  setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETTwoPrim));
  
  Entity derivedEntity = new Entity()
      .addProperty(createPrimitive("PropertyInt16", (short) 32766))
      .addProperty(createPrimitive("PropertyString", "Test String1"))
      .addProperty(createPrimitive("AdditionalPropertyString_5", "Additional String1"));
      derivedEntity.setType(EntityTypeProvider.nameETBase.getFullQualifiedNameAsString());
      entityCollection.getEntities().add(derivedEntity);
      
  createEntityId(edm, odata, "ESTwoPrimDerived", entityCollection);
  createOperations("ESTwoPrimDerived", entityCollection, EntityTypeProvider.nameETTwoPrim);
  return entityCollection;
}
 
Example #26
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Storage(final OData odata, final Edm edm) {
  
  this.odata = odata;
  this.edm = edm;
  this.manager = new TransactionalEntityManager(edm);
  
  initProductSampleData();
  initCategorySampleData();
  linkProductsAndCategories();
}
 
Example #27
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private EntityCollection createESTwoKeyNav(final Edm edm, final OData odata) {
  final EntityCollection entityCollection = new EntityCollection();

  entityCollection.getEntities().add(createESTwoKeyNavEntity((short) 1, "1"));
  entityCollection.getEntities().add(createESTwoKeyNavEntity((short) 1, "2"));
  entityCollection.getEntities().add(createESTwoKeyNavEntity((short) 2, "1"));
  entityCollection.getEntities().add(createESTwoKeyNavEntity((short) 3, "1"));

  setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav));
  createEntityId(edm, odata, "ESTwoKeyNav", entityCollection);
  createOperations("ESTwoKeyNav", entityCollection, EntityTypeProvider.nameETTwoKeyNav);
  return entityCollection;
}
 
Example #28
Source File: OlingoSampleApp.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private ClientEntitySetIterator<ClientEntitySet, ClientEntity> readEntities(Edm edm, URI absoluteUri) {
  System.out.println("URI = " + absoluteUri);
  ODataEntitySetIteratorRequest<ClientEntitySet, ClientEntity> request = 
    client.getRetrieveRequestFactory().getEntitySetIteratorRequest(absoluteUri);
  // odata4 sample/server limitation not handling metadata=full
  request.setAccept("application/json;odata.metadata=minimal");
  ODataRetrieveResponse<ClientEntitySetIterator<ClientEntitySet, ClientEntity>> response = request.execute(); 
    
  return response.getBody();
}
 
Example #29
Source File: MetadataTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void readAnnotationOnContainer() {
  final Edm edm = fetchEdm();
  assertNotNull(edm);
  EdmEntityContainer container = edm.getEntityContainer();
  assertEquals(5, container.getAnnotations().size());
  assertEquals("HeaderInfo", container.getAnnotations().get(1).getTerm().getName());
}
 
Example #30
Source File: AbstractUtility.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public AbstractUtility(final Edm metadata, final EdmSchema schema, final String basePackage) {
  this.basePackage = basePackage;
  this.schemaName = schema.getAlias();
  this.namespace = schema.getNamespace();
  this.edm = metadata;
  this.schema = schema;

  collectEntityTypes();
}