Search in sources :

Example 6 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class VerboseErrorResponsesTestBinder method configure.

@Override
protected void configure() {
    EntityDictionary dictionary = EntityDictionary.builder().injector(injector::inject).checks(TestCheckMappings.MAPPINGS).build();
    bind(dictionary).to(EntityDictionary.class);
    // Elide instance
    bindFactory(new Factory<Elide>() {

        @Override
        public Elide provide() {
            DefaultFilterDialect defaultFilterStrategy = new DefaultFilterDialect(dictionary);
            RSQLFilterDialect rsqlFilterStrategy = RSQLFilterDialect.builder().dictionary(dictionary).build();
            MultipleFilterDialect multipleFilterStrategy = new MultipleFilterDialect(Arrays.asList(rsqlFilterStrategy, defaultFilterStrategy), Arrays.asList(rsqlFilterStrategy, defaultFilterStrategy));
            Elide elide = new Elide(new ElideSettingsBuilder(getDataStore()).withAuditLogger(auditLogger).withJoinFilterDialect(multipleFilterStrategy).withSubqueryFilterDialect(multipleFilterStrategy).withEntityDictionary(dictionary).withVerboseErrors().build());
            elide.doScans();
            return elide;
        }

        @Override
        public void dispose(Elide elide) {
        // do nothing
        }
    }).to(Elide.class).named("elide");
    bind(new BillingService() {

        @Override
        public long purchase(Invoice invoice) {
            return 0;
        }
    }).to(BillingService.class);
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Invoice(example.models.triggers.Invoice) MultipleFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.MultipleFilterDialect) DefaultFilterDialect(com.yahoo.elide.core.filter.dialect.jsonapi.DefaultFilterDialect) Elide(com.yahoo.elide.Elide) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) BillingService(example.models.triggers.services.BillingService)

Example 7 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class DefaultAsyncAPIDAOTest method setupMocks.

@BeforeEach
public void setupMocks() {
    dataStore = mock(DataStore.class);
    asyncQuery = mock(AsyncQuery.class);
    asyncQueryResult = mock(AsyncQueryResult.class);
    filter = mock(FilterExpression.class);
    tx = mock(DataStoreTransaction.class);
    Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
    EntityDictionary dictionary = EntityDictionary.builder().checks(checkMappings).build();
    dictionary.bindEntity(AsyncQuery.class);
    dictionary.bindEntity(AsyncQueryResult.class);
    ElideSettings elideSettings = new ElideSettingsBuilder(dataStore).withEntityDictionary(dictionary).withJoinFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withSubqueryFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build();
    elide = new Elide(elideSettings);
    when(dataStore.beginTransaction()).thenReturn(tx);
    asyncAPIDAO = new DefaultAsyncAPIDAO(elide.getElideSettings(), dataStore);
}
Also used : HashMap(java.util.HashMap) Check(com.yahoo.elide.core.security.checks.Check) AsyncQueryResult(com.yahoo.elide.async.models.AsyncQueryResult) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) DataStore(com.yahoo.elide.core.datastore.DataStore) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) ElideSettings(com.yahoo.elide.ElideSettings) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Elide(com.yahoo.elide.Elide) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class AsyncAPICancelRunnableTest method setupMocks.

