package com.sap.core.odata.core.ep.aggregator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.sap.core.odata.api.edm.EdmEntitySet;
import com.sap.core.odata.api.uri.ExpandSelectTreeNode;
import com.sap.core.odata.core.ep.AbstractProviderTest;
import com.sap.core.odata.testutil.mock.MockFacade;

/**
 * @author SAP AG
 */
public class EntityInfoAggregatorTest extends AbstractProviderTest {

  public EntityInfoAggregatorTest(final StreamWriterImplType type) {
    super(type);
  }

  @Test
  public void testEntitySet() throws Exception {
    EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");

    ExpandSelectTreeNode epProperties = null;
    EntityInfoAggregator eia = EntityInfoAggregator.create(entitySet, epProperties);

    assertNotNull(eia);
    EntityPropertyInfo propertyInfoAge = eia.getPropertyInfo("Age");
    assertFalse(propertyInfoAge.isComplex());
    assertEquals("Age", propertyInfoAge.getName());
    assertEquals("Int32", propertyInfoAge.getType().getName());
    EntityPropertyInfo propertyInfoLocation = eia.getPropertyInfo("Location");
    assertTrue(propertyInfoLocation.isComplex());
    assertEquals("Location", propertyInfoLocation.getName());
    EntityComplexPropertyInfo comPropInfoLocation = (EntityComplexPropertyInfo) propertyInfoLocation;
    assertEquals(2, comPropInfoLocation.getPropertyInfos().size());
  }
}

@@ -176,16 +176,59 @@
 otNull;%0A
+import static org.junit.Assert.assertNull;%0A
 import s
@@ -262,16 +262,16 @@
 rtTrue;%0A
-
 %0Aimport 
@@ -335,16 +335,63 @@
 itySet;%0A
+import com.sap.core.odata.api.edm.EdmTypeKind;%0A
 import c
@@ -1408,32 +1408,77 @@
 n.isComplex());%0A
+    assertNull(eia.getPropertyInfo(%22City%22));%0A
     assertEquals
@@ -1557,142 +1557,1188 @@
 nfo 
-comPropInfoLocation = (EntityComplexPropertyInfo) propertyInfoLocation;%0A    assertEquals(2, comPropInfoLocation.getPropertyInfos().siz
+locationInfo = (EntityComplexPropertyInfo) propertyInfoLocation;%0A    assertEquals(2, locationInfo.getPropertyInfos().size());%0A    %0A    assertEquals(%22Country%22, locationInfo.getPropertyInfo(%22Country%22).getName());%0A    assertEquals(%22String%22, locationInfo.getPropertyInfo(%22Country%22).getType().getName());%0A    assertEquals(EdmTypeKind.SIMPLE, locationInfo.getPropertyInfo(%22Country%22).getType().getKind());%0A%0A    EntityComplexPropertyInfo cityInfo = (EntityComplexPropertyInfo) locationInfo.getPropertyInfo(%22City%22);%0A    assertTrue(cityInfo.isComplex());%0A    assertEquals(%22City%22, cityInfo.getName());%0A    assertEquals(%22City%22, cityInfo.getType().getName());%0A    assertEquals(EdmTypeKind.COMPLEX, cityInfo.getType().getKind());%0A    assertEquals(%22CityName%22, cityInfo.getPropertyInfo(%22CityName%22).getName());%0A    assertFalse(cityInfo.getPropertyInfo(%22CityName%22).isComplex());%0A    assertEquals(%22String%22, cityInfo.getPropertyInfo(%22CityName%22).getType().getName());%0A    assertEquals(%22PostalCode%22, cityInfo.getPropertyInfo(%22PostalCode%22).getName());%0A    assertFalse(cityInfo.getPropertyInfo(%22PostalCode%22).isComplex());%0A    assertEquals(%22String%22, cityInfo.getPropertyInfo(%22PostalCode%22).getType().getNam
 e())

Test for hierachical EDM structure