From e9a49dc69b0fbf43911857f30f01fbf47701ad64 Mon Sep 17 00:00:00 2001 From: aninhacostaribeiro Date: Tue, 14 Apr 2015 14:37:04 -0300 Subject: [PATCH] New tests to greenSitter core --- .../agent/AgentCommunicationComponent.java | 12 ++++-- .../TestAgentCommunicationComponent.java | 42 ++++++++++++++----- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/fogbowcloud/green/agent/AgentCommunicationComponent.java b/src/main/java/org/fogbowcloud/green/agent/AgentCommunicationComponent.java index 6e727b4..2385e1a 100644 --- a/src/main/java/org/fogbowcloud/green/agent/AgentCommunicationComponent.java +++ b/src/main/java/org/fogbowcloud/green/agent/AgentCommunicationComponent.java @@ -38,12 +38,12 @@ public AgentCommunicationComponent(Properties prop) { this.prop.getProperty("xmpp.password"), this.prop.getProperty("xmpp.host"), Integer.parseInt(this.prop.getProperty("xmpp.port"))); - if (this.prop.getProperty("green.threadTime") != null) { - this.threadTime = Integer.parseInt(this.prop - .getProperty("green.threadTime")); + if (this.prop.getProperty("green.threadTime") == null) { + this.threadTime = 60; } else{ - this.threadTime = 60; + this.threadTime = Integer.parseInt(this.prop + .getProperty("green.threadTime")); } } catch (Exception e) { @@ -59,6 +59,10 @@ protected void setRegister(XEP0077 register) { this.register = register; } + protected int getThreadTime() { + return threadTime; + } + protected static PacketFilter createPacketFilter(final String componentAddress) { return new PacketFilter() { @Override diff --git a/src/test/java/org/fogbowcloud/green/agent/TestAgentCommunicationComponent.java b/src/test/java/org/fogbowcloud/green/agent/TestAgentCommunicationComponent.java index d52618e..df3e051 100644 --- a/src/test/java/org/fogbowcloud/green/agent/TestAgentCommunicationComponent.java +++ b/src/test/java/org/fogbowcloud/green/agent/TestAgentCommunicationComponent.java @@ -17,16 +17,40 @@ import org.xmpp.packet.Packet; public class TestAgentCommunicationComponent { - + + private Properties createProperties() { + Properties prop = new Properties(); + prop.put("xmpp.jid", "jid@testagent.com"); + prop.put("xmpp.password", "tellnoone"); + prop.put("xmpp.host", "localhost"); + prop.put("xmpp.port", "23"); + prop.put("host.ip", "123.456.78.9"); + prop.put("host.name", "host"); + prop.put("host.macAddress", "A1:B2:C3:D4:E5:67"); + return prop; + } + + @Test + public void testThreadTimeIsNotSetted() { + Properties prop = createProperties(); + AgentCommunicationComponent acc = new AgentCommunicationComponent(prop); + Assert.assertEquals(60, acc.getThreadTime()); + } + + @Test + public void testThreadTimeIstSetted() { + Properties prop = createProperties(); + prop.put("green.threadTime", "50"); + AgentCommunicationComponent acc = new AgentCommunicationComponent(prop); + Assert.assertEquals(50, acc.getThreadTime()); + } + @Test public void testSendIamAliveSignal() { XMPPClient client = Mockito.mock(XMPPClient.class); Mockito.doReturn(Mockito.mock(XMPPConnection.class)).when(client) .getConnection(); - Properties prop = new Properties(); - prop.put("host.ip", "123.456.78.9"); - prop.put("host.name", "host"); - prop.put("host.macAddress", "A1:B2:C3:D4:E5:67"); + Properties prop = createProperties(); AgentCommunicationComponent acc = new AgentCommunicationComponent(prop); acc.setClient(client); @@ -54,10 +78,8 @@ public void testInitConnectException() throws XMPPException { public void testAccountAlreadyCreated () throws XMPPException { XMPPException e = new XMPPException(); XEP0077 register = Mockito.mock(XEP0077.class); - Properties prop = new Properties(); - prop.put("xmpp.jid", "jid@testagent.com"); - prop.put("xmpp.password", "tellnoone"); - XMPPClient client = Mockito.mock(XMPPClient.class); + Properties prop = createProperties(); +; XMPPClient client = Mockito.mock(XMPPClient.class); Mockito.doReturn(Mockito.mock(XMPPConnection.class)).when(client).getConnection(); Mockito.doThrow(e).when(register).createAccount("jid@testagent.com", "tellnoone"); AgentCommunicationComponent acc = new AgentCommunicationComponent(prop); @@ -165,6 +187,4 @@ public void testCallTurnOff() { pl.processPacket(Mockito.mock(Packet.class)); Mockito.verify(turnOff).suspend(); } - - }