@BeforeEach
public void setupMocks() {
    HashMapDataStore inMemoryStore = new HashMapDataStore(DefaultClassScanner.getInstance(), AsyncQuery.class.getPackage());
    Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
    elide = new Elide(new ElideSettingsBuilder(inMemoryStore).withEntityDictionary(EntityDictionary.builder().checks(checkMappings).build()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build());
    asyncAPIDao = mock(DefaultAsyncAPIDAO.class);
    cancelThread = new AsyncAPICancelRunnable(7, elide, asyncAPIDao);
    transactionRegistry = elide.getTransactionRegistry();
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMap(java.util.HashMap) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) Check(com.yahoo.elide.core.security.checks.Check) Elide(com.yahoo.elide.Elide) DefaultAsyncAPIDAO(com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class AsyncAPICleanerRunnableTest method setupMocks.

@BeforeEach
public void setupMocks() {
    HashMapDataStore inMemoryStore = new HashMapDataStore(DefaultClassScanner.getInstance(), AsyncQuery.class.getPackage());
    Map<String, Class<? extends Check>> checkMappings = new HashMap<>();
    elide = new Elide(new ElideSettingsBuilder(inMemoryStore).withEntityDictionary(EntityDictionary.builder().checks(checkMappings).build()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).build());
    asyncAPIDao = mock(DefaultAsyncAPIDAO.class);
    dateUtil = mock(DateUtil.class);
    cleanerThread = new AsyncAPICleanerRunnable(7, elide, 7, asyncAPIDao, dateUtil);
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMap(java.util.HashMap) DateUtil(com.yahoo.elide.async.service.DateUtil) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) AsyncQuery(com.yahoo.elide.async.models.AsyncQuery) Check(com.yahoo.elide.core.security.checks.Check) Elide(com.yahoo.elide.Elide) DefaultAsyncAPIDAO(com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class JMSDataStoreTest method testLoadObjects.

@Test
public void testLoadObjects() throws Exception {
    Author author1 = new Author();
    author1.setId(1);
    author1.setName("Jon Doe");
    Book book1 = new Book();
    book1.setTitle("Enders Game");
    book1.setId(1);
    book1.setAuthors(Sets.newHashSet(author1));
    Book book2 = new Book();
    book2.setTitle("Grapes of Wrath");
    book2.setId(2);
    try (DataStoreTransaction tx = store.beginReadTransaction()) {
        RequestScope scope = new RequestScope("/json", "/", NO_VERSION, null, tx, null, null, Collections.EMPTY_MAP, UUID.randomUUID(), new ElideSettingsBuilder(store).withEntityDictionary(dictionary).build());
        Iterable<Book> books = tx.loadObjects(EntityProjection.builder().argument(Argument.builder().name("topic").value(TopicType.ADDED).build()).type(Book.class).build(), scope);
        JMSContext context = connectionFactory.createContext();
        Destination destination = context.createTopic("bookAdded");
        JMSProducer producer = context.createProducer();
        ObjectMapper mapper = new ObjectMapper();
        producer.send(destination, mapper.writeValueAsString(book1));
        producer.send(destination, mapper.writeValueAsString(book2));
        Iterator<Book> booksIterator = books.iterator();
        assertTrue(booksIterator.hasNext());
        Book receivedBook = booksIterator.next();
        assertEquals("Enders Game", receivedBook.getTitle());
        assertEquals(1, receivedBook.getId());
        Set<Author> receivedAuthors = Sets.newHashSet((Iterable) tx.getToManyRelation(tx, receivedBook, Relationship.builder().name("authors").projection(EntityProjection.builder().type(Author.class).build()).build(), scope));
        assertTrue(receivedAuthors.contains(author1));
        assertTrue(booksIterator.hasNext());
        receivedBook = booksIterator.next();
        assertEquals("Grapes of Wrath", receivedBook.getTitle());
        assertEquals(2, receivedBook.getId());
        assertFalse(booksIterator.hasNext());
    }
}
Also used : Destination(javax.jms.Destination) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Book(example.Book) Author(example.Author) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) JMSProducer(javax.jms.JMSProducer) RequestScope(com.yahoo.elide.core.RequestScope) JMSContext(javax.jms.JMSContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)30 Elide (com.yahoo.elide.Elide)20 Check (com.yahoo.elide.core.security.checks.Check)12 HashMap (java.util.HashMap)12 HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10 RequestScope (com.yahoo.elide.core.RequestScope)9 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)7 Test (org.junit.jupiter.api.Test)7 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)5 RSQLFilterDialect (com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)5 User (com.yahoo.elide.core.security.User)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 ElideSettings (com.yahoo.elide.ElideSettings)4 AsyncQuery (com.yahoo.elide.async.models.AsyncQuery)4 Slf4jLogger (com.yahoo.elide.core.audit.Slf4jLogger)4 TestAuditLogger (com.yahoo.elide.core.audit.TestAuditLogger)4 ElideResponse (com.yahoo.elide.ElideResponse)3 DefaultAsyncAPIDAO (com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO)3 FileResultStorageEngine (com.yahoo.elide.async.service.storageengine.FileResultStorageEngine)3