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

The following examples show how to use org.apache.olingo.commons.api.edm.EdmKeyPropertyRef. 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: EdmKeyPropertyRefImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void aliasForPropertyInComplexPropertyOneLevel() {
  CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/Id").setAlias("alias");
  EdmEntityType etMock = mock(EdmEntityType.class);
  EdmProperty keyPropertyMock = mock(EdmProperty.class);
  EdmProperty compMock = mock(EdmProperty.class);
  EdmComplexType compTypeMock = mock(EdmComplexType.class);
  when(compTypeMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock);
  when(compMock.getType()).thenReturn(compTypeMock);
  when(etMock.getStructuralProperty("comp")).thenReturn(compMock);
  EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);
  assertEquals("alias", ref.getAlias());

  EdmProperty property = ref.getProperty();
  assertNotNull(property);
  assertTrue(property == keyPropertyMock);
}
 
Example #2
Source File: MetadataDocumentXmlSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void appendKey(final XMLStreamWriter writer, final EdmEntityType entityType) throws XMLStreamException {
  List<EdmKeyPropertyRef> keyPropertyRefs = entityType.getKeyPropertyRefs();
  if (keyPropertyRefs != null && !keyPropertyRefs.isEmpty()) {
    // Resolve Base Type key as it is shown in derived type
    EdmEntityType baseType = entityType.getBaseType();
    if (baseType != null && baseType.getKeyPropertyRefs() != null && !(baseType.getKeyPropertyRefs().isEmpty())) {
      return;
    }

    writer.writeStartElement(XML_KEY);
    for (EdmKeyPropertyRef keyRef : keyPropertyRefs) {
      writer.writeEmptyElement(XML_PROPERTY_REF);

      writer.writeAttribute(XML_NAME, keyRef.getName());

      if (keyRef.getAlias() != null) {
        writer.writeAttribute(XML_ALIAS, keyRef.getAlias());
      }
    }
    writer.writeEndElement();
  }
}
 
Example #3
Source File: MetadataDocumentJsonSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void appendKey(final JsonGenerator json, 
    final EdmEntityType entityType) throws SerializerException, IOException {
  List<EdmKeyPropertyRef> keyPropertyRefs = entityType.getKeyPropertyRefs();
  if (keyPropertyRefs != null && !keyPropertyRefs.isEmpty()) {
    // Resolve Base Type key as it is shown in derived type
    EdmEntityType baseType = entityType.getBaseType();
    if (baseType != null && baseType.getKeyPropertyRefs() != null && !(baseType.getKeyPropertyRefs().isEmpty())) {
      return;
    }
    json.writeArrayFieldStart(KEY);
    for (EdmKeyPropertyRef keyRef : keyPropertyRefs) {
      
      if (keyRef.getAlias() != null) {
        json.writeStartObject();
        json.writeStringField(keyRef.getAlias(), keyRef.getName());
        json.writeEndObject();
      } else {
        json.writeString(keyRef.getName());
      }
    }
    json.writeEndArray();
  }
}
 
Example #4
Source File: ParserHelper.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private static UriParameter keyValuePair(UriTokenizer tokenizer,
    final String keyPredicateName, final EdmEntityType edmEntityType,
    final Edm edm, final EdmType referringType, final Map<String, AliasQueryOption> aliases)
    throws UriParserException, UriValidationException {
  final EdmKeyPropertyRef keyPropertyRef = edmEntityType.getKeyPropertyRef(keyPredicateName);
  final EdmProperty edmProperty = keyPropertyRef == null ? null : keyPropertyRef.getProperty();
  if (edmProperty == null) {
    throw new UriValidationException(keyPredicateName + " is not a valid key property name.",
        UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, keyPredicateName);
  }
  ParserHelper.requireNext(tokenizer, TokenKind.EQ);
  if (tokenizer.next(TokenKind.COMMA) || tokenizer.next(TokenKind.CLOSE) || tokenizer.next(TokenKind.EOF)) {
    throw new UriParserSyntaxException("Key value expected.", UriParserSyntaxException.MessageKeys.SYNTAX);
  }
  if (nextPrimitiveTypeValue(tokenizer, (EdmPrimitiveType) edmProperty.getType(), edmProperty.isNullable())) {
    return createUriParameter(edmProperty, keyPredicateName, tokenizer.getText(), edm, referringType, aliases);
  } else {
    throw new UriParserSemanticException(keyPredicateName + " has not a valid  key value.",
        UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE, keyPredicateName);
  }
}
 
