use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class RatingMapperTest method testConvert.
@Test
public void testConvert() {
Instant now = Instant.now();
Date nowDate = Date.from(now);
// init
RatingEntity ratingEntity = new RatingEntity();
RatingAnswerEntity ratingAnswerEntity = new RatingAnswerEntity();
ratingAnswerEntity.setComment(RATING_RESPONSE_COMMENT);
ratingAnswerEntity.setCreatedAt(nowDate);
ratingAnswerEntity.setId(RATING_RESPONSE_ID);
ratingAnswerEntity.setUser(RATING_RESPONSE_AUTHOR);
ratingAnswerEntity.setUserDisplayName(RATING_RESPONSE_AUTHOR_DISPLAY_NAME);
ratingEntity.setAnswers(Arrays.asList(ratingAnswerEntity));
ratingEntity.setApi(RATING_API);
ratingEntity.setComment(RATING_COMMENT);
ratingEntity.setCreatedAt(nowDate);
ratingEntity.setId(RATING_ID);
ratingEntity.setRate((byte) 1);
ratingEntity.setTitle(RATING_TITLE);
ratingEntity.setUpdatedAt(nowDate);
ratingEntity.setUser(RATING_AUTHOR);
ratingEntity.setUserDisplayName(RATING_AUTHOR_DISPLAY_NAME);
UserEntity authorEntity = new UserEntity();
authorEntity.setId(RATING_AUTHOR);
UserEntity responseAuthorEntity = new UserEntity();
responseAuthorEntity.setId(RATING_RESPONSE_AUTHOR);
User author = new User();
author.setId(RATING_AUTHOR);
User responseAuthor = new User();
responseAuthor.setId(RATING_RESPONSE_AUTHOR);
doReturn(authorEntity).when(userService).findById(RATING_AUTHOR);
doReturn(responseAuthorEntity).when(userService).findById(RATING_RESPONSE_AUTHOR);
doReturn(author).when(userMapper).convert(authorEntity);
doReturn(responseAuthor).when(userMapper).convert(responseAuthorEntity);
Rating responseRating = ratingMapper.convert(ratingEntity, uriInfo);
assertNotNull(responseRating);
List<RatingAnswer> answers = responseRating.getAnswers();
assertNotNull(answers);
assertEquals(1, answers.size());
RatingAnswer ratingAnswer = answers.get(0);
assertNotNull(ratingAnswer);
assertEquals(RATING_RESPONSE_COMMENT, ratingAnswer.getComment());
assertEquals(now.toEpochMilli(), ratingAnswer.getDate().toInstant().toEpochMilli());
assertEquals(responseAuthor, ratingAnswer.getAuthor());
assertEquals(author, responseRating.getAuthor());
assertEquals(RATING_COMMENT, responseRating.getComment());
assertEquals(RATING_TITLE, responseRating.getTitle());
assertEquals(now.toEpochMilli(), responseRating.getDate().toInstant().toEpochMilli());
assertEquals(RATING_ID, responseRating.getId());
assertEquals(Integer.valueOf(1), responseRating.getValue());
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiMapperTest method testConvert.
@Test
public void testConvert() {
Instant now = Instant.now();
Date nowDate = Date.from(now);
// init
apiEntity = new ApiEntity();
apiEntity.setId(API_ID);
apiEntity.setDescription(API_DESCRIPTION);
apiEntity.setName(API_NAME);
apiEntity.setLabels(new ArrayList<>(Arrays.asList(API_LABEL)));
doThrow(CategoryNotFoundException.class).when(categoryService).findNotHiddenById(API_CATEGORY_HIDDEN);
apiEntity.setCategories(new HashSet<>(Arrays.asList(API_CATEGORY, API_CATEGORY_HIDDEN)));
apiEntity.setEntrypoints(Arrays.asList(new ApiEntrypointEntity(API_ENTRYPOINT_1), new ApiEntrypointEntity(API + "/foo")));
Map<String, Object> metadata = new HashMap<>();
metadata.put("meta", API);
apiEntity.setMetadata(metadata);
apiEntity.setVersion(API_VERSION);
UserEntity ownerEntity = new UserEntity();
ownerEntity.setId(API_OWNER_ID);
ownerEntity.setEmail(API_OWNER_EMAIL);
ownerEntity.setFirstname(API_OWNER_FIRSTNAME);
ownerEntity.setLastname(API_OWNER_LASTNAME);
apiEntity.setPrimaryOwner(new PrimaryOwnerEntity(ownerEntity));
RatingSummaryEntity ratingSummaryEntity = new RatingSummaryEntity();
ratingSummaryEntity.setAverageRate(Double.valueOf(4.2));
ratingSummaryEntity.setNumberOfRatings(10);
doReturn(true).when(ratingService).isEnabled();
doReturn(ratingSummaryEntity).when(ratingService).findSummaryByApi(API_ID);
doReturn(true).when(parameterService).findAsBoolean(Key.PORTAL_APIS_CATEGORY_ENABLED, ParameterReferenceType.ENVIRONMENT);
Proxy proxy = new Proxy();
proxy.setVirtualHosts(Collections.singletonList(new VirtualHost("/foo")));
apiEntity.setProxy(proxy);
apiEntity.setLifecycleState(ApiLifecycleState.PUBLISHED);
apiEntity.setUpdatedAt(nowDate);
// Test
Api responseApi = apiMapper.convert(apiEntity);
assertNotNull(responseApi);
assertNull(responseApi.getPages());
assertNull(responseApi.getPlans());
assertEquals(API_DESCRIPTION, responseApi.getDescription());
assertEquals(API_ID, responseApi.getId());
assertEquals(API_NAME, responseApi.getName());
assertEquals(API_VERSION, responseApi.getVersion());
assertFalse(responseApi.getDraft());
List<String> entrypoints = responseApi.getEntrypoints();
assertNotNull(entrypoints);
assertEquals(2, entrypoints.size());
assertEquals(API_ENTRYPOINT_1, entrypoints.get(0));
assertEquals(API + "/foo", entrypoints.get(1));
List<String> labels = responseApi.getLabels();
assertNotNull(labels);
assertTrue(labels.contains(API_LABEL));
User owner = responseApi.getOwner();
assertNotNull(owner);
assertEquals(API_OWNER_ID, owner.getId());
assertEquals(API_OWNER_EMAIL, owner.getEmail());
assertEquals(API_OWNER_FIRSTNAME + ' ' + API_OWNER_LASTNAME, owner.getDisplayName());
assertEquals(now.toEpochMilli(), responseApi.getUpdatedAt().toInstant().toEpochMilli());
List<String> categories = responseApi.getCategories();
assertNotNull(categories);
assertTrue(categories.contains(API_CATEGORY));
RatingSummary ratingSummary = responseApi.getRatingSummary();
assertNotNull(ratingSummary);
assertEquals(Double.valueOf(4.2), ratingSummary.getAverage());
assertEquals(BigDecimal.valueOf(10), ratingSummary.getCount());
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class UserMapperTest method testConvertUserEntity.
@Test
public void testConvertUserEntity() {
Instant now = Instant.now();
Date nowDate = Date.from(now);
// init
UserEntity userEntity = new UserEntity();
userEntity.setCreatedAt(nowDate);
userEntity.setEmail(USER_EMAIL);
userEntity.setFirstname(USER_FIRSTNAME);
userEntity.setId(USER_ID);
userEntity.setLastConnectionAt(nowDate);
userEntity.setLastname(USER_LASTNAME);
userEntity.setPassword(USER_PASSWORD);
userEntity.setPicture(USER_PICTURE);
userEntity.setRoles(null);
userEntity.setSource(USER_SOURCE);
userEntity.setSourceId(USER_SOURCE_ID);
userEntity.setStatus(USER_STATUS);
userEntity.setUpdatedAt(nowDate);
// Test
User responseUser = userMapper.convert(userEntity);
assertNotNull(responseUser);
assertEquals(USER_ID, responseUser.getId());
assertEquals(USER_EMAIL, responseUser.getEmail());
assertEquals(USER_FIRSTNAME, responseUser.getFirstName());
assertEquals(USER_LASTNAME, responseUser.getLastName());
assertEquals(USER_FIRSTNAME + ' ' + USER_LASTNAME, responseUser.getDisplayName());
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_RestoreTest method shouldRestoreApp.
@Test
public void shouldRestoreApp() throws TechnicalException {
Application app = fakeApp(false);
app.setStatus(ApplicationStatus.ARCHIVED);
when(applicationRepository.findById(APP)).thenReturn(Optional.of(app));
when(applicationRepository.update(app)).thenReturn(fakeApp(true));
when(subscriptionService.findByApplicationAndPlan(any(), any())).thenReturn(Collections.emptyList());
when(userService.findById(any())).thenReturn(new UserEntity());
ApplicationEntity result = applicationService.restore(APP);
verify(membershipService, times(1)).deleteReference(MembershipReferenceType.APPLICATION, APP);
verify(membershipService, times(1)).addRoleToMemberOnReference(any(), any(), any());
verify(genericNotificationConfigService, times(1)).deleteReference(NotificationReferenceType.APPLICATION, APP);
verify(portalNotificationConfigService, times(1)).deleteReference(NotificationReferenceType.APPLICATION, APP);
verify(auditService, times(1)).createApplicationAuditLog(any(), any(), any(), any(), any(), any());
Assertions.assertThat(result.getStatus()).isEqualTo(ApplicationStatus.ACTIVE.name());
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class MembershipCommandHandlerTest method handleWithRole.
@Test
public void handleWithRole() {
MembershipPayload membershipPayload = new MembershipPayload();
membershipPayload.setUserId("user#1");
membershipPayload.setOrganizationId("orga#1");
membershipPayload.setReferenceType(MembershipReferenceType.ORGANIZATION.name());
membershipPayload.setReferenceId("orga#1");
membershipPayload.setRole("ORGANIZATION_OWNER");
MembershipCommand command = new MembershipCommand(membershipPayload);
UserEntity user = new UserEntity();
user.setId(UUID.random().toString());
RoleEntity role = new RoleEntity();
role.setId(UUID.random().toString());
role.setScope(RoleScope.ORGANIZATION);
role.setName("ADMIN");
when(userService.findBySource(COCKPIT_SOURCE, membershipPayload.getUserId(), false)).thenReturn(user);
when(roleService.findByScopeAndName(RoleScope.ORGANIZATION, "ADMIN")).thenReturn(Optional.of(role));
TestObserver<MembershipReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertNoErrors();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
ArgumentCaptor<MembershipService.MembershipReference> membershipReference = ArgumentCaptor.forClass(MembershipService.MembershipReference.class);
ArgumentCaptor<MembershipService.MembershipMember> membershipMember = ArgumentCaptor.forClass(MembershipService.MembershipMember.class);
ArgumentCaptor<List<MembershipService.MembershipRole>> membershipRoles = ArgumentCaptor.forClass(List.class);
verify(membershipService).updateRolesToMemberOnReference(membershipReference.capture(), membershipMember.capture(), membershipRoles.capture(), eq(COCKPIT_SOURCE), eq(false));
assertEquals(MembershipReferenceType.ORGANIZATION, membershipReference.getValue().getType());
assertEquals(membershipPayload.getReferenceId(), membershipReference.getValue().getId());
assertEquals(MembershipMemberType.USER, membershipMember.getValue().getMemberType());
assertEquals(user.getId(), membershipMember.getValue().getMemberId());
assertTrue(membershipRoles.getValue().size() == 1 && membershipRoles.getValue().stream().allMatch(membershipRole -> membershipRole.getScope() == role.getScope() && membershipRole.getName().equals(role.getName())));
}
Aggregations