Search in sources :

Example 26 with ApplicationListItem

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());
}
Also used : ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) ApplicationCriteria(io.gravitee.repository.management.api.search.ApplicationCriteria) Test(org.junit.Test)

Example 27 with ApplicationListItem

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());
}
Also used : ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Example 28 with ApplicationListItem

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());
}
Also used : ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) UserDetails(io.gravitee.rest.api.idp.api.authentication.UserDetails) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) TopApiEntity(io.gravitee.rest.api.model.TopApiEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) Test(org.junit.Test)

Example 29 with ApplicationListItem

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());
}
Also used : ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) FilterableItem(io.gravitee.rest.api.model.filtering.FilterableItem) Test(org.junit.Test)

Aggregations

ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)29 Test (org.junit.Test)16 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)11 Response (javax.ws.rs.core.Response)9 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)8 SubscriptionQuery (io.gravitee.rest.api.model.subscription.SubscriptionQuery)7 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)6 Collectors (java.util.stream.Collectors)6 ApplicationService (io.gravitee.rest.api.service.ApplicationService)5 java.util (java.util)5 MediaType (io.gravitee.common.http.MediaType)4 FilterableItem (io.gravitee.rest.api.model.filtering.FilterableItem)4 Inject (javax.inject.Inject)4 Before (org.junit.Before)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 SimpleEvent (io.gravitee.common.event.impl.SimpleEvent)3 UserEntity (io.gravitee.rest.api.model.UserEntity)3 AlertTriggerEntity (io.gravitee.rest.api.model.alert.AlertTriggerEntity)3 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)3 Application (io.gravitee.rest.api.portal.rest.model.Application)3