Search in sources :

Example 11 with DocAnnotationData

use of com.mercedesbenz.sechub.docgen.DocAnnotationData in project sechub by mercedes-benz.

the class ClasspathDataCollectorTest method mustbedocumented_annotation_data_can_be_fetched_and_at_least_one_spring_schedule_documentation_found.

@Test
public void mustbedocumented_annotation_data_can_be_fetched_and_at_least_one_spring_schedule_documentation_found() {
    ClasspathDataCollector collector = new ClasspathDataCollector();
    List<DocAnnotationData> data = collector.fetchMustBeDocumentParts();
    assertNotNull(data);
    assertFalse(data.isEmpty());
    Iterator<DocAnnotationData> iterator = data.iterator();
    boolean atLeastOneDescribedSpringScheduleFound = false;
    while (iterator.hasNext()) {
        DocAnnotationData d = iterator.next();
        assertNotNull(d);
        if (!atLeastOneDescribedSpringScheduleFound) {
            if (d.springScheduled != null) {
                if (d.description != null && !d.description.isEmpty()) {
                    atLeastOneDescribedSpringScheduleFound = true;
                }
            }
        }
    }
    assertTrue(atLeastOneDescribedSpringScheduleFound);
}
Also used : DocAnnotationData(com.mercedesbenz.sechub.docgen.DocAnnotationData) Test(org.junit.Test)

Example 12 with DocAnnotationData

use of com.mercedesbenz.sechub.docgen.DocAnnotationData in project sechub by mercedes-benz.

the class ClasspathDataCollectorTest method mockconfiguration_annotation_data_can_be_fetched_and_at_least_one_spring_value_documentation_found.

@Test
public void mockconfiguration_annotation_data_can_be_fetched_and_at_least_one_spring_value_documentation_found() {
    ClasspathDataCollector collector = new ClasspathDataCollector();
    List<DocAnnotationData> data = collector.fetchMockAdapterSpringValueDocumentationParts();
    assertNotNull(data);
    assertFalse(data.isEmpty());
    Iterator<DocAnnotationData> iterator = data.iterator();
    boolean atLeastOneDescribedSpringValueFound = false;
    while (iterator.hasNext()) {
        DocAnnotationData d = iterator.next();
        assertNotNull(d);
        if (!atLeastOneDescribedSpringValueFound) {
            if (d.springValue != null) {
                if (d.description != null && !d.description.isEmpty()) {
                    atLeastOneDescribedSpringValueFound = true;
                }
            }
        }
    }
    assertTrue(atLeastOneDescribedSpringValueFound);
}
Also used : DocAnnotationData(com.mercedesbenz.sechub.docgen.DocAnnotationData) Test(org.junit.Test)

Example 13 with DocAnnotationData

use of com.mercedesbenz.sechub.docgen.DocAnnotationData in project sechub by mercedes-benz.

the class MockPropertiesDescriptionGenerator method generate.

public String generate(ClasspathDataCollector collector) {
    if (collector == null) {
        return "";
    }
    List<DocAnnotationData> list = collector.fetchMustBeDocumentParts();
    if (list == null || list.isEmpty()) {
        return "";
    }
    StringBuilder sb = new StringBuilder();
    Map<String, SortedSet<TableRow>> rowMap = new TreeMap<>();
    for (DocAnnotationData data : list) {
        if (SimpleStringUtils.isEmpty(data.springValue)) {
            continue;
        }
        SpringValue extracted = springValueExtractor.extract(data.springValue);
        TableRow row = new TableRow();
        row.defaultValue = extracted.getDefaultValue();
        row.propertyKey = extracted.getKey();
        row.description = data.description;
        SortedSet<TableRow> rows = rowMap.get(data.scope);
        if (rows == null) {
            rows = new TreeSet<>();
            rowMap.put(data.scope, rows);
        }
        rows.add(row);
    }
    if (rowMap.isEmpty()) {
        return "";
    }
    for (Map.Entry<String, SortedSet<TableRow>> entries : rowMap.entrySet()) {
        SortedSet<TableRow> table = entries.getValue();
        sb.append("[options=\"header\",cols=\"1,1,1\"]\n");
        sb.append(".").append(buildTitle(entries.getKey()));
        sb.append("\n|===\n");
        sb.append("|Key   |Default   |Description \n");
        sb.append("//----------------------\n");
        for (TableRow row : table) {
            sb.append("|").append(row.propertyKey);
            sb.append("|").append(row.defaultValue);
            sb.append("|").append(row.description);
            sb.append("\n");
        }
        sb.append("\n|===\n\n");
    }
    return sb.toString();
}
Also used : DocAnnotationData(com.mercedesbenz.sechub.docgen.DocAnnotationData) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) SpringValue(com.mercedesbenz.sechub.docgen.spring.SpringValueExtractor.SpringValue) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 14 with DocAnnotationData

