Fix ConnectionManager and add test for LoginCommand
This commit is contained in:
parent
3a58c6824d
commit
580c0bed80
@ -54,13 +54,10 @@ public class ConnectionManager {
|
|||||||
private PreferenceStore prefStore;
|
private PreferenceStore prefStore;
|
||||||
private ApiConnection connection;
|
private ApiConnection connection;
|
||||||
|
|
||||||
private static class ConnectionManagerHolder {
|
private static final ConnectionManager instance = new ConnectionManager();
|
||||||
|
|
||||||
private static final ConnectionManager instance = new ConnectionManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConnectionManager getInstance() {
|
public static ConnectionManager getInstance() {
|
||||||
return ConnectionManagerHolder.instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConnectionManager() {
|
private ConnectionManager() {
|
||||||
@ -78,7 +75,6 @@ public class ConnectionManager {
|
|||||||
obj.put("password", password);
|
obj.put("password", password);
|
||||||
array.put(obj);
|
array.put(obj);
|
||||||
prefStore.put(PREFERENCE_STORE_KEY, array);
|
prefStore.put(PREFERENCE_STORE_KEY, array);
|
||||||
// TODO save preferences (find out how)
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -108,7 +104,7 @@ public class ConnectionManager {
|
|||||||
|
|
||||||
public JSONObject getStoredCredentials() {
|
public JSONObject getStoredCredentials() {
|
||||||
JSONArray array = (JSONArray) prefStore.get(PREFERENCE_STORE_KEY);
|
JSONArray array = (JSONArray) prefStore.get(PREFERENCE_STORE_KEY);
|
||||||
if (array.length() > 0) {
|
if (array != null && array.length() > 0) {
|
||||||
try {
|
try {
|
||||||
return array.getJSONObject(0);
|
return array.getJSONObject(0);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package org.openrefine.wikidata.commands;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class LoginCommandTest extends CommandTest {
|
||||||
|
|
||||||
|
@BeforeMethod
|
||||||
|
public void SetUp()
|
||||||
|
throws JSONException {
|
||||||
|
command = new LoginCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoCredentials() throws ServletException, IOException {
|
||||||
|
command.doPost(request, response);
|
||||||
|
|
||||||
|
assertEquals("{\"logged_in\":false,\"username\":null}", writer.toString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user