use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiSubscribersResourceTest method shouldGetApiSubscribersNotAsPrimaryOwner.
@Test
public void shouldGetApiSubscribersNotAsPrimaryOwner() {
ApiEntity mockApi = new ApiEntity();
mockApi.setId(API);
UserEntity user = new UserEntity();
user.setId("ANOTHER_NAME");
PrimaryOwnerEntity primaryOwner = new PrimaryOwnerEntity(user);
mockApi.setPrimaryOwner(primaryOwner);
Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
doReturn(mockApis).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
TopHitsAnalytics mockAnalytics = new TopHitsAnalytics();
Map<String, Long> mockedValues = new HashMap<>();
mockedValues.put("A", 10L);
mockedValues.put("B", 20L);
mockedValues.put("C", 30L);
mockAnalytics.setValues(mockedValues);
doReturn(mockAnalytics).when(analyticsService).execute(any(GroupByQuery.class));
SubscriptionEntity subA1 = new SubscriptionEntity();
subA1.setApplication("A");
subA1.setApi(API);
SubscriptionEntity subC1 = new SubscriptionEntity();
subC1.setApplication("C");
subC1.setApi(API);
doReturn(Arrays.asList(subA1, subC1)).when(subscriptionService).search(any());
ApplicationEntity appA = new ApplicationEntity();
appA.setId("A");
doReturn(appA).when(applicationService).findById("A");
doReturn(new Application().id("A")).when(applicationMapper).convert(eq(appA), any());
ApplicationEntity appC = new ApplicationEntity();
appC.setId("C");
doReturn(appC).when(applicationService).findById("C");
doReturn(new Application().id("C")).when(applicationMapper).convert(eq(appC), any());
ApplicationListItem appLIA = new ApplicationListItem();
appLIA.setId("A");
ApplicationListItem appLIC = new ApplicationListItem();
appLIC.setId("C");
doReturn(new HashSet<>(Arrays.asList(appLIA, appLIC))).when(applicationService).findByUser(USER_NAME);
final Response response = target(API).path("subscribers").request().get();
assertEquals(OK_200, response.getStatus());
ArgumentCaptor<SubscriptionQuery> queryCaptor = ArgumentCaptor.forClass(SubscriptionQuery.class);
Mockito.verify(subscriptionService).search(queryCaptor.capture());
SubscriptionQuery value = queryCaptor.getValue();
assertNotNull(value.getApplications());
assertEquals(2, value.getApplications().size());
assertTrue(value.getApplications().contains("A"));
assertTrue(value.getApplications().contains("C"));
final ApplicationsResponse applicationsResponse = response.readEntity(ApplicationsResponse.class);
assertNotNull(applicationsResponse);
assertEquals(2, applicationsResponse.getData().size());
assertEquals("C", applicationsResponse.getData().get(0).getId());
assertEquals("A", applicationsResponse.getData().get(1).getId());
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class UserResourceTest method shouldGetCurrentUserWithEmptyManagementConfig.
@Test
public void shouldGetCurrentUserWithEmptyManagementConfig() {
when(userService.findByIdWithRoles(USER_NAME)).thenReturn(new UserEntity());
when(permissionService.hasManagementRights(USER_NAME)).thenReturn(Boolean.TRUE);
when(configService.getConsoleSettings()).thenReturn(new ConsoleSettingsEntity());
final Response response = target().request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
ArgumentCaptor<String> userId = ArgumentCaptor.forClass(String.class);
Mockito.verify(userService).findByIdWithRoles(userId.capture());
assertEquals(USER_NAME, userId.getValue());
User user = response.readEntity(User.class);
assertNotNull(user);
assertNull(user.getConfig());
assertNotNull(user.getLinks());
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class UserResourceTest method shouldUpdateCurrentUser.
@Test
public void shouldUpdateCurrentUser() {
UserInput userInput = new UserInput();
final String newAvatar = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
final String expectedAvatar = "data:image/gif;base64,R0lGODlhyADIAPAAAAAAAP///ywAAAAAyADIAEAC/4SPqcvtD6OctNqL" + "s968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5LL5jE6r1+y2+w2Py+" + "f0uv2Oz+v3/L7/DxgoOEhYaHiImKi4yNjo+AgZKTlJWWl5iZmpucnZ6fkJGio6SlpqeoqaqrrK2ur6ChsrO0tba3uLm6u7y9vr" + "+wscLDxMXGx8jJysvMzc7PwMHS09TV1tfY2drb3N3e39DR4uPk5ebn6Onq6+zt7u/g4fLz9PX29/j5+vv8/f7/8PMKDAgQQLGj" + "yIMKHChQwbOnwIMaLEiRQrWryIMaPGjQYcO3osUwAAOw==";
userInput.setAvatar(newAvatar);
userInput.setId(USER_NAME);
when(userService.update(eq(USER_NAME), any())).thenReturn(new UserEntity());
final Response response = target().request().put(Entity.json(userInput));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
ArgumentCaptor<UpdateUserEntity> user = ArgumentCaptor.forClass(UpdateUserEntity.class);
Mockito.verify(userService).update(eq(USER_NAME), user.capture());
final UpdateUserEntity updateUserEntity = user.getValue();
assertNotNull(updateUserEntity);
assertEquals(expectedAvatar, updateUserEntity.getPicture());
assertNull(updateUserEntity.getStatus());
User updateUser = response.readEntity(User.class);
assertNotNull(updateUser);
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class UserResourceTest method shouldGetCurrentUserWithManagementConfigWithoutUrl.
@Test
public void shouldGetCurrentUserWithManagementConfigWithoutUrl() {
when(userService.findByIdWithRoles(USER_NAME)).thenReturn(new UserEntity());
when(permissionService.hasManagementRights(USER_NAME)).thenReturn(Boolean.TRUE);
ConsoleSettingsEntity consoleConfigEntity = new ConsoleSettingsEntity();
when(configService.getConsoleSettings()).thenReturn(consoleConfigEntity);
final Response response = target().request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
ArgumentCaptor<String> userId = ArgumentCaptor.forClass(String.class);
Mockito.verify(userService).findByIdWithRoles(userId.capture());
assertEquals(USER_NAME, userId.getValue());
User user = response.readEntity(User.class);
assertNotNull(user);
assertNull(user.getConfig());
assertNotNull(user.getLinks());
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class UserResourceTest method shouldGetUserAvatar.
@Test
public void shouldGetUserAvatar() throws IOException {
doReturn(new UserEntity()).when(userService).findById(any());
final Response response = target().path("avatar").request().get();
assertEquals(OK_200, response.getStatus());
}
Aggregations