Skip to content

Commit

Permalink
IntegrationTest spotless (opensearch-project#2863)
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Crawford <[email protected]>
  • Loading branch information
stephen-crawford authored and RyanL1997 committed Jun 29, 2023
1 parent b6bfb11 commit ef048a2
Show file tree
Hide file tree
Showing 38 changed files with 7,336 additions and 6,728 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ spotless {
target '**/com/amazon/dlic/**/*.java'
target '**/com/amazon/security/**/*.java'
target '**/test/**/*.java'
target '**/integrationTest/**/*.java'

removeUnusedImports()
eclipse().configFile rootProject.file('formatter/formatterConfig.xml')
Expand Down Expand Up @@ -113,6 +114,7 @@ spotless {
targetExclude '**/com/amazon/dlic/**/*.java'
targetExclude '**/com/amazon/security/**/*.java'
targetExclude '**/test/**/*.java'
targetExclude '**/integrationTest/**/*.java'

trimTrailingWhitespace()
endWithNewline();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@

class NodeAndClusterIdConverter {

public NodeAndClusterIdConverter() {}

public NodeAndClusterIdConverter() {
}
public static void setNodeIdAndClusterId(String nodeId, String clusterUUID) {}

public static void setNodeIdAndClusterId(String nodeId, String clusterUUID) {
}

public void format(LogEvent event, StringBuilder toAppendTo) {
}
public void format(LogEvent event, StringBuilder toAppendTo) {}
}
27 changes: 15 additions & 12 deletions src/integrationTest/java/org/opensearch/node/PluginAwareNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@

public class PluginAwareNode extends Node {

private final boolean clusterManagerEligible;

@SafeVarargs
public PluginAwareNode(boolean clusterManagerEligible, final Settings preparedSettings, final Class<? extends Plugin>... plugins) {
super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, Collections.emptyMap(), null, () -> System.getenv("HOSTNAME")), Arrays.asList(plugins), true);
this.clusterManagerEligible = clusterManagerEligible;
}


public boolean isClusterManagerEligible() {
return clusterManagerEligible;
}
private final boolean clusterManagerEligible;

@SafeVarargs
public PluginAwareNode(boolean clusterManagerEligible, final Settings preparedSettings, final Class<? extends Plugin>... plugins) {
super(
InternalSettingsPreparer.prepareEnvironment(preparedSettings, Collections.emptyMap(), null, () -> System.getenv("HOSTNAME")),
Arrays.asList(plugins),
true
);
this.clusterManagerEligible = clusterManagerEligible;
}

public boolean isClusterManagerEligible() {
return clusterManagerEligible;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,41 @@

class ConfigurationFiles {

public static void createRoleMappingFile(File destination) {
String resource = "roles_mapping.yml";
copyResourceToFile(resource, destination);
}
public static void createRoleMappingFile(File destination) {
String resource = "roles_mapping.yml";
copyResourceToFile(resource, destination);
}

public static void createConfigFile(File destination) {
String resource = "config.yml";
copyResourceToFile(resource, destination);
}
public static Path createConfigurationDirectory() {
try {
Path tempDirectory = Files.createTempDirectory("test-security-config");
String[] configurationFiles = {
"config.yml",
"action_groups.yml",
"config.yml",
"internal_users.yml",
"roles.yml",
"roles_mapping.yml",
"security_tenants.yml",
"tenants.yml" };
for (String fileName : configurationFiles) {
Path configFileDestination = tempDirectory.resolve(fileName);
copyResourceToFile(fileName, configFileDestination.toFile());
}
return tempDirectory.toAbsolutePath();
} catch (IOException ex) {
throw new RuntimeException("Cannot create directory with security plugin configuration.", ex);
}
}

public static Path createConfigurationDirectory() {
try {
Path tempDirectory = Files.createTempDirectory("test-security-config");
String[] configurationFiles = {
"config.yml",
"action_groups.yml",
"config.yml",
"internal_users.yml",
"roles.yml",
"roles_mapping.yml",
"security_tenants.yml",
"tenants.yml"
};
for (String fileName : configurationFiles) {
Path configFileDestination = tempDirectory.resolve(fileName);
copyResourceToFile(fileName, configFileDestination.toFile());
}
return tempDirectory.toAbsolutePath();
} catch (IOException ex) {
throw new RuntimeException("Cannot create directory with security plugin configuration.", ex);
}
}

private static void copyResourceToFile(String resource, File destination) {
try(InputStream input = ConfigurationFiles.class.getClassLoader().getResourceAsStream(resource)) {
Objects.requireNonNull(input, "Cannot find source resource " + resource);
try(OutputStream output = new FileOutputStream(destination)) {
input.transferTo(output);
}
} catch (IOException e) {
throw new RuntimeException("Cannot create file with security plugin configuration", e);
}
}
private static void copyResourceToFile(String resource, File destination) {
try (InputStream input = ConfigurationFiles.class.getClassLoader().getResourceAsStream(resource)) {
Objects.requireNonNull(input, "Cannot find source resource " + resource);
try (OutputStream output = new FileOutputStream(destination)) {
input.transferTo(output);
}
} catch (IOException e) {
throw new RuntimeException("Cannot create file with security plugin configuration", e);
}
}
}
Loading

0 comments on commit ef048a2

Please sign in to comment.