Skip to content

Commit

Permalink
New tests to greenSitter core
Browse files Browse the repository at this point in the history
  • Loading branch information
RibeiroAna committed Apr 14, 2015
1 parent b95a898 commit e9a49dc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,40 @@
import org.xmpp.packet.Packet;

public class TestAgentCommunicationComponent {


private Properties createProperties() {
Properties prop = new Properties();
prop.put("xmpp.jid", "[email protected]");
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);
Expand Down Expand Up @@ -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", "[email protected]");
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("[email protected]", "tellnoone");
AgentCommunicationComponent acc = new AgentCommunicationComponent(prop);
Expand Down Expand Up @@ -165,6 +187,4 @@ public void testCallTurnOff() {
pl.processPacket(Mockito.mock(Packet.class));
Mockito.verify(turnOff).suspend();
}


}

0 comments on commit e9a49dc

Please sign in to comment.