Search in sources :

Example 16 with Attribute

use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.

the class ParameterizedModelTest method testFetch.

@Test
public void testFetch() {
    ParameterizedModel testModel = spy(ParameterizedModel.class);
    Attribute testAttribute = Attribute.builder().type(STRING_TYPE).name("foo").build();
    String testValue = "bar";
    testModel.addAttributeValue(testAttribute, testValue);
    assertEquals(testValue, testModel.fetch(testAttribute.getAlias(), "blah"));
}
Also used : Attribute(com.yahoo.elide.core.request.Attribute) Test(org.junit.jupiter.api.Test)

Example 17 with Attribute

use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.

the class ParameterizedModelTest method testFetchDefault.

@Test
public void testFetchDefault() {
    ParameterizedModel testModel = spy(ParameterizedModel.class);
    Attribute testAttribute = Attribute.builder().type(STRING_TYPE).name("foo").build();
    String testValue = "blah";
    assertEquals(testValue, testModel.fetch(testAttribute.getAlias(), testValue));
}
Also used : Attribute(com.yahoo.elide.core.request.Attribute) Test(org.junit.jupiter.api.Test)

Example 18 with Attribute

use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.

the class ParameterizedModelTest method testInvokeException.

@Test
public void testInvokeException() {
    ParameterizedModel testModel = spy(ParameterizedModel.class);
    Attribute testAttribute = Attribute.builder().type(STRING_TYPE).name("foo").build();
    Exception exception = assertThrows(InvalidParameterizedAttributeException.class, () -> testModel.invoke(testAttribute));
    assertEquals("No attribute found with matching parameters for attribute: Attribute(name=foo)", exception.getMessage());
}
Also used : Attribute(com.yahoo.elide.core.request.Attribute) InvalidParameterizedAttributeException(com.yahoo.elide.core.exceptions.InvalidParameterizedAttributeException) Test(org.junit.jupiter.api.Test)

Example 19 with Attribute

use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.

the class GraphQLEntityProjectMakerTest method testParameterizedAttributeDefaultValue.

@Test
public void testParameterizedAttributeDefaultValue() {
    String graphQLRequest = document(selection(field("parameterizedExample", selections(field("attribute"))))).toQuery();
    GraphQLEntityProjectionMaker projectionMaker = new GraphQLEntityProjectionMaker(settings);
    GraphQLProjectionInfo projectionInfo = projectionMaker.make(graphQLRequest);
    assertEquals(1, projectionInfo.getProjections().size());
    EntityProjection projection = projectionInfo.getProjections().values().iterator().next();
    // Verify Entity Argument
    assertEquals(1, projection.getArguments().size());
    Argument entityArgument = projection.getArguments().iterator().next();
    assertEquals("entityArgument", entityArgument.getName());
    assertEquals(String.class, entityArgument.getType());
    assertEquals("defaultArgValue", entityArgument.getValue());
    // Verify Attribute Argument
    assertEquals(1, projection.getAttributes().size());
    Attribute attribute = projection.getAttributes().iterator().next();
    assertEquals(1, attribute.getArguments().size());
    Argument argument = attribute.getArguments().iterator().next();
    assertEquals("argument", argument.getName());
    assertEquals(String.class, argument.getType());
    assertEquals("defaultValue", argument.getValue());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) Argument(com.yahoo.elide.core.request.Argument) Attribute(com.yahoo.elide.core.request.Attribute) PersistentResourceFetcherTest(com.yahoo.elide.graphql.PersistentResourceFetcherTest) Test(org.junit.jupiter.api.Test)

Example 20 with Attribute

use of com.yahoo.elide.core.request.Attribute in project elide by yahoo.

the class GraphQLEntityProjectMakerTest method testParameterizedAttribute.

@Test
public void testParameterizedAttribute() {
    String graphQLRequest = document(selection(field("parameterizedExample", arguments(argument("entityArgument", "xyz", true)), selections(field("attribute", arguments(argument("argument", "abc", true))))))).toQuery();
    GraphQLEntityProjectionMaker projectionMaker = new GraphQLEntityProjectionMaker(settings);
    GraphQLProjectionInfo projectionInfo = projectionMaker.make(graphQLRequest);
    assertEquals(1, projectionInfo.getProjections().size());
    EntityProjection projection = projectionInfo.getProjections().values().iterator().next();
    // Verify Entity Argument
    assertEquals(1, projection.getArguments().size());
    Argument entityArgument = projection.getArguments().iterator().next();
    assertEquals("entityArgument", entityArgument.getName());
    assertEquals(String.class, entityArgument.getType());
    assertEquals("xyz", entityArgument.getValue());
    // Verify Attribute Argument
    assertEquals(1, projection.getAttributes().size());
    Attribute attribute = projection.getAttributes().iterator().next();
    assertEquals(1, attribute.getArguments().size());
    Argument argument = attribute.getArguments().iterator().next();
    assertEquals("argument", argument.getName());
    assertEquals(String.class, argument.getType());
    assertEquals("abc", argument.getValue());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) Argument(com.yahoo.elide.core.request.Argument) Attribute(com.yahoo.elide.core.request.Attribute) PersistentResourceFetcherTest(com.yahoo.elide.graphql.PersistentResourceFetcherTest) Test(org.junit.jupiter.api.Test)

Aggregations

Attribute (com.yahoo.elide.core.request.Attribute)24 Test (org.junit.jupiter.api.Test)19 EntityProjection (com.yahoo.elide.core.request.EntityProjection)11 TableExport (com.yahoo.elide.async.models.TableExport)9 LinkedHashSet (java.util.LinkedHashSet)8 LinkedHashMap (java.util.LinkedHashMap)5 Argument (com.yahoo.elide.core.request.Argument)4 PersistentResource (com.yahoo.elide.core.PersistentResource)3 Resource (com.yahoo.elide.jsonapi.models.Resource)3 PersistentResourceFetcherTest (com.yahoo.elide.graphql.PersistentResourceFetcherTest)2 PatchRequestScope (com.yahoo.elide.jsonapi.extensions.PatchRequestScope)2 Parent (example.Parent)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Path (com.yahoo.elide.core.Path)1 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 BadRequestException (com.yahoo.elide.core.exceptions.BadRequestException)1 InvalidEntityBodyException (com.yahoo.elide.core.exceptions.InvalidEntityBodyException)1 InvalidParameterizedAttributeException (com.yahoo.elide.core.exceptions.InvalidParameterizedAttributeException)1