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
92fa2db7
Commit
92fa2db7
authored
Apr 09, 2015
by
aninhacostaribeiro
Browse files
Changed Properties Mock for the real method
parent
b8f8b3d7
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/fogbowcloud/green/agent/AgentCommunicationComponent.java
View file @
92fa2db7
...
...
@@ -140,7 +140,7 @@ public class AgentCommunicationComponent {
.
elements
(
"query"
).
get
(
0
);
query
.
addElement
(
"ip"
).
setText
(
this
.
prop
.
getProperty
(
"host.ip"
));
query
.
addElement
(
"macAddress"
).
setText
(
this
.
prop
.
getProperty
(
"host.macAddress"
));
this
.
prop
.
getProperty
(
"host.macAddress"
));
query
.
addElement
(
"hostName"
)
.
setText
(
this
.
prop
.
getProperty
(
"host.name"
));
client
.
getConnection
().
sendPacket
(
iq
);
...
...
src/main/java/org/fogbowcloud/green/agent/TurnOff.java
View file @
92fa2db7
...
...
@@ -38,7 +38,6 @@ public class TurnOff {
try
{
Process
process
=
pb
.
start
();
process
.
waitFor
();
System
.
out
.
println
(
process
.
getInputStream
().
read
());
}
catch
(
Exception
e
)
{
LOGGER
.
warn
(
"It was not possible to turn down this host"
,
e
);
}
...
...
src/main/java/org/fogbowcloud/green/server/communication/ServerCommunicationComponent.java
View file @
92fa2db7
...
...
@@ -51,7 +51,6 @@ public class ServerCommunicationComponent extends XMPPComponent {
IQ
iq
=
new
IQ
(
Type
.
set
);
iq
.
setTo
(
hostJID
);
iq
.
getElement
().
addElement
(
"query"
,
"org.fogbowcloud.green.GoToBed"
);
System
.
out
.
println
(
iq
);
packetSender
.
sendPacket
(
iq
);
}
...
...
src/test/java/org/fogbowcloud/green/agent/TestAgentCommunicationComponent.java
View file @
92fa2db7
...
...
@@ -23,12 +23,12 @@ public class TestAgentCommunicationComponent {
XMPPClient
client
=
Mockito
.
mock
(
XMPPClient
.
class
);
Mockito
.
doReturn
(
Mockito
.
mock
(
XMPPConnection
.
class
)).
when
(
client
)
.
getConnection
();
Properties
prop
=
Mockito
.
mock
(
Properties
.
class
);
Mockito
.
doReturn
(
"123.456.78.9"
).
when
(
prop
).
getProperty
(
"host.ip
"
);
Mockito
.
doReturn
(
"host"
).
when
(
prop
).
getProperty
(
"host.name"
);
Mockito
.
doReturn
(
"A1:B2:C3:D4:E5:67"
)
.
when
(
prop
)
.
getProperty
(
"host.macAddress"
);
AgentCommunicationComponent
acc
=
new
AgentCommunicationComponent
(
prop
);
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"
)
;
AgentCommunicationComponent
acc
=
new
AgentCommunicationComponent
(
prop
);
acc
.
setClient
(
client
);
IQ
expectedIQ
=
acc
.
sendIamAliveSignal
();
Assert
.
assertEquals
(
expectedIQ
.
getElement
().
element
(
"query"
)
...
...
@@ -44,7 +44,7 @@ public class TestAgentCommunicationComponent {
XMPPClient
client
=
Mockito
.
mock
(
XMPPClient
.
class
);
XMPPException
e
=
new
XMPPException
();
Mockito
.
doThrow
(
e
).
when
(
client
).
connect
();
Properties
prop
=
Mockito
.
mock
(
Properties
.
class
);
Properties
prop
=
new
Properties
(
);
AgentCommunicationComponent
acc
=
new
AgentCommunicationComponent
(
prop
);
acc
.
setClient
(
client
);
Assert
.
assertEquals
(
false
,
acc
.
init
());
...
...
@@ -54,11 +54,11 @@ public class TestAgentCommunicationComponent {
public
void
testAccountAlreadyCreated
()
throws
XMPPException
{
XMPPException
e
=
new
XMPPException
();
XEP0077
register
=
Mockito
.
mock
(
XEP0077
.
class
);
Properties
prop
=
Mockito
.
mock
(
Properties
.
class
);
Properties
prop
=
new
Properties
();
prop
.
put
(
"xmpp.jid"
,
"jid@testagent.com"
);
prop
.
put
(
"xmpp.password"
,
"tellnoone"
);
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
);
...
...
src/test/java/org/fogbowcloud/green/agent/TestTurnOff.java
View file @
92fa2db7
...
...
@@ -4,13 +4,12 @@ import java.util.Properties;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
public
class
TestTurnOff
{
@Test
public
void
testTurnDownCommandIsNull
()
{
Properties
prop
=
Mockito
.
mock
(
Properties
.
class
);
Properties
prop
=
new
Properties
(
);
TurnOff
turnOff
=
new
TurnOff
(
prop
);
turnOff
.
startTurnOff
();
Assert
.
assertEquals
(
"sudo"
,
turnOff
.
getPb
().
command
().
get
(
0
));
...
...
@@ -20,9 +19,8 @@ public class TestTurnOff {
@Test
public
void
testTurnDownCommandIsSettedandASudoOne
()
{
Properties
prop
=
Mockito
.
mock
(
Properties
.
class
);
Mockito
.
doReturn
(
"pm-hibernate"
).
when
(
prop
)
.
getProperty
(
"green.TurnOffCommand"
);
Properties
prop
=
new
Properties
();
prop
.
put
(
"green.TurnOffCommand"
,
"pm-hibernate"
);
TurnOff
turnOff
=
new
TurnOff
(
prop
);
turnOff
.
startTurnOff
();
Assert
.
assertEquals
(
"sudo"
,
turnOff
.
getPb
().
command
().
get
(
0
));
...
...
@@ -32,9 +30,8 @@ public class TestTurnOff {
@Test
public
void
testTurnDownCommandisNotInSudoers
()
{
Properties
prop
=
Mockito
.
mock
(
Properties
.
class
);
Mockito
.
doReturn
(
"other-suspend-command"
).
when
(
prop
)
.
getProperty
(
"green.TurnOffCommand"
);
Properties
prop
=
new
Properties
();
prop
.
put
(
"green.TurnOffCommand"
,
"other-suspend-command"
);
TurnOff
turnOff
=
new
TurnOff
(
prop
);
turnOff
.
startTurnOff
();
Assert
.
assertEquals
(
"other-suspend-command"
,
...
...
src/test/java/org/fogbowcloud/green/server/communication/TestServerCommunicationComponent.java
View file @
92fa2db7
package
org.fogbowcloud.green.server.communication
;
import
java.util.Properties
;
import
org.dom4j.Element
;
import
org.fogbowcloud.green.server.core.greenStrategy.DefaultGreenStrategy
;
import
org.jamppa.component.PacketSender
;
...
...
@@ -13,7 +12,6 @@ import org.mockito.Mockito;
import
org.xmpp.packet.IQ
;
public
class
TestServerCommunicationComponent
{
private
Properties
createProperties
()
{
Properties
prop
=
new
Properties
();
prop
.
put
(
"xmpp.jid"
,
"123.456.255.255"
);
...
...
@@ -22,53 +20,53 @@ public class TestServerCommunicationComponent {
prop
.
put
(
"xmpp.port"
,
"1"
);
return
prop
;
}
@Test
public
void
testCreationWakeUpCommand
()
{
Properties
prop
=
createProperties
();
prop
.
put
(
"wol.broadcast.address"
,
"123.456.255.255"
);
ServerCommunicationComponent
scc
=
new
ServerCommunicationComponent
(
prop
,
Mockito
.
mock
(
DefaultGreenStrategy
.
class
));
ServerCommunicationComponent
scc
=
new
ServerCommunicationComponent
(
prop
,
Mockito
.
mock
(
DefaultGreenStrategy
.
class
));
ProcessBuilder
pb
=
scc
.
createProcessBuilder
(
"A1:B2:C3:D4:E5:67"
);
Assert
.
assertEquals
(
"powerwake"
,
pb
.
command
().
get
(
0
));
Assert
.
assertEquals
(
"-b"
,
pb
.
command
().
get
(
1
));
Assert
.
assertEquals
(
"123.456.255.255"
,
pb
.
command
().
get
(
2
));
Assert
.
assertEquals
(
"A1:B2:C3:D4:E5:67"
,
pb
.
command
().
get
(
3
));
}
private
IQ
matchIQ
()
{
return
Matchers
.
argThat
(
new
ArgumentMatcher
<
IQ
>()
{
@Override
public
boolean
matches
(
Object
argument
)
{
if
(!(
argument
instanceof
IQ
))
{
return
false
;
}
IQ
argIQ
=
(
IQ
)
argument
;
if
((
argIQ
.
getTo
()
==
null
)
||
(!
argIQ
.
getTo
().
toBareJID
().
equals
(
"host@jid.com"
)))
{
return
false
;
}
if
(
argIQ
.
getElement
().
element
(
"query"
)
==
null
)
{
return
false
;
}
Element
query
=
argIQ
.
getElement
().
element
(
"query"
);
if
(!
query
.
getNamespaceURI
().
equals
(
"org.fogbowcloud.green.GoToBed"
))
{
return
false
;
}
return
true
;
}
}
);
@Override
public
boolean
matches
(
Object
argument
)
{
if
(!(
argument
instanceof
IQ
))
{
return
false
;
}
IQ
argIQ
=
(
IQ
)
argument
;
if
((
argIQ
.
getTo
()
==
null
)
||
(!
argIQ
.
getTo
().
toBareJID
().
equals
(
"host@jid.com"
)))
{
return
false
;
}
if
(
argIQ
.
getElement
().
element
(
"query"
)
==
null
)
{
return
false
;
}
Element
query
=
argIQ
.
getElement
().
element
(
"query"
);
if
(!
query
.
getNamespaceURI
().
equals
(
"org.fogbowcloud.green.GoToBed"
))
{
return
false
;
}
return
true
;
}
});
}
@Test
public
void
testSendIdleHostsToBed
()
{
Properties
prop
=
createProperties
();
ServerCommunicationComponent
scc
=
new
ServerCommunicationComponent
(
prop
,
Mockito
.
mock
(
DefaultGreenStrategy
.
class
));
ServerCommunicationComponent
scc
=
new
ServerCommunicationComponent
(
prop
,
Mockito
.
mock
(
DefaultGreenStrategy
.
class
));
PacketSender
packetSender
=
Mockito
.
mock
(
PacketSender
.
class
);
scc
.
setPacketSender
(
packetSender
);
scc
.
sendIdleHostToBed
(
"host@jid.com"
);
Mockito
.
verify
(
packetSender
).
sendPacket
(
matchIQ
());
}
}
}
\ No newline at end of file
src/test/java/org/fogbowcloud/green/server/core/greenStrategy/TestDefaultGreenStrategy.java
View file @
92fa2db7
...
...
@@ -25,7 +25,7 @@ public class TestDefaultGreenStrategy {
}
@Test
public
void
testCheck
HostLastSeen
()
{
public
void
testCheck
ExpiredHots
()
{
Host
lost
=
new
Host
(
"lost"
,
0
,
true
,
true
,
0
,
0
,
0
);
lost
.
setLastSeen
(
0
);
Host
stilll
=
new
Host
(
"stilll"
,
0
,
true
,
true
,
0
,
0
,
0
);
...
...
@@ -48,7 +48,7 @@ public class TestDefaultGreenStrategy {
}
@Test
public
void
testRetrievingHosts
()
{
public
void
testRetrievingHosts
FromTheCloud
()
{
Host
toBeFound
=
new
Host
(
"found"
,
0
,
true
,
true
,
0
,
0
,
0
);
List
<
Host
>
hosts
=
new
LinkedList
<
Host
>();
hosts
.
add
(
toBeFound
);
...
...
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