Example #5
Source File: ExpressionParserTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test(expected = UriParserSemanticException.class)
public void testPropertyPathExpWithoutType() throws Exception {
  final String entitySetName = "ESName";
  final String keyPropertyName = "a";
  EdmProperty keyProperty = mockProperty(keyPropertyName,
      OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String));
  EdmKeyPropertyRef keyPropertyRef = mockKeyPropertyRef(keyPropertyName, keyProperty);
  EdmEntityType entityType = mockEntityType(keyPropertyName, keyPropertyRef);
  Mockito.when(entityType.getPropertyNames()).thenReturn(Collections.singletonList(keyPropertyName));
  Mockito.when(entityType.getProperty(keyPropertyName)).thenReturn(keyProperty);
  EdmEntitySet entitySet = mockEntitySet(entitySetName, entityType);
  EdmEntityContainer container = mockContainer(entitySetName, entitySet);
  Edm mockedEdm = Mockito.mock(Edm.class);
  Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container);
  
  UriTokenizer tokenizer = new UriTokenizer("a eq \'abc\'");
  new ExpressionParser(mockedEdm, odata).parse(tokenizer, null, null, null);
}
 
Example #6
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 #7
Source File: ExpressionParserTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test(expected = UriParserSemanticException.class)
public void testPropertyPathExpWithoutProperty() throws Exception {
  final String entitySetName = "ESName";
  final String keyPropertyName = "a";
  EdmProperty keyProperty = mockProperty(keyPropertyName, 
      OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String));
  EdmKeyPropertyRef keyPropertyRef = mockKeyPropertyRef(keyPropertyName, keyProperty);
  EdmEntityType entityType = mockEntityType(keyPropertyName, keyPropertyRef);
  Mockito.when(entityType.getFullQualifiedName()).thenReturn(new FullQualifiedName("test.ETName"));
  EdmEntitySet entitySet = mockEntitySet(entitySetName, entityType);
  EdmEntityContainer container = mockContainer(entitySetName, entitySet);
  Edm mockedEdm = Mockito.mock(Edm.class);
  Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container);
  
  UriTokenizer tokenizer = new UriTokenizer("a eq \'abc\'");
  new ExpressionParser(mockedEdm, odata).parse(tokenizer, entityType, null, null);
}
 
Example #8
Source File: EdmKeyPropertyRefImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void aliasForPropertyInComplexPropertyTwoLevels() {
  CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/comp2/Id").setAlias("alias");
  EdmEntityType etMock = mock(EdmEntityType.class);
  EdmProperty keyPropertyMock = mock(EdmProperty.class);
  EdmProperty compMock = mock(EdmProperty.class);
  EdmComplexType compTypeMock = mock(EdmComplexType.class);
  EdmProperty comp2Mock = mock(EdmProperty.class);
  EdmComplexType comp2TypeMock = mock(EdmComplexType.class);
  when(comp2TypeMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock);
  when(comp2Mock.getType()).thenReturn(comp2TypeMock);
  when(compTypeMock.getStructuralProperty("comp2")).thenReturn(comp2Mock);
  when(compMock.getType()).thenReturn(compTypeMock);
  when(etMock.getStructuralProperty("comp")).thenReturn(compMock);
  EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);

  EdmProperty property = ref.getProperty();
  assertNotNull(property);
  assertTrue(property == keyPropertyMock);
}
 
Example #9
Source File: EdmEntityTypeImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void keyBehaviourWithBasetype() {
  List<String> keyPredicateNames = typeWithBaseType.getKeyPredicateNames();
  assertEquals(1, keyPredicateNames.size());
  assertEquals("Id", keyPredicateNames.get(0));

  EdmKeyPropertyRef keyPropertyRef = typeWithBaseType.getKeyPropertyRef("Id");
  assertNotNull(keyPropertyRef);
  assertEquals("Id", keyPropertyRef.getName());
  assertNull(keyPropertyRef.getAlias());

  List<EdmKeyPropertyRef> keyPropertyRefs = typeWithBaseType.getKeyPropertyRefs();
  assertNotNull(keyPropertyRefs);
  assertEquals(1, keyPropertyRefs.size());
  assertEquals("Id", keyPropertyRefs.get(0).getName());
  for (int i = 0; i < keyPropertyRefs.size(); i++) {
    assertEquals(keyPropertyRefs.get(i).getName(), typeWithBaseType.getKeyPropertyRefs().get(i).getName());
  }
}
 
