Search in sources :

Example 61 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class MatchesTemplateVisitorTest method setup.

@BeforeEach
public void setup() {
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(PlayerStats.class);
    dictionary.bindEntity(Player.class);
    dictionary.addArgumentToAttribute(dictionary.getEntityClass("playerStats", EntityDictionary.NO_VERSION), "recordedDate", new ArgumentType("grain", ClassType.STRING_TYPE, TimeGrain.DAY));
    dialect = RSQLFilterDialect.builder().dictionary(dictionary).addDefaultArguments(false).build();
}
Also used : ArgumentType(com.yahoo.elide.core.dictionary.ArgumentType) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 62 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class SplitFilterExpressionVisitorTest method setupEntityDictionary.

@BeforeAll
public static void setupEntityDictionary() {
    EntityDictionary entityDictionary = EntityDictionary.builder().build();
    entityDictionary.bindEntity(PlayerStats.class);
    entityDictionary.bindEntity(Country.class);
    entityDictionary.bindEntity(SubCountry.class);
    entityDictionary.bindEntity(Player.class);
    Namespace namespace = new Namespace(DEFAULT_NAMESPACE);
    Table table = new SQLTable(namespace, ClassType.of(PlayerStats.class), entityDictionary);
    splitFilterExpressionVisitor = new SplitFilterExpressionVisitor(table);
}
Also used : SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) PlayerStats(example.PlayerStats) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 63 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class JoinPathTest method init.

@BeforeAll
public static void init() {
    Set<Type<?>> models = new HashSet<>();
    models.add(ClassType.of(PlayerStats.class));
    models.add(ClassType.of(CountryView.class));
    models.add(ClassType.of(Country.class));
    models.add(ClassType.of(SubCountry.class));
    models.add(ClassType.of(Player.class));
    models.add(ClassType.of(PlayerRanking.class));
    models.add(ClassType.of(CountryViewNested.class));
    models.add(ClassType.of(PlayerStatsWithView.class));
    EntityDictionary dictionary = EntityDictionary.builder().build();
    models.stream().forEach(dictionary::bindEntity);
    store = new MetaDataStore(dictionary.getScanner(), models, true);
    store.populateEntityDictionary(dictionary);
    DataSource mockDataSource = mock(DataSource.class);
    // The query engine populates the metadata store with actual tables.
    new SQLQueryEngine(store, (unused) -> new ConnectionDetails(mockDataSource, SQLDialectFactory.getDefaultDialect()));
}
Also used : SQLQueryEngine(com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine) Player(example.Player) CountryViewNested(example.dimensions.CountryViewNested) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) ConnectionDetails(com.yahoo.elide.datastores.aggregation.queryengines.sql.ConnectionDetails) PlayerStats(example.PlayerStats) SubCountry(example.dimensions.SubCountry) DataSource(javax.sql.DataSource) ClassType(com.yahoo.elide.core.type.ClassType) Type(com.yahoo.elide.core.type.Type) PlayerStatsWithView(example.PlayerStatsWithView) PlayerRanking(example.PlayerRanking) SubCountry(example.dimensions.SubCountry) Country(example.dimensions.Country) CountryView(example.dimensions.CountryView) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) HashSet(java.util.HashSet) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 64 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class ElideStandaloneConfigStoreTest method init.

