Search in sources :

Example 1 with IntegrationTestEventHistory

use of com.mercedesbenz.sechub.sharedkernel.messaging.IntegrationTestEventHistory in project sechub by mercedes-benz.

the class UseCaseEventOverviewPlantUmlGenerator method generateFile.

private void generateFile(File jsonSourceFile) {
    String fileName = jsonSourceFile.getName();
    if (!fileName.endsWith(".json")) {
        if (DEBUG) {
            LOG.info("ignoring filename:{}", fileName);
        }
        return;
    } else {
        if (DEBUG) {
            LOG.info("inspect filename:{}", fileName);
        }
    }
    String variant = filenameVariantconverter.getVariantFromFilename(fileName);
    String originFileName = filenameVariantconverter.getFilenameWithoutVariant(fileName);
    String usecaseId = originFileName.substring(0, originFileName.length() - 5);
    /* .json = 5 chars */
    UseCaseIdentifier usecaseIdentifier;
    try {
        usecaseIdentifier = UseCaseIdentifier.valueOf(usecaseId.toUpperCase());
    } catch (RuntimeException e) {
        LOG.error("File not a usecase:" + jsonSourceFile);
        return;
    }
    LOG.info("Generate for usecase:{}, using json file: {}", usecaseIdentifier.name(), jsonSourceFile.getAbsolutePath());
    if (jsonSourceFile.getAbsolutePath().endsWith("uc_admin_enables_scheduler_job_processing.json")) {
        System.out.println("got");
    }
    String json = reader.loadTextFile(jsonSourceFile);
    IntegrationTestEventHistory history = IntegrationTestEventHistory.fromJSONString(json);
    try {
        generate(history, usecaseIdentifier, variant);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException("Wrong class names? Maybe you need to retrigger Integration tests to get new JSON files!", e);
    } catch (IOException e) {
        throw new IllegalStateException("Was not able to write file!", e);
    }
}
Also used : UseCaseIdentifier(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseIdentifier) IntegrationTestEventHistory(com.mercedesbenz.sechub.sharedkernel.messaging.IntegrationTestEventHistory) IOException(java.io.IOException)

Example 2 with IntegrationTestEventHistory

use of com.mercedesbenz.sechub.sharedkernel.messaging.IntegrationTestEventHistory in project sechub by mercedes-benz.

the class AssertEventInspection method assertEventInspectionFailsButGeneratesTestCaseProposal.

/**
 * @formatter:off
 *
 * Will always fail but generates a test case proposal for current event situation.
 * Start the test, copy proposal snippet (at the end of first stacktrace element) and
 * it will work. This is very convenient to create new event trace tests...
 *
 * (of course you should still validate that the generated test is correct)
 * @param waitSeconds amount of seconds to wait before fetching history and generating test case
 * @formatter:on
 */
public static void assertEventInspectionFailsButGeneratesTestCaseProposal(int waitSeconds) {
    /* we weait for events handled */
    waitSeconds(waitSeconds);
    IntegrationTestEventHistory history2 = TestAPI.fetchEventInspectionHistory();
    String historyJSON = prettyPrintHistory(history2);
    String codeSnippet = createAssertTestExampleCodeSnippet(history2);
    System.out.println("History:\n" + historyJSON + "\n\nGenerated test code:\n\n" + codeSnippet);
    fail("Unimplemented testcase. Please use next generated test snippet inside your test:\n\n" + codeSnippet);
}
Also used : IntegrationTestEventHistory(com.mercedesbenz.sechub.sharedkernel.messaging.IntegrationTestEventHistory)

Aggregations

IntegrationTestEventHistory (com.mercedesbenz.sechub.sharedkernel.messaging.IntegrationTestEventHistory)2 UseCaseIdentifier (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseIdentifier)1 IOException (java.io.IOException)1