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