@Override
 @Transactional
 public StreamContent getStreamContent(String language, String name)
     throws ContentNotFoundException {
   StreamContent streamContent = streamContentService.findByLanguageAndName(language, name);
   if (streamContent == null) {
     throw new ContentNotFoundException();
   }
   streamContent.setContent(retrieveStreamContentData(streamContent));
   return streamContent;
 }
Esempio n. 2
0
  @Test
  public void shouldEditStreamContent() throws Exception {
    StreamContent streamContent =
        new StreamContent(STREAM_LANGUAGE, STREAM_NAME, null, STREAM_CHECKSUM, STREAM_CONTENT_TYPE);
    MultipartFile file = mock(MultipartFile.class);

    when(cmsLiteService.getStreamContent(STREAM_LANGUAGE, STREAM_NAME)).thenReturn(streamContent);
    when(file.getBytes()).thenReturn(ArrayUtils.EMPTY_BYTE_ARRAY);
    when(file.getBytes()).thenReturn("new file".getBytes());
    when(file.getContentType()).thenReturn("text/plain");

    resourceController.editStreamContent(STREAM_LANGUAGE, STREAM_NAME, file);

    ArgumentCaptor<StreamContent> captor = ArgumentCaptor.forClass(StreamContent.class);

    verify(cmsLiteService).addContent(captor.capture());

    streamContent.setContent(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY);
    streamContent.setContentType("text/plain");
    streamContent.setChecksum(md5Hex("new file".getBytes()));

    assertEquals(streamContent, captor.getValue());
  }