Skip to content

Commit

Permalink
Comply
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Dec 30, 2024
1 parent e76111c commit 15f8677
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 75 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<hsqldb.version>2.7.4</hsqldb.version>
<test.source.path>${project.build.directory}/test-source-path</test.source.path>

<targetJdk>11</targetJdk>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.File;
import java.io.FileFilter;
import java.nio.file.Path;
import net.tirasa.connid.bundles.csvdir.CSVDirConfiguration;

public class FileSystem {
Expand All @@ -29,7 +30,7 @@ public class FileSystem {

public FileSystem(final CSVDirConfiguration conf) {
this.conf = conf;
this.sourcePath = new File(conf.getSourcePath());
this.sourcePath = Path.of(conf.getSourcePath()).toFile();
this.fileFilter = new FileFilter() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package net.tirasa.connid.bundles.csvdir.database;

import java.io.File;
import java.nio.file.Path;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -50,7 +51,7 @@ public FileToDB(final CSVDirConnection conn) {
public String createDbForCreate() {
File file = fileSystem.getLastModifiedCsvFile();
if (file == null) {
file = new File(DEFAULT_PREFIX + Utilities.randomNumber() + ".csv");
file = Path.of(DEFAULT_PREFIX + Utilities.randomNumber() + ".csv").toFile();
}
return bindFileTable(file);
}
Expand Down
127 changes: 54 additions & 73 deletions src/test/java/net/tirasa/connid/bundles/csvdir/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
Expand All @@ -39,8 +39,6 @@
import org.identityconnectors.framework.common.objects.Attribute;
import org.identityconnectors.framework.common.objects.AttributeBuilder;
import org.identityconnectors.framework.common.objects.Name;
import org.identityconnectors.framework.impl.api.APIConfigurationImpl;
import org.identityconnectors.framework.impl.api.local.JavaClassProperties;
import org.identityconnectors.test.common.TestHelpers;
import org.junit.jupiter.api.BeforeAll;

Expand All @@ -56,15 +54,15 @@ public static void readTestProperties() {
try {
InputStream propStream = AbstractTest.class.getResourceAsStream("/test.properties");
props.load(propStream);
testSourceDir = new File(props.getProperty("testSourcePath"));
testSourceDir = Path.of(props.getProperty("testSourcePath")).toFile();
} catch (Exception e) {
fail("Could not load test.properties: " + e.getMessage());
}
assertNotNull(testSourceDir);
assertTrue(testSourceDir.exists() ? testSourceDir.isDirectory() : testSourceDir.mkdir());
}

protected CSVDirConfiguration createConfiguration(final String mask) {
protected static CSVDirConfiguration createConfiguration(final String mask) {
// create the connector configuration..
final CSVDirConfiguration config = new CSVDirConfiguration();
config.setFileMask(mask);
Expand All @@ -89,7 +87,7 @@ protected CSVDirConfiguration createConfiguration(final String mask) {
return config;
}

protected CSVDirConfiguration createMultiOCsConfiguration(final String mask) {
protected static CSVDirConfiguration createMultiOCsConfiguration(final String mask) {
// create the connector configuration..
final CSVDirConfiguration config = new CSVDirConfiguration();
config.setFileMask(mask);
Expand Down Expand Up @@ -117,44 +115,36 @@ protected CSVDirConfiguration createMultiOCsConfiguration(final String mask) {
return config;
}

protected ConnectorFacade createMultiOCsFacade(final String mask) {
protected static ConnectorFacade createMultiOCsFacade(final String mask) {
final ConnectorFacadeFactory factory = ConnectorFacadeFactory.getInstance();

final CSVDirConfiguration cfg = createMultiOCsConfiguration(mask);
final APIConfiguration impl = TestHelpers.createTestConfiguration(CSVDirConnector.class, cfg);
// TODO: remove the line below when using ConnId >= 1.4.0.1
((APIConfigurationImpl) impl).
setConfigurationProperties(JavaClassProperties.createConfigurationProperties(cfg));

return factory.newInstance(impl);
}

protected ConnectorFacade createFacade(final String mask) {
protected static ConnectorFacade createFacade(final String mask) {
final ConnectorFacadeFactory factory = ConnectorFacadeFactory.getInstance();

final CSVDirConfiguration cfg = createConfiguration(mask);
final APIConfiguration impl = TestHelpers.createTestConfiguration(CSVDirConnector.class, cfg);
// TODO: remove the line below when using ConnId >= 1.4.0.1
((APIConfigurationImpl) impl).
setConfigurationProperties(JavaClassProperties.createConfigurationProperties(cfg));

return factory.newInstance(impl);
}

protected File createFile(final String name, final List<TestAccount> testAccounts)
throws IOException {

protected static File createFile(final String name, final List<TestAccount> testAccounts) throws IOException {
final File file = File.createTempFile(name, ".csv", testSourceDir);
file.deleteOnExit();

final PrintWriter wrt = writeOutFileData(file);
writeOutEachUser(wrt, testAccounts);
wrt.close();
try (PrintWriter wrt = writeOutFileData(file.toPath())) {
writeOutEachUser(wrt, testAccounts);
}

return file;
}

private void writeOutEachUser(
private static void writeOutEachUser(
final PrintWriter wrt,
final List<TestAccount> testAccounts) {

Expand All @@ -171,65 +161,56 @@ private void writeOutEachUser(
}
}

protected File createSampleFile(final String name, final int THOUSANDS)
throws IOException {

protected static File createSampleFile(final String name, final int thousands) throws IOException {
final File file = File.createTempFile(name, ".csv", testSourceDir);
file.deleteOnExit();

final PrintWriter wrt = writeOutFileData(file);

if (IGNORE_HEADER) {
wrt.println(TestAccountsValue.HEADER.toLine(
TestAccountsValue.FIELD_DELIMITER,
TestAccountsValue.TEXT_QUALIFIER));
try (PrintWriter wrt = writeOutFileData(file.toPath())) {
if (IGNORE_HEADER) {
wrt.println(TestAccountsValue.HEADER.toLine(
TestAccountsValue.FIELD_DELIMITER,
TestAccountsValue.TEXT_QUALIFIER));
}

for (int i = 0; i < thousands; i++) {
TestAccount account = new TestAccount(
"accountid" + i,
"firstname",
"lastname",
"email",
"changeNumber",
"password",
"no");

wrt.println(account.toLine(
TestAccountsValue.FIELD_DELIMITER,
TestAccountsValue.TEXT_QUALIFIER));
}
}

for (int i = 0; i < THOUSANDS; i++) {
TestAccount account = new TestAccount(
"accountid" + i,
"firstname",
"lastname",
"email",
"changeNumber",
"password",
"no");

wrt.println(account.toLine(
TestAccountsValue.FIELD_DELIMITER,
TestAccountsValue.TEXT_QUALIFIER));
}
wrt.close();
return file;
}

private PrintWriter writeOutFileData(final File file)
throws FileNotFoundException {
return new PrintWriter(new OutputStreamWriter(
new FileOutputStream(file), getUTF8Charset()));
}

private Charset getUTF8Charset() {
return Charset.forName("UTF-8");
private static PrintWriter writeOutFileData(final Path file) throws IOException {
return new PrintWriter(new OutputStreamWriter(Files.newOutputStream(file), StandardCharsets.UTF_8));
}

protected File updateFile(final File file, final List<TestAccount> testAccounts)
throws IOException {

final BufferedWriter bufferedWriter = new BufferedWriter(
new FileWriter(file, true));
for (TestAccount user : testAccounts) {
bufferedWriter.write(user.toLine(TestAccountsValue.FIELD_DELIMITER,
TestAccountsValue.TEXT_QUALIFIER));
bufferedWriter.newLine();
protected static File updateFile(final File file, final List<TestAccount> testAccounts) throws IOException {
try (BufferedWriter bufferedWriter = Files.newBufferedWriter(
file.toPath(), StandardOpenOption.APPEND, StandardOpenOption.WRITE)) {

for (TestAccount user : testAccounts) {
bufferedWriter.write(user.toLine(
TestAccountsValue.FIELD_DELIMITER,
TestAccountsValue.TEXT_QUALIFIER));
bufferedWriter.newLine();
}
bufferedWriter.flush();
}
bufferedWriter.flush();
bufferedWriter.close();
return file;
}

protected Set<Attribute> buildTestAttributes(final Name name) {
final Set<Attribute> attributes = new HashSet<Attribute>();
protected static Set<Attribute> buildTestAttributes(final Name name) {
final Set<Attribute> attributes = new HashSet<>();

attributes.add(name);
attributes.add(AttributeBuilder.build(TestAccountsValue.FIRSTNAME, "pmassi"));
Expand All @@ -242,17 +223,17 @@ protected Set<Attribute> buildTestAttributes(final Name name) {
return attributes;
}

protected Set<Attribute> setAccountId(final Set<Attribute> attributes) {
protected static Set<Attribute> setAccountId(final Set<Attribute> attributes) {
attributes.add(AttributeBuilder.build(TestAccountsValue.ACCOUNTID, "___mperro123"));
return attributes;
}

protected Set<Attribute> setEmployee(final Set<Attribute> attributes) {
protected static Set<Attribute> setEmployee(final Set<Attribute> attributes) {
attributes.add(AttributeBuilder.build("OC", "_EMPLOYEE_"));
return attributes;
}

protected Set<Attribute> setManager(final Set<Attribute> attributes) {
protected static Set<Attribute> setManager(final Set<Attribute> attributes) {
attributes.add(AttributeBuilder.build("OC", "_MANAGER_"));
return attributes;
}
Expand Down

0 comments on commit 15f8677

Please sign in to comment.