Search in sources :

Example 11 with RestResponse

use of com.runwaysdk.mvc.RestResponse in project geoprism-registry by terraframe.

the class AccountServiceControllerTest method newInstanceWithRolesEmptyOrgString.

/**
 * Test returning all possible roles that can be assigned to a person by
 * passing in an empty string for the organizations.
 */
@Test
public void newInstanceWithRolesEmptyOrgString() {
    RestResponse response = (RestResponse) controller.newInstance(clientRequest, "[]");
    createUserWithRoles(response);
}
Also used : RestResponse(com.runwaysdk.mvc.RestResponse) Test(org.junit.Test)

Example 12 with RestResponse

use of com.runwaysdk.mvc.RestResponse in project geoprism-registry by terraframe.

the class AccountServiceControllerTest method createUser.

private JSONObject createUser(String userName, String roleNames) {
    RestResponse response = (RestResponse) controller.newInstance(clientRequest, "[" + moiOrg.getCode() + "]");
    Pair userPair = (Pair) response.getAttribute("user");
    GeoprismUserDTO user = (GeoprismUserDTO) userPair.getFirst();
    Pair rolesPair = (Pair) response.getAttribute("roles");
    JSONArray roleJSONArray = (JSONArray) rolesPair.getFirst();
    JSONObject jsonUser = new JSONObject();
    jsonUser.put(GeoprismUserDTO.FIRSTNAME, "Some Firstname");
    jsonUser.put(GeoprismUserDTO.LASTNAME, "Some Lastame");
    jsonUser.put(GeoprismUserDTO.USERNAME, userName);
    jsonUser.put(GeoprismUserDTO.EMAIL, userName);
    jsonUser.put(GeoprismUserDTO.PASSWORD, "123456");
    response = (RestResponse) controller.apply(clientRequest, jsonUser.toString(), "[" + roleNames + "]");
    userPair = (Pair) response.getAttribute("user");
    jsonUser = (JSONObject) userPair.getFirst();
    return jsonUser;
}
Also used : JSONObject(org.json.JSONObject) RestResponse(com.runwaysdk.mvc.RestResponse) JSONArray(org.json.JSONArray) Pair(com.runwaysdk.Pair) GeoprismUserDTO(net.geoprism.GeoprismUserDTO)

Example 13 with RestResponse

use of com.runwaysdk.mvc.RestResponse in project geoprism-registry by terraframe.

the class AccountServiceControllerTest method newInstaneWithOrgRoles.

/**
 * Test returning possible roles that can be assigned to a person for a given
 * organization.
 */
@Test
@SuppressWarnings("rawtypes")
public void newInstaneWithOrgRoles() {
    RestResponse response = (RestResponse) controller.newInstance(clientRequest, "[" + moiOrg.getCode() + "]");
    Pair pair = (Pair) response.getAttribute("roles");
    JSONArray roleJSONArray = (JSONArray) pair.getFirst();
    Assert.assertEquals(7, roleJSONArray.length());
    Set<String> rolesFoundSet = new HashSet<String>();
    rolesFoundSet.add(RegistryRole.Type.getRA_RoleName(moiOrg.getCode()));
    rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), district.getCode()));
    rolesFoundSet.add(RegistryRole.Type.getRC_RoleName(moiOrg.getCode(), district.getCode()));
    rolesFoundSet.add(RegistryRole.Type.getAC_RoleName(moiOrg.getCode(), district.getCode()));
    rolesFoundSet.add(RegistryRole.Type.getRM_RoleName(moiOrg.getCode(), village.getCode()));
    rolesFoundSet.add(RegistryRole.Type.getRC_RoleName(moiOrg.getCode(), village.getCode()));
    rolesFoundSet.add(RegistryRole.Type.getAC_RoleName(moiOrg.getCode(), village.getCode()));
    this.assertReturnedRoles(roleJSONArray, rolesFoundSet, false);
}
Also used : RestResponse(com.runwaysdk.mvc.RestResponse) JSONArray(org.json.JSONArray) Pair(com.runwaysdk.Pair) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

RestResponse (com.runwaysdk.mvc.RestResponse)13 Endpoint (com.runwaysdk.mvc.Endpoint)8 JSONArray (org.json.JSONArray)7 JSONObject (org.json.JSONObject)5 JsonArray (com.google.gson.JsonArray)4 Date (java.util.Date)4 RegistryRole (org.commongeoregistry.adapter.metadata.RegistryRole)4 Test (org.junit.Test)4 Pair (com.runwaysdk.Pair)3 GeoprismUserDTO (net.geoprism.GeoprismUserDTO)3 HashSet (java.util.HashSet)2 InputStream (java.io.InputStream)1