Search in sources :

Example 51 with AnyValue

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();
}
Also used : MapValueBuilder(org.neo4j.values.virtual.MapValueBuilder) InputPosition(org.neo4j.graphdb.InputPosition) AnyValue(org.neo4j.values.AnyValue) Notification(org.neo4j.graphdb.Notification) ListValueBuilder(org.neo4j.values.virtual.ListValueBuilder)

Example 52 with AnyValue

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);
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Example 53 with AnyValue

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);
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Example 54 with AnyValue

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)));
}
Also used : Context(org.neo4j.kernel.api.procedure.Context) DatabaseState(org.neo4j.dbms.DatabaseState) CommunityDatabaseState(org.neo4j.dbms.CommunityDatabaseState) CommunityDatabaseState(org.neo4j.dbms.CommunityDatabaseState) ResourceTracker(org.neo4j.kernel.api.ResourceTracker) StubDatabaseStateService(org.neo4j.dbms.StubDatabaseStateService) AnyValue(org.neo4j.values.AnyValue) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) Test(org.junit.jupiter.api.Test)

Example 55 with AnyValue

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)));
}
Also used : StubDatabaseStateService(org.neo4j.dbms.StubDatabaseStateService) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Aggregations

AnyValue (org.neo4j.values.AnyValue)95 Test (org.junit.jupiter.api.Test)58 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)19 ListValue (org.neo4j.values.virtual.ListValue)14 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)11 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)11 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)10 List (java.util.List)9 TextValue (org.neo4j.values.storable.TextValue)9 RawIterator (org.neo4j.collection.RawIterator)8 MapValue (org.neo4j.values.virtual.MapValue)8 Context (org.neo4j.kernel.api.procedure.Context)7 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)7 ArrayList (java.util.ArrayList)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Values.stringValue (org.neo4j.values.storable.Values.stringValue)6 LocalDate (java.time.LocalDate)5 LocalTime (java.time.LocalTime)5 ZonedDateTime (java.time.ZonedDateTime)5 Arrays (java.util.Arrays)5