use of dev.hilla.Endpoint in project flow by vaadin.
the class GeneratorUtilsTest method should_BeConsideredAsHavingAnAnnotation_When_GivenClassHavsAnnotationDeclarationAndTheImport.
@Test
public void should_BeConsideredAsHavingAnAnnotation_When_GivenClassHavsAnnotationDeclarationAndTheImport() {
NodeWithAnnotations<?> declarationWithEndpointAnnotation = Mockito.mock(NodeWithAnnotations.class);
CompilationUnit compilationUnitWithVaadinEndpointImport = Mockito.mock(CompilationUnit.class);
AnnotationExpr endpointAnnotation = Mockito.mock(AnnotationExpr.class);
Mockito.doReturn(Optional.of(endpointAnnotation)).when(declarationWithEndpointAnnotation).getAnnotationByClass(Endpoint.class);
NodeList<ImportDeclaration> imports = new NodeList<>();
ImportDeclaration importDeclaration = Mockito.mock(ImportDeclaration.class);
Mockito.doReturn(Endpoint.class.getName()).when(importDeclaration).getNameAsString();
imports.add(importDeclaration);
Mockito.doReturn(imports).when(compilationUnitWithVaadinEndpointImport).getImports();
Assert.assertTrue("A class with a Vaadin Endpoint should be considered as an Endpoint", GeneratorUtils.hasAnnotation(declarationWithEndpointAnnotation, compilationUnitWithVaadinEndpointImport, Endpoint.class));
}
use of dev.hilla.Endpoint in project flow by vaadin.
the class AbstractEndpointGenerationTest method assertClassPathsRecursive.
private int assertClassPathsRecursive(Paths actualPaths, Class<?> testEndpointClass, Class<?> testMethodsClass, HashMap<String, Class<?>> typeArguments) {
if (!testMethodsClass.equals(testEndpointClass) && !testMethodsClass.isAnnotationPresent(EndpointExposed.class)) {
return 0;
}
int pathCount = 0;
for (Method expectedEndpointMethod : testMethodsClass.getDeclaredMethods()) {
if (!Modifier.isPublic(expectedEndpointMethod.getModifiers()) || accessChecker.getAccessAnnotationChecker().getSecurityTarget(expectedEndpointMethod).isAnnotationPresent(DenyAll.class)) {
continue;
}
pathCount++;
String expectedEndpointUrl = String.format("/%s/%s", getEndpointName(testEndpointClass), expectedEndpointMethod.getName());
PathItem actualPath = actualPaths.get(expectedEndpointUrl);
assertNotNull(String.format("Expected to find a path '%s' for the endpoint method '%s' in the class '%s'", expectedEndpointUrl, expectedEndpointMethod, testEndpointClass), actualPath);
assertPath(testEndpointClass, expectedEndpointMethod, actualPath, typeArguments);
}
Type genericSuperClass = testMethodsClass.getGenericSuperclass();
pathCount += assertClassPathsRecursive(actualPaths, testEndpointClass, applyTypeArguments(genericSuperClass, typeArguments), extractTypeArguments(genericSuperClass, typeArguments));
for (Type genericInterface : testMethodsClass.getGenericInterfaces()) {
pathCount += assertClassPathsRecursive(actualPaths, testEndpointClass, applyTypeArguments(genericInterface, typeArguments), extractTypeArguments(genericInterface, typeArguments));
}
return pathCount;
}
use of dev.hilla.Endpoint in project flow by vaadin.
the class AbstractEndpointGenerationTest method assertComponentSchemas.
private void assertComponentSchemas(Map<String, Schema> actualSchemas, List<Class<?>> testEndpointClasses) {
int schemasCount = 0;
for (Class<?> expectedSchemaClass : testEndpointClasses) {
schemasCount++;
Schema actualSchema = actualSchemas.get(expectedSchemaClass.getCanonicalName());
assertNotNull(String.format("Expected to have a schema defined for a class '%s'", expectedSchemaClass), actualSchema);
assertSchema(actualSchema, expectedSchemaClass, new HashMap<>());
}
assertEquals("Expected to have all endpoint classes defined in schemas", schemasCount, actualSchemas.size());
}
use of dev.hilla.Endpoint in project flow by vaadin.
the class AbstractEndpointGenerationTest method assertRequestSchema.
private void assertRequestSchema(Schema requestSchema, Class<?>[] parameterTypes, List<HashMap<String, Class<?>>> parameterTypeArguments, Parameter[] parameters) {
Map<String, Schema> properties = requestSchema.getProperties();
assertEquals("Request schema should have the same amount of properties as the corresponding endpoint method parameters number", parameterTypes.length, properties.size());
int index = 0;
for (Map.Entry<String, Schema> stringSchemaEntry : properties.entrySet()) {
assertSchema(stringSchemaEntry.getValue(), parameterTypes[index], parameterTypeArguments.get(index));
List requiredList = requestSchema.getRequired();
assertTrue(requiredList.contains(stringSchemaEntry.getKey()));
index++;
}
}
use of dev.hilla.Endpoint in project flow by vaadin.
the class GeneratorUtilsTest method should_Not_BeConsideredAsHavingAnAnnotation_When_GivenClassDoesNotHaveAnnotationDeclarationNorImport.
@Test
public void should_Not_BeConsideredAsHavingAnAnnotation_When_GivenClassDoesNotHaveAnnotationDeclarationNorImport() {
NodeWithAnnotations<?> declarationWithoutEndpointAnnotation = Mockito.mock(NodeWithAnnotations.class);
CompilationUnit compilationUnitWithoutEndpointImport = Mockito.mock(CompilationUnit.class);
Mockito.doReturn(Optional.empty()).when(declarationWithoutEndpointAnnotation).getAnnotationByClass(Endpoint.class);
Mockito.doReturn(new NodeList<>()).when(compilationUnitWithoutEndpointImport).getImports();
Assert.assertFalse("A class without Endpoint annotation nor import should not be considered as an Endpoint", GeneratorUtils.hasAnnotation(declarationWithoutEndpointAnnotation, compilationUnitWithoutEndpointImport, Endpoint.class));
}
Aggregations