summaryrefslogtreecommitdiff
path: root/same/src/test/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-12 19:40:18 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-12 19:40:18 +0100
commit0c1fe5d3169b069bc88c1de7375658c1c885487c (patch)
treee0798abe13d1aec257a5f28030b99b21c57a68ba /same/src/test/java/com
parent1972b666d6eefcdcafee27cd5d9b86762ab59c87 (diff)
Client begins in disconnected state.
Diffstat (limited to 'same/src/test/java/com')
-rw-r--r--same/src/test/java/com/orbekk/same/ClientTest.java35
-rw-r--r--same/src/test/java/com/orbekk/same/MasterTest.java5
2 files changed, 38 insertions, 2 deletions
diff --git a/same/src/test/java/com/orbekk/same/ClientTest.java b/same/src/test/java/com/orbekk/same/ClientTest.java
index 91f9760..d20b1d3 100644
--- a/same/src/test/java/com/orbekk/same/ClientTest.java
+++ b/same/src/test/java/com/orbekk/same/ClientTest.java
@@ -1,9 +1,17 @@
package com.orbekk.same;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import org.junit.Before;
import org.junit.Test;
-import static org.mockito.Mockito.*;
+
+import com.orbekk.util.DelayedOperation;
public class ClientTest {
private State state = new State("ClientNetwork");
@@ -11,6 +19,29 @@ public class ClientTest {
private Client client = new Client(state, connections,
"http://client/ClientService.json");
private ClientService clientS = client.getService();
+ private MasterService mockMaster = mock(MasterService.class);
+
+ @Before public void setUp() {
+ connections.masterMap.put("master", mockMaster);
+ }
+
+ @Test public void disconnectedFailsUpdate() throws Exception {
+ ClientInterface clientI = client.getInterface();
+ DelayedOperation op = clientI.set(null);
+ assertTrue(op.isDone());
+ assertFalse(op.getStatus().isOk());
+ }
+
+ @Test public void connectedUpdateWorks() throws Exception {
+ clientS.masterTakeover("master", null, 0);
+ ClientInterface clientI = client.getInterface();
+ State.Component component = new State.Component(
+ "TestVariable", 1, "meow");
+ when(mockMaster.updateStateRequest("TestVariable", "meow", 1))
+ .thenReturn(true);
+ DelayedOperation op = clientI.set(component);
+ assertTrue(op.getStatus().isOk());
+ }
@Test public void testSetState() throws Exception {
clientS.setState("TestState", "Test data", 100);
diff --git a/same/src/test/java/com/orbekk/same/MasterTest.java b/same/src/test/java/com/orbekk/same/MasterTest.java
index 09ac6a1..3a8bd5a 100644
--- a/same/src/test/java/com/orbekk/same/MasterTest.java
+++ b/same/src/test/java/com/orbekk/same/MasterTest.java
@@ -31,6 +31,11 @@ public class MasterTest {
public void discoveryRequest(String remoteUrl) throws Exception {
throw new Exception("Unreachable client");
}
+
+ @Override
+ public void masterTakeover(String masterUrl, String networkName, int masterId)
+ throws Exception {
+ }
}
@Before