Example #10
Source File: EdmEntityTypeImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void keyBehaviour() {
  List<String> keyPredicateNames = baseType.getKeyPredicateNames();
  assertEquals(1, keyPredicateNames.size());
  assertEquals("Id", keyPredicateNames.get(0));

  EdmKeyPropertyRef keyPropertyRef = baseType.getKeyPropertyRef("Id");
  assertNotNull(keyPropertyRef);
  assertEquals("Id", keyPropertyRef.getName());
  assertNull(keyPropertyRef.getAlias());

  EdmProperty keyProperty = keyPropertyRef.getProperty();
  assertNotNull(keyProperty);
  assertEquals(baseType.getProperty("Id"), keyProperty);

  List<EdmKeyPropertyRef> keyPropertyRefs = baseType.getKeyPropertyRefs();
  assertNotNull(keyPropertyRefs);
  assertEquals(1, keyPropertyRefs.size());
  assertEquals("Id", keyPropertyRefs.get(0).getName());
}
 
Example #11
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Object findPropertyRefValue(Entity entity, EdmKeyPropertyRef refType) {
  final int INDEX_ERROR_CODE = -1;
  final String propertyPath = refType.getName();
  String tmpPropertyName;
  int lastIndex;
  int index = propertyPath.indexOf('/');
  if (index == INDEX_ERROR_CODE) {
      index  = propertyPath.length();
  }
  tmpPropertyName = propertyPath.substring(0, index);
  //get first property
  Property prop = entity.getProperty(tmpPropertyName);
  //get following properties
  while (index < propertyPath.length()) {
      lastIndex = ++index;
      index = propertyPath.indexOf('/', index+1);
      if (index == INDEX_ERROR_CODE) {
          index = propertyPath.length();
      }
      tmpPropertyName = propertyPath.substring(lastIndex, index);
      prop = findProperty(tmpPropertyName, prop.asComplex().getValue());
   }
  return prop.getValue();
}
 
Example #12
Source File: EdmEntityTypeImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void checkBaseType() {
  if (!baseTypeChecked) {
    if (baseTypeName != null) {
      baseType = buildBaseType(baseTypeName);
      entityBaseType = (EdmEntityType) baseType;
    }
    if (baseType == null
        || (baseType.isAbstract() && ((EdmEntityType) baseType).getKeyPropertyRefs().isEmpty())) {
      final List<CsdlPropertyRef> key = entityType.getKey();
      if (key != null) {
        final List<EdmKeyPropertyRef> edmKey = new ArrayList<EdmKeyPropertyRef>();
        for (CsdlPropertyRef ref : key) {
          edmKey.add(new EdmKeyPropertyRefImpl(this, ref));
        }
        setEdmKeyPropertyRef(edmKey);
      }
    }
    baseTypeChecked = true;
  }
}
 
Example #13
Source File: ODataAdapter.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method check whether propertyName is a keyProperty or not.
 *
 * @param edmEntityType EdmEntityType
 * @param propertyName  PropertyName
 * @return isKey
 */
private boolean isKey(EdmEntityType edmEntityType, String propertyName) {
    List<EdmKeyPropertyRef> keyPropertyRefs = edmEntityType.getKeyPropertyRefs();
    for (EdmKeyPropertyRef propRef : keyPropertyRefs) {
        if (propRef.getName().equals(propertyName)) {
            return true;
        }
    }
    return false;
}
 
Example #14
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private boolean isKey(EdmEntityType edmEntityType, String propertyName) {
  
  List<EdmKeyPropertyRef> keyPropertyRefs = edmEntityType.getKeyPropertyRefs();
  for (EdmKeyPropertyRef propRef : keyPropertyRefs) {
    String keyPropertyName = propRef.getName();
    if (keyPropertyName.equals(propertyName)) {
      return true;
    }
  }
  return false;
}
 
