use of io.gravitee.rest.api.model.application.ApplicationListItem in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_FindByNameTest method shouldNotFindByName.
@Test
public void shouldNotFindByName() throws Exception {
when(membershipService.getMembershipsByMemberAndReference(any(), any(), any())).thenReturn(Collections.emptySet());
when(applicationRepository.search(any(), any())).thenReturn(new Page<>(Collections.emptyList(), 0, 0, 0));
Set<ApplicationListItem> set = applicationService.findByNameAndStatus(null, "a", "ACTIVE");
assertNotNull(set);
assertEquals("result is empty", 0, set.size());
ArgumentCaptor<ApplicationCriteria> queryCaptor = ArgumentCaptor.forClass(ApplicationCriteria.class);
Mockito.verify(applicationRepository).search(queryCaptor.capture(), any());
final ApplicationCriteria query = queryCaptor.getValue();
assertEquals("a", query.getName());
}
use of io.gravitee.rest.api.model.application.ApplicationListItem in project gravitee-management-rest-api by gravitee-io.
the class ApiService_FindByUserTest method shouldFindByUser.
@Test
public void shouldFindByUser() throws TechnicalException {
when(apiRepository.search(new ApiCriteria.Builder().environmentId("DEFAULT").ids(api.getId()).build())).thenReturn(singletonList(api));
MembershipEntity membership = new MembershipEntity();
membership.setId("id");
membership.setMemberId(USER_NAME);
membership.setMemberType(MembershipMemberType.USER);
membership.setReferenceId(api.getId());
membership.setReferenceType(MembershipReferenceType.API);
membership.setRoleId("API_USER");
when(membershipService.getMembershipsByMemberAndReference(MembershipMemberType.USER, USER_NAME, MembershipReferenceType.API)).thenReturn(Collections.singleton(membership));
RoleEntity poRole = new RoleEntity();
poRole.setId("API_PRIMARY_OWNER");
when(roleService.findPrimaryOwnerRoleByOrganization(any(), any())).thenReturn(poRole);
MemberEntity poMember = new MemberEntity();
poMember.setId("admin");
poMember.setRoles(Collections.singletonList(poRole));
when(membershipService.getMembersByReferencesAndRole(MembershipReferenceType.API, Collections.singletonList(api.getId()), "API_PRIMARY_OWNER")).thenReturn(new HashSet(Arrays.asList(poMember)));
final ApplicationListItem application = new ApplicationListItem();
application.setId("appId");
final Set<ApiEntity> apiEntities = apiService.findByUser(USER_NAME, null, false);
assertNotNull(apiEntities);
assertEquals(1, apiEntities.size());
}
use of io.gravitee.rest.api.model.application.ApplicationListItem in project gravitee-management-rest-api by gravitee-io.
the class FilteringServiceTest method shouldGetMineApi.
@Test
public void shouldGetMineApi() {
final Authentication authentication = mock(Authentication.class);
when(authentication.getPrincipal()).thenReturn(new UserDetails("user", "", emptyList()));
final SecurityContext securityContext = mock(SecurityContext.class);
when(securityContext.getAuthentication()).thenReturn(authentication);
SecurityContextHolder.setContext(securityContext);
ApplicationListItem appA = new ApplicationListItem();
appA.setId("A");
ApplicationListItem appB = new ApplicationListItem();
appB.setId("B");
ApplicationListItem appC = new ApplicationListItem();
appC.setId("C");
doReturn(new HashSet<ApplicationListItem>(Arrays.asList(appC, appB, appA))).when(applicationService).findByUser(any());
SubscriptionEntity subA1 = new SubscriptionEntity();
subA1.setApplication("A");
subA1.setApi("1");
SubscriptionEntity subA2 = new SubscriptionEntity();
subA2.setApplication("A");
subA2.setApi("2");
SubscriptionEntity subB1 = new SubscriptionEntity();
subB1.setApplication("B");
subB1.setApi("1");
SubscriptionEntity subC4 = new SubscriptionEntity();
subC4.setApplication("C");
subC4.setApi("4");
SubscriptionEntity subC8 = new SubscriptionEntity();
subC8.setApplication("C");
subC8.setApi("8");
doReturn(Arrays.asList(subC8, subA2, subB1, subC4, subA1)).when(subscriptionService).search(any());
FilteredEntities<ApiEntity> apiEntityFilteredEntities = filteringService.filterApis(mockApis, FilteringService.FilterType.MINE, null);
List<ApiEntity> filteredItems = apiEntityFilteredEntities.getFilteredItems();
assertEquals(2, filteredItems.size());
assertEquals("1", filteredItems.get(0).getId());
assertEquals("4", filteredItems.get(1).getId());
}
use of io.gravitee.rest.api.model.application.ApplicationListItem in project gravitee-management-rest-api by gravitee-io.
the class FilteringServiceTest method shouldGetApplicationsOrderByNbSubscriptionsDescAndName.
@Test
public void shouldGetApplicationsOrderByNbSubscriptionsDescAndName() {
ApplicationListItem applicationListItem1 = new ApplicationListItem();
applicationListItem1.setId("A");
applicationListItem1.setName("A");
ApplicationListItem applicationListItem2 = new ApplicationListItem();
applicationListItem2.setId("B");
applicationListItem2.setName("b");
ApplicationListItem applicationListItem3 = new ApplicationListItem();
applicationListItem3.setId("C");
applicationListItem3.setName("C");
ApplicationListItem applicationListItem4 = new ApplicationListItem();
applicationListItem4.setId("D");
applicationListItem4.setName("d");
Set<FilterableItem> mockApplications = new HashSet<>(Arrays.asList(applicationListItem1, applicationListItem2, applicationListItem3, applicationListItem4));
SubscriptionEntity subA1 = new SubscriptionEntity();
subA1.setApplication("A");
SubscriptionEntity subA2 = new SubscriptionEntity();
subA2.setApplication("A");
SubscriptionEntity subB1 = new SubscriptionEntity();
subB1.setApplication("B");
SubscriptionEntity subB2 = new SubscriptionEntity();
subB2.setApplication("B");
SubscriptionEntity subB3 = new SubscriptionEntity();
subB3.setApplication("B");
SubscriptionEntity subC1 = new SubscriptionEntity();
subC1.setApplication("C");
SubscriptionEntity subC2 = new SubscriptionEntity();
subC2.setApplication("C");
SubscriptionEntity subC3 = new SubscriptionEntity();
subC3.setApplication("C");
SubscriptionEntity subD1 = new SubscriptionEntity();
subD1.setApplication("D");
SubscriptionEntity subD2 = new SubscriptionEntity();
subD2.setApplication("D");
doReturn(Arrays.asList(subA1, subA2, subB1, subB2, subB3, subC1, subC2, subC3, subD1, subD2)).when(subscriptionService).search(any());
FilteredEntities<FilterableItem> applicationListItemFilteredEntities = filteringService.getEntitiesOrderByNumberOfSubscriptions(mockApplications, false, false);
List<FilterableItem> filteredItems = applicationListItemFilteredEntities.getFilteredItems();
assertEquals("B", filteredItems.get(0).getId());
assertEquals("C", filteredItems.get(1).getId());
assertEquals("A", filteredItems.get(2).getId());
assertEquals("D", filteredItems.get(3).getId());
}
Aggregations