use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testForInvalidArgument.
@Test
public void testForInvalidArgument() throws Exception {
outContent.reset();
String[] args1 = { "--value", "testvalue1", "--master", "master" };
KnoxCLI cli = new KnoxCLI();
cli.setConf(new GatewayConfigImpl());
int rc = cli.run(args1);
assertEquals(-2, rc);
assertTrue(outContent.toString().contains("ERROR: Invalid Command"));
}
use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testRemoteConfigurationRegistryUploadProviderConfig.
@Test
public void testRemoteConfigurationRegistryUploadProviderConfig() throws Exception {
outContent.reset();
final String providerConfigName = "my-provider-config.xml";
final String providerConfigContent = "<gateway/>\n";
final File testRoot = TestUtils.createTempDir(this.getClass().getName());
try {
final File testRegistry = new File(testRoot, "registryRoot");
final File testProviderConfig = new File(testRoot, providerConfigName);
final String[] args = { "upload-provider-config", testProviderConfig.getAbsolutePath(), "--registry-client", "test_client", "--master", "master" };
FileUtils.writeStringToFile(testProviderConfig, providerConfigContent);
KnoxCLI cli = new KnoxCLI();
Configuration config = new GatewayConfigImpl();
// Configure a client for the test local filesystem registry implementation
config.set("gateway.remote.config.registry.test_client", "type=LocalFileSystem;address=" + testRegistry);
cli.setConf(config);
// Run the test command
int rc = cli.run(args);
// Validate the result
assertEquals(0, rc);
outContent.reset();
final String[] listArgs = { "list-provider-configs", "--registry-client", "test_client" };
cli.run(listArgs);
String outStr = outContent.toString().trim();
assertTrue(outStr.startsWith("Provider Configurations"));
assertTrue(outStr.endsWith(")\n" + providerConfigName));
File registryFile = new File(testRegistry, "knox/config/shared-providers/" + providerConfigName);
assertTrue(registryFile.exists());
assertEquals(FileUtils.readFileToString(registryFile), providerConfigContent);
} finally {
FileUtils.forceDelete(testRoot);
}
}
use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testRemoteConfigurationRegistryDeleteProviderConfig.
@Test
public void testRemoteConfigurationRegistryDeleteProviderConfig() throws Exception {
outContent.reset();
// Create a provider config
final String providerConfigName = "my-provider-config.xml";
final String providerConfigContent = "<gateway/>\n";
final File testRoot = TestUtils.createTempDir(this.getClass().getName());
try {
final File testRegistry = new File(testRoot, "registryRoot");
final File testProviderConfig = new File(testRoot, providerConfigName);
final String[] createArgs = { "upload-provider-config", testProviderConfig.getAbsolutePath(), "--registry-client", "test_client", "--master", "master" };
FileUtils.writeStringToFile(testProviderConfig, providerConfigContent);
KnoxCLI cli = new KnoxCLI();
Configuration config = new GatewayConfigImpl();
// Configure a client for the test local filesystem registry implementation
config.set("gateway.remote.config.registry.test_client", "type=LocalFileSystem;address=" + testRegistry);
cli.setConf(config);
// Run the test command
int rc = cli.run(createArgs);
// Validate the result
assertEquals(0, rc);
File registryFile = new File(testRegistry, "knox/config/shared-providers/" + providerConfigName);
assertTrue(registryFile.exists());
outContent.reset();
// Delete the created provider config
final String[] deleteArgs = { "delete-provider-config", providerConfigName, "--registry-client", "test_client", "--master", "master" };
rc = cli.run(deleteArgs);
assertEquals(0, rc);
assertFalse(registryFile.exists());
// Try to delete a provider config that does not exist
rc = cli.run(new String[] { "delete-provider-config", "imaginary-providers.xml", "--registry-client", "test_client", "--master", "master" });
assertEquals(0, rc);
} finally {
FileUtils.forceDelete(testRoot);
}
}
use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testGatewayAndClusterStores.
@Test
public void testGatewayAndClusterStores() throws Exception {
GatewayConfigImpl config = new GatewayConfigImpl();
FileUtils.deleteQuietly(new File(config.getGatewaySecurityDir()));
outContent.reset();
String[] gwCreateArgs = { "create-alias", "alias1", "--value", "testvalue1", "--master", "master" };
int rc = 0;
KnoxCLI cli = new KnoxCLI();
cli.setConf(config);
rc = cli.run(gwCreateArgs);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("alias1 has been successfully " + "created."));
AliasService as = cli.getGatewayServices().getService(GatewayServices.ALIAS_SERVICE);
outContent.reset();
String[] clusterCreateArgs = { "create-alias", "alias2", "--value", "testvalue1", "--cluster", "test", "--master", "master" };
cli = new KnoxCLI();
cli.setConf(config);
rc = cli.run(clusterCreateArgs);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("alias2 has been successfully " + "created."));
outContent.reset();
String[] args2 = { "list-alias", "--master", "master" };
cli = new KnoxCLI();
rc = cli.run(args2);
assertEquals(0, rc);
assertFalse(outContent.toString(), outContent.toString().contains("alias2"));
assertTrue(outContent.toString(), outContent.toString().contains("alias1"));
char[] passwordChars = as.getPasswordFromAliasForCluster("test", "alias2");
assertNotNull(passwordChars);
assertTrue(new String(passwordChars), "testvalue1".equals(new String(passwordChars)));
outContent.reset();
String[] args1 = { "list-alias", "--cluster", "test", "--master", "master" };
cli = new KnoxCLI();
rc = cli.run(args1);
assertEquals(0, rc);
assertFalse(outContent.toString(), outContent.toString().contains("alias1"));
assertTrue(outContent.toString(), outContent.toString().contains("alias2"));
outContent.reset();
String[] args4 = { "delete-alias", "alias1", "--master", "master" };
cli = new KnoxCLI();
rc = cli.run(args4);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("alias1 has been successfully " + "deleted."));
outContent.reset();
String[] args5 = { "delete-alias", "alias2", "--cluster", "test", "--master", "master" };
cli = new KnoxCLI();
rc = cli.run(args5);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("alias2 has been successfully " + "deleted."));
}
use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class GatewayGlobalConfigTest method testForUpdatedDeploymentDir.
@Test
public void testForUpdatedDeploymentDir() {
String homeDirName = getHomeDirName("conf-demo/conf/gateway-site.xml");
System.setProperty(GatewayConfigImpl.GATEWAY_HOME_VAR, homeDirName);
System.setProperty(GatewayConfigImpl.GATEWAY_DATA_HOME_VAR, homeDirName);
GatewayConfig config = new GatewayConfigImpl();
assertTrue(("target/test").equalsIgnoreCase(config.getGatewayDeploymentDir()));
}
Aggregations