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();
}
}
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;
}
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);
}
}
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;
}
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());
}
Aggregations