Java Code Examples for com.google.cloud.datastore.Entity#getList()
The following examples show how to use
com.google.cloud.datastore.Entity#getList() .
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: DefaultDatastoreEntityConverterTests.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
@Test public void testCollectionFieldsUnsupportedWriteOnly() { TestItemUnsupportedFields.CollectionOfUnsupportedTypes item = getCollectionOfUnsupportedTypesItem(); DatastoreEntityConverter entityConverter = new DefaultDatastoreEntityConverter(new DatastoreMappingContext(), new TwoStepsConversions(new DatastoreCustomConversions(Collections.singletonList( getNewTypeToIntegerConverter())), null, datastoreMappingContext)); Entity.Builder builder = getEntityBuilder(); entityConverter.write(item, builder); Entity entity = builder.build(); List<Value<?>> intList = entity.getList("unsupportedElts"); assertThat(intList.stream().map(Value::get).collect(Collectors.toList())) .as("validate int list values").isEqualTo(Arrays.asList(1L, 0L)); }
Example 2
Source File: DefaultDatastoreEntityConverterTests.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
@Test public void testCollectionFieldsUnsupportedWriteRead() { TestItemUnsupportedFields.CollectionOfUnsupportedTypes item = getCollectionOfUnsupportedTypesItem(); DatastoreEntityConverter entityConverter = new DefaultDatastoreEntityConverter(new DatastoreMappingContext(), new TwoStepsConversions(new DatastoreCustomConversions(Arrays.asList( getIntegerToNewTypeConverter(), getNewTypeToIntegerConverter() )), null, datastoreMappingContext)); Entity.Builder builder = getEntityBuilder(); entityConverter.write(item, builder); Entity entity = builder.build(); List<Value<?>> intList = entity.getList("unsupportedElts"); assertThat(intList.stream().map(Value::get).collect(Collectors.toList())) .as("validate long list values").isEqualTo(Arrays.asList(1L, 0L)); TestItemUnsupportedFields.CollectionOfUnsupportedTypes read = entityConverter.read(TestItemUnsupportedFields.CollectionOfUnsupportedTypes.class, entity); assertThat(read.equals(item)).as("read object should be equal to original").isTrue(); }
Example 3
Source File: DefaultDatastoreEntityConverterTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void testCollectionFieldsNulls() { TestDatastoreItemCollections item = new TestDatastoreItemCollections( Arrays.asList(1, 2), null, null, new boolean[] {true, false}, null, null); Entity.Builder builder = getEntityBuilder(); ENTITY_CONVERTER.write(item, builder); Entity entity = builder.build(); List<Value<?>> intList = entity.getList("intList"); assertThat(intList.stream().map(Value::get).collect(Collectors.toList())) .as("validate int list values").isEqualTo(Arrays.asList(1L, 2L)); List<Value<?>> stringArray = entity.getList("stringArray"); assertThat(stringArray) .as("validate string array is null").isNull(); List<Value<?>> beanContext = entity.getList("beanContext"); assertThat(beanContext) .as("validate bean context is null") .isNull(); TestDatastoreItemCollections readItem = ENTITY_CONVERTER.read(TestDatastoreItemCollections.class, entity); assertThat(item.equals(readItem)).as("read object should be equal to original").isTrue(); }
Example 4
Source File: ConceptsTest.java From java-docs-samples with Apache License 2.0 | 5 votes |
@Test public void testPropertyByKindRunQuery() { setUpQueryTests(); // [START datastore_property_by_kind_run_query] Key key = datastore.newKeyFactory().setKind("__kind__").newKey("Task"); Query<Entity> query = Query.newEntityQueryBuilder() .setKind("__property__") .setFilter(PropertyFilter.hasAncestor(key)) .build(); QueryResults<Entity> results = datastore.run(query); Map<String, Collection<String>> representationsByProperty = new HashMap<>(); while (results.hasNext()) { Entity result = results.next(); String propertyName = result.getKey().getName(); List<StringValue> representations = result.getList("property_representation"); Collection<String> currentRepresentations = representationsByProperty.get(propertyName); if (currentRepresentations == null) { currentRepresentations = new HashSet<>(); representationsByProperty.put(propertyName, currentRepresentations); } for (StringValue value : representations) { currentRepresentations.add(value.get()); } } // [END datastore_property_by_kind_run_query] Map<String, Collection<String>> expected = ImmutableMap.<String, Collection<String>>builder() .put("category", Collections.singleton("STRING")) .put("done", Collections.singleton("BOOLEAN")) .put("completed", Collections.singleton("BOOLEAN")) .put("priority", Collections.singleton("INT64")) .put("created", Collections.singleton("INT64")) .put("percent_complete", Collections.singleton("DOUBLE")) .put("tag", Collections.singleton("STRING")) .build(); assertEquals(expected, representationsByProperty); }