use of org.apache.karaf.jaas.config.impl.Config in project karaf by apache.
the class ManageRealmCommandTest method testSelectByIndex.
@Test
public void testSelectByIndex() throws Exception {
ManageRealmCommand cmd = new ManageRealmCommand();
// set up two realms, each containing 1 module
Config realm1 = newConfigNamed("realm1");
realm1.setModules(new Module[] { newModuleNamed("module1") });
Config realm2 = newConfigNamed("realm2");
realm2.setModules(new Module[] { newModuleNamed("module2") });
Config[] realms = { realm1, realm2 };
doVerifyIndex(cmd, 1, realms);
doVerifyIndex(cmd, 2, realms);
}
use of org.apache.karaf.jaas.config.impl.Config in project karaf by apache.
the class ManageRealmCommandTest method doVerifyIndex.
/**
* Verify that command selects the correct realm, given some index.
*
* @param cmd the command to use.
* @param index the index to verify.
* @param realms the array of realms.
* @throws Exception in case of failure.
*/
private void doVerifyIndex(ManageRealmCommand cmd, int index, Config[] realms) throws Exception {
// prepare mocks
Session session = createMock(Session.class);
BundleContext bundleContext = createMock(BundleContext.class);
Bundle bundle = createMock(Bundle.class);
// prepare command
cmd.index = index;
cmd.setRealms(Arrays.asList(realms));
cmd.setSession(session);
for (Config realm : realms) realm.setBundleContext(bundleContext);
Object[] mocks = { session, bundleContext, bundle };
expect(session.get(ManageRealmCommand.JAAS_REALM)).andReturn(null).anyTimes();
expect(session.get(ManageRealmCommand.JAAS_ENTRY)).andReturn(null).anyTimes();
expect(session.get(ManageRealmCommand.JAAS_CMDS)).andReturn(null).anyTimes();
expect(bundleContext.getBundle()).andReturn(bundle).anyTimes();
expect(bundle.getBundleId()).andReturn(4711L).anyTimes();
// verify that the correct realm is returned -- cmd.index is 1-based
session.put(ManageRealmCommand.JAAS_REALM, realms[index - 1]);
session.put(eq(ManageRealmCommand.JAAS_ENTRY), anyObject());
session.put(eq(ManageRealmCommand.JAAS_CMDS), anyObject());
// start the test
replay(mocks);
cmd.execute();
verify(mocks);
}
use of org.apache.karaf.jaas.config.impl.Config in project karaf by apache.
the class ManageRealmCommandTest method newConfigNamed.
private Config newConfigNamed(String name) {
Config res = new Config();
res.setName(name);
return res;
}
Aggregations