use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class AbstractCypherAdapterStream method convertNotifications.
private static AnyValue convertNotifications(Iterable<Notification> notifications) {
ListValueBuilder listValueBuilder = ListValueBuilder.newListBuilder();
for (Notification notification : notifications) {
// position is optional
InputPosition pos = notification.getPosition();
boolean includePosition = !pos.equals(InputPosition.empty);
int size = includePosition ? 5 : 4;
MapValueBuilder builder = new MapValueBuilder(size);
builder.add("code", utf8Value(notification.getCode()));
builder.add("title", utf8Value(notification.getTitle()));
builder.add("description", utf8Value(notification.getDescription()));
builder.add("severity", utf8Value(notification.getSeverity().toString()));
if (includePosition) {
// only add the position if it is not empty
builder.add("position", VirtualValues.map(new String[] { "offset", "line", "column" }, new AnyValue[] { intValue(pos.getOffset()), intValue(pos.getLine()), intValue(pos.getColumn()) }));
}
listValueBuilder.add(builder.build());
}
return listValueBuilder.build();
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ValueUtilsTest method shouldHandleIterator.
@Test
void shouldHandleIterator() {
// Given
Iterator<Integer> iterator = Arrays.asList(1, 2, 3).iterator();
// When
AnyValue of = ValueUtils.of(iterator);
// Then
assertThat(of).isInstanceOf(ListValue.class);
ListValue listValue = (ListValue) of;
assertThat(listValue.value(0)).isEqualTo(intValue(1));
assertThat(listValue.value(1)).isEqualTo(intValue(2));
assertThat(listValue.value(2)).isEqualTo(intValue(3));
assertThat(listValue.size()).isEqualTo(3);
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ValueUtilsTest method shouldHandleIterable.
@Test
void shouldHandleIterable() {
// Given
Iterable<Integer> collection = Arrays.asList(1, 2, 3);
// When
AnyValue of = ValueUtils.of(collection);
// Then
assertThat(of).isInstanceOf(ListValue.class);
ListValue listValue = (ListValue) of;
assertThat(listValue.value(0)).isEqualTo(intValue(1));
assertThat(listValue.value(1)).isEqualTo(intValue(2));
assertThat(listValue.value(2)).isEqualTo(intValue(3));
assertThat(listValue.size()).isEqualTo(3);
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class CommunityDatabaseStateProcedureTest method shouldThrowWhenDatabaseNotFound.
@Test
void shouldThrowWhenDatabaseNotFound() throws ProcedureException {
// given
var existing = idRepository.getRaw("existing");
var nonExisting = idRepository.getRaw("nonExisting");
idRepository.filter(nonExisting.name());
Map<NamedDatabaseId, DatabaseState> states = Map.of(existing, new CommunityDatabaseState(existing, true, false, null));
var stateService = new StubDatabaseStateService(states, CommunityDatabaseState::unknown);
var procedure = procedure(stateService);
// when/then
// Should not throw
procedure.apply(mock(Context.class), new AnyValue[] { stringValue(existing.name()) }, mock(ResourceTracker.class));
// Should throw
assertThrows(ProcedureException.class, () -> procedure.apply(mock(Context.class), new AnyValue[] { stringValue(nonExisting.name()) }, mock(ResourceTracker.class)));
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class CommunityDatabaseStateProcedureTest method shouldThrowWithInvalidInput.
@Test
void shouldThrowWithInvalidInput() {
var procedure = procedure(new StubDatabaseStateService(CommunityDatabaseState::unknown));
assertThrows(IllegalArgumentException.class, () -> procedure.apply(mock(Context.class), new AnyValue[] {}, mock(ResourceTracker.class)));
assertThrows(IllegalArgumentException.class, () -> procedure.apply(mock(Context.class), new AnyValue[] { null }, mock(ResourceTracker.class)));
assertThrows(IllegalArgumentException.class, () -> procedure.apply(mock(Context.class), new AnyValue[] { intValue(42), stringValue("The answer") }, mock(ResourceTracker.class)));
}
Aggregations