Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fogbow
fogbow-green-sitter
Commits
ff9a697b
Commit
ff9a697b
authored
Apr 01, 2015
by
aninhacostaribeiro
Browse files
Added a test to agent communication plugin
parent
4e79d2bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/fogbowcloud/green/agent/AgentCommunicationComponent.java
View file @
ff9a697b
...
...
@@ -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
()
{
...
...
src/main/java/org/fogbowcloud/green/server/core/plugins/openstack/OpenStackInfoPlugin.java
View file @
ff9a697b
...
...
@@ -37,13 +37,14 @@ public class OpenStackInfoPlugin implements CloudInfoPlugin {
.
authenticate
();
}
p
rivate
List
<
String
>
getHostsName
()
{
p
ublic
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
;
}
...
...
src/test/java/org/fogbowcloud/green/agent/TestAgentCommunicationComponent.java
0 → 100644
View file @
ff9a697b
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"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment