Commit ff9a697b authored by aninhacostaribeiro's avatar aninhacostaribeiro
Browse files

Added a test to agent communication plugin

parent 4e79d2bf
......@@ -43,6 +43,10 @@ public class AgentCommunicationComponent {
LOGGER.fatal("The configuration file is not correct", e);
}
}
protected void setClient(XMPPClient client) {
this.client = client;
}
public Boolean init() {
XEP0077 register = new XEP0077();
......@@ -103,7 +107,7 @@ public class AgentCommunicationComponent {
return true;
}
public void sendIamAliveSignal() {
public IQ sendIamAliveSignal() {
IQ iq = new IQ(Type.get);
iq.setTo(this.prop.getProperty("xmpp.component"));
iq.getElement().addElement("query", NAMESPACE);
......@@ -117,6 +121,7 @@ public class AgentCommunicationComponent {
.setText(this.prop.getProperty("host.name"));
client.getConnection().sendPacket(iq);
LOGGER.info("IAmAlive signal sent to " + iq.getTo());
return iq;
}
public void start() {
......
......@@ -37,13 +37,14 @@ public class OpenStackInfoPlugin implements CloudInfoPlugin {
.authenticate();
}
private List<String> getHostsName() {
public List<String> getHostsName() {
List<? extends Hypervisor> hypervisors = os().compute().hypervisors()
.list();
List<String> hostsName = new LinkedList<String>();
for (Hypervisor hypervisor : hypervisors) {
hostsName.add(hypervisor.getHypervisorHostname());
}
System.out.println(hostsName.toString());
return hostsName;
}
......
package org.fogbowcloud.green.agent;
import java.util.Properties;
import org.junit.Assert;
import org.jamppa.client.XMPPClient;
import org.jivesoftware.smack.XMPPConnection;
import org.junit.Test;
import org.mockito.Mockito;
import org.xmpp.packet.IQ;
public class TestAgentCommunicationComponent {
private XMPPClient createXMPPClientMock() {
XMPPClient client = Mockito.mock(XMPPClient.class);
Mockito.doReturn(Mockito.mock(XMPPConnection.class)).when(client)
.getConnection();
return client;
}
private Properties createPropMock(String hostName, String ip,
String macAddress) {
Properties prop = Mockito.mock(Properties.class);
Mockito.doReturn(ip).when(prop).getProperty("host.ip");
Mockito.doReturn(hostName).when(prop).getProperty("host.name");
Mockito.doReturn(macAddress).when(prop).getProperty("host.macAddress");
return prop;
}
@Test
public void testSendIamAliveSignal() {
XMPPClient client = createXMPPClientMock();
Properties prop = createPropMock("host", "123.456.78.9", "A1:B2:C3:D4:E5:67");
AgentCommunicationComponent acc = new AgentCommunicationComponent(prop);
acc.setClient(client);
IQ expectedIQ = acc.sendIamAliveSignal();
Assert.assertEquals(expectedIQ.getElement().element("query").elementText("ip"),"123.456.78.9");
Assert.assertEquals(expectedIQ.getElement().element("query").elementText("hostName"),"host");
Assert.assertEquals(expectedIQ.getElement().element("query").elementText("macAddress"),"A1:B2:C3:D4:E5:67");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment