Search in sources :

Example 1 with DocAnnotationData

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

the class AnnotationDataLocationExtractorTest method empty_data_results_in_empty_string.

@Test
public void empty_data_results_in_empty_string() throws Exception {
    /* prepare */
    DocAnnotationData data = new DocAnnotationData();
    /* execute */
    String result = extractorToTest.extractLocation(data);
    /* test */
    assertEquals("", result);
}
Also used : DocAnnotationData(com.mercedesbenz.sechub.docgen.DocAnnotationData) Test(org.junit.Test)

Example 2 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_value_documentation_found.

@Test
public void mustbedocumented_annotation_data_can_be_fetched_and_at_least_one_spring_value_documentation_found() {
    ClasspathDataCollector collector = new ClasspathDataCollector();
    List<DocAnnotationData> data = collector.fetchMustBeDocumentParts();
    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 3 with DocAnnotationData

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

the class DocGenUtilTest method spring_scheduled__is_collected_by_build_method_and_set_to_data.

@Test
public void spring_scheduled__is_collected_by_build_method_and_set_to_data() throws Exception {
    /* prepare */
    AnnotatedElement element = mock(AnnotatedElement.class);
    MustBeDocumented info = mock(MustBeDocumented.class);
    Scheduled scheduled = mock(Scheduled.class);
    when(scheduled.cron()).thenReturn("crondata");
    when(element.getDeclaredAnnotation(Scheduled.class)).thenReturn(scheduled);
    /* execute */
    DocAnnotationData data = DocGeneratorUtil.buildDataForMustBeDocumented(info, element);
    /* test */
    assertEquals(scheduled, data.springScheduled);
}
Also used : Scheduled(org.springframework.scheduling.annotation.Scheduled) AnnotatedElement(java.lang.reflect.AnnotatedElement) DocAnnotationData(com.mercedesbenz.sechub.docgen.DocAnnotationData) MustBeDocumented(com.mercedesbenz.sechub.sharedkernel.MustBeDocumented) Test(org.junit.Test)

Example 4 with DocAnnotationData

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

the class KubernetesTemplateFilesGenerator method generateDeploymentFilePart.

private void generateDeploymentFilePart(KubernetesFiles result, List<DocAnnotationData> list) {
    for (DocAnnotationData data : list) {
        generateDeploymentCode(result, data);
    }
    String generatorName = getClass().getSimpleName();
    StringBuilder all = new StringBuilder();
    newLine(all, "# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #");
    newLine(all, "# + Next kubernetes source is generated by: " + generatorName);
    newLine(all, "# + when your code changes and you have new keys etc. please generate again and replace block  ");
    newLine(all, "# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #");
    for (StringBuilder code : result.deploymentMap.values()) {
        all.append(code);
    }
    newLine(all, "# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #");
    newLine(all, "# + End of generated source from: " + getClass().getSimpleName());
    newLine(all, "# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #");
    result.serverDeploymentYaml = all.toString();
}
Also used : DocAnnotationData(com.mercedesbenz.sechub.docgen.DocAnnotationData)

Example 5 with DocAnnotationData

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

the class ScheduleDescriptionGenerator 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 (data.springScheduled == null) {
            continue;
        }
        SpringSchedule extracted = springScheduledExtractor.extract(data.springScheduled);
        TableRow row = new TableRow();
        row.scheduleType = extracted.getScheduleType().getText();
        row.scheduleDefinition = extracted.getScheduleDefinition();
        row.description = data.description;
        row.location = locationExtractor.extractLocation(data);
        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,6,6\"]\n");
        sb.append(".").append(buildTitle(entries.getKey()));
        sb.append("\n|===\n");
        sb.append("|Type   |Definition   |Description\n");
        sb.append("//----------------------\n");
        for (TableRow row : table) {
            sb.append("|").append(row.scheduleType);
            sb.append("|").append(row.scheduleDefinition);
            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) SpringSchedule(com.mercedesbenz.sechub.docgen.spring.SpringScheduleExtractor.SpringSchedule) TreeMap(java.util.TreeMap) Map(java.util.Map)

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