Example #15
Source File: ExpressionParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropertyPathExp() throws Exception {
  final String entitySetName = "ESName";
  final String keyPropertyName = "a";
  EdmProperty keyProperty = mockProperty(keyPropertyName,
      OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String));
  EdmKeyPropertyRef keyPropertyRef = mockKeyPropertyRef(keyPropertyName, keyProperty);
  EdmEntityType entityType = mockEntityType(keyPropertyName, keyPropertyRef);
  Mockito.when(entityType.getPropertyNames()).thenReturn(Collections.singletonList(keyPropertyName));
  Mockito.when(entityType.getProperty(keyPropertyName)).thenReturn(keyProperty);
  EdmEntitySet entitySet = mockEntitySet(entitySetName, entityType);
  EdmEntityContainer container = mockContainer(entitySetName, entitySet);
  Edm mockedEdm = Mockito.mock(Edm.class);
  Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container);
  
  UriTokenizer tokenizer = new UriTokenizer("a eq \'abc\'");
  Expression expression = new ExpressionParser(mockedEdm, odata).parse(tokenizer, 
      entityType, null, null);
  assertNotNull(expression);
  assertEquals("{[a] EQ \'abc\'}", expression.toString());
  
  tokenizer = new UriTokenizer("a in (\'abc\', \'xyz\')");
  expression = new ExpressionParser(mockedEdm, odata).parse(tokenizer, 
      entityType, null, null);
  assertNotNull(expression);
  assertEquals("{[a] IN [\'abc\', \'xyz\']}", expression.toString());
  try {
    tokenizer = new UriTokenizer("a in (\'abc\', 10)");
    expression = new ExpressionParser(mockedEdm, odata).parse(tokenizer, 
        entityType, null, null);
  } catch (UriParserSemanticException e) {
    assertEquals("Incompatible types.", e.getMessage());
  }
}
 
Example #16
Source File: ExpressionParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * @param keyPropertyName
 * @param keyPropertyRef
 * @return
 */
private EdmEntityType mockEntityType(final String keyPropertyName, EdmKeyPropertyRef keyPropertyRef) {
  EdmEntityType entityType = Mockito.mock(EdmEntityType.class);
  Mockito.when(entityType.getKeyPredicateNames()).thenReturn(Collections.singletonList(keyPropertyName));
  Mockito.when(entityType.getKeyPropertyRefs()).thenReturn(Collections.singletonList(keyPropertyRef));
  return entityType;
}
 
Example #17
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private boolean isKey(EdmEntityType edmEntityType, String propertyName) {
  List<EdmKeyPropertyRef> keyPropertyRefs = edmEntityType.getKeyPropertyRefs();
  for (EdmKeyPropertyRef propRef : keyPropertyRefs) {
    String keyPropertyName = propRef.getName();
    if (keyPropertyName.equals(propertyName)) {
      return true;
    }
  }
  return false;
}
 
Example #18
Source File: ExpressionParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
/**
 * @param keyPropertyName
 * @param keyProperty
 * @return
 */
private EdmKeyPropertyRef mockKeyPropertyRef(final String keyPropertyName, EdmProperty keyProperty) {
  EdmKeyPropertyRef keyPropertyRef = Mockito.mock(EdmKeyPropertyRef.class);
  Mockito.when(keyPropertyRef.getName()).thenReturn(keyPropertyName);
  Mockito.when(keyPropertyRef.getProperty()).thenReturn(keyProperty);
  return keyPropertyRef;
}
 
Example #19
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private boolean isKey(EdmEntityType edmEntityType, String propertyName) {
  
  List<EdmKeyPropertyRef> keyPropertyRefs = edmEntityType.getKeyPropertyRefs();
  for (EdmKeyPropertyRef propRef : keyPropertyRefs) {
    String keyPropertyName = propRef.getName();
    if (keyPropertyName.equals(propertyName)) {
      return true;
    }
  }
  return false;
}
 
Example #20
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private boolean isKey(EdmEntityType edmEntityType, String propertyName) {
  List<EdmKeyPropertyRef> keyPropertyRefs = edmEntityType.getKeyPropertyRefs();
  for (EdmKeyPropertyRef propRef : keyPropertyRefs) {
    String keyPropertyName = propRef.getName();
    if (keyPropertyName.equals(propertyName)) {
      return true;
    }
  }
  return false;
}
 
