Skip to content

Commit

Permalink
ECOAPI-661 - Adição da primitiva listRoles (#23)
Browse files Browse the repository at this point in the history
* Adição da primitiva listRoles

* Update src/test/java/br/com/senior/core/authorization/AuthorizationIT.java

Co-authored-by: Andre <meirezende@hotmail.com>

* Update src/main/java/br/com/senior/core/authorization/AuthorizationClient.java

Co-authored-by: Andre <meirezende@hotmail.com>

Co-authored-by: Andre <meirezende@hotmail.com>
  • Loading branch information
Paulo-Weber and andremrezende authored Jun 22, 2020
1 parent 4be6e7f commit ffa88e7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package br.com.senior.core.authorization;

import br.com.senior.core.authentication.pojos.LoginInput;
import br.com.senior.core.authentication.pojos.LoginMFAInput;
import br.com.senior.core.authentication.pojos.LoginWithKeyInput;
import br.com.senior.core.authentication.pojos.LoginInput;
import br.com.senior.core.authentication.pojos.LoginMFAInput;
import br.com.senior.core.authentication.pojos.LoginWithKeyInput;
Expand All @@ -19,6 +22,8 @@
import br.com.senior.core.authorization.pojos.GetResourceOutput;
import br.com.senior.core.authorization.pojos.GetRoleInput;
import br.com.senior.core.authorization.pojos.GetRoleOutput;
import br.com.senior.core.authorization.pojos.ListRolesInput;
import br.com.senior.core.authorization.pojos.ListRolesOutput;
import br.com.senior.core.authorization.pojos.SaveResourcesInput;
import br.com.senior.core.authorization.pojos.SaveResourcesOutput;
import br.com.senior.core.authorization.pojos.UnassignUsersInput;
Expand All @@ -36,7 +41,7 @@
@FieldDefaults(level = AccessLevel.PRIVATE)
public class AuthorizationClient extends BaseClient {

String token;
final String token;

/**
* Construtor
Expand Down Expand Up @@ -178,4 +183,15 @@ public GetRoleOutput getRole(GetRoleInput payload) throws ServiceException {
public DeleteRoleOutput deleteRole(DeleteRoleInput payload) throws ServiceException {
return execute(getActionsUrl(EndpointPath.Authorization.DELETE_ROLE), payload, this.token, DeleteRoleOutput.class);
}

/**
* Retorna os dados de um papel
*
* @param payload - Payload de entrada com o nome do papel a ser consultado
* @return - Payload de saída com os dados do papel
* @throws ServiceException - Erro tratado de serviço
*/
public ListRolesOutput listRoles(ListRolesInput payload) throws ServiceException {
return execute(getQueriesUrl(EndpointPath.Authorization.LIST_ROLES), payload, this.token, ListRolesOutput.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package br.com.senior.core.authorization.pojos;

import br.com.senior.core.user.pojos.Pagination;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;

@Getter
@FieldDefaults(level = AccessLevel.PRIVATE)
@AllArgsConstructor
@NoArgsConstructor
public class ListRolesInput {

/**
* O valor a ser pesquisado no nome dos papéis
*/
String searchValue;
/**
* As configurações de paginação da listagem. Não definido, retornará os 10 primeiros resultados.
*/
Pagination pagination;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package br.com.senior.core.authorization.pojos;

import br.com.senior.core.user.pojos.ListInformation;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;

@Getter
@FieldDefaults(level = AccessLevel.PRIVATE)
@AllArgsConstructor
@NoArgsConstructor
public class ListRolesOutput {

/**
* Os elementos retornados pela listagem
*/
java.util.List<Role> roles;
/**
* Informações sobre os resultados da listagem
*/
ListInformation listInformation;

}
1 change: 1 addition & 0 deletions src/main/java/br/com/senior/core/utils/EndpointPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Authorization {
public static final String SAVE_RESOURCES = "saveResources";
public static final String DELETE_RESOURCES = "deleteResources";
public static final String GET_ROLE = "getRole";
public static final String LIST_ROLES = "listRoles";
public static final String CREATE_ROLE = "createRole";
public static final String DELETE_ROLE = "deleteRole";
public static final String GET_ASSIGN_USERS = "getAssignedUsers";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
import java.util.Collections;
import java.util.List;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import br.com.senior.core.BaseIT;
import br.com.senior.core.authorization.pojos.Action;
import br.com.senior.core.authorization.pojos.AssignUsersInput;
import br.com.senior.core.authorization.pojos.CheckAccessInput;
Expand All @@ -24,11 +19,18 @@
import br.com.senior.core.authorization.pojos.GetResourceOutput;
import br.com.senior.core.authorization.pojos.GetRoleInput;
import br.com.senior.core.authorization.pojos.GetRoleOutput;
import br.com.senior.core.authorization.pojos.ListRolesInput;
import br.com.senior.core.authorization.pojos.ListRolesOutput;
import br.com.senior.core.authorization.pojos.PermissionToCheck;
import br.com.senior.core.authorization.pojos.Resource;
import br.com.senior.core.authorization.pojos.SaveResourcesInput;
import br.com.senior.core.authorization.pojos.SaveResourcesOutput;
import br.com.senior.core.authorization.pojos.UnassignUsersInput;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import br.com.senior.core.BaseIT;
import br.com.senior.core.base.ServiceException;

/**
Expand Down Expand Up @@ -95,6 +97,17 @@ public void testCreateAndGetRole() throws ServiceException {
}
}

@Test
public void testCreateAndListRoles() throws ServiceException {
Assert.assertThrows(ServiceException.class, this::getRole);
try {
Assert.assertNotNull(createRole());
Assert.assertNotNull(listRoles());
} finally {
deleteRole();
}
}

@Test
public void testCreateAndDeleteRoles() throws ServiceException {
Assert.assertThrows(ServiceException.class, this::getRole);
Expand Down Expand Up @@ -157,6 +170,11 @@ private CreateRoleOutput createRole() throws ServiceException {
return new AuthorizationClient(token).createRole(input);
}

private ListRolesOutput listRoles() throws ServiceException {
ListRolesInput input = new ListRolesInput();
return new AuthorizationClient(token).listRoles(input);
}

private DeleteRoleOutput deleteRole() throws ServiceException {
DeleteRoleInput input = new DeleteRoleInput(ROLE_NAME);
return new AuthorizationClient(token).deleteRole(input);
Expand Down

0 comments on commit ffa88e7

Please sign in to comment.