use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testCreateMaster.
@Test
public void testCreateMaster() throws Exception {
GatewayConfigImpl config = new GatewayConfigImpl();
FileUtils.deleteQuietly(new File(config.getGatewaySecurityDir()));
outContent.reset();
String[] args = { "create-master", "--master", "master" };
int rc = 0;
KnoxCLI cli = new KnoxCLI();
cli.setConf(config);
rc = cli.run(args);
assertEquals(0, rc);
MasterService ms = cli.getGatewayServices().getService("MasterService");
// assertTrue(ms.getClass().getName(), ms.getClass().getName().equals("kjdfhgjkhfdgjkh"));
assertTrue(new String(ms.getMasterSecret()), "master".equals(new String(ms.getMasterSecret())));
assertTrue(outContent.toString(), outContent.toString().contains("Master secret has been persisted to disk."));
}
use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testRemoteConfigurationRegistryUploadDescriptor.
@Test
public void testRemoteConfigurationRegistryUploadDescriptor() throws Exception {
outContent.reset();
final String descriptorName = "my-topology.json";
final String descriptorContent = testDescriptorContentJSON;
final File testRoot = TestUtils.createTempDir(this.getClass().getName());
try {
final File testRegistry = new File(testRoot, "registryRoot");
final File testDescriptor = new File(testRoot, descriptorName);
final String[] args = { "upload-descriptor", testDescriptor.getAbsolutePath(), "--registry-client", "test_client", "--master", "master" };
FileUtils.writeStringToFile(testDescriptor, descriptorContent);
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-descriptors", "--registry-client", "test_client" };
cli.run(listArgs);
String outStr = outContent.toString().trim();
assertTrue(outStr.startsWith("Descriptors"));
assertTrue(outStr.endsWith(")\n" + descriptorName));
File registryFile = new File(testRegistry, "knox/config/descriptors/" + descriptorName);
assertTrue(registryFile.exists());
assertEquals(FileUtils.readFileToString(registryFile), descriptorContent);
} finally {
FileUtils.forceDelete(testRoot);
}
}
use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testRemoteConfigurationRegistryDeleteDescriptor.
@Test
public void testRemoteConfigurationRegistryDeleteDescriptor() throws Exception {
outContent.reset();
final String descriptorName = "my-topology.json";
final String descriptorContent = testDescriptorContentJSON;
final File testRoot = TestUtils.createTempDir(this.getClass().getName());
try {
final File testRegistry = new File(testRoot, "registryRoot");
final File testDescriptor = new File(testRoot, descriptorName);
final String[] createArgs = { "upload-descriptor", testDescriptor.getAbsolutePath(), "--registry-client", "test_client", "--master", "master" };
FileUtils.writeStringToFile(testDescriptor, descriptorContent);
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/descriptors/" + descriptorName);
assertTrue(registryFile.exists());
outContent.reset();
// Delete the created provider config
final String[] deleteArgs = { "delete-descriptor", descriptorName, "--registry-client", "test_client", "--master", "master" };
rc = cli.run(deleteArgs);
assertEquals(0, rc);
assertFalse(registryFile.exists());
// Try to delete a descriptor that does not exist
rc = cli.run(new String[] { "delete-descriptor", "bogus.json", "--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 testSuccessfulAliasLifecycle.
@Test
public void testSuccessfulAliasLifecycle() throws Exception {
outContent.reset();
String[] args1 = { "create-alias", "alias1", "--value", "testvalue1", "--master", "master" };
int rc = 0;
KnoxCLI cli = new KnoxCLI();
cli.setConf(new GatewayConfigImpl());
rc = cli.run(args1);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("alias1 has been successfully " + "created."));
outContent.reset();
String[] args2 = { "list-alias", "--master", "master" };
rc = cli.run(args2);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("alias1"));
outContent.reset();
String[] args4 = { "delete-alias", "alias1", "--master", "master" };
rc = cli.run(args4);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("alias1 has been successfully " + "deleted."));
outContent.reset();
rc = cli.run(args2);
assertEquals(0, rc);
assertFalse(outContent.toString(), outContent.toString().contains("alias1"));
}
use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testListRemoteConfigurationRegistryClients.
@Test
public void testListRemoteConfigurationRegistryClients() throws Exception {
outContent.reset();
KnoxCLI cli = new KnoxCLI();
String[] args = { "list-registry-clients", "--master", "master" };
Configuration config = new GatewayConfigImpl();
cli.setConf(config);
// Test with no registry clients configured
int rc = cli.run(args);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().isEmpty());
// Test with a single client configured
// Configure a client for the test local filesystem registry implementation
config.set("gateway.remote.config.registry.test_client", "type=LocalFileSystem;address=/test1");
cli.setConf(config);
outContent.reset();
rc = cli.run(args);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("test_client"));
// Configure another client for the test local filesystem registry implementation
config.set("gateway.remote.config.registry.another_client", "type=LocalFileSystem;address=/test2");
cli.setConf(config);
outContent.reset();
rc = cli.run(args);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("test_client"));
assertTrue(outContent.toString(), outContent.toString().contains("another_client"));
}
Aggregations