Example #21
Source File: ExpressionParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void testComplexPropertyPathExp() throws Exception {
  final String entitySetName = "ESName";
  final String keyPropertyName = "a";
  final String complexPropertyName = "comp";
  final String propertyName = "prop";
  EdmProperty keyProperty = mockProperty(keyPropertyName, 
      OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String));
  EdmKeyPropertyRef keyPropertyRef = mockKeyPropertyRef(keyPropertyName, keyProperty);
  EdmProperty property = mockProperty(propertyName, 
      OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String));
  
  EdmComplexType complexType = mockComplexType(propertyName, property);
  EdmProperty complexProperty = mockProperty(complexPropertyName, complexType);
  
  EdmEntityType entityType = mockEntityType(keyPropertyName, keyPropertyRef);
  Mockito.when(entityType.getPropertyNames()).thenReturn(Arrays.asList(keyPropertyName, complexPropertyName));
  Mockito.when(entityType.getProperty(keyPropertyName)).thenReturn(keyProperty);
  Mockito.when(entityType.getProperty(complexPropertyName)).thenReturn(complexProperty);
  EdmEntitySet entitySet = mockEntitySet(entitySetName, entityType);
  EdmEntityContainer container = mockContainer(entitySetName, entitySet);
  Edm mockedEdm = Mockito.mock(Edm.class);
  Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container);
  
  UriTokenizer tokenizer = new UriTokenizer("comp/prop eq \'abc\'");
  Expression expression = new ExpressionParser(mockedEdm, odata).parse(tokenizer, 
      entityType, null, null);
  assertNotNull(expression);
  assertEquals("{[comp, prop] EQ \'abc\'}", expression.toString());
  
  tokenizer = new UriTokenizer("comp/prop in (\'abc\','xyz')");
  expression = new ExpressionParser(mockedEdm, odata).parse(tokenizer, 
      entityType, null, null);
  assertNotNull(expression);
  assertEquals("{[comp, prop] IN [\'abc\', \'xyz\']}", expression.toString());
}
 
Example #22
Source File: ExpressionParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void testLambdaPropertyPathExp() throws Exception {
  final String entitySetName = "ESName";
  final String keyPropertyName = "a";
  final String complexPropertyName = "comp";
  final String propertyName = "prop";
  EdmProperty keyProperty = mockProperty(keyPropertyName, 
      OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String));
  EdmKeyPropertyRef keyPropertyRef = mockKeyPropertyRef(keyPropertyName, keyProperty);
  EdmProperty property = mockProperty(propertyName, 
      OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String));
  
  EdmComplexType complexType = mockComplexType(propertyName, property);
  EdmProperty complexProperty = mockProperty(complexPropertyName, complexType);
  Mockito.when(complexProperty.isCollection()).thenReturn(true);
  
  EdmEntityType entityType = mockEntityType(keyPropertyName, keyPropertyRef);
  Mockito.when(entityType.getPropertyNames()).thenReturn(Arrays.asList(keyPropertyName, complexPropertyName));
  Mockito.when(entityType.getProperty(keyPropertyName)).thenReturn(keyProperty);
  Mockito.when(entityType.getProperty(complexPropertyName)).thenReturn(complexProperty);
  Mockito.when(entityType.getFullQualifiedName()).thenReturn(new FullQualifiedName("test.ET"));
  EdmEntitySet entitySet = mockEntitySet(entitySetName, entityType);
  EdmEntityContainer container = mockContainer(entitySetName, entitySet);
  Edm mockedEdm = Mockito.mock(Edm.class);
  Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container);
  
  UriTokenizer tokenizer = new UriTokenizer("comp/any(d:d/prop eq \'abc\')");
  Expression expression = new ExpressionParser(mockedEdm, odata).parse(tokenizer, 
      entityType, null, null);
  assertNotNull(expression);
  assertEquals("[comp, any]", expression.toString());
  
  tokenizer = new UriTokenizer("comp/all(d:d/prop eq \'abc\')");
  expression = new ExpressionParser(mockedEdm, odata).parse(tokenizer, 
      entityType, null, null);
  assertNotNull(expression);
  assertEquals("[comp, all]", expression.toString());
}
 
Example #23
Source File: ExpressionParserTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void testNavigationPropertyPathExp() throws Exception {
  final String entitySetName = "ESName";
  final String keyPropertyName = "a";
  final String complexPropertyName = "comp";
  final String propertyName = "navProp";
  EdmProperty keyProperty = mockProperty(keyPropertyName, 
      OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String));
  EdmKeyPropertyRef keyPropertyRef = mockKeyPropertyRef(keyPropertyName, keyProperty);
  
  EdmEntityType targetEntityType = mockEntityType(keyPropertyName, keyPropertyRef);
  Mockito.when(targetEntityType.getFullQualifiedName()).thenReturn(new FullQualifiedName("test.TargetET"));
  EdmNavigationProperty navProperty = mockNavigationProperty(propertyName, targetEntityType);
  
  EdmComplexType complexType = mockComplexType(propertyName, navProperty);
  EdmProperty complexProperty = mockProperty(complexPropertyName, complexType);
  
  EdmEntityType startEntityType = mockEntityType(keyPropertyName, keyPropertyRef);
  Mockito.when(startEntityType.getFullQualifiedName()).thenReturn(new FullQualifiedName("test.StartET"));
  Mockito.when(startEntityType.getPropertyNames()).thenReturn(
      Arrays.asList(keyPropertyName, complexPropertyName));
  Mockito.when(startEntityType.getProperty(keyPropertyName)).thenReturn(keyProperty);
  Mockito.when(startEntityType.getProperty(complexPropertyName)).thenReturn(complexProperty);
  EdmEntitySet entitySet = mockEntitySet(entitySetName, startEntityType);
  EdmEntityContainer container = mockContainer(entitySetName, entitySet);
  Edm mockedEdm = Mockito.mock(Edm.class);
  Mockito.when(mockedEdm.getEntityContainer()).thenReturn(container);
  
  UriTokenizer tokenizer = new UriTokenizer("comp/navProp");
  final Expression expression = new ExpressionParser(mockedEdm, odata).parse(tokenizer, 
      startEntityType, null, null);
  assertNotNull(expression);
  assertEquals("[comp, navProp]", expression.toString());
}
 
