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
4b5f4793
Commit
4b5f4793
authored
Apr 07, 2015
by
aninhacostaribeiro
Browse files
Added new tests
parent
1e87be58
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/fogbowcloud/green/agent/AgentCommunicationComponent.java
View file @
4b5f4793
...
...
@@ -29,6 +29,7 @@ public class AgentCommunicationComponent {
private
Properties
prop
;
private
int
threadTime
;
private
XMPPClient
client
;
XEP0077
register
=
new
XEP0077
();
public
AgentCommunicationComponent
(
Properties
prop
)
{
try
{
...
...
@@ -53,21 +54,25 @@ public class AgentCommunicationComponent {
protected
void
setClient
(
XMPPClient
client
)
{
this
.
client
=
client
;
}
protected
void
setRegister
(
XEP0077
register
)
{
this
.
register
=
register
;
}
public
Boolean
init
()
{
XEP0077
register
=
new
XEP0077
();
try
{
this
.
client
.
registerPlugin
(
register
);
this
.
client
.
connect
();
}
catch
(
Exception
e
)
{
LOGGER
.
fatal
(
"It was not possible to connect to server"
,
e
);
e
.
printStackTrace
();
return
false
;
}
try
{
register
.
createAccount
(
this
.
prop
.
getProperty
(
"xmpp.jid"
),
this
.
prop
.
getProperty
(
"xmpp.password"
));
}
catch
(
XMPPException
e
)
{
LOGGER
.
fatal
(
"It was not possible to create the account"
,
e
);
LOGGER
.
warn
(
"It was not possible to create the account"
,
e
);
}
try
{
this
.
client
.
login
();
...
...
@@ -93,17 +98,17 @@ public class AgentCommunicationComponent {
return
false
;
}
if
(
packet
.
getError
()
!=
null
)
{
LOGGER
.
warn
(
"IAmAlive packet returned an error: "
+
packet
.
toXML
());
LOGGER
.
fatal
(
"IAmAlive packet returned an error: "
+
packet
.
toXML
());
return
false
;
}
Element
queryEl
=
packet
.
getElement
().
element
(
"query"
);
if
(
queryEl
==
null
)
{
LOGGER
.
info
(
"There is no query element in the response packet"
);
LOGGER
.
fatal
(
"There is no query element in the response packet"
);
return
false
;
}
String
ns
=
queryEl
.
getNamespaceURI
();
if
(!
ns
.
equals
(
"org.fogbowcloud.green.GoToBed"
))
{
LOGGER
.
info
(
"Query element has a different namespace: "
+
ns
);
LOGGER
.
fatal
(
"Query element has a different namespace: "
+
ns
);
return
false
;
}
...
...
src/test/java/org/fogbowcloud/green/agent/TestAgentCommunicationComponent.java
View file @
4b5f4793
...
...
@@ -39,11 +39,30 @@ public class TestAgentCommunicationComponent {
XMPPClient
client
=
Mockito
.
mock
(
XMPPClient
.
class
);
XMPPException
e
=
new
XMPPException
();
Mockito
.
doThrow
(
e
).
when
(
client
).
connect
();
Mockito
.
doThrow
(
e
).
when
(
client
).
registerPlugin
(
new
XEP0077
());
Properties
prop
=
Mockito
.
mock
(
Properties
.
class
);
AgentCommunicationComponent
acc
=
new
AgentCommunicationComponent
(
prop
);
acc
.
setClient
(
client
);
Assert
.
assertEquals
(
false
,
acc
.
init
());
}
@Test
public
void
testAccountAlreadyCreated
()
throws
XMPPException
{
XMPPException
e
=
new
XMPPException
();
XEP0077
register
=
Mockito
.
mock
(
XEP0077
.
class
);
Properties
prop
=
Mockito
.
mock
(
Properties
.
class
);
XMPPClient
client
=
Mockito
.
mock
(
XMPPClient
.
class
);
Mockito
.
doReturn
(
Mockito
.
mock
(
XMPPConnection
.
class
)).
when
(
client
).
getConnection
();
Mockito
.
doReturn
(
"jid@testagent.com"
).
when
(
prop
).
getProperty
(
"xmpp.jid"
);
Mockito
.
doReturn
(
"tellnoone"
).
when
(
prop
).
getProperty
(
"xmpp.password"
);
Mockito
.
doThrow
(
e
).
when
(
register
).
createAccount
(
"jid@testagent.com"
,
"tellnoone"
);
AgentCommunicationComponent
acc
=
new
AgentCommunicationComponent
(
prop
);
acc
.
setRegister
(
register
);
acc
.
setClient
(
client
);
Assert
.
assertEquals
(
true
,
acc
.
init
());
}
@Test
public
void
testPacketFromUnexpectedSource
()
{
}
}
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