Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

343 modify checkstyle to remove unnecessary checks and stop console output by checkstyle #345

Merged
merged 8 commits into from
Oct 1, 2024
Merged
256 changes: 148 additions & 108 deletions checkstyle.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.adorsys.datasafe.business.impl.e2e;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.common.io.ByteStreams;
import de.adorsys.datasafe.business.impl.service.DefaultDatasafeServices;
import de.adorsys.datasafe.business.impl.service.VersionedDatasafeServices;
Expand Down Expand Up @@ -32,10 +34,6 @@
import de.adorsys.datasafe.types.api.types.ReadKeyPassword;
import de.adorsys.datasafe.types.api.utils.Obfuscate;
import de.adorsys.datasafe.types.api.utils.ReadKeyPasswordTestFactory;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -47,9 +45,9 @@
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -120,7 +118,7 @@ protected void writeDataToPrivate(UserIDAuth auth, String path, String data) {
@SneakyThrows
protected void writeDataToInbox(UserIDAuth owner, UserIDAuth auth, String path, String data) {
try (OutputStream stream = writeToInbox.write(
WriteInboxRequest.forDefaultPublic(owner, Collections.singleton(auth.getUserID()), path)
WriteInboxRequest.forDefaultPublic(owner, Collections.singleton(auth.getUserID()), path)
)) {

stream.write(data.getBytes(UTF_8));
Expand All @@ -134,7 +132,7 @@ protected AbsoluteLocation<ResolvedResource> getFirstFileInPrivate(UserIDAuth ow

protected List<AbsoluteLocation<ResolvedResource>> getAllFilesInPrivate(UserIDAuth owner) {
try (Stream<AbsoluteLocation<ResolvedResource>> ls = listPrivate.list(
ListRequest.forDefaultPrivate(owner, "./")
ListRequest.forDefaultPrivate(owner, "./")
)) {
List<AbsoluteLocation<ResolvedResource>> files = ls.collect(Collectors.toList());
log.info("{} has {} in PRIVATE", owner.getUserID(), files);
Expand Down Expand Up @@ -178,7 +176,7 @@ protected AbsoluteLocation<ResolvedResource> getFirstFileInInbox(UserIDAuth inbo

protected List<AbsoluteLocation<ResolvedResource>> getAllFilesInInbox(UserIDAuth inboxOwner) {
try (Stream<AbsoluteLocation<ResolvedResource>> ls = listInbox.list(
ListRequest.forDefaultPrivate(inboxOwner, "./")
ListRequest.forDefaultPrivate(inboxOwner, "./")
)) {
List<AbsoluteLocation<ResolvedResource>> files = ls.collect(Collectors.toList());
log.info("{} has {} in INBOX", inboxOwner, files);
Expand All @@ -194,7 +192,7 @@ protected void registerJohnAndJane() {
@SneakyThrows
protected void sendToInbox(UserIDAuth from, UserID to, String filename, String data) {
try (OutputStream stream = writeToInbox.write(
WriteInboxRequest.forDefaultPublic(from, Collections.singleton(to), "./" + filename)
WriteInboxRequest.forDefaultPublic(from, Collections.singleton(to), "./" + filename)
)) {
stream.write(data.getBytes());
}
Expand Down Expand Up @@ -229,11 +227,11 @@ protected UserIDAuth createJohnTestUser(int i) {
protected void assertPrivateSpaceList(UserIDAuth user, String root, String... expected) {
List<String> paths;
try (Stream<AbsoluteLocation<ResolvedResource>> ls =
listPrivate.list(ListRequest.forDefaultPrivate(user, root))
listPrivate.list(ListRequest.forDefaultPrivate(user, root))
) {
paths = ls
.map(it -> it.getResource().asPrivate().decryptedPath().asString())
.collect(Collectors.toList());
.map(it -> it.getResource().asPrivate().decryptedPath().asString())
.collect(Collectors.toList());
}

assertThat(paths).containsExactlyInAnyOrder(expected);
Expand All @@ -242,11 +240,11 @@ protected void assertPrivateSpaceList(UserIDAuth user, String root, String... ex
protected void assertInboxSpaceList(UserIDAuth user, String root, String... expected) {
List<String> paths;
try (Stream<AbsoluteLocation<ResolvedResource>> ls =
listInbox.list(ListRequest.forDefaultPrivate(user, root))
listInbox.list(ListRequest.forDefaultPrivate(user, root))
) {
paths = ls
.map(it -> it.getResource().asPrivate().decryptedPath().asString())
.collect(Collectors.toList());
.map(it -> it.getResource().asPrivate().decryptedPath().asString())
.collect(Collectors.toList());
}

assertThat(paths).containsExactlyInAnyOrder(expected);
Expand All @@ -255,8 +253,8 @@ protected void assertInboxSpaceList(UserIDAuth user, String root, String... expe
@SneakyThrows
protected void assertRootDirIsEmpty(WithStorageProvider.StorageDescriptor descriptor) {
try (Stream<AbsoluteLocation<ResolvedResource>> ls = descriptor.getStorageService().get()
.list(
new AbsoluteLocation<>(BasePrivateResource.forPrivate(descriptor.getLocation())))
.list(
new AbsoluteLocation<>(BasePrivateResource.forPrivate(descriptor.getLocation())))
) {
assertThat(ls).isEmpty();
}
Expand All @@ -267,17 +265,17 @@ protected void assertRootDirIsEmpty(WithStorageProvider.StorageDescriptor descri
// however we can't remove anything above
try (Stream<Path> files = Files.walk(Paths.get(descriptor.getLocation().asURI()))) {
assertThat(files)
.allMatch(it -> it.toFile().isDirectory())
.extracting(Path::toUri)
.extracting(it -> descriptor.getLocation().asURI().relativize(it))
.extracting(URI::toString)
.containsExactlyInAnyOrder(
"",
"users/",
"profiles/",
"profiles/public/",
"profiles/private/"
);
.allMatch(it -> it.toFile().isDirectory())
.extracting(Path::toUri)
.extracting(it -> descriptor.getLocation().asURI().relativize(it))
.extracting(URI::toString)
.containsExactlyInAnyOrder(
"",
"users/",
"profiles/",
"profiles/public/",
"profiles/private/"
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package de.adorsys.datasafe.business.impl.e2e;

import static de.adorsys.datasafe.business.impl.e2e.Const.FOLDER;
import static de.adorsys.datasafe.business.impl.e2e.Const.MESSAGE_ONE;
import static de.adorsys.datasafe.business.impl.e2e.Const.PRIVATE_FILE;
import static de.adorsys.datasafe.business.impl.e2e.Const.PRIVATE_FILE_PATH;
import static de.adorsys.datasafe.business.impl.e2e.Const.SHARED_FILE;
import static de.adorsys.datasafe.business.impl.e2e.Const.SHARED_FILE_PATH;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
Expand All @@ -23,14 +32,11 @@
import de.adorsys.datasafe.types.api.resource.Uri;
import de.adorsys.datasafe.types.api.types.BaseTypePasswordStringException;
import de.adorsys.datasafe.types.api.types.ReadKeyPassword;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;

import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.security.UnrecoverableKeyException;
import java.util.Arrays;
Expand All @@ -39,16 +45,11 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static de.adorsys.datasafe.business.impl.e2e.Const.FOLDER;
import static de.adorsys.datasafe.business.impl.e2e.Const.MESSAGE_ONE;
import static de.adorsys.datasafe.business.impl.e2e.Const.PRIVATE_FILE;
import static de.adorsys.datasafe.business.impl.e2e.Const.PRIVATE_FILE_PATH;
import static de.adorsys.datasafe.business.impl.e2e.Const.SHARED_FILE;
import static de.adorsys.datasafe.business.impl.e2e.Const.SHARED_FILE_PATH;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;

/**
* Tests that validates basic functionality - storing data to inbox, privatespace, listing files, etc.
Expand All @@ -64,11 +65,9 @@ class BasicFunctionalityIT extends BaseE2EIT {


/**
*
* In this test, password is provided as char[].
* This means after every operation, the password in cleared.
* This is tested for read/write/list/remove
*
*/
@SneakyThrows
@ParameterizedTest
Expand Down Expand Up @@ -284,9 +283,10 @@ void testWriteToPrivateListPrivateReadPrivateAndSendToAndReadFromInbox(
removeFromPrivate(jane, privateJane.getResource().asPrivate());
removeFromInbox(john, inboxJohn.getResource().asPrivate());
}

@ParameterizedTest
@MethodSource("allStorages")
void testWriteToPrivateListPrivateReadPrivateAndSendToAndReadFromInboxCustom( WithStorageProvider.StorageDescriptor descriptor) {
void testWriteToPrivateListPrivateReadPrivateAndSendToAndReadFromInboxCustom(WithStorageProvider.StorageDescriptor descriptor) {
String yamlFixture = "config/mutable.yaml";
customInit(descriptor, yamlFixture);

Expand Down Expand Up @@ -425,6 +425,7 @@ private void init(WithStorageProvider.StorageDescriptor descriptor) {
this.location = descriptor.getLocation();
this.storage = descriptor.getStorageService().get();
}

private void customInit(WithStorageProvider.StorageDescriptor descriptor, String yamlFixture) {
MutableEncryptionConfig config = readResource(mapper, yamlFixture, MutableEncryptionConfig.class);
DefaultDatasafeServices datasafeServices = DatasafeServicesProvider
Expand All @@ -438,8 +439,7 @@ private void customInit(WithStorageProvider.StorageDescriptor descriptor, String
private static <T> T readResource(ObjectMapper mapper, String path, Class<T> type) {
try (Reader reader = Resources.asCharSource(Resources.getResource(path), StandardCharsets.UTF_8).openStream()) {
return mapper.readValue(reader, type);
}
catch (IOException e) {
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package de.adorsys.datasafe.business.impl.e2e;

import static de.adorsys.datasafe.types.api.actions.ListRequest.forDefaultPrivate;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import com.google.common.io.ByteStreams;
import com.google.common.io.MoreFiles;
import de.adorsys.datasafe.business.impl.e2e.metrtics.TestMetricCollector;
Expand All @@ -12,16 +18,6 @@
import de.adorsys.datasafe.types.api.resource.AbsoluteLocation;
import de.adorsys.datasafe.types.api.resource.ResolvedResource;
import de.adorsys.datasafe.types.api.resource.Uri;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.encoders.Hex;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -44,13 +40,15 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static de.adorsys.datasafe.types.api.actions.ListRequest.forDefaultPrivate;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.encoders.Hex;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Multithreaded test of basic operations.
Expand Down Expand Up @@ -155,7 +153,7 @@ void writeToPrivateListPrivateInDifferentThreads(WithStorageProvider.StorageDesc
metricCollector.setDataSize(size);
metricCollector.setStorageType(storage.getClass().getSimpleName());
metricCollector.setNumberOfThreads(poolSize);
metricCollector.writeToJSON();//json files in target folder
metricCollector.writeToJSON(); //json files in target folder

deleteTestFile(testFile);
}
Expand Down Expand Up @@ -299,7 +297,7 @@ private void init(WithStorageProvider.StorageDescriptor descriptor) {
protected void writeDataToFileForUser(UserIDAuth john, String filePathForWriting, Path filePathForReading,
CountDownLatch latch) {
try (OutputStream write = writeToPrivate.write(WriteRequest.forDefaultPrivate(john, filePathForWriting));
FileInputStream fis = new FileInputStream(filePathForReading.toFile())
FileInputStream fis = new FileInputStream(filePathForReading.toFile())
) {
ByteStreams.copy(fis, write);
} catch (IOException e) {
Expand All @@ -311,10 +309,10 @@ protected void writeDataToFileForUser(UserIDAuth john, String filePathForWriting

@BeforeAll
public static void setUp() {
if(System.getenv("NUMBER_OF_TEST_USERS") != null) {
if (System.getenv("NUMBER_OF_TEST_USERS") != null) {
NUMBER_OF_TEST_USERS = Integer.parseInt(System.getenv("NUMBER_OF_TEST_USERS"));
}
if(System.getenv("NUMBER_OF_TEST_FILES") != null) {
if (System.getenv("NUMBER_OF_TEST_FILES") != null) {
NUMBER_OF_TEST_FILES = Integer.parseInt(System.getenv("NUMBER_OF_TEST_FILES"));
EXPECTED_NUMBER_OF_FILES_PER_USER = NUMBER_OF_TEST_FILES;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ private void tamperFilenameByReplacingOneCharOfPath(AbsoluteLocation<ResolvedRes
}

log.info("About to tamper path `{}`", pathAsString);
pathAsString = pathAsString.substring(0, characterToTamper - 1)
+ randomChar(pathAsString.charAt(characterToTamper))
+ pathAsString.substring(characterToTamper);
pathAsString = pathAsString.substring(0, characterToTamper - 1) +
randomChar(pathAsString.charAt(characterToTamper)) +
pathAsString.substring(characterToTamper);
log.info("Tampered path as `{}`", pathAsString);
Files.createDirectories(Paths.get(pathAsString).getParent());
Files.write(Paths.get(pathAsString), privateBytes, StandardOpenOption.CREATE);
Expand Down
Loading