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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations