Search in sources :

Example 1 with VirtualHost

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);
}
Also used : RatingSummary(io.gravitee.rest.api.portal.rest.model.RatingSummary) Proxy(io.gravitee.definition.model.Proxy) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) VirtualHost(io.gravitee.definition.model.VirtualHost) Api(io.gravitee.rest.api.portal.rest.model.Api) Test(org.junit.Test)

Example 2 with VirtualHost

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

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;
}
Also used : Proxy(io.gravitee.definition.model.Proxy) HashMap(java.util.HashMap) PrimaryOwnerEntity(io.gravitee.rest.api.model.PrimaryOwnerEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) VirtualHost(io.gravitee.definition.model.VirtualHost) UserEntity(io.gravitee.rest.api.model.UserEntity) Date(java.util.Date) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with VirtualHost

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")));
}
Also used : Api(io.gravitee.repository.management.model.Api) VirtualHost(io.gravitee.definition.model.VirtualHost) Test(org.junit.Test)

Example 5 with VirtualHost

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")));
}
Also used : Api(io.gravitee.repository.management.model.Api) VirtualHost(io.gravitee.definition.model.VirtualHost) Test(org.junit.Test)

Aggregations

VirtualHost (io.gravitee.definition.model.VirtualHost)25 Test (org.junit.Test)17 Api (io.gravitee.repository.management.model.Api)10 Proxy (io.gravitee.definition.model.Proxy)7 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)6 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)6 UpdateApiEntity (io.gravitee.rest.api.model.api.UpdateApiEntity)3 Date (java.util.Date)3 PrimaryOwnerEntity (io.gravitee.rest.api.model.PrimaryOwnerEntity)2 UserEntity (io.gravitee.rest.api.model.UserEntity)2 Api (io.gravitee.rest.api.portal.rest.model.Api)2 RatingSummary (io.gravitee.rest.api.portal.rest.model.RatingSummary)2 Before (org.junit.Before)2 RatingSummaryEntity (io.gravitee.rest.api.model.RatingSummaryEntity)1 ApiEntrypointEntity (io.gravitee.rest.api.model.api.ApiEntrypointEntity)1 DuplicateApiEntity (io.gravitee.rest.api.model.api.DuplicateApiEntity)1 PageQuery (io.gravitee.rest.api.model.documentation.PageQuery)1 User (io.gravitee.rest.api.portal.rest.model.User)1 UuidString (io.gravitee.rest.api.service.common.UuidString)1 InvalidVirtualHostException (io.gravitee.rest.api.service.exceptions.InvalidVirtualHostException)1