use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerImplTest method testGetDefaultComponent.
/**
* Test getDefaultComponent.
*/
public void testGetDefaultComponent() {
try {
try {
manager.getDefaultComponent(0, null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.getDefaultComponent(Integer.MAX_VALUE, null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.getDefaultComponent(dummyHandle, "dummyType");
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
TestClient client = new TestClient(clientName);
ClientInfo info = manager.login(client);
assertTrue(info.getHandle() != 0);
try {
manager.getDefaultComponent(info.getHandle(), null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.getDefaultComponent(info.getHandle(), "invalid");
fail();
} catch (NoDefaultComponentException ndce) {
System.out.println("This is OK: " + ndce.getMessage());
}
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount3COB = new TestComponent("MOUNT3");
supportedComponents.put("MOUNT3", mount3COB);
container.setSupportedComponents(supportedComponents);
/*ClientInfo containerInfo = */
manager.login(container);
try {
ComponentInfo componentInfo = manager.getDefaultComponent(info.getHandle(), "IDL:alma/MOUNT_ACS/Mount:1.0");
assertTrue(componentInfo != null);
assertEquals(componentInfo.getComponent(), mount3COB);
} catch (NoDefaultComponentException ndce) {
fail();
}
} catch (AcsJNoPermissionEx e) {
fail("No permission");
} catch (NoDefaultComponentException e) {
fail();
}
}
use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerImplTest method testUnregisterComponent.
public void testUnregisterComponent() {
//test invalid
try {
manager.unregisterComponent(0, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
//test invalid
try {
manager.unregisterComponent(Integer.MAX_VALUE, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
//test invalid
try {
manager.unregisterComponent(dummyHandle, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
//test invalid
try {
manager.unregisterComponent(dummyHandle, Integer.MAX_VALUE);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
try {
//unregister valid
ClientInfo info = manager.login(new TestClient(anotherName));
int handle = 0;
try {
handle = manager.registerComponent(info.getHandle(), dummyURI, type, new TestComponent(cobName));
} catch (AcsJBadParameterEx e) {
fail();
}
try {
manager.unregisterComponent(info.getHandle(), handle);
} catch (AcsJBadParameterEx e) {
fail();
}
//duplicate unregistration
try {
manager.unregisterComponent(info.getHandle(), handle);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: duplicate unregistration " + bpe.toString());
}
manager.logout(info.getHandle());
} catch (AcsJNoPermissionEx e) {
e.printStackTrace();
fail("No permission");
}
}
use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerImplTest method testForceReleaseComponent.
public void testForceReleaseComponent() {
try {
try {
manager.forceReleaseComponent(0, null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
try {
manager.forceReleaseComponent(Integer.MAX_VALUE, null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
try {
manager.forceReleaseComponent(dummyHandle, dummyURI);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
TestAdministrator admin = new TestAdministrator(administratorName);
ClientInfo adminInfo = manager.login(admin);
assertTrue(adminInfo.getHandle() != 0);
TestClient client = new TestClient(clientName);
ClientInfo info = manager.login(client);
assertTrue(info.getHandle() != 0);
TestClient client2 = new TestClient(clientName + "2");
ClientInfo info2 = manager.login(client2);
assertTrue(info2.getHandle() != 0);
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
Component mount4COB = new TestComponent("MOUNT4");
supportedComponents.put("MOUNT1", mount1COB);
supportedComponents.put("MOUNT4", mount4COB);
container.setSupportedComponents(supportedComponents);
ClientInfo containerInfo = manager.login(container);
// client activate
URI mount4 = null;
try {
mount4 = new URI("MOUNT4");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount4, true, status);
assertEquals(mount4COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// client2 activate
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info2.getHandle(), mount4, true, status);
assertEquals(mount4COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
// there should be only two Components activated (MOUNT1 and MOUNT4)
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(2, infos.length);
/*
// test forceful release (no permission - no admin)
try
{
manager.forceReleaseComponent(info.getHandle(), mount4);
fail();
}
catch (AcsJNoPermissionEx npe)
{
System.out.println("This is OK: "+npe.toString());
}
*/
// TODO tmp - due to Heiko's hack
System.out.println("This is OK: Insufficient rights.");
// test forceful release
int clients;
try {
clients = manager.forceReleaseComponent(adminInfo.getHandle(), mount4);
assertEquals(2, clients);
} catch (AcsJBadParameterEx e) {
fail();
}
// there should be only one component activated (MOUNT1)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(1, infos.length);
// admin activate
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(adminInfo.getHandle(), mount4, true, status);
assertEquals(mount4COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// there should be two components activated (MOUNT1 and MOUNT4)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(2, infos.length);
try {
clients = manager.releaseComponent(adminInfo.getHandle(), mount4);
assertEquals(2, clients);
} catch (AcsJBadParameterEx e) {
fail();
}
// there should be two components activated (MOUNT1 and MOUNT4)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(2, infos.length);
// there should be two components activated (MOUNT1 and MOUNT4)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "MOUNT4", "*", true);
assertEquals(1, infos.length);
IntArray compClients = infos[0].getClients();
assertEquals(2, compClients.size());
assertTrue(compClients.contains(info.getHandle()));
assertTrue(compClients.contains(info2.getHandle()));
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerProxy method getComponent.
/**
* @see com.cosylab.acs.maci.Manager#getComponent(int, java.net.URI, boolean, com.cosylab.acs.maci.StatusHolder)
*/
public Component getComponent(int id, URI curl, boolean activate, StatusHolder status) throws AcsJNoPermissionEx {
try {
Component retVal = null;
org.omg.CORBA.Object object = manager.get_component(id, curl.toString(), activate);
if (object != null) {
retVal = new ComponentProxy(curl.toString(), object);
}
return retVal;
} catch (NoPermissionEx npex) {
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Remote manager has thrown no permission exception.");
npe.setID(HandleHelper.toString(id));
npe.setProtectedResource(curl.toString());
throw npe;
} catch (Exception ex) {
//throw re;
return null;
}
}
use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerProxy method getComponentInfo.
/**
* @see com.cosylab.acs.maci.Manager#getComponentInfo(int, int[], java.lang.String, java.lang.String, boolean)
*/
public ComponentInfo[] getComponentInfo(int id, int[] handles, String name_wc, String type_wc, boolean activeOnly) throws AcsJNoPermissionEx {
try {
// returned value
ComponentInfo[] retVal = null;
// transform to CORBA specific
si.ijs.maci.ComponentInfo[] infos = manager.get_component_info(id, handles, name_wc, type_wc, activeOnly);
if (infos != null) {
retVal = new ComponentInfo[infos.length];
for (int i = 0; i < infos.length; i++) {
ComponentInfo componentInfo = new ComponentInfo(infos[i].h, infos[i].name, infos[i].type, infos[i].code, new ComponentProxy(infos[i].name, infos[i].reference));
componentInfo.setContainer(infos[i].container);
componentInfo.setContainerName(infos[i].container_name);
componentInfo.setAccessRights(ContainerProxy.inverseMapAccessRights(infos[i].access));
componentInfo.setClients(new IntArray(infos[i].clients));
componentInfo.setInterfaces(infos[i].interfaces);
retVal[i] = componentInfo;
}
}
return retVal;
} catch (NoPermissionEx npex) {
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Remote manager has thrown no permission exception.");
npe.setID(HandleHelper.toString(id));
throw npe;
} catch (Exception ex) {
//throw re;
return null;
}
}
Aggregations