Search in sources :

Example 1 with TestJSONHelper

use of com.mercedesbenz.sechub.integrationtest.internal.TestJSONHelper in project sechub by mercedes-benz.

the class CreateOverviewCSVExportAction method execute.

@Override
public void execute(ActionEvent e) {
    Row title = Row.builder().add("Project").add("Owner").add("Users").add("whitelists").add("information").build();
    Grid grid = new Grid(title);
    List<String> projectIds = loadProjectIds();
    List<String> allUsers = loadUserIds();
    List<String> signupUsers = loadSignupUserIds();
    int projectsDone = 0;
    for (String projectId : projectIds) {
        outputAsTextOnSuccess("Loading project :" + projectId + " ->" + projectsDone + "/" + projectIds.size());
        String data = getContext().getAdministration().fetchProjectInfo(projectId);
        TestJSONHelper jsonHelper = TestJSONHelper.get();
        JsonNode tree = jsonHelper.readTree(data);
        JsonNode usersNode = tree.get("users");
        JsonNode ownerNode = tree.get("owner");
        JsonNode whiteListsNode = tree.get("whiteList");
        StringBuilder userListSb = createCommaSeparatedListOfEntries(usersNode, allUsers);
        StringBuilder whiteListSb = createCommaSeparatedListOfEntries(whiteListsNode);
        Row row = Row.builder().add(projectId).add(ownerNode.asText()).add(userListSb.toString()).add(whiteListSb.toString()).add("").build();
        grid.add(row);
        projectsDone++;
    }
    /* add unrelated users in pseudo - project */
    Row row1 = Row.builder().add("<NO PROJECT>").add("<NO OWNER>").add(allUsers.toString()).add("").add("Inside SecHub registered, but not assigned to any project!").build();
    grid.add(row1);
    /* add signup users in pseudo - project */
    for (String signupUser : signupUsers) {
        Row row2 = Row.builder().add("<WAITING SIGNUP>").add("<NO OWNER>").add(signupUser).add("").add("Waiting for signup").build();
        grid.add(row2);
    }
    try {
        Path tempFile = Files.createTempFile("sechub_devtools_adminui_export", ".csv");
        try (BufferedWriter buffer = Files.newBufferedWriter(tempFile)) {
            buffer.write(grid.toCSVString());
            outputAsTextOnSuccess("written CSV data to " + tempFile.toAbsolutePath().toFile().getAbsolutePath());
        }
    } catch (IOException e2) {
        outputAsTextOnSuccess("FAILED");
        e2.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) Grid(com.mercedesbenz.sechub.developertools.admin.export.Grid) TestJSONHelper(com.mercedesbenz.sechub.integrationtest.internal.TestJSONHelper) JsonNode(com.fasterxml.jackson.databind.JsonNode) Row(com.mercedesbenz.sechub.developertools.admin.export.Row) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 2 with TestJSONHelper

use of com.mercedesbenz.sechub.integrationtest.internal.TestJSONHelper in project sechub by mercedes-benz.

the class CreateOverviewCSVExportAction method loadSignupUserIds.

private List<String> loadSignupUserIds() {
    String data = getContext().getAdministration().fetchSignups();
    TestJSONHelper jsonHelper = TestJSONHelper.get();
    JsonNode tree = jsonHelper.readTree(data);
    List<String> ids = new ArrayList<>();
    Iterator<JsonNode> iditerator = tree.elements();
    while (iditerator.hasNext()) {
        JsonNode dNode = iditerator.next();
        String userId = dNode.get("userId").asText();
        String emailAdress = dNode.get("emailAdress").asText();
        ids.add(userId + " <" + emailAdress + ">");
    }
    outputAsTextOnSuccess("Found " + ids.size() + " watting signups.");
    return ids;
}
Also used : ArrayList(java.util.ArrayList) TestJSONHelper(com.mercedesbenz.sechub.integrationtest.internal.TestJSONHelper) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 3 with TestJSONHelper

use of com.mercedesbenz.sechub.integrationtest.internal.TestJSONHelper in project sechub by mercedes-benz.

the class TestAPI method fetchMetaDataInspections.

public static List<Map<String, Object>> fetchMetaDataInspections() {
    TestURLBuilder urlBuilder = IntegrationTestContext.get().getUrlBuilder();
    String url = urlBuilder.buildFetchMetaDataInspectionsURL();
    String json = IntegrationTestContext.get().getSuperAdminRestHelper().getJSON(url);
    TestJSONHelper jsonHelper = TestJSONHelper.get();
    List<Map<String, Object>> data;
    try {
        data = jsonHelper.getMapper().readValue(json, new TypeReference<List<Map<String, Object>>>() {
        });
        return data;
    } catch (JsonProcessingException e) {
        throw new AssertionError("Was not able to read meta data json", e);
    }
}
Also used : TestURLBuilder(com.mercedesbenz.sechub.test.TestURLBuilder) TestJSONHelper(com.mercedesbenz.sechub.integrationtest.internal.TestJSONHelper) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with TestJSONHelper

use of com.mercedesbenz.sechub.integrationtest.internal.TestJSONHelper in project sechub by mercedes-benz.

the class AsUser method createProject.

/**
 * User trigger create of project
 *
 * @param project
 * @throws RestClientException
 */
public AsUser createProject(TestProject project, String ownerUserId) {
    if (ownerUserId == null) {
        // we use always the user how creates the project as owner when not explicit set
        ownerUserId = this.user.getUserId();
    }
    /* @formatter:off */
    StringBuilder json = new StringBuilder();
    TestJSONHelper jsonHelper = TestJSONHelper.get();
    json.append("{\n" + " \"apiVersion\":\"1.0\",\n" + " \"name\":\"" + project.getProjectId() + "\",\n" + " \"owner\":\"" + ownerUserId + "\",\n" + " \"description\":\"" + project.getDescription() + "\"");
    if (!project.getWhiteListUrls().isEmpty()) {
        json.append(",\n \"whiteList\" : {\"uris\":[");
        for (Iterator<String> it = project.getWhiteListUrls().iterator(); it.hasNext(); ) {
            String url = it.next();
            json.append("\"" + url + "\"");
            if (it.hasNext()) {
                json.append(",");
            }
        }
        json.append("]\n");
        json.append("                 }\n");
    }
    json.append("}\n");
    jsonHelper.assertValidJson(json.toString());
    /* @formatter:on */
    getRestHelper().postJson(getUrlBuilder().buildAdminCreatesProjectUrl(), json.toString());
    return this;
}
Also used : TestJSONHelper(com.mercedesbenz.sechub.integrationtest.internal.TestJSONHelper)

Example 5 with TestJSONHelper

use of com.mercedesbenz.sechub.integrationtest.internal.TestJSONHelper in project sechub by mercedes-benz.

the class DeveloperAdministration method updateProjectMetaData.

public void updateProjectMetaData(String projectId, String result) {
    TestJSONHelper jsonHelper = TestJSONHelper.get();
    JsonNode jsonNode = jsonHelper.readTree(result);
    StringBuilder sb = new StringBuilder();
    sb.append("{\"apiVersion\":\"1.0\", \"metaData\":\n" + jsonNode.toPrettyString() + "\n}");
    getRestHelper().postJson(getUrlBuilder().buildUpdateProjectMetaData(projectId), sb.toString());
}
Also used : TestJSONHelper(com.mercedesbenz.sechub.integrationtest.internal.TestJSONHelper) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

TestJSONHelper (com.mercedesbenz.sechub.integrationtest.internal.TestJSONHelper)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ArrayList (java.util.ArrayList)4 Map (java.util.Map)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 Grid (com.mercedesbenz.sechub.developertools.admin.export.Grid)1 Row (com.mercedesbenz.sechub.developertools.admin.export.Row)1 TestURLBuilder (com.mercedesbenz.sechub.test.TestURLBuilder)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1