From 3c10794255657ad51f8355aaf4c6a4cec353fc78 Mon Sep 17 00:00:00 2001 From: flaminiaScarciofolo Date: Thu, 11 Jul 2024 17:55:57 +0200 Subject: [PATCH] [SELC-5144] Refactor usergroup client to use generated interface --- connector-api/pom.xml | 6 +- .../rest/docs/openapi/user-group-docs.json | 977 ++++++++++++++++++ connector/rest/pom.xml | 54 +- .../rest/UserGroupConnectorImpl.java | 91 +- .../rest/client/UserGroupRestClient.java | 51 +- .../rest/model/mapper/GroupMapper.java | 15 + .../config/user-group-rest-client.properties | 16 +- .../rest/UserGroupConnectorImplTest.java | 264 +++-- .../rest/client/UserGroupRestClientTest.java | 108 +- .../test/resources/stubs/createUserGroup.json | 2 +- .../stubs/createUserGroupRequest.json | 2 +- ...onId_notEmptyProductId_notEmptyUserId.json | 4 +- .../stubs/groupResponse_toGroupInfo.json | 4 +- .../mappings/activateUserGroup.json | 2 +- .../mappings/addMemberToUserGroup.json | 2 +- .../user-group/mappings/createGroup.json | 2 +- .../mappings/deleteMemberFromUserGroup.json | 2 +- .../mappings/deleteMemberFromUserGroups.json | 2 +- .../user-group/mappings/deleteUserGroup.json | 2 +- .../mappings/getUserGroupInfo_fullyNull.json | 2 +- .../getUserGroupInfo_fullyValued.json | 2 +- .../mappings/getUserGroups_fullyValued.json | 2 +- .../getUserGroups_fullyValuedPageable.json | 2 +- .../user-group/mappings/suspendUserGroup.json | 2 +- .../user-group/mappings/updateUserGroup.json | 2 +- .../userGroupInfoGetUserGroupByIdSingle.json | 2 +- .../stubs/userGroupInfoGetUserGroups.json | 2 +- .../stubs/userGroupInfoNullModifiedBy.json | 4 +- .../resources/stubs/userGroupResponse.json | 2 +- .../userGroupResponseNullModifiedBy.json | 2 +- .../stubs/userGroupResponseSingle.json | 2 +- 31 files changed, 1346 insertions(+), 286 deletions(-) create mode 100644 connector/rest/docs/openapi/user-group-docs.json create mode 100644 connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/model/mapper/GroupMapper.java diff --git a/connector-api/pom.xml b/connector-api/pom.xml index f467da1e2..61d08fd39 100644 --- a/connector-api/pom.xml +++ b/connector-api/pom.xml @@ -23,9 +23,13 @@ it.pagopa.selfcare onboarding-sdk-product - 0.1.12 + 0.1.16 compile + + org.springframework.data + spring-data-commons + diff --git a/connector/rest/docs/openapi/user-group-docs.json b/connector/rest/docs/openapi/user-group-docs.json new file mode 100644 index 000000000..57768303f --- /dev/null +++ b/connector/rest/docs/openapi/user-group-docs.json @@ -0,0 +1,977 @@ +{ + "openapi" : "3.0.3", + "info" : { + "title" : "user-group-ms", + "description" : "The services described in this section deal with the management of UserGroup entity, providing the necessary methods for its creation, consultation and activation.", + "version" : "1.0.0-SNAPSHOT" + }, + "servers" : [ { + "url" : "{url}:{port}{basePath}", + "variables" : { + "url" : { + "default" : "http://localhost" + }, + "port" : { + "default" : "80" + }, + "basePath" : { + "default" : "" + } + } + } ], + "tags" : [ { + "name" : "UserGroup", + "description" : "User group endpoint CRUD operations" + } ], + "paths" : { + "/v1/user-groups" : { + "get" : { + "tags" : [ "UserGroup", "external-v2", "support", "support-pnpg" ], + "summary" : "getUserGroups", + "description" : "Service that allows to get a list of UserGroup entities", + "operationId" : "getUserGroupsUsingGET", + "parameters" : [ { + "name" : "institutionId", + "in" : "query", + "description" : "Users group's institutionId", + "required" : false, + "style" : "form", + "schema" : { + "type" : "string" + } + }, { + "name" : "page", + "in" : "query", + "description" : "The page number to access (0 indexed, defaults to 0)", + "required" : false, + "style" : "form", + "allowReserved" : true, + "schema" : { + "type" : "integer", + "format" : "int32" + } + }, { + "name" : "size", + "in" : "query", + "description" : "Number of records per page (defaults to 20, max 2000)", + "required" : false, + "style" : "form", + "allowReserved" : true, + "schema" : { + "type" : "integer", + "format" : "int32" + } + }, { + "name" : "sort", + "in" : "query", + "description" : "Sorting criteria in the format: property(,asc|desc). Default sort order is ascending. Multiple sort criteria are supported.", + "required" : false, + "style" : "form", + "allowReserved" : true, + "schema" : { + "type" : "array", + "items" : { + "type" : "string" + } + } + }, { + "name" : "productId", + "in" : "query", + "description" : "Users group's productId", + "required" : false, + "style" : "form", + "schema" : { + "type" : "string" + } + }, { + "name" : "userId", + "in" : "query", + "description" : "Member's unique identifier", + "required" : false, + "style" : "form", + "schema" : { + "type" : "string", + "format" : "uuid" + } + }, { + "name" : "status", + "in" : "query", + "description" : "If filter on status is present, it must be used with at least one of the other filters", + "required" : false, + "style" : "form", + "explode" : true, + "schema" : { + "type" : "string", + "enum" : [ "ACTIVE", "DELETED", "SUSPENDED" ] + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/PageOfUserGroupResource" + } + } + } + }, + "400" : { + "description" : "Bad Request", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "401" : { + "description" : "Unauthorized", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "404" : { + "description" : "Not Found", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "500" : { + "description" : "Internal Server Error", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + } + }, + "security" : [ { + "bearerAuth" : [ "global" ] + } ] + }, + "post" : { + "tags" : [ "UserGroup" ], + "summary" : "createGroup", + "description" : "Service that allows the insert of a new occurrence for the UserGroup entity", + "operationId" : "createGroupUsingPOST", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/CreateUserGroupDto" + } + } + } + }, + "responses" : { + "201" : { + "description" : "Created", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/UserGroupResource" + } + } + } + }, + "400" : { + "description" : "Bad Request", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "401" : { + "description" : "Unauthorized", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "409" : { + "description" : "Conflict", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "500" : { + "description" : "Internal Server Error", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + } + }, + "security" : [ { + "bearerAuth" : [ "global" ] + } ] + } + }, + "/v1/user-groups/members/{memberId}" : { + "delete" : { + "tags" : [ "UserGroup" ], + "summary" : "deleteMemberFromUserGroups", + "description" : "Service to delete a member from a specific UserGroup entity", + "operationId" : "deleteMemberFromUserGroupsUsingDELETE", + "parameters" : [ { + "name" : "memberId", + "in" : "path", + "description" : "Member's unique identifier", + "required" : true, + "style" : "simple", + "schema" : { + "type" : "string", + "format" : "uuid" + } + }, { + "name" : "institutionId", + "in" : "query", + "description" : "institutionId", + "required" : true, + "style" : "form", + "schema" : { + "type" : "string" + } + }, { + "name" : "productId", + "in" : "query", + "description" : "productId", + "required" : true, + "style" : "form", + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "204" : { + "description" : "No Content" + }, + "400" : { + "description" : "Bad Request", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "401" : { + "description" : "Unauthorized", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "500" : { + "description" : "Internal Server Error", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + } + }, + "security" : [ { + "bearerAuth" : [ "global" ] + } ] + } + }, + "/v1/user-groups/{id}" : { + "get" : { + "tags" : [ "UserGroup" ], + "summary" : "getUserGroup", + "description" : "Service to get a specific UserGroup entity", + "operationId" : "getUserGroupUsingGET", + "parameters" : [ { + "name" : "id", + "in" : "path", + "description" : "Users group's unique identifier", + "required" : true, + "style" : "simple", + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/UserGroupResource" + } + } + } + }, + "400" : { + "description" : "Bad Request", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "401" : { + "description" : "Unauthorized", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "404" : { + "description" : "Not Found", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "500" : { + "description" : "Internal Server Error", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + } + }, + "security" : [ { + "bearerAuth" : [ "global" ] + } ] + }, + "put" : { + "tags" : [ "UserGroup" ], + "summary" : "updateUserGroup", + "description" : "Service that allows the modification of a specific occurrence for the UserGroup entity by an Admin user", + "operationId" : "updateUserGroupUsingPUT", + "parameters" : [ { + "name" : "id", + "in" : "path", + "description" : "Users group's unique identifier", + "required" : true, + "style" : "simple", + "schema" : { + "type" : "string" + } + } ], + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/UpdateUserGroupDto" + } + } + } + }, + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/UserGroupResource" + } + } + } + }, + "400" : { + "description" : "Bad Request", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "401" : { + "description" : "Unauthorized", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "409" : { + "description" : "Conflict", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "500" : { + "description" : "Internal Server Error", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + } + }, + "security" : [ { + "bearerAuth" : [ "global" ] + } ] + }, + "delete" : { + "tags" : [ "UserGroup" ], + "summary" : "deleteGroup", + "description" : "Service that allows the deletion of a specific occurrence for the UserGroup entity by an Admin user", + "operationId" : "deleteGroupUsingDELETE", + "parameters" : [ { + "name" : "id", + "in" : "path", + "description" : "Users group's unique identifier", + "required" : true, + "style" : "simple", + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "204" : { + "description" : "No Content" + }, + "400" : { + "description" : "Bad Request", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "401" : { + "description" : "Unauthorized", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "500" : { + "description" : "Internal Server Error", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + } + }, + "security" : [ { + "bearerAuth" : [ "global" ] + } ] + } + }, + "/v1/user-groups/{id}/activate" : { + "post" : { + "tags" : [ "UserGroup" ], + "summary" : "activateGroup", + "description" : "Service that allows the activation of a specific occurrence for the UserGroup entity by an Admin user", + "operationId" : "activateGroupUsingPOST", + "parameters" : [ { + "name" : "id", + "in" : "path", + "description" : "Users group's unique identifier", + "required" : true, + "style" : "simple", + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "204" : { + "description" : "No Content" + }, + "400" : { + "description" : "Bad Request", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "401" : { + "description" : "Unauthorized", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "500" : { + "description" : "Internal Server Error", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + } + }, + "security" : [ { + "bearerAuth" : [ "global" ] + } ] + } + }, + "/v1/user-groups/{id}/members/{memberId}" : { + "put" : { + "tags" : [ "UserGroup" ], + "summary" : "addMemberToUserGroup", + "description" : "Service to add a member to a specific UserGroup entity", + "operationId" : "addMemberToUserGroupUsingPUT", + "parameters" : [ { + "name" : "id", + "in" : "path", + "description" : "Users group's unique identifier", + "required" : true, + "style" : "simple", + "schema" : { + "type" : "string" + } + }, { + "name" : "memberId", + "in" : "path", + "description" : "Member's unique identifier", + "required" : true, + "style" : "simple", + "schema" : { + "type" : "string", + "format" : "uuid" + } + } ], + "responses" : { + "204" : { + "description" : "No Content" + }, + "400" : { + "description" : "Bad Request", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "401" : { + "description" : "Unauthorized", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "500" : { + "description" : "Internal Server Error", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + } + }, + "security" : [ { + "bearerAuth" : [ "global" ] + } ] + }, + "delete" : { + "tags" : [ "UserGroup" ], + "summary" : "deleteMemberFromUserGroup", + "description" : "Service to delete a member from a specific UserGroup entity", + "operationId" : "deleteMemberFromUserGroupUsingDELETE", + "parameters" : [ { + "name" : "id", + "in" : "path", + "description" : "Users group's unique identifier", + "required" : true, + "style" : "simple", + "schema" : { + "type" : "string" + } + }, { + "name" : "memberId", + "in" : "path", + "description" : "Member's unique identifier", + "required" : true, + "style" : "simple", + "schema" : { + "type" : "string", + "format" : "uuid" + } + } ], + "responses" : { + "204" : { + "description" : "No Content" + }, + "400" : { + "description" : "Bad Request", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "401" : { + "description" : "Unauthorized", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "500" : { + "description" : "Internal Server Error", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + } + }, + "security" : [ { + "bearerAuth" : [ "global" ] + } ] + } + }, + "/v1/user-groups/{id}/suspend" : { + "post" : { + "tags" : [ "UserGroup" ], + "summary" : "suspendGroup", + "description" : "Service that allows the suspension of a specific occurrence for the UserGroup entity by an Admin user", + "operationId" : "suspendGroupUsingPOST", + "parameters" : [ { + "name" : "id", + "in" : "path", + "description" : "Users group's unique identifier", + "required" : true, + "style" : "simple", + "schema" : { + "type" : "string" + } + } ], + "responses" : { + "204" : { + "description" : "No Content" + }, + "400" : { + "description" : "Bad Request", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "401" : { + "description" : "Unauthorized", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + }, + "500" : { + "description" : "Internal Server Error", + "content" : { + "application/problem+json" : { + "schema" : { + "$ref" : "#/components/schemas/Problem" + } + } + } + } + }, + "security" : [ { + "bearerAuth" : [ "global" ] + } ] + } + } + }, + "components" : { + "schemas" : { + "CreateUserGroupDto" : { + "title" : "CreateUserGroupDto", + "required" : [ "description", "institutionId", "members", "name", "productId", "status" ], + "type" : "object", + "properties" : { + "description" : { + "type" : "string", + "description" : "Users group's description" + }, + "institutionId" : { + "type" : "string", + "description" : "Users group's institutionId" + }, + "members" : { + "uniqueItems" : true, + "type" : "array", + "description" : "List of all the members of the group", + "items" : { + "type" : "string", + "format" : "uuid" + } + }, + "name" : { + "type" : "string", + "description" : "Users group's name" + }, + "productId" : { + "type" : "string", + "description" : "Users group's productId" + }, + "status" : { + "type" : "string", + "description" : "Users group's status", + "enum" : [ "ACTIVE", "DELETED", "SUSPENDED" ] + } + } + }, + "InvalidParam" : { + "title" : "InvalidParam", + "required" : [ "name", "reason" ], + "type" : "object", + "properties" : { + "name" : { + "type" : "string", + "description" : "Invalid parameter name." + }, + "reason" : { + "type" : "string", + "description" : "Invalid parameter reason." + } + } + }, + "PageOfUserGroupResource" : { + "title" : "PageOfUserGroupResource", + "required" : [ "content", "number", "size", "totalElements", "totalPages" ], + "type" : "object", + "properties" : { + "content" : { + "type" : "array", + "description" : "The page content", + "items" : { + "$ref" : "#/components/schemas/UserGroupResource" + } + }, + "number" : { + "type" : "integer", + "description" : "The number of the current page", + "format" : "int32" + }, + "size" : { + "type" : "integer", + "description" : "The size of the page", + "format" : "int32" + }, + "totalElements" : { + "type" : "integer", + "description" : "The total amount of elements", + "format" : "int64" + }, + "totalPages" : { + "type" : "integer", + "description" : "The number of total pages", + "format" : "int32" + } + } + }, + "Problem" : { + "title" : "Problem", + "required" : [ "status", "title" ], + "type" : "object", + "properties" : { + "detail" : { + "type" : "string", + "description" : "Human-readable description of this specific problem." + }, + "instance" : { + "type" : "string", + "description" : "A URI that describes where the problem occurred." + }, + "invalidParams" : { + "type" : "array", + "description" : "A list of invalid parameters details.", + "items" : { + "$ref" : "#/components/schemas/InvalidParam" + } + }, + "status" : { + "type" : "integer", + "description" : "The HTTP status code.", + "format" : "int32", + "example" : 500 + }, + "title" : { + "type" : "string", + "description" : "Short human-readable summary of the problem." + }, + "type" : { + "type" : "string", + "description" : "A URL to a page with more details regarding the problem." + } + }, + "description" : "A \"problem detail\" as a way to carry machine-readable details of errors (https://datatracker.ietf.org/doc/html/rfc7807)" + }, + "UpdateUserGroupDto" : { + "title" : "UpdateUserGroupDto", + "required" : [ "description", "members", "name" ], + "type" : "object", + "properties" : { + "description" : { + "type" : "string", + "description" : "Users group's description" + }, + "members" : { + "uniqueItems" : true, + "type" : "array", + "description" : "List of all the members of the group", + "items" : { + "type" : "string", + "format" : "uuid" + } + }, + "name" : { + "type" : "string", + "description" : "Users group's name" + } + } + }, + "UserGroupResource" : { + "title" : "UserGroupResource", + "required" : [ "description", "id", "institutionId", "name", "productId", "status" ], + "type" : "object", + "properties" : { + "createdAt" : { + "type" : "string", + "description" : "Date on which the group was created", + "format" : "date-time" + }, + "createdBy" : { + "type" : "string", + "description" : "User by which the group was created" + }, + "description" : { + "type" : "string", + "description" : "Users group's description" + }, + "id" : { + "type" : "string", + "description" : "Users group's unique identifier" + }, + "institutionId" : { + "type" : "string", + "description" : "Users group's institutionId" + }, + "members" : { + "type" : "array", + "description" : "List of all the members of the group", + "items" : { + "type" : "string", + "format" : "uuid" + } + }, + "modifiedAt" : { + "type" : "string", + "description" : "Date on which the group was modified", + "format" : "date-time" + }, + "modifiedBy" : { + "type" : "string", + "description" : "User by which the group was modified" + }, + "name" : { + "type" : "string", + "description" : "Users group's name" + }, + "productId" : { + "type" : "string", + "description" : "Users group's productId" + }, + "status" : { + "type" : "string", + "description" : "Users group's status", + "enum" : [ "ACTIVE", "DELETED", "SUSPENDED" ] + } + } + } + }, + "securitySchemes" : { + "bearerAuth" : { + "type" : "http", + "description" : "A bearer token in the format of a JWS and conformed to the specifications included in [RFC8725](https://tools.ietf.org/html/RFC8725)", + "scheme" : "bearer", + "bearerFormat" : "JWT" + } + } + } +} \ No newline at end of file diff --git a/connector/rest/pom.xml b/connector/rest/pom.xml index b997bc0eb..80da2e412 100644 --- a/connector/rest/pom.xml +++ b/connector/rest/pom.xml @@ -77,13 +77,6 @@ - - - - org.openapitools - openapi-generator-maven-plugin - 6.3.0 - selfcare-ms-backoffice-backend @@ -115,13 +108,6 @@ - - - - org.openapitools - openapi-generator-maven-plugin - 6.3.0 - user-ms @@ -153,6 +139,46 @@ + + user-group-ms + + generate + + process-resources + + ${project.basedir}/docs/openapi/user-group-docs.json + spring + spring-cloud + + false + false + + true + ${project.groupId}.group.generated.openapi.v1 + ${project.groupId}.group.generated.openapi.v1.dto + ${project.groupId}.group.generated.openapi.v1.api + ${project.groupId}.group.generated.openapi.v1.config + @lombok.Builder; @lombok.NoArgsConstructor; @lombok.AllArgsConstructor + java8 + true + true + none + source + false + false + true + false + false + custom + + + DateTime=Instant + + + Instant=java.time.Instant + + + diff --git a/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/UserGroupConnectorImpl.java b/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/UserGroupConnectorImpl.java index 80cd55567..3b1de3ec7 100644 --- a/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/UserGroupConnectorImpl.java +++ b/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/UserGroupConnectorImpl.java @@ -6,41 +6,51 @@ import it.pagopa.selfcare.dashboard.connector.model.user.User; import it.pagopa.selfcare.dashboard.connector.model.user.UserInfo; import it.pagopa.selfcare.dashboard.connector.rest.client.UserGroupRestClient; -import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.CreateUserGroupRequestDto; -import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.UpdateUserGroupRequestDto; -import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.UserGroupResponse; +import it.pagopa.selfcare.dashboard.connector.rest.model.mapper.GroupMapper; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.CreateUserGroupDto; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.PageOfUserGroupResource; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.UpdateUserGroupDto; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.UserGroupResource; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.UUID; import java.util.function.Function; import java.util.stream.Collectors; @Slf4j @Service +@RequiredArgsConstructor public class UserGroupConnectorImpl implements UserGroupConnector { private final UserGroupRestClient restClient; + private final GroupMapper groupMapper; static final String REQUIRED_GROUP_ID_MESSAGE = "A user group id is required"; - static final Function GROUP_RESPONSE_TO_GROUP_INFO = groupResponse -> { + static final Function GROUP_RESPONSE_TO_GROUP_INFO = groupResponse -> { UserGroupInfo groupInfo = new UserGroupInfo(); groupInfo.setId(groupResponse.getId()); groupInfo.setInstitutionId(groupResponse.getInstitutionId()); groupInfo.setProductId(groupResponse.getProductId()); groupInfo.setName(groupResponse.getName()); groupInfo.setDescription(groupResponse.getDescription()); - groupInfo.setStatus(groupResponse.getStatus()); + if(Objects.nonNull(groupResponse.getStatus())) { + groupInfo.setStatus(UserGroupStatus.valueOf(groupResponse.getStatus().getValue())); + } if (groupResponse.getMembers() != null) { List members = groupResponse.getMembers().stream().map(id -> { UserInfo member = new UserInfo(); - member.setId(id); + member.setId(id.toString()); return member; }).collect(Collectors.toList()); groupInfo.setMembers(members); @@ -60,24 +70,15 @@ public class UserGroupConnectorImpl implements UserGroupConnector { return groupInfo; }; - @Autowired - public UserGroupConnectorImpl(UserGroupRestClient restClient) { - this.restClient = restClient; - } - @Override public String createUserGroup(CreateUserGroup userGroup) { log.trace("createUserGroup start"); log.debug("createUserGroup userGroup = {}", userGroup); Assert.notNull(userGroup, "A User Group is required"); - CreateUserGroupRequestDto userGroupRequest = new CreateUserGroupRequestDto(); - userGroupRequest.setDescription(userGroup.getDescription()); - userGroupRequest.setMembers(userGroup.getMembers()); - userGroupRequest.setInstitutionId(userGroup.getInstitutionId()); - userGroupRequest.setProductId(userGroup.getProductId()); - userGroupRequest.setName(userGroup.getName()); - userGroupRequest.setStatus(UserGroupStatus.ACTIVE); - String groupId = restClient.createUserGroup(userGroupRequest).getId(); + CreateUserGroupDto userGroupDto = groupMapper.toCreateUserGroupDto(userGroup); + ResponseEntity responseEntity = restClient._createGroupUsingPOST(userGroupDto); + UserGroupResource userGroupResource = responseEntity.getBody(); + String groupId = userGroupResource != null ? userGroupResource.getId() : null; log.debug("createUserGroup result = {}", groupId); log.trace("createUserGroup end"); return groupId; @@ -88,7 +89,7 @@ public void delete(String groupId) { log.trace("delete start"); log.debug("delete groupId = {}", groupId); Assert.hasText(groupId, REQUIRED_GROUP_ID_MESSAGE); - restClient.deleteUserGroupById(groupId); + restClient._deleteGroupUsingDELETE(groupId); log.trace("delete end"); } @@ -99,7 +100,7 @@ public void deleteMembers(String memberId, String institutionId, String productI Assert.hasText(memberId, "Required memberId"); Assert.hasText(institutionId, "Required institutionId"); Assert.hasText(productId, "Required productId"); - restClient.deleteMembers(UUID.fromString(memberId), institutionId, productId); + restClient._deleteMemberFromUserGroupsUsingDELETE(UUID.fromString(memberId), institutionId, productId); log.trace("delete end"); } @@ -108,7 +109,7 @@ public void activate(String groupId) { log.trace("activate start"); log.debug("activate groupId = {}", groupId); Assert.hasText(groupId, REQUIRED_GROUP_ID_MESSAGE); - restClient.activateUserGroupById(groupId); + restClient._activateGroupUsingPOST(groupId); log.trace("activate end"); } @@ -117,7 +118,7 @@ public void suspend(String groupId) { log.trace("suspend start"); log.debug("suspend groupId = {}", groupId); Assert.hasText(groupId, REQUIRED_GROUP_ID_MESSAGE); - restClient.suspendUserGroupById(groupId); + restClient._suspendGroupUsingPOST(groupId); log.trace("suspend end"); } @@ -127,11 +128,8 @@ public void updateUserGroup(String id, UpdateUserGroup userGroup) { log.debug("updateUserGroup userGroup = {}", userGroup); Assert.hasText(id, REQUIRED_GROUP_ID_MESSAGE); Assert.notNull(userGroup, "A User Group is required"); - UpdateUserGroupRequestDto userGroupRequest = new UpdateUserGroupRequestDto(); - userGroupRequest.setDescription(userGroup.getDescription()); - userGroupRequest.setMembers(userGroup.getMembers()); - userGroupRequest.setName(userGroup.getName()); - restClient.updateUserGroupById(id, userGroupRequest); + UpdateUserGroupDto updateUserGroupDto = groupMapper.toUpdateUserGroupDto(userGroup); + restClient._updateUserGroupUsingPUT(id, updateUserGroupDto); log.trace("updateUserGroup end"); } @@ -141,7 +139,7 @@ public UserGroupInfo getUserGroupById(String id) { log.trace("getUserGroupById start"); log.debug("getUseGroupById id = {}", id); Assert.hasText(id, REQUIRED_GROUP_ID_MESSAGE); - UserGroupResponse response = restClient.getUserGroupById(id); + UserGroupResource response = restClient._getUserGroupUsingGET(id).getBody(); UserGroupInfo groupInfo = GROUP_RESPONSE_TO_GROUP_INFO.apply(response); log.debug("getUseGroupById groupInfo = {}", groupInfo); log.trace("getUserGroupById end"); @@ -154,7 +152,7 @@ public void addMemberToUserGroup(String id, UUID userId) { log.debug("addMemberToUserGroup id = {}, userId = {}", id, userId); Assert.hasText(id, REQUIRED_GROUP_ID_MESSAGE); Assert.notNull(userId, "A userId is required"); - restClient.addMemberToUserGroup(id, userId); + restClient._addMemberToUserGroupUsingPUT(id, userId); log.trace("addMemberToUserGroup end"); } @@ -164,7 +162,7 @@ public void deleteMemberFromUserGroup(String id, UUID userId) { log.debug("deleteMemberFromUserGroup id = {}, userId = {}", id, userId); Assert.hasText(id, REQUIRED_GROUP_ID_MESSAGE); Assert.notNull(userId, "A userId is required"); - restClient.deleteMemberFromUserGroup(id, userId); + restClient._deleteMemberFromUserGroupUsingDELETE(id, userId); log.trace("deleteMemberFromUserGroup end"); } @@ -173,15 +171,32 @@ public void deleteMemberFromUserGroup(String id, UUID userId) { public Page getUserGroups(UserGroupFilter filter, Pageable pageable) { log.trace("getUserGroups start"); log.debug("getUserGroups institutionId = {}, productId = {}, userId = {}, pageable = {}", filter.getInstitutionId(), filter.getProductId(), filter.getUserId(), pageable); - final Page userGroups = restClient.getUserGroups(filter.getInstitutionId().orElse(null), - filter.getProductId().orElse(null), - filter.getUserId().orElse(null), - List.of(UserGroupStatus.ACTIVE, UserGroupStatus.SUSPENDED), - pageable) - .map(GROUP_RESPONSE_TO_GROUP_INFO); + + List sortParams = new ArrayList<>(); + if (pageable.getSort().isSorted()) { + pageable.getSort().forEach(order -> sortParams.add(order.getProperty() + "," + order.getDirection())); + } + + final PageOfUserGroupResource userGroupResources = restClient._getUserGroupsUsingGET(filter.getInstitutionId().orElse(null), + pageable.getPageNumber(), + pageable.getPageSize(), + sortParams, + filter.getProductId().orElse(null), + filter.getUserId().orElse(null), + String.join(",", UserGroupStatus.ACTIVE.name(), UserGroupStatus.SUSPENDED.name())).getBody(); + + assert userGroupResources != null; + final Page userGroups = convertToUserGroupInfoPage(userGroupResources, pageable); log.debug("getUserGroups result = {}", userGroups); log.trace("getUserGroups end"); return userGroups; } + private Page convertToUserGroupInfoPage(PageOfUserGroupResource userGroupResources, Pageable pageable) { + return new PageImpl<>( + userGroupResources.getContent().stream().map(GROUP_RESPONSE_TO_GROUP_INFO).collect(Collectors.toList()), + pageable, + userGroupResources.getTotalElements() == null ? 0 : userGroupResources.getTotalElements() + ); + } } diff --git a/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/client/UserGroupRestClient.java b/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/client/UserGroupRestClient.java index 877943d07..32568699a 100644 --- a/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/client/UserGroupRestClient.java +++ b/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/client/UserGroupRestClient.java @@ -4,6 +4,7 @@ import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.CreateUserGroupRequestDto; import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.UpdateUserGroupRequestDto; import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.UserGroupResponse; +import it.pagopa.selfcare.group.generated.openapi.v1.api.UserGroupApi; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -13,54 +14,6 @@ import java.util.UUID; @FeignClient(name = "${rest-client.user-groups.serviceCode}", url = "${rest-client.user-groups.base-url}") -public interface UserGroupRestClient { +public interface UserGroupRestClient extends UserGroupApi { - @PostMapping(value = "${rest-client.user-groups.createUserGroup.path}") - @ResponseBody - UserGroupResponse createUserGroup(@RequestBody CreateUserGroupRequestDto createUserGroupRequestDto); - - @DeleteMapping(value = "${rest-client.user-group.deleteUserGroup.path}") - @ResponseBody - void deleteUserGroupById(@PathVariable("id") String id); - - @PostMapping(value = "${rest-client.user-group.activateUserGroup.path}") - @ResponseBody - void activateUserGroupById(@PathVariable("id") String id); - - @PostMapping(value = "${rest-client.user-group.suspendUserGroup.path}") - @ResponseBody - void suspendUserGroupById(@PathVariable("id") String id); - - @PutMapping(value = "${rest-client.user-group.updateUserGroup.path}") - @ResponseBody - void updateUserGroupById(@PathVariable("id") String id, - @RequestBody UpdateUserGroupRequestDto updateUserGroupRequestDto); - - @GetMapping(value = "${rest-client.user-group.getUserGroupById.path}") - @ResponseBody - UserGroupResponse getUserGroupById(@PathVariable("id") String id); - - @PutMapping(value = "${rest-client.user-group.addMemberToUserGroup.path}") - @ResponseBody - void addMemberToUserGroup(@PathVariable("id") String id, @PathVariable("memberId") UUID userId); - - @DeleteMapping(value = "${rest-client.user-group.deleteMemberFromUserGroup.path}") - @ResponseBody - void deleteMemberFromUserGroup(@PathVariable("id") String id, - @PathVariable("memberId") UUID memberId); - - @DeleteMapping(value = "${rest-client.user-group.deleteMembers.path}") - @ResponseBody - void deleteMembers(@PathVariable("memberId") UUID memberId, - @RequestParam(value = "institutionId", required = false) String institutionId, - @RequestParam(value = "productId", required = false) String productId); - - - @GetMapping(value = "${rest-client.user-group.getUserGroups.path}") - @ResponseBody - Page getUserGroups(@RequestParam(value = "institutionId", required = false) String institutionId, - @RequestParam(value = "productId", required = false) String productId, - @RequestParam(value = "userId", required = false) UUID memberId, - @RequestParam(value = "status", required = false) List status, - Pageable pageable); } diff --git a/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/model/mapper/GroupMapper.java b/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/model/mapper/GroupMapper.java new file mode 100644 index 000000000..9f838f3ae --- /dev/null +++ b/connector/rest/src/main/java/it/pagopa/selfcare/dashboard/connector/rest/model/mapper/GroupMapper.java @@ -0,0 +1,15 @@ +package it.pagopa.selfcare.dashboard.connector.rest.model.mapper; + +import it.pagopa.selfcare.dashboard.connector.model.groups.CreateUserGroup; +import it.pagopa.selfcare.dashboard.connector.model.groups.UpdateUserGroup; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.CreateUserGroupDto; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.UpdateUserGroupDto; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface GroupMapper { + + CreateUserGroupDto toCreateUserGroupDto(CreateUserGroup createUserGroup); + + UpdateUserGroupDto toUpdateUserGroupDto(UpdateUserGroup updateUserGroup); +} diff --git a/connector/rest/src/main/resources/config/user-group-rest-client.properties b/connector/rest/src/main/resources/config/user-group-rest-client.properties index a18034e54..ec760f310 100644 --- a/connector/rest/src/main/resources/config/user-group-rest-client.properties +++ b/connector/rest/src/main/resources/config/user-group-rest-client.properties @@ -1,13 +1,7 @@ rest-client.user-groups.serviceCode=user-groups -rest-client.user-groups.base-url=${MS_USER_GROUP_URL:https://10.1.1.250:80}/user-groups/v1 -rest-client.user-groups.createUserGroup.path=/ -rest-client.user-group.deleteUserGroup.path=/{id} -rest-client.user-group.activateUserGroup.path=/{id}/activate -rest-client.user-group.suspendUserGroup.path=/{id}/suspend -rest-client.user-group.updateUserGroup.path=/{id} -rest-client.user-group.getUserGroupById.path=/{id} -rest-client.user-group.getUserGroups.path=/ -rest-client.user-group.deleteMembers.path=/members/{memberId} -rest-client.user-group.addMemberToUserGroup.path=/{id}/members/{memberId} -rest-client.user-group.deleteMemberFromUserGroup.path=/{id}/members/{memberId} +rest-client.user-groups.base-url=${MS_USER_GROUP_URL:https://10.1.1.250:80} feign.client.config.user-groups.requestInterceptors[0]=it.pagopa.selfcare.commons.connector.rest.interceptor.AuthorizationHeaderInterceptor +feign.client.config.user-groups.connectTimeout=${SELFCARE_USER_REST_CLIENT_CONNECT_TIMEOUT:${REST_CLIENT_CONNECT_TIMEOUT:5000}} +feign.client.config.user-groups.readTimeout=${SELFCARE_USER_REST_CLIENT_READ_TIMEOUT:${REST_CLIENT_READ_TIMEOUT:5000}} +feign.client.config.user-groups.loggerLevel=${SELFCARE_USER_REST_CLIENT_LOGGER_LEVEL:${REST_CLIENT_LOGGER_LEVEL:FULL}} +feign.client.config.user-groups.errorDecoder=it.pagopa.selfcare.dashboard.connector.rest.decoder.FeignErrorDecoder diff --git a/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserGroupConnectorImplTest.java b/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserGroupConnectorImplTest.java index a178756fc..63a0d87e0 100644 --- a/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserGroupConnectorImplTest.java +++ b/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserGroupConnectorImplTest.java @@ -3,9 +3,11 @@ import com.fasterxml.jackson.core.type.TypeReference; import it.pagopa.selfcare.dashboard.connector.model.groups.*; import it.pagopa.selfcare.dashboard.connector.rest.client.UserGroupRestClient; -import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.CreateUserGroupRequestDto; -import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.UpdateUserGroupRequestDto; -import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.UserGroupResponse; +import it.pagopa.selfcare.dashboard.connector.rest.model.mapper.GroupMapper; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.CreateUserGroupDto; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.PageOfUserGroupResource; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.UpdateUserGroupDto; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.UserGroupResource; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -14,7 +16,11 @@ import org.mockito.*; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.io.ClassPathResource; -import org.springframework.data.domain.*; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.http.ResponseEntity; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -23,15 +29,14 @@ import java.util.List; import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; import static it.pagopa.selfcare.commons.utils.TestUtils.mockInstance; import static it.pagopa.selfcare.dashboard.connector.rest.UserGroupConnectorImpl.REQUIRED_GROUP_ID_MESSAGE; -import static java.util.Collections.emptyList; import static java.util.UUID.randomUUID; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import static org.springframework.data.support.PageableExecutionUtils.getPage; @ExtendWith(MockitoExtension.class) @@ -43,11 +48,14 @@ class UserGroupConnectorImplTest extends BaseConnectorTest { @InjectMocks private UserGroupConnectorImpl groupConnector; + @Spy + private GroupMapper groupMapper; + @Captor - private ArgumentCaptor requestDtoArgumentCaptor; + private ArgumentCaptor requestDtoArgumentCaptor; @Captor - private ArgumentCaptor updateRequestCaptor; + private ArgumentCaptor updateRequestCaptor; @BeforeEach public void setUp() { @@ -67,27 +75,27 @@ void createGroup_nullGroup() { @Test void createGroup() throws IOException { - ClassPathResource resource = new ClassPathResource("stubs/createUserGroup.json"); - byte[] resourceStream = Files.readAllBytes(resource.getFile().toPath()); - CreateUserGroup userGroup = objectMapper.readValue(resourceStream, new TypeReference<>() { + ClassPathResource userGroupResource = new ClassPathResource("stubs/createUserGroup.json"); + CreateUserGroup userGroup = objectMapper.readValue(userGroupResource.getInputStream(), new TypeReference<>() { }); - - ClassPathResource resourceRequest = new ClassPathResource("stubs/createUserGroupRequest.json"); - byte[] resourceStreamRequest = Files.readAllBytes(resourceRequest.getFile().toPath()); - CreateUserGroupRequestDto userGroupRequest = objectMapper.readValue(resourceStreamRequest, new TypeReference<>() { + ClassPathResource requestResource = new ClassPathResource("stubs/createUserGroupRequest.json"); + CreateUserGroupDto expectedRequest = objectMapper.readValue(requestResource.getInputStream(), new TypeReference<>() { }); - - ClassPathResource ResponseResource = new ClassPathResource("stubs/userGroupResponse.json"); - byte[] responseStream = Files.readAllBytes(ResponseResource.getFile().toPath()); - UserGroupResponse response = objectMapper.readValue(responseStream, new TypeReference<>() { + ClassPathResource responseResource = new ClassPathResource("stubs/userGroupResponse.json"); + UserGroupResource mockedResponse = objectMapper.readValue(responseResource.getInputStream(), new TypeReference<>() { }); - when(restClientMock.createUserGroup(userGroupRequest)).thenReturn(response); + when(groupMapper.toCreateUserGroupDto(any(CreateUserGroup.class))).thenReturn(expectedRequest); + when(restClientMock._createGroupUsingPOST(any(CreateUserGroupDto.class))).thenReturn(ResponseEntity.of(Optional.of(mockedResponse))); + String groupId = groupConnector.createUserGroup(userGroup); - assertEquals(response.getId(), groupId); - Mockito.verify(restClientMock, times(1)) - .createUserGroup(requestDtoArgumentCaptor.capture()); + verify(groupMapper, times(1)).toCreateUserGroupDto(refEq(userGroup)); + verify(restClientMock, times(1))._createGroupUsingPOST(requestDtoArgumentCaptor.capture()); + CreateUserGroupDto capturedRequest = requestDtoArgumentCaptor.getValue(); + assertNotNull(capturedRequest); + assertEquals(expectedRequest, capturedRequest); + assertEquals(mockedResponse.getId(), groupId); } @Test @@ -117,20 +125,32 @@ void updateGroup_nullId() { @Test void updateGroup() { - + // Arrange String groupId = "groupId"; UpdateUserGroup userGroup = mockInstance(new UpdateUserGroup()); - userGroup.setMembers(List.of("string1", "string2")); + userGroup.setMembers(List.of("895b4af3-7fa7-4442-8a0d-a2b05c6c719f", "895b4af3-7fa7-4442-8a0d-a2b05c6c719c")); - Executable executable = () -> groupConnector.updateUserGroup(groupId, userGroup); + UpdateUserGroupDto expectedRequest = new UpdateUserGroupDto(); + expectedRequest.setName(userGroup.getName()); + expectedRequest.setDescription(userGroup.getDescription()); + expectedRequest.setMembers(userGroup.getMembers().stream().map(UUID::fromString).collect(Collectors.toSet())); - assertDoesNotThrow(executable); + // Mock the behavior of groupMapper to return the expected DTO + when(groupMapper.toUpdateUserGroupDto(any(UpdateUserGroup.class))).thenReturn(expectedRequest); + + // Act + groupConnector.updateUserGroup(groupId, userGroup); + + // Assert verify(restClientMock, times(1)) - .updateUserGroupById(any(), updateRequestCaptor.capture()); - UpdateUserGroupRequestDto request = updateRequestCaptor.getValue(); - assertEquals(userGroup.getName(), request.getName()); - assertEquals(userGroup.getDescription(), request.getDescription()); - assertEquals(userGroup.getMembers(), request.getMembers()); + ._updateUserGroupUsingPUT(eq(groupId), updateRequestCaptor.capture()); + UpdateUserGroupDto actualRequest = updateRequestCaptor.getValue(); + + assertNotNull(actualRequest); + assertEquals(expectedRequest.getName(), actualRequest.getName()); + assertEquals(expectedRequest.getDescription(), actualRequest.getDescription()); + assertEquals(expectedRequest.getMembers(), actualRequest.getMembers()); + verifyNoMoreInteractions(restClientMock); } @@ -142,7 +162,7 @@ void delete() { groupConnector.delete(groupId); //then verify(restClientMock, times(1)) - .deleteUserGroupById(groupId); + ._deleteGroupUsingDELETE(groupId); verifyNoMoreInteractions(restClientMock); } @@ -164,7 +184,7 @@ void activate() { groupConnector.activate(groupId); //then verify(restClientMock, times(1)) - .activateUserGroupById(groupId); + ._activateGroupUsingPOST(groupId); verifyNoMoreInteractions(restClientMock); } @@ -186,7 +206,7 @@ void suspend() { groupConnector.suspend(groupId); //then verify(restClientMock, times(1)) - .suspendUserGroupById(groupId); + ._suspendGroupUsingPOST(groupId); verifyNoMoreInteractions(restClientMock); } @@ -207,7 +227,7 @@ void getUserGroupById() throws IOException { ClassPathResource resource = new ClassPathResource("stubs/userGroupResponseSingle.json"); byte[] resourceStream = Files.readAllBytes(resource.getFile().toPath()); - UserGroupResponse expectedResponse = objectMapper.readValue(resourceStream, new TypeReference<>() { + UserGroupResource expectedResponse = objectMapper.readValue(resourceStream, new TypeReference<>() { }); ClassPathResource resourceResponse = new ClassPathResource("stubs/userGroupInfoGetUserGroupByIdSingle.json"); @@ -215,12 +235,12 @@ void getUserGroupById() throws IOException { UserGroupInfo expectedGroupInfoResponse = objectMapper.readValue(resourceStreamResponse, new TypeReference<>() { }); - when(restClientMock.getUserGroupById(anyString())).thenReturn(expectedResponse); + when(restClientMock._getUserGroupUsingGET(anyString())).thenReturn(ResponseEntity.of(Optional.of(expectedResponse))); UserGroupInfo groupInfo = groupConnector.getUserGroupById(id); assertEquals(expectedGroupInfoResponse, groupInfo); - verify(restClientMock, times(1)).getUserGroupById(anyString()); + verify(restClientMock, times(1))._getUserGroupUsingGET(anyString()); verifyNoMoreInteractions(restClientMock); } @@ -231,7 +251,7 @@ void getUserGroupById_nullModifiedBy() throws IOException { ClassPathResource resource = new ClassPathResource("stubs/userGroupResponseNullModifiedBy.json"); byte[] resourceStream = Files.readAllBytes(resource.getFile().toPath()); - UserGroupResponse expectedResponse = objectMapper.readValue(resourceStream, new TypeReference<>() { + UserGroupResource expectedResponse = objectMapper.readValue(resourceStream, new TypeReference<>() { }); ClassPathResource resourceResponse = new ClassPathResource("stubs/userGroupInfoNullModifiedBy.json"); @@ -239,11 +259,11 @@ void getUserGroupById_nullModifiedBy() throws IOException { UserGroupInfo expectedGroupInfo = objectMapper.readValue(resourceStreamResponse, new TypeReference<>() { }); - when(restClientMock.getUserGroupById(anyString())).thenReturn(expectedResponse); + when(restClientMock._getUserGroupUsingGET(anyString())).thenReturn(ResponseEntity.of(Optional.of(expectedResponse))); UserGroupInfo groupInfo = groupConnector.getUserGroupById(id); assertEquals(expectedGroupInfo, groupInfo); - verify(restClientMock, times(1)).getUserGroupById(anyString()); + verify(restClientMock, times(1))._getUserGroupUsingGET(anyString()); } @Test @@ -267,7 +287,7 @@ void addMemberToUserGroup() { //then assertDoesNotThrow(executable); verify(restClientMock, times(1)) - .addMemberToUserGroup(anyString(), any()); + ._addMemberToUserGroupUsingPUT(anyString(), any()); verifyNoMoreInteractions(restClientMock); } @@ -304,7 +324,7 @@ void deleteMemberFromUserGroup() { //then assertDoesNotThrow(executable); verify(restClientMock, times(1)) - .deleteMemberFromUserGroup(anyString(), any()); + ._deleteMemberFromUserGroupUsingDELETE(anyString(), any()); verifyNoMoreInteractions(restClientMock); } @@ -336,11 +356,12 @@ void getUserGroups() throws IOException { // Given Optional institutionId = Optional.of("institutionId"); Optional productId = Optional.of("productId"); - Optional userId = Optional.of(randomUUID()); + Optional userId = Optional.of(UUID.fromString("895b4af3-7fa7-4442-8a0d-a2b05c6c719f")); UserGroupFilter filter = new UserGroupFilter(); filter.setInstitutionId(institutionId); filter.setProductId(productId); filter.setUserId(userId); + Pageable pageable = PageRequest.of(0, 1, Sort.by("name")); ClassPathResource resource = new ClassPathResource("stubs/userGroupInfoGetUserGroups.json"); @@ -350,40 +371,56 @@ void getUserGroups() throws IOException { ClassPathResource ResponseResource = new ClassPathResource("stubs/userGroupResponse.json"); byte[] responseStream = Files.readAllBytes(ResponseResource.getFile().toPath()); - UserGroupResponse response = objectMapper.readValue(responseStream, new TypeReference<>() { + UserGroupResource response = objectMapper.readValue(responseStream, new TypeReference<>() { }); + // Extract page number and page size from pageable + int pageNumber = pageable.getPageNumber(); + int pageSize = pageable.getPageSize(); + + // Convert Sort to a list of strings if sorting is needed and supported + List sortCriteria = pageable.getSort().stream() + .map(order -> order.getProperty() + "," + order.getDirection()) + .collect(Collectors.toList()); + + PageOfUserGroupResource pageOfUserGroupResource = new PageOfUserGroupResource(); + pageOfUserGroupResource.setContent(List.of(response)); - when(restClientMock.getUserGroups(filter.getInstitutionId().orElse(null), + when(restClientMock._getUserGroupsUsingGET( + filter.getInstitutionId().orElse(null), + pageNumber, + pageSize, + sortCriteria, filter.getProductId().orElse(null), filter.getUserId().orElse(null), - List.of(UserGroupStatus.ACTIVE, UserGroupStatus.SUSPENDED), - pageable)) - .thenReturn(new PageImpl<>(List.of(response))); + String.join(",", UserGroupStatus.ACTIVE.name(), UserGroupStatus.SUSPENDED.name()))) + .thenReturn(ResponseEntity.ok(pageOfUserGroupResource)); Page groupInfos = groupConnector.getUserGroups(filter, pageable); assertEquals(1, groupInfos.getTotalElements()); assertEquals(userGroupInfo, groupInfos.getContent().get(0)); Mockito.verify(restClientMock, times(1)) - .getUserGroups(filter.getInstitutionId().orElse(null), + ._getUserGroupsUsingGET( + filter.getInstitutionId().orElse(null), + pageNumber, + pageSize, + sortCriteria, filter.getProductId().orElse(null), filter.getUserId().orElse(null), - List.of(UserGroupStatus.ACTIVE, UserGroupStatus.SUSPENDED), - pageable); + String.join(",", UserGroupStatus.ACTIVE.name(), UserGroupStatus.SUSPENDED.name())); UserGroupInfo actualUserGroupInfo = groupInfos.getContent().get(0); assertEquals(userGroupInfo, actualUserGroupInfo); - } @Test void getUserGroups_nullResponse_emptyInstitutionId_emptyProductId_emptyUserId_unPaged() { //given UserGroupFilter filter = new UserGroupFilter(); - Pageable pageable = Pageable.unpaged(); - when(restClientMock.getUserGroups(any(), any(), any(), any(), any())) - .thenAnswer(invocation -> getPage(emptyList(), invocation.getArgument(4, Pageable.class), () -> 0L)); + Pageable pageable = PageRequest.of(0, 1, Sort.by("name")); + when(restClientMock._getUserGroupsUsingGET(any(), any(), any(), any(), any(), any(), any())) + .thenReturn(ResponseEntity.ok(new PageOfUserGroupResource())); //when Page groupInfos = groupConnector.getUserGroups(filter, pageable); //then @@ -400,18 +437,27 @@ void getUserGroups_notEmptyInstitutionId_notEmptyProductId() throws IOException UserGroupFilter filter = new UserGroupFilter(); filter.setInstitutionId(institutionId); filter.setProductId(productId); - Pageable pageable = Pageable.unpaged(); - UserGroupResponse response1 = mockInstance(new UserGroupResponse(), "setMembers"); - response1.setMembers(List.of("123", "321")); - response1.setCreatedAt(Instant.MAX); - response1.setModifiedAt(Instant.MAX); - when(restClientMock.getUserGroups(anyString(), anyString(), any(), any(), any())) - .thenAnswer(invocation -> getPage(List.of(response1), invocation.getArgument(4, Pageable.class), () -> 1L)); + + Pageable pageable = PageRequest.of(0, 1, Sort.by("name")); + + UUID member = UUID.fromString("895b4af3-7fa7-4442-8a0d-a2b05c6c719f"); + UUID member2 = UUID.fromString("895b4af3-7fa7-4442-8a0d-a2b05c6c719a"); + UserGroupResource resource = mockInstance(new UserGroupResource()); + resource.setMembers(List.of(member, member2)); + resource.setCreatedAt(Instant.MAX); + resource.setModifiedAt(Instant.MAX); + + PageOfUserGroupResource pageOfUserGroupResource = new PageOfUserGroupResource(); + pageOfUserGroupResource.setContent(List.of(resource)); + ResponseEntity responseEntity = ResponseEntity.ok(pageOfUserGroupResource); + + when(restClientMock._getUserGroupsUsingGET(filter.getInstitutionId().orElse(null), pageable.getPageNumber(), pageable.getPageSize(), List.of("name,ASC"), filter.getProductId().orElse(null), null, String.join(",", UserGroupStatus.ACTIVE.name(), UserGroupStatus.SUSPENDED.name()))) + .thenReturn(responseEntity); //when Page groupInfos = groupConnector.getUserGroups(filter, pageable); - ClassPathResource resource = new ClassPathResource("stubs/getUserGroups_notEmptyInstitutionId_notEmptyProductId_notEmptyUserId.json"); - byte[] resourceStream = Files.readAllBytes(resource.getFile().toPath()); + ClassPathResource resource1 = new ClassPathResource("stubs/getUserGroups_notEmptyInstitutionId_notEmptyProductId_notEmptyUserId.json"); + byte[] resourceStream = Files.readAllBytes(resource1.getFile().toPath()); String expectedUserGroupInfoJson = new String(resourceStream, StandardCharsets.UTF_8); UserGroupInfo expectedUserGroupInfo = objectMapper.readValue(expectedUserGroupInfoJson, UserGroupInfo.class); @@ -419,66 +465,90 @@ void getUserGroups_notEmptyInstitutionId_notEmptyProductId() throws IOException //then assertEquals(groupInfos.getContent().get(0), expectedUserGroupInfo); verify(restClientMock, times(1)) - .getUserGroups(eq(institutionId.get()), eq(productId.get()), isNull(), eq(List.of(UserGroupStatus.ACTIVE, UserGroupStatus.SUSPENDED)), isNotNull()); - verifyNoMoreInteractions(restClientMock); + ._getUserGroupsUsingGET(filter.getInstitutionId().orElse(null), pageable.getPageNumber(), pageable.getPageSize(), List.of("name,ASC"), filter.getProductId().orElse(null), null, String.join(",", UserGroupStatus.ACTIVE.name(), UserGroupStatus.SUSPENDED.name())); } @Test void getUserGroups_notEmptyUserId() throws IOException { - //given - Optional userId = Optional.of(randomUUID()); + + UUID userId = UUID.randomUUID(); UserGroupFilter filter = new UserGroupFilter(); - filter.setUserId(userId); - Pageable pageable = Pageable.unpaged(); - UserGroupResponse response1 = mockInstance(new UserGroupResponse(), "setMembers"); - response1.setMembers(List.of("123", "321")); - response1.setCreatedAt(Instant.MAX); - response1.setModifiedAt(Instant.MAX); - when(restClientMock.getUserGroups(any(), any(), any(), anyList(), any())) - .thenAnswer(invocation -> getPage(List.of(response1), invocation.getArgument(4, Pageable.class), () -> 1L)); - //when + filter.setInstitutionId(Optional.of("institutionId")); + filter.setUserId(Optional.of(userId)); + filter.setProductId(Optional.of("productId")); + + UUID member = UUID.fromString("895b4af3-7fa7-4442-8a0d-a2b05c6c719f"); + UUID member2 = UUID.fromString("895b4af3-7fa7-4442-8a0d-a2b05c6c719a"); + UserGroupResource resource = mockInstance(new UserGroupResource()); + resource.setMembers(List.of(member, member2)); + resource.setCreatedAt(Instant.MAX); + resource.setModifiedAt(Instant.MAX); + + Pageable pageable = PageRequest.of(1, 1, Sort.by("name")); + + List sortCriteria = pageable.getSort().stream() + .map(order -> order.getProperty() + "," + order.getDirection()) + .toList(); + + PageOfUserGroupResource pageOfUserGroupResource = new PageOfUserGroupResource(); + pageOfUserGroupResource.setContent(List.of(resource)); + ResponseEntity responseEntity = ResponseEntity.ok(pageOfUserGroupResource); + + when(restClientMock._getUserGroupsUsingGET(filter.getInstitutionId().orElse(null), pageable.getPageNumber(), pageable.getPageSize(), sortCriteria, filter.getProductId().orElse(null), userId, String.join(",", UserGroupStatus.ACTIVE.name(), UserGroupStatus.SUSPENDED.name()))) + .thenReturn(responseEntity); + Page groupInfos = groupConnector.getUserGroups(filter, pageable); - //then - ClassPathResource resource = new ClassPathResource("stubs/getUserGroups_notEmptyInstitutionId_notEmptyProductId_notEmptyUserId.json"); - byte[] resourceStream = Files.readAllBytes(resource.getFile().toPath()); + ClassPathResource resource1 = new ClassPathResource("stubs/getUserGroups_notEmptyInstitutionId_notEmptyProductId_notEmptyUserId.json"); + byte[] resourceStream = Files.readAllBytes(resource1.getFile().toPath()); String expectedUserGroupInfoJson = new String(resourceStream, StandardCharsets.UTF_8); UserGroupInfo expectedUserGroupInfo = objectMapper.readValue(expectedUserGroupInfoJson, UserGroupInfo.class); assertEquals(groupInfos.getContent().get(0), expectedUserGroupInfo); verify(restClientMock, times(1)) - .getUserGroups(isNull(), isNull(), eq(userId.get()), eq(List.of(UserGroupStatus.ACTIVE, UserGroupStatus.SUSPENDED)), isNotNull()); + ._getUserGroupsUsingGET(filter.getInstitutionId().orElse(null), pageable.getPageNumber(), pageable.getPageSize(), sortCriteria, filter.getProductId().orElse(null), userId, String.join(",", UserGroupStatus.ACTIVE.name(), UserGroupStatus.SUSPENDED.name())); verifyNoMoreInteractions(restClientMock); } + @Test void getUserGroups_nullGroupInfos() { - //given UserGroupFilter filter = new UserGroupFilter(); - Pageable pageable = Pageable.unpaged(); - when(restClientMock.getUserGroups(any(), any(), any(), any(), any())) - .thenAnswer(invocation -> getPage(emptyList(), invocation.getArgument(4, Pageable.class), () -> 0L)); - //when + filter.setInstitutionId(Optional.of("institutionId")); + filter.setProductId(Optional.of("productId")); + filter.setUserId(Optional.of(UUID.fromString("f36f7205-23ed-4726-b757-0ed5537fee03"))); + + Pageable pageable = PageRequest.of(1, 1, Sort.by("name")); + + List sortCriteria = pageable.getSort().stream() + .map(order -> order.getProperty() + "," + order.getDirection()) + .toList(); + + when(restClientMock._getUserGroupsUsingGET(filter.getInstitutionId().orElse(null), pageable.getPageNumber(), pageable.getPageSize(), sortCriteria, filter.getProductId().orElse(null), filter.getUserId().orElse(null), String.join(",", UserGroupStatus.ACTIVE.name(), UserGroupStatus.SUSPENDED.name()))) + .thenReturn(ResponseEntity.ok(new PageOfUserGroupResource())); + Page groupInfos = groupConnector.getUserGroups(filter, pageable); - //then + assertNotNull(groupInfos); assertTrue(groupInfos.isEmpty()); verify(restClientMock, times(1)) - .getUserGroups(isNull(), isNull(), isNull(), eq(List.of(UserGroupStatus.ACTIVE, UserGroupStatus.SUSPENDED)), isNotNull()); + ._getUserGroupsUsingGET(filter.getInstitutionId().orElse(null), pageable.getPageNumber(), pageable.getPageSize(), sortCriteria, filter.getProductId().orElse(null), filter.getUserId().orElse(null), String.join(",", UserGroupStatus.ACTIVE.name(), UserGroupStatus.SUSPENDED.name())); verifyNoMoreInteractions(restClientMock); } @Test void groupResponse_toGroupInfo() throws IOException { //given - UserGroupResponse response1 = mockInstance(new UserGroupResponse(), "setMembers"); - response1.setMembers(List.of("123", "321")); - response1.setCreatedAt(Instant.MAX); - response1.setModifiedAt(Instant.MAX); + UserGroupResource response = mockInstance(new UserGroupResource(), "setMembers"); + UUID id = UUID.fromString("895b4af3-7fa7-4442-8a0d-a2b05c6c719f"); + UUID id1 = UUID.fromString("b339c8b4-b749-4498-82eb-1ad2e3761079"); + response.setMembers(List.of(id, id1)); + response.setCreatedAt(Instant.MAX); + response.setModifiedAt(Instant.MAX); //when - UserGroupInfo groupInfo = UserGroupConnectorImpl.GROUP_RESPONSE_TO_GROUP_INFO.apply(response1); + UserGroupInfo groupInfo = UserGroupConnectorImpl.GROUP_RESPONSE_TO_GROUP_INFO.apply(response); //then ClassPathResource resource = new ClassPathResource("stubs/groupResponse_toGroupInfo.json"); byte[] resourceStream = Files.readAllBytes(resource.getFile().toPath()); @@ -491,7 +561,7 @@ void groupResponse_toGroupInfo() throws IOException { @Test void groupResponse_toGroupInfo_nullMembers() throws IOException { //given - UserGroupResponse response1 = mockInstance(new UserGroupResponse(), "setMembers"); + UserGroupResource response1 = mockInstance(new UserGroupResource(), "setMembers"); response1.setCreatedAt(Instant.MAX); response1.setModifiedAt(Instant.MAX); //when @@ -519,7 +589,7 @@ void deleteMembers() { //when assertDoesNotThrow(executable); verify(restClientMock, times(1)) - .deleteMembers(memberId, institutionId, productId); + ._deleteMemberFromUserGroupsUsingDELETE(memberId, institutionId, productId); verifyNoMoreInteractions(restClientMock); } @@ -536,4 +606,4 @@ void deleteMembers_institutionId() { verifyNoMoreInteractions(restClientMock); } -} \ No newline at end of file +} diff --git a/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/client/UserGroupRestClientTest.java b/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/client/UserGroupRestClientTest.java index 6d4aa9784..7fd7f69cb 100644 --- a/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/client/UserGroupRestClientTest.java +++ b/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/client/UserGroupRestClientTest.java @@ -9,6 +9,10 @@ import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.CreateUserGroupRequestDto; import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.UpdateUserGroupRequestDto; import it.pagopa.selfcare.dashboard.connector.rest.model.user_group.UserGroupResponse; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.CreateUserGroupDto; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.PageOfUserGroupResource; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.UpdateUserGroupDto; +import it.pagopa.selfcare.group.generated.openapi.v1.dto.UserGroupResource; import lombok.SneakyThrows; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Order; @@ -23,14 +27,12 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; +import org.springframework.http.ResponseEntity; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.support.TestPropertySourceUtils; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import static org.junit.jupiter.api.Assertions.*; @@ -80,10 +82,10 @@ private enum TestCase { @Test void createGroup() { //given - CreateUserGroupRequestDto request = TestUtils.mockInstance(new CreateUserGroupRequestDto()); - request.setMembers(List.of(TestUtils.mockInstance(UUID.randomUUID().toString()))); + CreateUserGroupDto request = TestUtils.mockInstance(new CreateUserGroupDto()); + request.setMembers(Set.of(TestUtils.mockInstance(UUID.randomUUID()))); //when - Executable executable = () -> restClient.createUserGroup(request); + Executable executable = () -> restClient._createGroupUsingPOST(request); //then assertDoesNotThrow(executable); } @@ -93,7 +95,7 @@ void deleteUserGroup() { //given String id = "id"; //when - Executable executable = () -> restClient.deleteUserGroupById(id); + Executable executable = () -> restClient._deleteGroupUsingDELETE(id); //then assertDoesNotThrow(executable); } @@ -103,7 +105,7 @@ void activateUserGroup() { //given String id = "id"; //when - Executable executable = () -> restClient.activateUserGroupById(id); + Executable executable = () -> restClient._activateGroupUsingPOST(id); //then assertDoesNotThrow(executable); } @@ -113,7 +115,7 @@ void suspendUserGroup() { //given String id = "id"; //when - Executable executable = () -> restClient.suspendUserGroupById(id); + Executable executable = () -> restClient._suspendGroupUsingPOST(id); //then assertDoesNotThrow(executable); } @@ -122,10 +124,10 @@ void suspendUserGroup() { void updateUserGroup() { //given String id = "id"; - UpdateUserGroupRequestDto request = TestUtils.mockInstance(new UpdateUserGroupRequestDto()); - request.setMembers(List.of(TestUtils.mockInstance(UUID.randomUUID().toString()))); + UpdateUserGroupDto request = TestUtils.mockInstance(new UpdateUserGroupDto()); + request.setMembers(Set.of(TestUtils.mockInstance(UUID.randomUUID()))); //when - Executable executable = () -> restClient.updateUserGroupById(id, request); + Executable executable = () -> restClient._updateUserGroupUsingPUT(id, request); //then assertDoesNotThrow(executable); } @@ -135,7 +137,7 @@ void getUserGroupInfo_fullyValued() { //given String groupId = testCase2igroupdMap.get(TestCase.FULLY_VALUED); //when - UserGroupResponse response = restClient.getUserGroupById(groupId); + UserGroupResource response = restClient._getUserGroupUsingGET(groupId).getBody(); //then assertNotNull(response); assertNotNull(response.getCreatedAt()); @@ -156,7 +158,7 @@ void getUserGroupInfo_fullyNull() { //given String groupId = testCase2igroupdMap.get(TestCase.FULLY_NULL); //when - UserGroupResponse response = restClient.getUserGroupById(groupId); + UserGroupResource response = restClient._getUserGroupUsingGET(groupId).getBody(); //then assertNotNull(response); Assertions.assertNull(response.getCreatedAt()); @@ -177,7 +179,7 @@ void addMemberToUserGroup() { String groupId = "groupId"; UUID memberId = UUID.randomUUID(); //when - Executable executable = () -> restClient.addMemberToUserGroup(groupId, memberId); + Executable executable = () -> restClient._addMemberToUserGroupUsingPUT(groupId, memberId); //then assertDoesNotThrow(executable); } @@ -188,7 +190,7 @@ void deleteMemberFromUserGroup() { String groupId = "groupId"; UUID memberId = UUID.randomUUID(); //when - Executable executable = () -> restClient.deleteMemberFromUserGroup(groupId, memberId); + Executable executable = () -> restClient._deleteMemberFromUserGroupUsingDELETE(groupId, memberId); //then assertDoesNotThrow(executable); } @@ -200,25 +202,27 @@ void getUserGroups_fullyValued() { String productId = null; UUID userId = null; Pageable pageable = Pageable.unpaged(); + String status = String.join(",", UserGroupStatus.ACTIVE.name(), UserGroupStatus.SUSPENDED.name()); + List sortParams = new ArrayList<>(); // when - Page response = restClient.getUserGroups(institutionId, productId, userId, List.of(UserGroupStatus.ACTIVE, UserGroupStatus.SUSPENDED), pageable); + ResponseEntity response = restClient._getUserGroupsUsingGET(institutionId,3,2 , sortParams,productId, userId, status); //then assertNotNull(response); - assertEquals(0, response.getNumber()); - assertEquals(20, response.getSize()); - assertEquals(1, response.getTotalElements()); - assertEquals(1, response.getTotalPages()); - assertNotNull(response.getContent()); - assertNotNull(response.getContent().get(0).getCreatedAt()); - assertNotNull(response.getContent().get(0).getCreatedBy()); - assertNotNull(response.getContent().get(0).getDescription()); - assertNotNull(response.getContent().get(0).getId()); - assertNotNull(response.getContent().get(0).getMembers()); - assertNotNull(response.getContent().get(0).getName()); - assertNotNull(response.getContent().get(0).getInstitutionId()); - assertNotNull(response.getContent().get(0).getModifiedAt()); - assertNotNull(response.getContent().get(0).getModifiedBy()); - assertNotNull(response.getContent().get(0).getStatus()); + assertEquals(0, Objects.requireNonNull(response.getBody()).getNumber()); + assertEquals(20, response.getBody().getSize()); + assertEquals(1, response.getBody().getTotalElements()); + assertEquals(1, response.getBody().getTotalPages()); + assertNotNull(response.getBody().getContent()); + assertNotNull(response.getBody().getContent().get(0).getCreatedAt()); + assertNotNull(response.getBody().getContent().get(0).getCreatedBy()); + assertNotNull(response.getBody().getContent().get(0).getDescription()); + assertNotNull(response.getBody().getContent().get(0).getId()); + assertNotNull(response.getBody().getContent().get(0).getMembers()); + assertNotNull(response.getBody().getContent().get(0).getName()); + assertNotNull(response.getBody().getContent().get(0).getInstitutionId()); + assertNotNull(response.getBody().getContent().get(0).getModifiedAt()); + assertNotNull(response.getBody().getContent().get(0).getModifiedBy()); + assertNotNull(response.getBody().getContent().get(0).getStatus()); } @Test @@ -227,26 +231,28 @@ void getUserGroups_fullyValuedPageable() { String institutionId = null; String productId = null; UUID userId = null; + String status = String.join(",", UserGroupStatus.ACTIVE.name(), UserGroupStatus.SUSPENDED.name()); + List sortParams = new ArrayList<>(); Pageable pageable = PageRequest.of(0, 1, Sort.by("name")); // when - Page response = restClient.getUserGroups(institutionId, productId, userId, List.of(UserGroupStatus.ACTIVE, UserGroupStatus.SUSPENDED), pageable); + ResponseEntity response = restClient._getUserGroupsUsingGET(institutionId,3,2 , sortParams,productId, userId, status); //then assertNotNull(response); - assertEquals(0, response.getNumber()); - assertEquals(20, response.getSize()); - assertEquals(1, response.getTotalElements()); - assertEquals(1, response.getTotalPages()); - assertNotNull(response.getContent()); - assertNotNull(response.getContent().get(0).getCreatedAt()); - assertNotNull(response.getContent().get(0).getCreatedBy()); - assertNotNull(response.getContent().get(0).getDescription()); - assertNotNull(response.getContent().get(0).getId()); - assertNotNull(response.getContent().get(0).getMembers()); - assertNotNull(response.getContent().get(0).getName()); - assertNotNull(response.getContent().get(0).getInstitutionId()); - assertNotNull(response.getContent().get(0).getModifiedAt()); - assertNotNull(response.getContent().get(0).getModifiedBy()); - assertNotNull(response.getContent().get(0).getStatus()); + assertEquals(0, Objects.requireNonNull(response.getBody()).getNumber()); + assertEquals(20, response.getBody().getSize()); + assertEquals(1, response.getBody().getTotalElements()); + assertEquals(1, response.getBody().getTotalPages()); + assertNotNull(response.getBody().getContent()); + assertNotNull(response.getBody().getContent().get(0).getCreatedAt()); + assertNotNull(response.getBody().getContent().get(0).getCreatedBy()); + assertNotNull(response.getBody().getContent().get(0).getDescription()); + assertNotNull(response.getBody().getContent().get(0).getId()); + assertNotNull(response.getBody().getContent().get(0).getMembers()); + assertNotNull(response.getBody().getContent().get(0).getName()); + assertNotNull(response.getBody().getContent().get(0).getInstitutionId()); + assertNotNull(response.getBody().getContent().get(0).getModifiedAt()); + assertNotNull(response.getBody().getContent().get(0).getModifiedBy()); + assertNotNull(response.getBody().getContent().get(0).getStatus()); } @Test @@ -256,9 +262,9 @@ void deleteMemberFromUserGroups() { String productId = "productId"; UUID memberId = UUID.randomUUID(); //when - Executable executable = () -> restClient.deleteMembers(memberId, institutionId, productId); + Executable executable = () -> restClient._deleteMemberFromUserGroupsUsingDELETE(memberId, institutionId, productId); //then assertDoesNotThrow(executable); } -} \ No newline at end of file +} diff --git a/connector/rest/src/test/resources/stubs/createUserGroup.json b/connector/rest/src/test/resources/stubs/createUserGroup.json index 0de2bb890..ac15084cb 100644 --- a/connector/rest/src/test/resources/stubs/createUserGroup.json +++ b/connector/rest/src/test/resources/stubs/createUserGroup.json @@ -1,7 +1,7 @@ { "name": "groupName", "description": "groupDescription", - "members": ["string1", "string2"], + "members": ["895b4af3-7fa7-4442-8a0d-a2b05c6c719f", "895b4af3-7fa7-4442-8a0d-a2b05c6c719c"], "institutionId": "institutionId", "productId": "productId" } \ No newline at end of file diff --git a/connector/rest/src/test/resources/stubs/createUserGroupRequest.json b/connector/rest/src/test/resources/stubs/createUserGroupRequest.json index 5236c1c51..2e681f40f 100644 --- a/connector/rest/src/test/resources/stubs/createUserGroupRequest.json +++ b/connector/rest/src/test/resources/stubs/createUserGroupRequest.json @@ -4,5 +4,5 @@ "name": "groupName", "description": "groupDescription", "status": "ACTIVE", - "members": ["string1", "string2"] + "members": ["895b4af3-7fa7-4442-8a0d-a2b05c6c719f", "895b4af3-7fa7-4442-8a0d-a2b05c6c719c"] } \ No newline at end of file diff --git a/connector/rest/src/test/resources/stubs/getUserGroups_notEmptyInstitutionId_notEmptyProductId_notEmptyUserId.json b/connector/rest/src/test/resources/stubs/getUserGroups_notEmptyInstitutionId_notEmptyProductId_notEmptyUserId.json index 006863760..2da2a405a 100644 --- a/connector/rest/src/test/resources/stubs/getUserGroups_notEmptyInstitutionId_notEmptyProductId_notEmptyUserId.json +++ b/connector/rest/src/test/resources/stubs/getUserGroups_notEmptyInstitutionId_notEmptyProductId_notEmptyUserId.json @@ -7,7 +7,7 @@ "status": "ACTIVE", "members": [ { - "id": "123", + "id": "895b4af3-7fa7-4442-8a0d-a2b05c6c719f", "user": null, "role": null, "products": null, @@ -16,7 +16,7 @@ "userMailUuid": null }, { - "id": "321", + "id": "895b4af3-7fa7-4442-8a0d-a2b05c6c719a", "user": null, "role": null, "products": null, diff --git a/connector/rest/src/test/resources/stubs/groupResponse_toGroupInfo.json b/connector/rest/src/test/resources/stubs/groupResponse_toGroupInfo.json index 006863760..8d525db28 100644 --- a/connector/rest/src/test/resources/stubs/groupResponse_toGroupInfo.json +++ b/connector/rest/src/test/resources/stubs/groupResponse_toGroupInfo.json @@ -7,7 +7,7 @@ "status": "ACTIVE", "members": [ { - "id": "123", + "id": "895b4af3-7fa7-4442-8a0d-a2b05c6c719f", "user": null, "role": null, "products": null, @@ -16,7 +16,7 @@ "userMailUuid": null }, { - "id": "321", + "id": "b339c8b4-b749-4498-82eb-1ad2e3761079", "user": null, "role": null, "products": null, diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/activateUserGroup.json b/connector/rest/src/test/resources/stubs/user-group/mappings/activateUserGroup.json index be5eb2c7c..6857d13af 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/activateUserGroup.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/activateUserGroup.json @@ -1,7 +1,7 @@ { "request": { "method": "POST", - "urlPathPattern": "/user-groups/v1/\\w+/activate" + "urlPathPattern": "/v1/user-groups/\\w+/activate" }, "response": { "status": "204", diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/addMemberToUserGroup.json b/connector/rest/src/test/resources/stubs/user-group/mappings/addMemberToUserGroup.json index a5c7858f5..0172c6ec2 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/addMemberToUserGroup.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/addMemberToUserGroup.json @@ -1,7 +1,7 @@ { "request": { "method": "PUT", - "urlPathPattern": "/user-groups/v1/\\w+/members/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}" + "urlPathPattern": "/v1/user-groups/\\w+/members/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}" }, "response": { "status": "200", diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/createGroup.json b/connector/rest/src/test/resources/stubs/user-group/mappings/createGroup.json index 62ae082bf..184e33471 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/createGroup.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/createGroup.json @@ -1,7 +1,7 @@ { "request": { "method": "POST", - "urlPathPattern": "/user-groups/v1/", + "urlPathPattern": "/v1/user-groups", "bodyPatterns": [ { "matchesJsonPath": "*" diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/deleteMemberFromUserGroup.json b/connector/rest/src/test/resources/stubs/user-group/mappings/deleteMemberFromUserGroup.json index 2db31f348..19c49002b 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/deleteMemberFromUserGroup.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/deleteMemberFromUserGroup.json @@ -1,7 +1,7 @@ { "request": { "method": "DELETE", - "urlPathPattern": "/user-groups/v1/\\w+/members/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}" + "urlPathPattern": "/v1/user-groups/\\w+/members/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}" }, "response": { "status": "200", diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/deleteMemberFromUserGroups.json b/connector/rest/src/test/resources/stubs/user-group/mappings/deleteMemberFromUserGroups.json index f3d2cdbff..a03d83216 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/deleteMemberFromUserGroups.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/deleteMemberFromUserGroups.json @@ -1,7 +1,7 @@ { "request": { "method": "DELETE", - "urlPathPattern": "/user-groups/v1/members/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}" + "urlPathPattern": "/v1/user-groups/members/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}" }, "response": { "status": "200", diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/deleteUserGroup.json b/connector/rest/src/test/resources/stubs/user-group/mappings/deleteUserGroup.json index 9df868334..b342f43d5 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/deleteUserGroup.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/deleteUserGroup.json @@ -1,7 +1,7 @@ { "request": { "method": "DELETE", - "urlPathPattern": "/user-groups/v1/\\w+" + "urlPathPattern": "/v1/user-groups/\\w+" }, "response": { "status": "204", diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroupInfo_fullyNull.json b/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroupInfo_fullyNull.json index 6c5d11682..ceda23d9d 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroupInfo_fullyNull.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroupInfo_fullyNull.json @@ -1,7 +1,7 @@ { "request": { "method": "GET", - "urlPath": "/user-groups/v1/groupId2" + "urlPath": "/v1/user-groups/groupId2" }, "response": { "status": "200", diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroupInfo_fullyValued.json b/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroupInfo_fullyValued.json index bd6f5e626..cc7e07d3f 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroupInfo_fullyValued.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroupInfo_fullyValued.json @@ -1,7 +1,7 @@ { "request": { "method": "GET", - "urlPath": "/user-groups/v1/groupId1" + "urlPath": "/v1/user-groups/groupId1" }, "response": { "status": "200", diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroups_fullyValued.json b/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroups_fullyValued.json index f2d7b0042..5e2fdcb7a 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroups_fullyValued.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroups_fullyValued.json @@ -2,7 +2,7 @@ "priority": 1, "request": { "method": "GET", - "urlPath": "/user-groups/v1/" + "urlPath": "/v1/user-groups" }, "response": { "status": "200", diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroups_fullyValuedPageable.json b/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroups_fullyValuedPageable.json index d8bdfc45c..2a981646e 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroups_fullyValuedPageable.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/getUserGroups_fullyValuedPageable.json @@ -2,7 +2,7 @@ "priority": 2, "request": { "method": "GET", - "urlPath": "/user-groups/v1/", + "urlPath": "/v1/user-groups/", "queryParameters": { "page": { "equalTo": "0" diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/suspendUserGroup.json b/connector/rest/src/test/resources/stubs/user-group/mappings/suspendUserGroup.json index aa4d9ac62..808aa0fbc 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/suspendUserGroup.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/suspendUserGroup.json @@ -1,7 +1,7 @@ { "request": { "method": "POST", - "urlPathPattern": "/user-groups/v1/\\w+/suspend" + "urlPathPattern": "/v1/user-groups/\\w+/suspend" }, "response": { "status": "200", diff --git a/connector/rest/src/test/resources/stubs/user-group/mappings/updateUserGroup.json b/connector/rest/src/test/resources/stubs/user-group/mappings/updateUserGroup.json index 09a8d7e48..ec529dc4a 100644 --- a/connector/rest/src/test/resources/stubs/user-group/mappings/updateUserGroup.json +++ b/connector/rest/src/test/resources/stubs/user-group/mappings/updateUserGroup.json @@ -1,7 +1,7 @@ { "request": { "method": "PUT", - "urlPathPattern": "/user-groups/v1/\\w+" + "urlPathPattern": "/v1/user-groups/\\w+" }, "response": { "status": "204", diff --git a/connector/rest/src/test/resources/stubs/userGroupInfoGetUserGroupByIdSingle.json b/connector/rest/src/test/resources/stubs/userGroupInfoGetUserGroupByIdSingle.json index c029acf03..01f5d96b5 100644 --- a/connector/rest/src/test/resources/stubs/userGroupInfoGetUserGroupByIdSingle.json +++ b/connector/rest/src/test/resources/stubs/userGroupInfoGetUserGroupByIdSingle.json @@ -7,7 +7,7 @@ "status": "ACTIVE", "members": [ { - "id": "memberId1", + "id": "895b4af3-7fa7-4442-8a0d-a2b05c6c719f", "user": null, "role": null, "products": null, diff --git a/connector/rest/src/test/resources/stubs/userGroupInfoGetUserGroups.json b/connector/rest/src/test/resources/stubs/userGroupInfoGetUserGroups.json index 09dfcbf72..b9888b247 100644 --- a/connector/rest/src/test/resources/stubs/userGroupInfoGetUserGroups.json +++ b/connector/rest/src/test/resources/stubs/userGroupInfoGetUserGroups.json @@ -7,7 +7,7 @@ "status": "ACTIVE", "members": [ { - "id": "userId1" + "id": "895b4af3-7fa7-4442-8a0d-a2b05c6c719f" } ], "createdAt": "2022-01-01T00:00:00Z", diff --git a/connector/rest/src/test/resources/stubs/userGroupInfoNullModifiedBy.json b/connector/rest/src/test/resources/stubs/userGroupInfoNullModifiedBy.json index e3383abdd..559318cdb 100644 --- a/connector/rest/src/test/resources/stubs/userGroupInfoNullModifiedBy.json +++ b/connector/rest/src/test/resources/stubs/userGroupInfoNullModifiedBy.json @@ -7,7 +7,7 @@ "status": "ACTIVE", "members": [ { - "id": "memberId1", + "id": "123e4567-e89b-12d3-a456-426614174000", "user": null, "role": null, "products": null, @@ -16,7 +16,7 @@ "userMailUuid": null }, { - "id": "memberId2", + "id": "123e4567-e89b-12d3-a456-426614174001", "user": null, "role": null, "products": null, diff --git a/connector/rest/src/test/resources/stubs/userGroupResponse.json b/connector/rest/src/test/resources/stubs/userGroupResponse.json index e0c3f9c8b..781d8210f 100644 --- a/connector/rest/src/test/resources/stubs/userGroupResponse.json +++ b/connector/rest/src/test/resources/stubs/userGroupResponse.json @@ -5,7 +5,7 @@ "name": "groupName", "description": "groupDescription", "status": "ACTIVE", - "members": ["userId1"], + "members": ["895b4af3-7fa7-4442-8a0d-a2b05c6c719f"], "createdAt": "2022-01-01T00:00:00Z", "createdBy": "creatorId", "modifiedAt": "2022-01-01T00:00:00Z", diff --git a/connector/rest/src/test/resources/stubs/userGroupResponseNullModifiedBy.json b/connector/rest/src/test/resources/stubs/userGroupResponseNullModifiedBy.json index 310adf010..1fdade2e3 100644 --- a/connector/rest/src/test/resources/stubs/userGroupResponseNullModifiedBy.json +++ b/connector/rest/src/test/resources/stubs/userGroupResponseNullModifiedBy.json @@ -5,7 +5,7 @@ "name": "groupName", "description": "groupDescription", "status": "ACTIVE", - "members": ["memberId1", "memberId2"], + "members": ["123e4567-e89b-12d3-a456-426614174000", "123e4567-e89b-12d3-a456-426614174001"], "createdAt": "2022-01-01T00:00:00Z", "createdBy": "creatorId", "modifiedAt": "2022-01-01T00:00:00Z", diff --git a/connector/rest/src/test/resources/stubs/userGroupResponseSingle.json b/connector/rest/src/test/resources/stubs/userGroupResponseSingle.json index 0269bef37..781d8210f 100644 --- a/connector/rest/src/test/resources/stubs/userGroupResponseSingle.json +++ b/connector/rest/src/test/resources/stubs/userGroupResponseSingle.json @@ -5,7 +5,7 @@ "name": "groupName", "description": "groupDescription", "status": "ACTIVE", - "members": ["memberId1"], + "members": ["895b4af3-7fa7-4442-8a0d-a2b05c6c719f"], "createdAt": "2022-01-01T00:00:00Z", "createdBy": "creatorId", "modifiedAt": "2022-01-01T00:00:00Z",