Search in sources :

Example 6 with GluuGroupApi

use of org.gluu.oxtrust.api.server.model.GluuGroupApi in project oxTrust by GluuFederation.

the class GroupWebResourceTest method searchGroupTest.

@Test
public void searchGroupTest() {
    String searchPattern = "manager";
    String SEARCH_QUERY = "?" + ApiConstants.SEARCH_PATTERN + "=" + searchPattern + "&size=5";
    HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.GROUPS + ApiConstants.SEARCH + SEARCH_QUERY);
    HttpResponse response = handle(request);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    HttpEntity entity = response.getEntity();
    try {
        String content = EntityUtils.toString(entity);
        GluuGroupApi[] groups = mapper.readValue(content, GluuGroupApi[].class);
        Assert.assertTrue(groups.length >= 1);
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) GluuGroupApi(org.gluu.oxtrust.api.server.model.GluuGroupApi) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with GluuGroupApi

use of org.gluu.oxtrust.api.server.model.GluuGroupApi in project oxTrust by GluuFederation.

the class GroupWebResourceTest method createGroupTest.

@Test
public void createGroupTest() {
    String name = "OxTrustApiGroup";
    GluuGroupApi group = getGroup(name);
    HttpPost request = new HttpPost(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.GROUPS);
    try {
        HttpEntity entity = new ByteArrayEntity(mapper.writeValueAsString(group).toString().getBytes("UTF-8"), ContentType.APPLICATION_FORM_URLENCODED);
        request.setEntity(entity);
        request.setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON);
        HttpResponse response = handle(request);
        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        HttpEntity result = response.getEntity();
        GluuGroupApi myGroup = mapper.readValue(EntityUtils.toString(result), GluuGroupApi.class);
        Assert.assertEquals(myGroup.getDisplayName(), name);
        Assert.assertEquals(myGroup.getStatus(), GluuStatus.ACTIVE);
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : GluuGroupApi(org.gluu.oxtrust.api.server.model.GluuGroupApi) HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with GluuGroupApi

use of org.gluu.oxtrust.api.server.model.GluuGroupApi in project oxTrust by GluuFederation.

the class GroupWebResourceTest method getGroupByInumTest.

@Test
public void getGroupByInumTest() {
    String inum = "60B7";
    HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.GROUPS + "/" + inum);
    HttpResponse response = handle(request);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    HttpEntity entity = response.getEntity();
    try {
        String content = EntityUtils.toString(entity);
        GluuGroupApi group = mapper.readValue(content, GluuGroupApi.class);
        Assert.assertNotNull(group);
        Assert.assertTrue(group.getDisplayName().contains("Manager"));
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) GluuGroupApi(org.gluu.oxtrust.api.server.model.GluuGroupApi) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

GluuGroupApi (org.gluu.oxtrust.api.server.model.GluuGroupApi)8 IOException (java.io.IOException)5 HttpEntity (org.apache.http.HttpEntity)5 HttpResponse (org.apache.http.HttpResponse)5 ParseException (org.apache.http.ParseException)5 Test (org.junit.Test)5 HttpGet (org.apache.http.client.methods.HttpGet)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 ArrayList (java.util.ArrayList)2 HttpPost (org.apache.http.client.methods.HttpPost)2 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)2 Operation (io.swagger.v3.oas.annotations.Operation)1 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)1 HttpPut (org.apache.http.client.methods.HttpPut)1 GluuGroup (org.gluu.oxtrust.model.GluuGroup)1 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)1