@@ -0,0 +1,2435 @@
+/*%0A */%0A%0Apackage com.googlecode.objectify.test;%0A%0Aimport com.google.cloud.datastore.Key;%0Aimport com.google.cloud.datastore.Value;%0Aimport com.googlecode.objectify.annotation.Cache;%0Aimport com.googlecode.objectify.annotation.Entity;%0Aimport com.googlecode.objectify.annotation.Id;%0Aimport com.googlecode.objectify.annotation.Index;%0Aimport com.googlecode.objectify.annotation.Unindex;%0Aimport com.googlecode.objectify.test.util.TestBase;%0Aimport lombok.Data;%0A%0Aimport static com.google.common.truth.Truth.assertThat;%0Aimport static com.googlecode.objectify.ObjectifyService.factory;%0Aimport static com.googlecode.objectify.ObjectifyService.ofy;%0A%0A/**%0A * https://github.com/objectify/objectify/issues/397%0A */%0Aclass IndexingEmbeddedTests2 extends TestBase %7B%0A%0A%09/** */%0A%09@Entity%0A%09@Cache%0A%09@Data%0A%09private static class EmbeddedEntity %7B%0A%09%09@Id Long id;%0A%09%09boolean foo;%0A%09%7D%0A%0A%09/** */%0A%09@Entity%0A%09@Cache%0A%09@Index%0A%09@Data%0A%09private static class UnindexEmbeddedEntity %7B%0A%09%09@Id Long id;%0A%09%09@Unindex EmbeddedEntity embeddedEntity;%0A%09%7D%0A%0A%09/** */%0A%09//@Test%0A%09void embeddedEntityFollowsNormalIndexingRules() throws Exception %7B%0A%09%09factory().register(UnindexEmbeddedEntity.class);%0A%0A%09%09final EmbeddedEntity embeddedEntity = new EmbeddedEntity();%0A%09%09embeddedEntity.id = 1L;%0A%09%09embeddedEntity.foo = true;%0A%0A%09%09final UnindexEmbeddedEntity thing = new UnindexEmbeddedEntity();%0A%09%09thing.id = 2L;%0A%09%09thing.embeddedEntity = embeddedEntity;%0A%0A%09%09final Key raw = ofy().save().entity(thing).now().getRaw();%0A%0A%09%09com.google.cloud.datastore.Entity datastoreEntity = datastore().get(raw);%0A%0A%09%09final Value%3C?%3E datastoreEmbeddedEntity = datastoreEntity.getValue(%22embeddedEntity%22);%0A%09%09assertThat(datastoreEmbeddedEntity).isNotNull();%0A%0A%09%09// The following line fails. Apparently, the embedded entity is indexed, despite the @Unindex annotation%0A%09%09assertThat(datastoreEmbeddedEntity.excludeFromIndexes()).isTrue();%0A%0A%09%09// JMS: This is unfortunately necessary because if you don't include the embedded entity in the index,%0A%09%09// then google's SDK de-indexes any children (even if they are marked as indexed). On the plus side,%0A%09%09// this shouldn't actually create an index or cost anything - only actual properties are indexed.%0A%09%09// See DatastoreTests.intermediateEmbeddedEntitiesAlwaysNeedToBeIndexed()%0A%0A%09%09// I'm leaving this test intact (but disabled) here because we might revisit it later if Google ever changes%0A%09%09// the SDK behavior - although that's unlikely since it would probably break backwards compatibility.%0A%09%7D%7D

Address the issue with embedded entities being indexed