@BeforeAll
public void init() throws Exception {
    configRoot = Files.createTempDirectory("test");
    settings = new ElideStandaloneTestSettings() {

        @Override
        public EntityDictionary getEntityDictionary(ServiceLocator injector, ClassScanner scanner, Optional<DynamicConfiguration> dynamicConfiguration, Set<Type<?>> entitiesToExclude) {
            Map<String, Class<? extends Check>> checks = new HashMap<>();
            if (getAnalyticProperties().enableDynamicModelConfigAPI()) {
                checks.put(ConfigChecks.CAN_CREATE_CONFIG, ConfigChecks.CanCreate.class);
                checks.put(ConfigChecks.CAN_READ_CONFIG, ConfigChecks.CanRead.class);
                checks.put(ConfigChecks.CAN_DELETE_CONFIG, ConfigChecks.CanDelete.class);
                checks.put(ConfigChecks.CAN_UPDATE_CONFIG, ConfigChecks.CanNotUpdate.class);
            }
            EntityDictionary dictionary = new EntityDictionary(// Checks
            checks, // Role Checks
            new HashMap<>(), new Injector() {

                @Override
                public void inject(Object entity) {
                    injector.inject(entity);
                }

                @Override
                public <T> T instantiate(Class<T> cls) {
                    return injector.create(cls);
                }
            }, // Serde Lookup
            CoerceUtil::lookup, entitiesToExclude, scanner);
            dynamicConfiguration.map(DynamicConfiguration::getRoles).orElseGet(Collections::emptySet).forEach(role -> dictionary.addRoleCheck(role, new Role.RoleMemberCheck(role)));
            return dictionary;
        }

        @Override
        public ElideStandaloneAnalyticSettings getAnalyticProperties() {
            return new ElideStandaloneAnalyticSettings() {

                @Override
                public boolean enableDynamicModelConfig() {
                    return true;
                }

                @Override
                public boolean enableDynamicModelConfigAPI() {
                    return true;
                }

                @Override
                public String getDynamicConfigPath() {
                    return configRoot.toFile().getAbsolutePath();
                }

                @Override
                public boolean enableAggregationDataStore() {
                    return true;
                }

                @Override
                public boolean enableMetaDataStore() {
                    return true;
                }
            };
        }
    };
    elide = new ElideStandalone(settings);
    elide.start(false);
}
Also used : ElideStandalone(com.yahoo.elide.standalone.ElideStandalone) HttpStatus(com.yahoo.elide.core.exceptions.HttpStatus) DynamicConfiguration(com.yahoo.elide.modelconfig.DynamicConfiguration) JSONAPI_CONTENT_TYPE(com.yahoo.elide.Elide.JSONAPI_CONTENT_TYPE) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ElideStandaloneSettings(com.yahoo.elide.standalone.config.ElideStandaloneSettings) HashMap(java.util.HashMap) Role(com.yahoo.elide.core.security.checks.prefab.Role) JsonApiDSL.attr(com.yahoo.elide.test.jsonapi.JsonApiDSL.attr) AfterAll(org.junit.jupiter.api.AfterAll) MediaType(javax.ws.rs.core.MediaType) TestInstance(org.junit.jupiter.api.TestInstance) BeforeAll(org.junit.jupiter.api.BeforeAll) GraphQLDSL.mutation(com.yahoo.elide.test.graphql.GraphQLDSL.mutation) ClassScanner(com.yahoo.elide.core.utils.ClassScanner) Injector(com.yahoo.elide.core.dictionary.Injector) Map(java.util.Map) RestAssured.when(io.restassured.RestAssured.when) GraphQLDSL.argument(com.yahoo.elide.test.graphql.GraphQLDSL.argument) JsonApiDSL.datum(com.yahoo.elide.test.jsonapi.JsonApiDSL.datum) Path(java.nio.file.Path) JsonApiDSL.type(com.yahoo.elide.test.jsonapi.JsonApiDSL.type) JsonApiDSL.links(com.yahoo.elide.test.jsonapi.JsonApiDSL.links) GraphQLDSL.selection(com.yahoo.elide.test.graphql.GraphQLDSL.selection) JsonApiDSL.attributes(com.yahoo.elide.test.jsonapi.JsonApiDSL.attributes) Check(com.yahoo.elide.core.security.checks.Check) Files(java.nio.file.Files) GraphQLDSL.selections(com.yahoo.elide.test.graphql.GraphQLDSL.selections) GraphQLDSL.field(com.yahoo.elide.test.graphql.GraphQLDSL.field) ElideStandaloneAnalyticSettings(com.yahoo.elide.standalone.config.ElideStandaloneAnalyticSettings) Set(java.util.Set) ConfigChecks(com.yahoo.elide.modelconfig.store.models.ConfigChecks) CoerceUtil(com.yahoo.elide.core.utils.coerce.CoerceUtil) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) JsonApiDSL.resource(com.yahoo.elide.test.jsonapi.JsonApiDSL.resource) GraphQLDSL(com.yahoo.elide.test.graphql.GraphQLDSL) Test(org.junit.jupiter.api.Test) JsonApiDSL.id(com.yahoo.elide.test.jsonapi.JsonApiDSL.id) GraphQLDSL.arguments(com.yahoo.elide.test.graphql.GraphQLDSL.arguments) JsonApiDSL.data(com.yahoo.elide.test.jsonapi.JsonApiDSL.data) Type(com.yahoo.elide.core.type.Type) Optional(java.util.Optional) RestAssured.given(io.restassured.RestAssured.given) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Collections(java.util.Collections) HashMap(java.util.HashMap) ClassScanner(com.yahoo.elide.core.utils.ClassScanner) DynamicConfiguration(com.yahoo.elide.modelconfig.DynamicConfiguration) Injector(com.yahoo.elide.core.dictionary.Injector) Collections(java.util.Collections) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) ElideStandaloneAnalyticSettings(com.yahoo.elide.standalone.config.ElideStandaloneAnalyticSettings) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Role(com.yahoo.elide.core.security.checks.prefab.Role) MediaType(javax.ws.rs.core.MediaType) Type(com.yahoo.elide.core.type.Type) ElideStandalone(com.yahoo.elide.standalone.ElideStandalone) HashMap(java.util.HashMap) Map(java.util.Map) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 65 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class SwaggerBuilderTest method testSortParameter.

