use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class JpaDataStoreTest method verifyJPQLGeneratorRegistration.
@Test
public void verifyJPQLGeneratorRegistration() {
@Include(rootLevel = false)
@Entity
class Test {
@Id
private long id;
@JPQLFilterFragment(operator = Operator.IN, generator = TestGenerator.class)
private String name;
}
EntityType mockType = mock(EntityType.class);
when(mockType.getJavaType()).thenReturn(Test.class);
Metamodel mockModel = mock(Metamodel.class);
when(mockModel.getEntities()).thenReturn(Sets.newHashSet(mockType));
EntityManager managerMock = mock(EntityManager.class);
when(managerMock.getMetamodel()).thenReturn(mockModel);
JpaDataStore store = new JpaDataStore(() -> managerMock, unused -> null);
EntityDictionary dictionary = EntityDictionary.builder().build();
try {
store.populateEntityDictionary(dictionary);
assertNotNull(FilterTranslator.lookupJPQLGenerator(Operator.IN, ClassType.of(Test.class), "name"));
} finally {
FilterTranslator.registerJPQLGenerator(Operator.IN, ClassType.of(Test.class), "name", null);
}
}
use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class TableTypeTest method testHiddenTableAnnotations.
@Test
void testHiddenTableAnnotations() throws Exception {
Table testTable = Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").hidden(true).schema("db1").category("category1").build();
TableType testType = new TableType(testTable);
Include include = (Include) testType.getAnnotation(Include.class);
assertNotNull(include);
TableMeta tableMeta = (TableMeta) testType.getAnnotation(TableMeta.class);
assertNotNull(tableMeta);
assertTrue(tableMeta.isHidden());
}
use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class TableTypeTest method testTableAnnotations.
@Test
void testTableAnnotations() throws Exception {
Set<String> tags = new HashSet<>(Arrays.asList("tag1", "tag2"));
Set<String> hints = new HashSet<>(Arrays.asList("hint1", "hint2"));
Table testTable = Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").schema("db1").category("category1").readAccess("Admin").dbConnectionName("dbConn").isFact(true).filterTemplate("a==b").tags(tags).hints(hints).build();
TableType testType = new TableType(testTable);
Include include = (Include) testType.getAnnotation(Include.class);
assertEquals("Table", include.name());
FromTable fromTable = (FromTable) testType.getAnnotation(FromTable.class);
assertEquals("db1.table1", fromTable.name());
assertEquals("dbConn", fromTable.dbConnectionName());
TableMeta tableMeta = (TableMeta) testType.getAnnotation(TableMeta.class);
assertEquals("foo", tableMeta.friendlyName());
assertEquals(CardinalitySize.MEDIUM, tableMeta.size());
assertEquals("A test table", tableMeta.description());
assertEquals("category1", tableMeta.category());
assertTrue(tableMeta.isFact());
assertEquals(tags, new HashSet<>(Arrays.asList(tableMeta.tags())));
assertEquals(hints, new HashSet<>(Arrays.asList(tableMeta.hints())));
assertEquals("a==b", tableMeta.filterTemplate());
ReadPermission readPermission = (ReadPermission) testType.getAnnotation(ReadPermission.class);
assertEquals("Admin", readPermission.expression());
}
use of com.yahoo.elide.annotation.Include 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());
}
use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class AggregationStorePermissionExecutorTest method testUserPermissions.
@Test
public void testUserPermissions() {
@Entity
@Include
@Value
@ReadPermission(expression = "user none or filter check")
class Model {
String filterDim;
long metric;
long metric2;
@ReadPermission(expression = "user all")
public String getFilterDim() {
return filterDim;
}
@ReadPermission(expression = "user none")
public long getMetric() {
return metric;
}
}
com.yahoo.elide.core.RequestScope scope = bindAndgetRequestScope(Model.class);
PermissionExecutor executor = scope.getPermissionExecutor();
// evaluated expression = user all
Assertions.assertEquals(ExpressionResult.PASS, executor.checkUserPermissions(ClassType.of(Model.class), ReadPermission.class, "filterDim"));
// evaluated expression = user none -> ForbiddenAccess
Assertions.assertThrows(ForbiddenAccessException.class, () -> executor.checkUserPermissions(ClassType.of(Model.class), ReadPermission.class, "metric"));
// evaluated expression = null -> false
Assertions.assertEquals(ExpressionResult.PASS, executor.checkSpecificFieldPermissions(new PersistentResource(new Model("dim1", 0, 1), "1", scope), null, ReadPermission.class, "metric2"));
// evaluated expression = (user none or filter check) AND (user all OR user none)
Assertions.assertEquals(ExpressionResult.DEFERRED, executor.checkUserPermissions(ClassType.of(Model.class), ReadPermission.class, new HashSet<>(Arrays.asList("filterDim", "metric"))));
// evaluated expression = (user all OR user none)
Assertions.assertEquals(ExpressionResult.PASS, executor.checkPermission(ReadPermission.class, new PersistentResource(new Model("dim1", 0, 1), "1", scope), new HashSet<>(Arrays.asList("filterDim", "metric"))));
// evaluated expression = (user none OR null)
Assertions.assertEquals(ExpressionResult.PASS, executor.checkPermission(ReadPermission.class, new PersistentResource(new Model("dim1", 0, 1), "1", scope), new HashSet<>(Arrays.asList("metric", "metric2"))));
}
Aggregations