use of com.google.storage.onestore.v3.OnestoreEntity.Reference in project appengine-java-standard by GoogleCloudPlatform.
the class KeyTranslatorTest method testConvertToPbTwoLevelsPut.
@Test
public void testConvertToPbTwoLevelsPut() throws Exception {
Key key1 = new Key("foo");
key1.simulatePutForTesting(12345L);
Key key2 = new Key("bar", key1);
key2.simulatePutForTesting(12346L);
assertThat(key2.isComplete()).isTrue();
assertThat(key2.getId()).isEqualTo(12346L);
Reference ref2 = KeyTranslator.convertToPb(key2);
assertThat(ref2.getPath().elementSize()).isEqualTo(2);
assertThat(ref2.getPath().elements().get(0).getType()).isEqualTo("foo");
assertThat(ref2.getPath().elements().get(0).hasId()).isTrue();
assertThat(ref2.getPath().elements().get(0).getId()).isEqualTo(12345L);
assertThat(ref2.getPath().elements().get(0).hasName()).isFalse();
assertThat(ref2.getPath().elements().get(1).getType()).isEqualTo("bar");
assertThat(ref2.getPath().elements().get(1).hasId()).isTrue();
assertThat(ref2.getPath().elements().get(1).getId()).isEqualTo(12346L);
assertThat(ref2.getPath().elements().get(1).hasName()).isFalse();
}
use of com.google.storage.onestore.v3.OnestoreEntity.Reference in project appengine-java-standard by GoogleCloudPlatform.
the class KeyTranslatorTest method testConvertToPbTwoLevelsNotPut.
@Test
public void testConvertToPbTwoLevelsNotPut() throws Exception {
Key key1 = new Key("foo");
key1.simulatePutForTesting(12345L);
Key key2 = new Key("bar", key1);
assertThat(key2.isComplete()).isFalse();
Reference ref2 = KeyTranslator.convertToPb(key2);
assertThat(ref2.getPath().elementSize()).isEqualTo(2);
assertThat(ref2.getPath().elements().get(0).getType()).isEqualTo("foo");
assertThat(ref2.getPath().elements().get(0).hasId()).isTrue();
assertThat(ref2.getPath().elements().get(0).getId()).isEqualTo(12345L);
assertThat(ref2.getPath().elements().get(0).hasName()).isFalse();
assertThat(ref2.getPath().elements().get(1).getType()).isEqualTo("bar");
assertThat(ref2.getPath().elements().get(1).hasId()).isFalse();
assertThat(ref2.getPath().elements().get(1).hasName()).isFalse();
}
use of com.google.storage.onestore.v3.OnestoreEntity.Reference in project appengine-java-standard by GoogleCloudPlatform.
the class ReferenceValues method toReferenceProperty.
/**
* Converts a {@link Reference} to a {@link PropertyValue}
*
* <p>with the same {@link PropertyValue.ReferenceValue}.
*
* <p>Doesn't do any validation!
*
* @return the corresponding {@link PropertyValue}
*/
public static PropertyValue toReferenceProperty(Reference key) {
PropertyValue prop = new PropertyValue();
PropertyValue.ReferenceValue ref = prop.getMutableReferenceValue();
if (key.hasApp()) {
ref.setAppAsBytes(key.getAppAsBytes());
}
if (key.hasDatabaseId()) {
ref.setDatabaseIdAsBytes(key.getDatabaseIdAsBytes());
}
if (key.hasNameSpace()) {
ref.setNameSpaceAsBytes(key.getNameSpaceAsBytes());
}
for (Path.Element keyElem : key.getPath().elements()) {
PropertyValue.ReferenceValuePathElement refElem = ref.addPathElement();
if (keyElem.hasType()) {
refElem.setTypeAsBytes(keyElem.getTypeAsBytes());
}
if (keyElem.hasId()) {
refElem.setId(keyElem.getId());
}
if (keyElem.hasName()) {
refElem.setNameAsBytes(keyElem.getNameAsBytes());
}
}
return prop;
}
Aggregations