use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.
the class ApiMapperTest method testMinimalConvert.
@Test
public void testMinimalConvert() {
// init
apiEntity = new ApiEntity();
apiEntity.setId(API_ID);
apiEntity.setDescription(API_DESCRIPTION);
Proxy proxy = new Proxy();
proxy.setVirtualHosts(Collections.singletonList(new VirtualHost("/foo")));
apiEntity.setProxy(proxy);
doReturn(false).when(ratingService).isEnabled();
apiEntity.setCategories(new HashSet<>(Arrays.asList(API_CATEGORY, API_CATEGORY_HIDDEN)));
doReturn(false).when(parameterService).findAsBoolean(Key.PORTAL_APIS_CATEGORY_ENABLED, ParameterReferenceType.ENVIRONMENT);
apiEntity.setLifecycleState(ApiLifecycleState.CREATED);
// Test
Api responseApi = apiMapper.convert(apiEntity);
assertNotNull(responseApi);
assertNull(responseApi.getPages());
assertNull(responseApi.getPlans());
assertEquals(API_DESCRIPTION, responseApi.getDescription());
assertEquals(API_ID, responseApi.getId());
assertNull(responseApi.getName());
assertNull(responseApi.getVersion());
assertTrue(responseApi.getDraft());
List<String> entrypoints = responseApi.getEntrypoints();
assertNull(entrypoints);
List<String> labels = responseApi.getLabels();
assertNotNull(labels);
assertEquals(0, labels.size());
assertNull(responseApi.getOwner());
List<String> categories = responseApi.getCategories();
assertNotNull(categories);
assertEquals(0, categories.size());
RatingSummary ratingSummary = responseApi.getRatingSummary();
assertNull(ratingSummary);
}
use of io.gravitee.definition.model.VirtualHost 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.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.
the class ApiDocumentTransformerTest method getApiEntity.
@NotNull
private ApiEntity getApiEntity() {
ApiEntity toTransform = new ApiEntity();
toTransform.setId("apiId");
toTransform.setName("name");
toTransform.setDescription("description");
toTransform.setReferenceId("xxxxxx");
toTransform.setReferenceType("env1");
UserEntity userEntity = new UserEntity();
userEntity.setId("userId");
userEntity.setEmail("userMail");
userEntity.setFirstname("userFirstname");
userEntity.setLastname("userLastname");
PrimaryOwnerEntity primaryOwnerEntity = new PrimaryOwnerEntity(userEntity);
toTransform.setPrimaryOwner(primaryOwnerEntity);
Proxy proxy = new Proxy();
proxy.setVirtualHosts(Arrays.asList(new VirtualHost("host", "path"), new VirtualHost("host2", "path2")));
toTransform.setProxy(proxy);
toTransform.setLabels(Arrays.asList("label1", "label2", "label2"));
toTransform.setCategories(new HashSet<>(Arrays.asList("cat1", "cat2")));
toTransform.setTags(new HashSet<>(Arrays.asList("tag1", "tag2")));
Date date = new Date();
toTransform.setCreatedAt(date);
toTransform.setUpdatedAt(date);
HashMap<String, Object> metadatas = new HashMap<>();
metadatas.put("metadata1", "value1");
metadatas.put("metadata2", "value2");
metadatas.put("metadata3", "value3");
toTransform.setMetadata(metadatas);
return toTransform;
}
use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceTest method shouldFail_create_existingSubPath.
@Test(expected = ApiContextPathAlreadyExistsException.class)
public void shouldFail_create_existingSubPath() {
Api api1 = createMock("mock1", "/context/subpath");
when(apiRepository.search(null)).thenReturn(Collections.singletonList(api1));
virtualHostService.sanitizeAndValidate(Collections.singletonList(new VirtualHost("/context")));
}
use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceTest method shouldSucceed_create_virtualHostWithSamePath.
@Test
public void shouldSucceed_create_virtualHostWithSamePath() {
Api api1 = createMock("mock1", "/context", "api.gravitee.io");
when(apiRepository.search(null)).thenReturn(Collections.singletonList(api1));
virtualHostService.sanitizeAndValidate(Collections.singletonList(new VirtualHost("/context")));
}
Aggregations