Search in sources :

Example 6 with DefaultParameterValue

use of org.neo4j.internal.kernel.api.procs.DefaultParameterValue in project neo4j by neo4j.

the class ListConverterTest method shouldHandleIntegerValue.

@Test
void shouldHandleIntegerValue() {
    // Given
    ListConverter converter = new ListConverter(Long.class, NTInteger, expressionEvaluator());
    String listString = "[1337, 42]";
    // When
    DefaultParameterValue converted = converter.apply(listString);
    // Then
    assertThat(converted).isEqualTo(ntList(asList(1337L, 42L), NTInteger));
}
Also used : DefaultParameterValue(org.neo4j.internal.kernel.api.procs.DefaultParameterValue) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) Test(org.junit.jupiter.api.Test)

Example 7 with DefaultParameterValue

use of org.neo4j.internal.kernel.api.procs.DefaultParameterValue in project neo4j by neo4j.

the class ListConverterTest method shouldHandleListsOfMaps.

@SuppressWarnings("unchecked")
@Test
void shouldHandleListsOfMaps() {
    // Given
    ListConverter converter = new ListConverter(Map.class, NTMap, expressionEvaluator());
    String mapString = "[{k1: 42}, {k1: 1337}]";
    // When
    DefaultParameterValue converted = converter.apply(mapString);
    // Then
    List<Object> list = (List<Object>) converted.value();
    assertThat(list.get(0)).isEqualTo(map("k1", 42L));
    assertThat(list.get(1)).isEqualTo(map("k1", 1337L));
}
Also used : DefaultParameterValue(org.neo4j.internal.kernel.api.procs.DefaultParameterValue) Collections.emptyList(java.util.Collections.emptyList) DefaultParameterValue.ntList(org.neo4j.internal.kernel.api.procs.DefaultParameterValue.ntList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) NTList(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) Test(org.junit.jupiter.api.Test)

Example 8 with DefaultParameterValue

use of org.neo4j.internal.kernel.api.procs.DefaultParameterValue in project neo4j by neo4j.

the class ListConverterTest method shouldHandleNestedLists.

@SuppressWarnings("unchecked")
@Test
void shouldHandleNestedLists() {
    // Given
    ParameterizedType type = mock(ParameterizedType.class);
    when(type.getActualTypeArguments()).thenReturn(new Type[] { Object.class });
    ListConverter converter = new ListConverter(type, NTList(NTAny), expressionEvaluator());
    String mapString = "[42, [42, 1337]]";
    // When
    DefaultParameterValue converted = converter.apply(mapString);
    // Then
    List<Object> list = (List<Object>) converted.value();
    assertThat(list.get(0)).isEqualTo(42L);
    assertThat(list.get(1)).isEqualTo(asList(42L, 1337L));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) DefaultParameterValue(org.neo4j.internal.kernel.api.procs.DefaultParameterValue) Collections.emptyList(java.util.Collections.emptyList) DefaultParameterValue.ntList(org.neo4j.internal.kernel.api.procs.DefaultParameterValue.ntList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) NTList(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) Test(org.junit.jupiter.api.Test)

Example 9 with DefaultParameterValue

use of org.neo4j.internal.kernel.api.procs.DefaultParameterValue in project neo4j by neo4j.

the class ListConverterTest method shouldHandleEmptyList.

@Test
void shouldHandleEmptyList() {
    // Given
    ListConverter converter = new ListConverter(String.class, NTString, expressionEvaluator());
    String listString = "[]";
    // When
    DefaultParameterValue converted = converter.apply(listString);
    // Then
    assertThat(converted).isEqualTo(ntList(emptyList(), NTString));
}
Also used : DefaultParameterValue(org.neo4j.internal.kernel.api.procs.DefaultParameterValue) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) Test(org.junit.jupiter.api.Test)

Example 10 with DefaultParameterValue

use of org.neo4j.internal.kernel.api.procs.DefaultParameterValue in project neo4j by neo4j.

the class MapConverterTest method shouldHandleNullValue.

@Test
void shouldHandleNullValue() {
    // Given
    String mapString = "{key: null}";
    // When
    DefaultParameterValue converted = converter.apply(mapString);
    // Then
    assertThat(converted).isEqualTo(ntMap(map("key", null)));
}
Also used : DefaultParameterValue(org.neo4j.internal.kernel.api.procs.DefaultParameterValue) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultParameterValue (org.neo4j.internal.kernel.api.procs.DefaultParameterValue)31 Test (org.junit.jupiter.api.Test)30 NTString (org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString)12 Arrays.asList (java.util.Arrays.asList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Map (java.util.Map)2 DefaultParameterValue.ntList (org.neo4j.internal.kernel.api.procs.DefaultParameterValue.ntList)2 DefaultParameterValue.ntMap (org.neo4j.internal.kernel.api.procs.DefaultParameterValue.ntMap)2 NTList (org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList)2 Parameter (java.lang.reflect.Parameter)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)1 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)1 Name (org.neo4j.procedure.Name)1 DefaultValueConverter (org.neo4j.procedure.impl.TypeCheckers.DefaultValueConverter)1