CaptureAgentStateServiceImpl implements CaptureAgentStateService, ManagedServiceFactory { @Override public void removeAgent(String agentName) throws NotFoundException { deleteAgentFromDatabase(agentName); } CaptureAgentStateServiceImpl(); @Reference(name = "security-service") void setSecurityService(SecurityService securityService); @Activate void activate(ComponentContext cc); @Deactivate void deactivate(); @Override Agent getAgent(String name); @Override String getAgentState(String agentName); @Override boolean setAgentState(String agentName, String state); @Override boolean setAgentUrl(String agentName, String agentUrl); @Override void removeAgent(String agentName); @Override Map<String, Agent> getKnownAgents(); @Override Properties getAgentCapabilities(String agentName); @Override Properties getAgentConfiguration(String agentName); @Override boolean setAgentConfiguration(String agentName, Properties configuration); @Override String getName(); @Override void updated(String pid, Dictionary<String, ?> properties); @Override void deleted(String pid); static final String PERSISTENCE_UNIT; static final String CAPTURE_AGENT_TIMEOUT_KEY; }
@Test public void removeAgent() { service.setAgentConfiguration("agent1", capabilities); assertEquals(1, service.getKnownAgents().size()); service.setAgentConfiguration("agent2", capabilities); service.setAgentState("agent2", UPLOADING); verifyAgent("notAnAgent", null, capabilities); verifyAgent("agent1", UNKNOWN, capabilities); verifyAgent("agent2", UPLOADING, capabilities); try { service.removeAgent("agent1"); assertEquals(1, service.getKnownAgents().size()); verifyAgent("notAnAgent", null, capabilities); verifyAgent("agent1", null, capabilities); verifyAgent("agent2", UPLOADING, capabilities); } catch (NotFoundException e) { fail(); } try { service.removeAgent("notAnAgent"); fail(); } catch (NotFoundException e) { assertNotNull(e); } assertEquals(1, service.getKnownAgents().size()); verifyAgent("notAnAgent", null, capabilities); verifyAgent("agent1", null, capabilities); verifyAgent("agent2", UPLOADING, capabilities); }