Add support for the new caminus permission API

This commit is contained in:
Trever Fischer
2012-03-18 23:25:51 -04:00
parent 16d74ab611
commit 42616a6f71
6 changed files with 173 additions and 83 deletions

View File

@ -52,9 +52,9 @@ public class APIServer {
ServletOutputStream out = resp.getOutputStream();
if (req.getPathInfo().equals("/TestUser"))
out.println("{valid: true, error: ''}");
out.println("{valid: true, error: '', permissions: ['*']}");
else
out.println("{valid: false, error: 'Test Failure'}");
out.println("{valid: false, error: 'Test Failure', permissions: []}");
}
}

View File

@ -25,16 +25,16 @@ import static org.junit.Assert.*;
import java.io.IOException;
import us.camin.JoinListener;
import us.camin.api.Server;
import us.camin.api.ValidationResponse;
public class JoinTest {
private JoinListener listener;
private Server api;
private APIServer server;
@Before public void setup() throws Exception {
server = new APIServer();
server.start();
listener = new JoinListener();
listener.setURL("http://localhost:8001/api/");
api = new Server("http://localhost:8001/api/");
}
@After public void teardown() throws Exception {
@ -42,16 +42,22 @@ public class JoinTest {
}
@Test public void validUser() throws IOException, JSONException {
assertTrue(listener.isUserAuthed("TestUser"));
ValidationResponse resp = api.validatePlayer("TestUser");
assertTrue(resp.valid);
assertNotNull(resp.permissions);
assertTrue(resp.permissions.length>0);
}
@Test public void invaliduser() throws IOException, JSONException {
assertFalse(listener.isUserAuthed("InvalidUser"));
ValidationResponse resp = api.validatePlayer("InvalidUser");
assertFalse(resp.valid);
assertNotNull(resp.permissions);
assertEquals(resp.permissions.length, 0);
}
@Test public void motd() throws IOException, JSONException {
String[] goodMOTD = {"Test MOTD"};
String[] motd = listener.fetchMOTD("TestUser");
String[] motd = api.fetchMOTD("TestUser");
assertArrayEquals(null, goodMOTD, motd);
}
}