Example #24
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private boolean isKey(EdmEntityType edmEntityType, String propertyName) {
  
  List<EdmKeyPropertyRef> keyPropertyRefs = edmEntityType.getKeyPropertyRefs();
  for (EdmKeyPropertyRef propRef : keyPropertyRefs) {
    String keyPropertyName = propRef.getName();
    if (keyPropertyName.equals(propertyName)) {
      return true;
    }
  }
  return false;
}
 
Example #25
Source File: AbstractUtility.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Map<String, String> getEntityKeyType(final EdmEntityType entityType) {
  EdmEntityType baseType = entityType;
  while (CollectionUtils.isEmpty(baseType.getKeyPredicateNames()) && baseType.getBaseType() != null) {
    baseType = getEdmTypeInfo(baseType.getBaseType().getFullQualifiedName().toString()).getEntityType();
  }

  final Map<String, String> res = new LinkedHashMap<String, String>();
  for (EdmKeyPropertyRef pref : baseType.getKeyPropertyRefs()) {
    res.put(pref.getName(),
            getJavaType(pref.getProperty().getType().getFullQualifiedName().toString()));
  }

  return res;
}
 
Example #26
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private boolean isKey(EdmEntityType edmEntityType, String propertyName) {
  
  List<EdmKeyPropertyRef> keyPropertyRefs = edmEntityType.getKeyPropertyRefs();
  for (EdmKeyPropertyRef propRef : keyPropertyRefs) {
    String keyPropertyName = propRef.getName();
    if (keyPropertyName.equals(propertyName)) {
      return true;
    }
  }
  return false;
}
 
Example #27
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private boolean isKey(EdmEntityType edmEntityType, String propertyName) {
  
  List<EdmKeyPropertyRef> keyPropertyRefs = edmEntityType.getKeyPropertyRefs();
  for (EdmKeyPropertyRef propRef : keyPropertyRefs) {
    String keyPropertyName = propRef.getName();
    if (keyPropertyName.equals(propertyName)) {
      return true;
    }
  }
  return false;
}
 
Example #28
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private boolean isKey(EdmEntityType edmEntityType, String propertyName) {
  List<EdmKeyPropertyRef> keyPropertyRefs = edmEntityType.getKeyPropertyRefs();
  for (EdmKeyPropertyRef propRef : keyPropertyRefs) {
    String keyPropertyName = propRef.getName();
    if (keyPropertyName.equals(propertyName)) {
      return true;
    }
  }
  return false;
}
 
Example #29
Source File: EdmKeyPropertyRefImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void noAlias() {
  CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("Id");
  EdmEntityType etMock = mock(EdmEntityType.class);
  EdmProperty keyPropertyMock = mock(EdmProperty.class);
  when(etMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock);
  EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);
  assertEquals("Id", ref.getName());
  assertNull(ref.getAlias());

  EdmProperty property = ref.getProperty();
  assertNotNull(property);
  assertTrue(property == keyPropertyMock);
  assertTrue(property == ref.getProperty());
}
 
Example #30
Source File: Storage.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private static boolean isKey(EdmEntityType edmEntityType, String propertyName) {
    List<EdmKeyPropertyRef> keyPropertyRefs = edmEntityType.getKeyPropertyRefs();
    for (EdmKeyPropertyRef propRef : keyPropertyRefs) {
        String keyPropertyName = propRef.getName();
        if (keyPropertyName.equals(propertyName)) {
            return true;
        }
    }
    return false;
}