Search in sources :

Example 11 with InlinePictureEntity

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

the class CategoryResourceTest method init.

@Before
public void init() throws IOException, URISyntaxException {
    resetAllMocks();
    CategoryEntity categoryEntity = new CategoryEntity();
    categoryEntity.setId(CATEGORY_ID);
    categoryEntity.setHidden(false);
    doReturn(categoryEntity).when(categoryService).findNotHiddenById(CATEGORY_ID);
    Set<ApiEntity> mockApis = new HashSet<>();
    doReturn(mockApis).when(apiService).findPublishedByUser(any());
    Mockito.when(categoryMapper.convert(any(), any())).thenCallRealMethod();
    mockImage = new InlinePictureEntity();
    apiLogoContent = Files.readAllBytes(Paths.get(this.getClass().getClassLoader().getResource("media/logo.svg").toURI()));
    mockImage.setContent(apiLogoContent);
    mockImage.setType("image/svg");
    doReturn(mockImage).when(categoryService).getPicture(CATEGORY_ID);
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) HashSet(java.util.HashSet) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Before(org.junit.Before)

Example 12 with InlinePictureEntity

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

the class PictureManagementTest method testPictureResponse.

@Test
public void testPictureResponse() throws IOException, URISyntaxException {
    Request request = Mockito.mock(Request.class);
    doReturn(null).when(request).evaluatePreconditions(any(EntityTag.class));
    InlinePictureEntity mockImage = new InlinePictureEntity();
    byte[] imageContent = Files.readAllBytes(Paths.get(this.getClass().getClassLoader().getResource("media/logo.svg").toURI()));
    mockImage.setContent(imageContent);
    mockImage.setType("image/svg");
    Response response = pictureResourceForTest.createPictureResponse(request, mockImage);
    assertEquals(OK_200, response.getStatus());
    MultivaluedMap<String, Object> headers = response.getHeaders();
    MediaType mediaType = (MediaType) headers.getFirst(HttpHeader.CONTENT_TYPE.asString());
    String etag = ((EntityTag) headers.getFirst("ETag")).getValue();
    assertEquals(mockImage.getType(), mediaType.toString());
    ByteArrayOutputStream baos = (ByteArrayOutputStream) response.getEntity();
    byte[] fileContent = baos.toByteArray();
    assertTrue(Arrays.equals(fileContent, imageContent));
    String expectedTag = Integer.toString(new String(fileContent).hashCode());
    assertEquals(expectedTag, etag);
    // test Cache
    ResponseBuilder responseBuilder = Response.notModified();
    doReturn(responseBuilder).when(request).evaluatePreconditions(any(EntityTag.class));
    final Response cachedResponse = pictureResourceForTest.createPictureResponse(request, mockImage);
    assertEquals(NOT_MODIFIED_304, cachedResponse.getStatus());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Test(org.junit.Test)

Example 13 with InlinePictureEntity

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

the class ThemeServiceTest method shouldGetLogo.

@Test
public void shouldGetLogo() throws TechnicalException {
    final Theme theme = mock(Theme.class, withSettings().lenient());
    Mockito.lenient().when(theme.getReferenceType()).thenReturn(ENVIRONMENT.name());
    when(theme.getReferenceId()).thenReturn("DEFAULT");
    when(theme.getLogo()).thenReturn(themeServiceImpl.getDefaultLogo());
    PictureEntity logo = themeService.getLogo(THEME_ID);
    assertNotNull(logo);
    assertTrue(logo instanceof InlinePictureEntity);
}
Also used : Theme(io.gravitee.repository.management.model.Theme) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) PictureEntity(io.gravitee.rest.api.model.PictureEntity) UrlPictureEntity(io.gravitee.rest.api.model.UrlPictureEntity) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Test(org.junit.Test)

Example 14 with InlinePictureEntity

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

the class ApiQualityMetricLogoTest method shouldBeValidIfNotNull.

@Test
public void shouldBeValidIfNotNull() {
    InlinePictureEntity apiPicture = mock(InlinePictureEntity.class);
    when(apiPicture.getContent()).thenReturn("abcd".getBytes());
    when(mockApiService.getPicture(API_ID)).thenReturn(apiPicture);
    ApiEntity api = mock(ApiEntity.class);
    when(api.getId()).thenReturn(API_ID);
    boolean valid = srv.isValid(api);
    assertTrue(valid);
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Test(org.junit.Test)

Example 15 with InlinePictureEntity

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

the class ApiQualityMetricLogoTest method shouldNotBeValidIfNull.

@Test
public void shouldNotBeValidIfNull() {
    InlinePictureEntity apiPicture = mock(InlinePictureEntity.class);
    when(mockApiService.getPicture(API_ID)).thenReturn(apiPicture);
    ApiEntity api = mock(ApiEntity.class);
    when(api.getId()).thenReturn(API_ID);
    boolean valid = srv.isValid(api);
    assertFalse(valid);
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Test(org.junit.Test)

Aggregations

InlinePictureEntity (io.gravitee.rest.api.model.InlinePictureEntity)15 UrlPictureEntity (io.gravitee.rest.api.model.UrlPictureEntity)4 Test (org.junit.Test)4 CategoryEntity (io.gravitee.rest.api.model.CategoryEntity)3 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 NewCategoryEntity (io.gravitee.rest.api.model.NewCategoryEntity)2 UpdateCategoryEntity (io.gravitee.rest.api.model.UpdateCategoryEntity)2 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)2 UuidString (io.gravitee.rest.api.service.common.UuidString)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Before (org.junit.Before)2 Theme (io.gravitee.repository.management.model.Theme)1 PictureEntity (io.gravitee.rest.api.model.PictureEntity)1 UpdateUserEntity (io.gravitee.rest.api.model.UpdateUserEntity)1 UserEntity (io.gravitee.rest.api.model.UserEntity)1 User (io.gravitee.rest.api.portal.rest.model.User)1 UserLinks (io.gravitee.rest.api.portal.rest.model.UserLinks)1 RequirePortalAuth (io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)1