Search in sources :

Example 1 with PrimaryOwnerEntity

use of io.gravitee.rest.api.model.PrimaryOwnerEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationMapperTest method init.

@Before
public void init() {
    now = Instant.now();
    Date nowDate = Date.from(now);
    applicationEntity = new ApplicationEntity();
    applicationListItem = new ApplicationListItem();
    // init
    reset(groupService);
    reset(userService);
    reset(userMapper);
    GroupEntity grpEntity = new GroupEntity();
    grpEntity.setId(APPLICATION_GROUP_ID);
    grpEntity.setName(APPLICATION_GROUP_NAME);
    when(groupService.findById(APPLICATION_GROUP_ID)).thenReturn(grpEntity);
    UserEntity userEntity = Mockito.mock(UserEntity.class);
    when(userEntity.getDisplayName()).thenReturn(APPLICATION_USER_DISPLAYNAME);
    when(userEntity.getEmail()).thenReturn(APPLICATION_USER_EMAIL);
    when(userEntity.getId()).thenReturn(APPLICATION_USER_ID);
    when(userService.findById(APPLICATION_USER_ID)).thenReturn(userEntity);
    when(userMapper.convert(userEntity)).thenCallRealMethod();
    when(userMapper.computeUserLinks(anyString(), any())).thenCallRealMethod();
    PrimaryOwnerEntity primaryOwner = new PrimaryOwnerEntity(userEntity);
    when(uriInfo.getBaseUriBuilder()).thenReturn(UriBuilder.fromPath(""));
    applicationEntity.setCreatedAt(nowDate);
    applicationEntity.setDescription(APPLICATION_DESCRIPTION);
    applicationEntity.setGroups(new HashSet<String>(Arrays.asList(APPLICATION_GROUP_ID)));
    applicationEntity.setId(APPLICATION_ID);
    applicationEntity.setName(APPLICATION_NAME);
    applicationEntity.setPrimaryOwner(primaryOwner);
    applicationEntity.setStatus(APPLICATION_STATUS);
    applicationEntity.setType(APPLICATION_TYPE);
    applicationEntity.setUpdatedAt(nowDate);
    applicationListItem.setCreatedAt(nowDate);
    applicationListItem.setDescription(APPLICATION_DESCRIPTION);
    applicationListItem.setGroups(new HashSet<String>(Arrays.asList(APPLICATION_GROUP_ID)));
    applicationListItem.setId(APPLICATION_ID);
    applicationListItem.setName(APPLICATION_NAME);
    applicationListItem.setPrimaryOwner(primaryOwner);
    applicationListItem.setStatus(APPLICATION_STATUS);
    applicationListItem.setType(APPLICATION_TYPE);
    applicationListItem.setUpdatedAt(nowDate);
}
Also used : ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) GroupEntity(io.gravitee.rest.api.model.GroupEntity) PrimaryOwnerEntity(io.gravitee.rest.api.model.PrimaryOwnerEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) UserEntity(io.gravitee.rest.api.model.UserEntity) Before(org.junit.Before)

Example 2 with PrimaryOwnerEntity

use of io.gravitee.rest.api.model.PrimaryOwnerEntity 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());
}
Also used : RatingSummary(io.gravitee.rest.api.portal.rest.model.RatingSummary) ApiEntrypointEntity(io.gravitee.rest.api.model.api.ApiEntrypointEntity) User(io.gravitee.rest.api.portal.rest.model.User) Instant(java.time.Instant) PrimaryOwnerEntity(io.gravitee.rest.api.model.PrimaryOwnerEntity) RatingSummaryEntity(io.gravitee.rest.api.model.RatingSummaryEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Proxy(io.gravitee.definition.model.Proxy) VirtualHost(io.gravitee.definition.model.VirtualHost) Api(io.gravitee.rest.api.portal.rest.model.Api) Test(org.junit.Test)

Example 3 with PrimaryOwnerEntity

use of io.gravitee.rest.api.model.PrimaryOwnerEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiService_FindPrimaryOwnerTest method testUserModeWithNonExistingPOUser.

@Test
public void testUserModeWithNonExistingPOUser() {
    setPrimaryOwnerMode("USER");
    setPoUserNonExisting();
    defineUser(CURRENT_USER);
    JsonNode definition = poUserDefinition();
    final PrimaryOwnerEntity primaryOwner = apiService.findPrimaryOwner(definition, CURRENT_USER);
    assertEquals(CURRENT_USER, primaryOwner.getId());
    assertEquals("USER", primaryOwner.getType());
}
Also used : PrimaryOwnerEntity(io.gravitee.rest.api.model.PrimaryOwnerEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 4 with PrimaryOwnerEntity

use of io.gravitee.rest.api.model.PrimaryOwnerEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiService_FindPrimaryOwnerTest method testHybridModeWithNoPO.

// HYBRID + import with no PO
@Test
public void testHybridModeWithNoPO() {
    setPrimaryOwnerMode("HYBRID");
    defineUser(CURRENT_USER);
    JsonNode definition = noPODefinition();
    final PrimaryOwnerEntity primaryOwner = apiService.findPrimaryOwner(definition, CURRENT_USER);
    assertEquals(CURRENT_USER, primaryOwner.getId());
    assertEquals("USER", primaryOwner.getType());
}
Also used : PrimaryOwnerEntity(io.gravitee.rest.api.model.PrimaryOwnerEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 5 with PrimaryOwnerEntity

use of io.gravitee.rest.api.model.PrimaryOwnerEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiService_FindPrimaryOwnerTest method testGroupModeWithNonExistingPOUserAndCurrentUserBelongsToAPoGroup.

@Test
public void testGroupModeWithNonExistingPOUserAndCurrentUserBelongsToAPoGroup() {
    setPrimaryOwnerMode("GROUP");
    addUserInPOGroup(CURRENT_USER, CURRENT_USER_PO_GROUP);
    setPoUserNonExisting();
    JsonNode definition = poUserDefinition();
    final PrimaryOwnerEntity primaryOwner = apiService.findPrimaryOwner(definition, CURRENT_USER);
    assertEquals(CURRENT_USER_PO_GROUP, primaryOwner.getId());
    assertEquals("GROUP", primaryOwner.getType());
}
Also used : PrimaryOwnerEntity(io.gravitee.rest.api.model.PrimaryOwnerEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Aggregations

PrimaryOwnerEntity (io.gravitee.rest.api.model.PrimaryOwnerEntity)26 Test (org.junit.Test)23 JsonNode (com.fasterxml.jackson.databind.JsonNode)16 UserEntity (io.gravitee.rest.api.model.UserEntity)9 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)8 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)3 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)3 Assert (org.junit.Assert)3 Before (org.junit.Before)3 Mockito (org.mockito.Mockito)3 NOT_FOUND_404 (io.gravitee.common.http.HttpStatusCode.NOT_FOUND_404)2 OK_200 (io.gravitee.common.http.HttpStatusCode.OK_200)2 Proxy (io.gravitee.definition.model.Proxy)2 VirtualHost (io.gravitee.definition.model.VirtualHost)2 RatingSummaryEntity (io.gravitee.rest.api.model.RatingSummaryEntity)2 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)2 TopHitsAnalytics (io.gravitee.rest.api.model.analytics.TopHitsAnalytics)2 GroupByQuery (io.gravitee.rest.api.model.analytics.query.GroupByQuery)2 ApiEntrypointEntity (io.gravitee.rest.api.model.api.ApiEntrypointEntity)2 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)2