Skip to content

Commit

Permalink
Process Include in package-info
Browse files Browse the repository at this point in the history
  • Loading branch information
wcekan committed Feb 20, 2021
1 parent c4b29bf commit 6a0a8c2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package com.yahoo.elide.core.datastore.inmemory;

import com.yahoo.elide.annotation.Exclude;
import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.core.DataStore;
import com.yahoo.elide.core.DataStoreTransaction;
Expand All @@ -15,6 +16,7 @@
import com.google.common.collect.Sets;
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand All @@ -23,6 +25,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

import javax.persistence.Entity;

/**
* Simple in-memory only database.
*/
Expand All @@ -42,7 +46,20 @@ public HashMapDataStore(Set<Package> beanPackages) {
for (Package beanPackage : beanPackages) {
ClassScanner.getAnnotatedClasses(beanPackage, Include.class).stream()
.filter(modelClass -> modelClass.getName().startsWith(beanPackage.getName()))
.forEach(modelClass -> dataStore.put(modelClass, Collections.synchronizedMap(new LinkedHashMap<>())));
.filter(modelClass -> dictionary.getFirstAnnotation(modelClass,
Arrays.asList(Include.class, Exclude.class)) instanceof Include)
.forEach(modelClass -> dataStore.put(modelClass,
Collections.synchronizedMap(new LinkedHashMap<>())));
}

for (Package beanPackage : beanPackages) {
ClassScanner.getAnnotatedClasses(beanPackage, Entity.class).stream()
.filter(modelClass -> modelClass.getName().startsWith(beanPackage.getName()))
.filter(modelClass -> !dataStore.containsKey(modelClass))
.filter(modelClass -> dictionary.getFirstAnnotation(modelClass,
Arrays.asList(Include.class, Exclude.class)) instanceof Include)
.forEach(modelClass -> dataStore.put(modelClass,
Collections.synchronizedMap(new LinkedHashMap<>())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.yahoo.elide.core.datastore.inmemory;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -27,6 +28,7 @@
import com.yahoo.elide.core.filter.expression.FilterExpression;
import com.yahoo.elide.core.pagination.Pagination;
import com.yahoo.elide.core.sort.Sorting;
import com.yahoo.elide.models.generics.Manager;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -518,7 +520,8 @@ public void testSortingRequiresInMemoryPagination() {

@Test
public void testInMemoryDataStore() {
HashMapDataStore wrapped = new HashMapDataStore(Book.class.getPackage());
HashMapDataStore wrapped = new HashMapDataStore(Sets.newHashSet(
Book.class.getPackage(), Manager.class.getPackage()));
InMemoryDataStore store = new InMemoryDataStore(wrapped);
DataStoreTransaction tx = store.beginReadTransaction();
assertEquals(InMemoryStoreTransaction.class, tx.getClass());
Expand All @@ -527,7 +530,6 @@ public void testInMemoryDataStore() {

String tos = store.toString();
assertTrue(tos.contains("Data store contents"));
assertTrue(tos.contains("Table class example.NoReadEntity contents"));
assertTrue(tos.contains("Table class example.Author contents"));
assertTrue(tos.contains("Table class example.Book contents"));
assertTrue(tos.contains("Table class example.Child contents"));
Expand All @@ -542,6 +544,7 @@ public void testInMemoryDataStore() {
assertTrue(tos.contains("Table class example.LineItem contents"));
assertTrue(tos.contains("Table class example.MapColorShape contents"));
assertTrue(tos.contains("Table class example.NoDeleteEntity contents"));
assertTrue(tos.contains("Table class example.NoReadEntity contents"));
assertTrue(tos.contains("Table class example.NoShareEntity contents"));
assertTrue(tos.contains("Table class example.NoUpdateEntity contents"));
assertTrue(tos.contains("Table class example.Parent contents"));
Expand All @@ -555,5 +558,8 @@ public void testInMemoryDataStore() {
assertTrue(tos.contains("Table class example.packageshareable.ContainerWithPackageShare contents"));
assertTrue(tos.contains("Table class example.packageshareable.ShareableWithPackageShare contents"));
assertTrue(tos.contains("Table class example.packageshareable.UnshareableWithEntityUnshare contents"));
assertTrue(tos.contains("Table class com.yahoo.elide.models.generics.Employee contents"));
assertTrue(tos.contains("Table class com.yahoo.elide.models.generics.Manager contents"));
assertFalse(tos.contains("Table class com.yahoo.elide.models.generics.Other contents"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2021, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/

package com.yahoo.elide.models.generics;

import com.yahoo.elide.annotation.Exclude;

import javax.persistence.Entity;

/**
* Helper class to test parameterized subclass/superclass hierarchies.
*/
@Entity
@Exclude
public class Other extends Peon<Manager> {
}

0 comments on commit 6a0a8c2

Please sign in to comment.