@Test
public void testSortParameter() {
    @Entity
    @Include
    class NothingToSort {

        @Id
        long name;
    }
    EntityDictionary entityDictionary = EntityDictionary.builder().build();
    entityDictionary.bindEntity(NothingToSort.class);
    Info info = new Info().title("Test Service").version(NO_VERSION);
    SwaggerBuilder builder = new SwaggerBuilder(entityDictionary, info);
    Swagger testSwagger = builder.build();
    List<Parameter> params = testSwagger.getPaths().get("/nothingToSort").getGet().getParameters();
    QueryParameter sortParam = (QueryParameter) params.stream().filter((param) -> param.getName().equals("sort")).findFirst().get();
    assertEquals("query", sortParam.getIn());
    List<String> sortValues = Arrays.asList("id", "-id");
    assertEquals(sortValues, ((StringProperty) sortParam.getItems()).getEnum());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Resource(com.yahoo.elide.swagger.model.Resource) Arrays(java.util.Arrays) Data(com.yahoo.elide.swagger.property.Data) Swagger(io.swagger.models.Swagger) Tag(io.swagger.models.Tag) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Include(com.yahoo.elide.annotation.Include) StringProperty(io.swagger.models.properties.StringProperty) HashMap(java.util.HashMap) Publisher(example.models.Publisher) ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) TestInstance(org.junit.jupiter.api.TestInstance) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Author(example.models.Author) BeforeAll(org.junit.jupiter.api.BeforeAll) Path(io.swagger.models.Path) Map(java.util.Map) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) Book(example.models.Book) RefProperty(io.swagger.models.properties.RefProperty) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Operation(io.swagger.models.Operation) Datum(com.yahoo.elide.swagger.property.Datum) Property(io.swagger.models.properties.Property) Id(javax.persistence.Id) Entity(javax.persistence.Entity) BodyParameter(io.swagger.models.parameters.BodyParameter) Set(java.util.Set) Parameter(io.swagger.models.parameters.Parameter) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Info(io.swagger.models.Info) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.junit.jupiter.api.Test) Response(io.swagger.models.Response) ObjectProperty(io.swagger.models.properties.ObjectProperty) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Relationship(com.yahoo.elide.swagger.property.Relationship) Optional(java.util.Optional) Entity(javax.persistence.Entity) QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) Include(com.yahoo.elide.annotation.Include) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Info(io.swagger.models.Info) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Test(org.junit.jupiter.api.Test)

Aggregations

EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)87 Test (org.junit.jupiter.api.Test)31 RequestScope (com.yahoo.elide.core.RequestScope)27 Include (com.yahoo.elide.annotation.Include)17 Entity (javax.persistence.Entity)17 HashSet (java.util.HashSet)16 Type (com.yahoo.elide.core.type.Type)13 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)12 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)10 Map (java.util.Map)10 BeforeAll (org.junit.jupiter.api.BeforeAll)10 PersistentResource (com.yahoo.elide.core.PersistentResource)9 Set (java.util.Set)9 ReadPermission (com.yahoo.elide.annotation.ReadPermission)8 ClassType (com.yahoo.elide.core.type.ClassType)8 List (java.util.List)8 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)7 DataStore (com.yahoo.elide.core.datastore.DataStore)7 InvalidObjectIdentifierException (com.yahoo.elide.core.exceptions.InvalidObjectIdentifierException)7 Check (com.yahoo.elide.core.security.checks.Check)7