Search in sources :

Example 66 with EntityDictionary

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

the class JsonApiModelResolverTest method setup.

@BeforeAll
public void setup() {
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(ENTITIES.get(KEY_BOOK));
    dictionary.bindEntity(ENTITIES.get(KEY_PUBLISHER));
    dictionary.bindEntity(ENTITIES.get(KEY_AUTHOR));
    converters = ModelConverters.getInstance();
    converters.addConverter(new JsonApiModelResolver(dictionary));
}
Also used : EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 67 with EntityDictionary

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

the class ConfigStoreIntegrationTestSetup method buildDictionary.

@Bean
public EntityDictionary buildDictionary(AutowireCapableBeanFactory beanFactory, ClassScanner scanner, @Autowired(required = false) DynamicConfiguration dynamicConfig, ElideConfigProperties settings, @Qualifier("entitiesToExclude") Set<Type<?>> entitiesToExclude) {
    Map<String, Class<? extends Check>> checks = new HashMap<>();
    if (settings.getDynamicConfig().isConfigApiEnabled()) {
        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) {
            beanFactory.autowireBean(entity);
        }

        @Override
        public <T> T instantiate(Class<T> cls) {
            return beanFactory.createBean(cls);
        }
    }, // Serde Lookup
    CoerceUtil::lookup, entitiesToExclude, scanner);
    return dictionary;
}
Also used : HashMap(java.util.HashMap) Check(com.yahoo.elide.core.security.checks.Check) CoerceUtil(com.yahoo.elide.core.utils.coerce.CoerceUtil) Injector(com.yahoo.elide.core.dictionary.Injector) ConfigChecks(com.yahoo.elide.modelconfig.store.models.ConfigChecks) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Bean(org.springframework.context.annotation.Bean)

Example 68 with EntityDictionary

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

the class VerifyFieldAccessFilterExpressionVisitorTest method setupMocks.

@BeforeEach
public void setupMocks() {
    // this will test with the default interface implementation
    scope = mock(RequestScope.class);
    PermissionExecutor permissionExecutor = mock(PermissionExecutor.class);
    DataStoreTransaction transaction = mock(DataStoreTransaction.class);
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(Book.class);
    dictionary.bindEntity(Author.class);
    when(scope.getDictionary()).thenReturn(dictionary);
    when(scope.getPermissionExecutor()).thenReturn(permissionExecutor);
    when(scope.getTransaction()).thenReturn(transaction);
    when(permissionExecutor.evaluateFilterJoinUserChecks(any(), any())).thenCallRealMethod();
    when(permissionExecutor.handleFilterJoinReject(any(), any(), any())).thenCallRealMethod();
}
Also used : PermissionExecutor(com.yahoo.elide.core.security.PermissionExecutor) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) RequestScope(com.yahoo.elide.core.RequestScope) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 69 with EntityDictionary

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

the class RSQLFilterDialectWithFIQLCompliantStrategyTest method init.

@BeforeAll
public static void init() {
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(Author.class);
    dictionary.bindEntity(Book.class);
    dialect = RSQLFilterDialect.builder().dictionary(dictionary).caseSensitivityStrategy(new CaseSensitivityStrategy.FIQLCompliant()).build();
}
Also used : EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 70 with EntityDictionary

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

the class PermissionExecutorTest method newResource.

public <T> PersistentResource<T> newResource(T obj, Class<T> cls, boolean markNew) {
    EntityDictionary dictionary = EntityDictionary.builder().checks(TestCheckMappings.MAPPINGS).build();
    dictionary.bindEntity(cls);
    RequestScope requestScope = new RequestScope(null, null, NO_VERSION, null, null, null, null, null, UUID.randomUUID(), getElideSettings(dictionary));
    PersistentResource resource = new PersistentResource<>(obj, requestScope.getUUIDFor(obj), requestScope);
    if (markNew) {
        requestScope.getNewPersistentResources().add(resource);
    }
    return resource;
}
Also used : PersistentResource(com.yahoo.elide.core.PersistentResource) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RequestScope(com.yahoo.elide.core.RequestScope)

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