use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseDefinition in project sechub by mercedes-benz.
the class UseCaseModel method getAnnotatedDef.
private UseCaseDef getAnnotatedDef(Class<?> clazzToFetch) {
UseCaseDef d = new UseCaseDef();
UseCaseDefinition def = clazzToFetch.getAnnotation(UseCaseDefinition.class);
if (def != null) {
d.title = def.title();
d.description = def.description();
d.group = convert(def.group());
} else {
PDSUseCaseDefinition pdsDef = clazzToFetch.getAnnotation(PDSUseCaseDefinition.class);
d.title = pdsDef.title();
d.description = pdsDef.description();
d.group = convert(pdsDef.group());
}
return d;
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseDefinition in project sechub by mercedes-benz.
the class UsecaseIdentifierUniqueUsageTest method usecases_are_using_apinames_only_one_time_means_unique.
/**
* This test is very important: if two annotations are using the same apiName,
* the OpenAPI file will be messed up. It is really important that an automated
* test checks for the apiName uniqueness.
*/
@Test
public void usecases_are_using_apinames_only_one_time_means_unique() {
Reflections reflections = ReflectionsFactory.create();
Map<String, String> map = new HashMap<>();
Set<Class<?>> usesCaseAnnotations = reflections.getTypesAnnotatedWith(UseCaseDefinition.class);
for (Class<?> clazz : usesCaseAnnotations) {
UseCaseDefinition useCaseDefinition = clazz.getAnnotation(UseCaseDefinition.class);
String apiName = useCaseDefinition.apiName();
if (APIConstants.NO_API_AVAILABLE.equals(apiName)) {
continue;
}
String annotationName = clazz.getSimpleName();
String foundAnnotationName = map.get(apiName);
if (foundAnnotationName != null) {
throw new IllegalStateException("Duplicate usage of apiName() found!\n" + annotationName + " uses API name: " + apiName + ", \n but this API name is already used by: " + foundAnnotationName);
}
map.put(apiName, annotationName);
}
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseDefinition in project sechub by mercedes-benz.
the class UsecaseIdentifierUniqueUsageTest method usecases_are_using_identifiers_only_one_time_means_unique.
/**
* This test is very important: if two annotations are using the same
* {@link UseCaseIdentifier} as id the documentation will forget the second one!
* So its really important that this is shown by an automated test
*/
@Test
public void usecases_are_using_identifiers_only_one_time_means_unique() {
Reflections reflections = ReflectionsFactory.create();
Map<String, String> map = new HashMap<>();
Set<Class<?>> usesCaseAnnotations = reflections.getTypesAnnotatedWith(UseCaseDefinition.class);
for (Class<?> clazz : usesCaseAnnotations) {
UseCaseDefinition def = clazz.getAnnotation(UseCaseDefinition.class);
String enumName = def.id().name();
String annotationName = clazz.getSimpleName();
String foundAnnotationName = map.get(enumName);
if (foundAnnotationName != null) {
throw new IllegalStateException("Duplicate usage of UseCaseIdentifier found!\n" + annotationName + " uses identifier enum:" + enumName + "," + "\n but this id is already used by:\n" + foundAnnotationName);
}
map.put(enumName, annotationName);
}
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseDefinition in project sechub by mercedes-benz.
the class RestDocFactory method createSummary.
public static String createSummary(Class<? extends Annotation> useCase) {
UseCaseDefinition usecaseAnnotation = useCase.getAnnotation(UseCaseDefinition.class);
StringBuilder sb = new StringBuilder();
if (usecaseAnnotation == null) {
throw new IllegalArgumentException("given use case must have annotation of use case definition inside but has not: " + useCase);
} else {
sb.append(usecaseAnnotation.title());
}
return sb.toString();
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseDefinition in project sechub by mercedes-benz.
the class UseCaseModel method fetchId.
private UseCaseId fetchId(Class<? extends Annotation> clazz) {
UseCaseId r = new UseCaseId();
Class<? extends Annotation> clazzToFetch = DocReflectionUtil.resolveUnproxiedClass(clazz);
UseCaseDefinition definition = clazzToFetch.getAnnotation(UseCaseDefinition.class);
if (definition != null) {
UseCaseIdentifier ide = definition.id();
r.name = ide.name();
r.uniqueId = ide.uniqueId();
return r;
}
PDSUseCaseDefinition definition2 = clazzToFetch.getAnnotation(PDSUseCaseDefinition.class);
if (definition2 == null) {
throw new IllegalStateException("cannot fetch id from " + clazz);
}
PDSUseCaseIdentifier ide = definition2.id();
r.name = ide.name();
r.uniqueId = ide.uniqueId();
return r;
}
Aggregations