use of com.mercedesbenz.sechub.docgen.DocAnnotationData in project sechub by mercedes-benz.

the class MockedAdaptersSpringValueDataCollector method addClassOnly.

private void addClassOnly(Set<Class<?>> types, List<DocAnnotationData> list) {
    for (Class<?> type : types) {
        Set<Method> methods = buildMethods(type);
        Set<Field> fields = buildFields(type);
        /* handle class annotations */
        Value info0 = type.getDeclaredAnnotation(Value.class);
        if (info0 != null) {
            DocAnnotationData data0 = DocGeneratorUtil.buildDataBy(info0, type);
            data0.linkedClass = type;
            list.add(data0);
        }
        /* handle method annotations */
        for (Method method : methods) {
            Value info1 = method.getDeclaredAnnotation(Value.class);
            if (info1 == null) {
                continue;
            }
            DocAnnotationData data1 = DocGeneratorUtil.buildDataBy(info1, method);
            data1.linkedMethod = method;
            list.add(data1);
        }
        /* handle field annotations */
        for (Field field : fields) {
            Value info2 = field.getDeclaredAnnotation(Value.class);
            if (info2 == null) {
                continue;
            }
            DocAnnotationData data2 = DocGeneratorUtil.buildDataBy(info2, field);
            data2.linkedField = field;
            list.add(data2);
        }
    }
}
Also used : Field(java.lang.reflect.Field) Value(org.springframework.beans.factory.annotation.Value) DocAnnotationData(com.mercedesbenz.sechub.docgen.DocAnnotationData) Method(java.lang.reflect.Method)

Example 15 with DocAnnotationData

use of com.mercedesbenz.sechub.docgen.DocAnnotationData in project sechub by mercedes-benz.

the class KubernetesTemplateFilesGenerator method newAnnotationData.

private DocAnnotationData newAnnotationData(String springValue, String scope, String description, boolean secret, String secretFileName) {
    DocAnnotationData data = new DocAnnotationData();
    data.isSecret = secret;
    data.description = description;
    data.scope = scope;
    data.springValue = springValue;
    data.options.put(OPTION_SECRET_FILE_NAME, secretFileName);
    return data;
}
Also used : DocAnnotationData(com.mercedesbenz.sechub.docgen.DocAnnotationData)

Aggregations

DocAnnotationData (com.mercedesbenz.sechub.docgen.DocAnnotationData)24 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)7 Scheduled (org.springframework.scheduling.annotation.Scheduled)4 SortedSet (java.util.SortedSet)3 TreeMap (java.util.TreeMap)3 SpringValue (com.mercedesbenz.sechub.docgen.spring.SpringValueExtractor.SpringValue)2 Map (java.util.Map)2 SpringSchedule (com.mercedesbenz.sechub.docgen.spring.SpringScheduleExtractor.SpringSchedule)1 MustBeDocumented (com.mercedesbenz.sechub.sharedkernel.MustBeDocumented)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Value (org.springframework.beans.factory.annotation.Value)1