<commit_before>package io.spacedog.client.http;

import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

import org.joda.time.DateTime;
import org.junit.Assert;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;

import io.spacedog.client.SpaceDog;
import io.spacedog.client.SpacePlatform;
import io.spacedog.client.credentials.Credentials;
import io.spacedog.client.credentials.CredentialsCreateRequest;
import io.spacedog.client.credentials.Passwords;
import io.spacedog.client.credentials.Roles;
import io.spacedog.utils.Json;
import io.spacedog.utils.Utils;

public class SpaceAssert extends Assert implements SpacePlatform, SpaceFields, SpaceParams {

	public static SpaceDog createTempDog(SpaceDog parentDog, String username, String... roles) {
		CredentialsCreateRequest createRequest = new CredentialsCreateRequest()//
				.username(username)//
				.password(<PASSWORD>())//
				.email(DEFAULT_EMAIL)//
				.roles(roles);
		parentDog.credentials().create(createRequest);
		return SpaceDog.dog(parentDog.backend()).username(username).password(createRequest.password());
	}

	public static SpaceDog signUpTempDog(SpaceBackend backend, String username) {
		return createTempDog(SpaceDog.dog(backend), username);
	}

	public static SpaceDog clearServer() {
		SpaceDog superdog = superdog();
		superdog.admin().clearBackend();
		return createTempDog(superdog, Roles.superadmin, Roles.superadmin);
	}

	public static void prepareTest() {
		prepareTest(true, false);
	}

	public static void prepareTest(boolean forTesting, boolean serverDebug) {

		SpaceRequest.setForTestingDefault(forTesting);
		SpaceRequest.setDebugServerDefault(serverDebug);

		StackTraceElement grandParentStackTraceElement = Utils.getGrandParentStackTraceElement();

		Utils.info();
		Utils.info("--- %s.%s() ---", //
				grandParentStackTraceElement.getClassName(), //
				grandParentStackTraceElement.getMethodName());
	}

	public static SpaceDog superdog() {
		return SpaceDog.dog()//
				.username(Credentials.SUPERDOG.username())//
				.password(SpaceEnv.env().superdogPassword());
	}

	public static DateTime assertDateIsValid(JsonNode date) {
		assertNotNull(date);
		if (!date.isTextual()) {
			Object[] args = { date };
			throw failure("json date [%s] is not valid", args);
		}
		return assertDateIsValid(date.asText());
	}

	public static DateTime assertDateIsValid(String date) {
		assertNotNull(date);<commit_msg>Add clearServer(SpaceBackend) and superdog(SpaceBackend) to SpaceAssert class<commit_after>package io.spacedog.client.http;

import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

import org.joda.time.DateTime;
import org.junit.Assert;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;

import io.spacedog.client.SpaceDog;
import io.spacedog.client.SpacePlatform;
import io.spacedog.client.credentials.Credentials;
import io.spacedog.client.credentials.CredentialsCreateRequest;
import io.spacedog.client.credentials.Passwords;
import io.spacedog.client.credentials.Roles;
import io.spacedog.utils.Json;
import io.spacedog.utils.Utils;

public class SpaceAssert extends Assert implements SpacePlatform, SpaceFields, SpaceParams {

	public static SpaceDog createTempDog(SpaceDog parentDog, String username, String... roles) {
		CredentialsCreateRequest createRequest = new CredentialsCreateRequest()//
				.username(username)//
				.password(<PASSWORD>())//
				.email(DEFAULT_EMAIL)//
				.roles(roles);
		parentDog.credentials().create(createRequest);
		return SpaceDog.dog(parentDog.backend()).username(username).password(createRequest.password());
	}

	public static SpaceDog signUpTempDog(SpaceBackend backend, String username) {
		return createTempDog(SpaceDog.dog(backend), username);
	}

	public static SpaceDog clearServer() {
		SpaceDog superdog = superdog();
		superdog.admin().clearBackend();
		return createTempDog(superdog, Roles.superadmin, Roles.superadmin);
	}

	public static SpaceDog clearServer(SpaceBackend backend) {
		SpaceDog superdog = superdog(backend);
		superdog.admin().clearBackend();
		return createTempDog(superdog, Roles.superadmin, Roles.superadmin);
	}

	public static void prepareTest() {
		prepareTest(true, false);
	}

	public static void prepareTest(boolean forTesting, boolean serverDebug) {

		SpaceRequest.setForTestingDefault(forTesting);
		SpaceRequest.setDebugServerDefault(serverDebug);

		StackTraceElement grandParentStackTraceElement = Utils.getGrandParentStackTraceElement();

		Utils.info();
		Utils.info("--- %s.%s() ---", //
				grandParentStackTraceElement.getClassName(), //
				grandParentStackTraceElement.getMethodName());
	}

	public static SpaceDog superdog() {
		return SpaceDog.dog()//
				.username(Credentials.SUPERDOG.username())//
				.password(SpaceEnv.env().superdogPassword());
	}

	public static SpaceDog superdog(SpaceBackend backend) {
		return SpaceDog.dog(backend)//
				.username(Credentials.SUPERDOG.username())//
				.password(SpaceEnv.env().superdogPassword());
	}

	public static DateTime assertDateIsValid(JsonNode date) {
		assertNotNull(date);
		if (!date.isTextual()) {
			Object[] args = { date };
			throw failure("json date [%s] is not valid", args);
		}
		return assertDateIsValid(date.asText());
	}

	public static DateTime assertDateIsValid(String date) {
		assertNotNull(date);
{'fraction_non_alphanumeric': 0.11926441706838065, 'fraction_numerical': 0.0, 'mean_word_length': 5.491309385863268, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5649893', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1637, 'n_words': 317}