public void initCapability() { try { log.info("INFO: Before test, getting queue..."); Assert.assertNotNull(queueManagerFactory); queueCapability = queueManagerFactory.create(mockResource); queueCapability.initialize(); protocolManager.getProtocolSessionManagerWithContext( mockResource.getResourceId(), newSessionContextNetconf()); // Test elements not null log.info("Checking chassis factory"); Assert.assertNotNull(chassisFactory); log.info("Checking capability descriptor"); Assert.assertNotNull(mockResource.getResourceDescriptor().getCapabilityDescriptor("chassis")); log.info("Creating chassis capability"); chassisCapability = chassisFactory.create(mockResource); Assert.assertNotNull(chassisCapability); chassisCapability.initialize(); mockResource.addCapability(chassisCapability); mockResource.addCapability(queueCapability); } catch (Exception e) { e.printStackTrace(); log.error(e.getMessage()); if (ExceptionUtils.getRootCause(e) != null) log.error(ExceptionUtils.getRootCause(e).getMessage()); Assert.fail(e.getMessage()); } }
public ICapability getCapability(List<ICapability> capabilities, String type) { for (ICapability capability : capabilities) { if (capability.getCapabilityInformation().getType().equals(type)) { return capability; } } return null; }
@Override public ICapability create(IResource resource) throws CapabilityException { ICapability capability = this.create( resource.getResourceDescriptor().getCapabilityDescriptor(QueueManager.QUEUE), resource.getResourceDescriptor().getId()); capability.setResource(resource); return capability; }
@Override public ICapability create(IResource resource) throws CapabilityException { ICapability capability = this.create( resource .getResourceDescriptor() .getCapabilityDescriptor(PowerSupplyCapability.CAPABILITY_TYPE), resource.getResourceDescriptor().getId()); capability.setResource(resource); return capability; }
@Test public void UpDownActionTest() throws CapabilityException { Response resp; QueueResponse queueResponse; resp = (Response) chassisCapability.sendMessage(ActionConstants.GETCONFIG, null); Assert.assertEquals(Status.QUEUED, resp.getStatus()); Assert.assertTrue(resp.getErrors().size() == 0); queueResponse = (QueueResponse) queueCapability.sendMessage(QueueConstants.EXECUTE, null); Assert.assertTrue(queueResponse.isOk()); String str = ""; ComputerSystem model = (ComputerSystem) mockResource.getModel(); Assert.assertNotNull(model); for (LogicalDevice device : model.getLogicalDevices()) { if (device instanceof EthernetPort) { EthernetPort port = (EthernetPort) device; Assert.assertNotNull("OperationalStatus must be set", port.getOperationalStatus()); str += "- EthernetPort: " + '\n'; str += port.getName() + '.' + port.getPortNumber() + '\n'; str += port.getOperationalStatus(); str += '\n'; for (ProtocolEndpoint protocolEndpoint : port.getProtocolEndpoint()) { if (protocolEndpoint instanceof IPProtocolEndpoint) { IPProtocolEndpoint ipProtocol = (IPProtocolEndpoint) protocolEndpoint; str += "ipv4: " + ipProtocol.getIPv4Address() + '\n'; str += "ipv6: " + ipProtocol.getIPv6Address() + '\n'; } } } else { str += "not searched device"; } } log.info(str); String interfaceName = "fe-0/1/3"; /* check model */ LogicalDevice logicalDevice = null; try { logicalDevice = getLogicalDevice(interfaceName, (ComputerSystem) mockResource.getModel()); } catch (Exception ex) { Assert.fail("LogicalDevice not found"); } if (logicalDevice.getOperationalStatus() != OperationalStatus.OK) { Assert.fail("The test can't be executed because the needed interface is down"); } /* send to change status */ resp = (Response) chassisCapability.sendMessage( ActionConstants.CONFIGURESTATUS, newParamsConfigureStatus(interfaceName, OperationalStatus.STOPPED)); Assert.assertEquals(Status.QUEUED, resp.getStatus()); Assert.assertTrue(resp.getErrors().size() == 0); Assert.assertTrue( ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 1); queueResponse = (QueueResponse) queueCapability.sendMessage(QueueConstants.EXECUTE, null); Assert.assertTrue(queueResponse.isOk()); Assert.assertTrue( ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 0); if (!isMock) { checkOperationalStatus( (ComputerSystem) mockResource.getModel(), interfaceName, OperationalStatus.STOPPED); } /* send to change status */ resp = (Response) chassisCapability.sendMessage( ActionConstants.CONFIGURESTATUS, newParamsConfigureStatus(interfaceName, OperationalStatus.OK)); Assert.assertEquals(Status.QUEUED, resp.getStatus()); Assert.assertTrue(resp.getErrors().size() == 0); Assert.assertTrue( ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 1); queueResponse = (QueueResponse) queueCapability.sendMessage(QueueConstants.EXECUTE, null); Assert.assertTrue(queueResponse.isOk()); Assert.assertTrue( ((List<IAction>) queueCapability.sendMessage(QueueConstants.GETQUEUE, null)).size() == 0); if (!isMock) { checkOperationalStatus( (ComputerSystem) mockResource.getModel(), interfaceName, OperationalStatus.OK); } }
public void addCapability(ICapability capability) { log.info("add Capability..."); capabilities.put(capability.getCapabilityInformation().getName(), capability); }