Exemplo n.º 1
0
  @Test
  public void shouldGetContents() throws Exception {
    StringContent stringContent = new StringContent(STRING_LANGUAGE, STRING_NAME, STRING_VALUE);
    StreamContent streamContent =
        new StreamContent(STREAM_LANGUAGE, STREAM_NAME, null, STREAM_CHECKSUM, STREAM_CONTENT_TYPE);
    GridSettings settings = createGridSettings("", true, true, "", 5, 1, "", "asc");
    List<ResourceDto> resourceDtos =
        asList(new ResourceDto(streamContent), new ResourceDto(stringContent));

    String expectedResponse = createResponse(new Resources(settings, resourceDtos));

    when(cmsLiteService.getAllContents()).thenReturn(asList(streamContent, stringContent));

    controller
        .perform(
            get(
                "/resource?name={name}&string={string}&stream={stream}&languages={languages}&rows={rows}&page={page}&sortColumn={sortColumn}&sortDirection={sortDirection}",
                "",
                true,
                true,
                "",
                5,
                1,
                "",
                "asc"))
        .andExpect(status().is(HttpStatus.OK.value()))
        .andExpect(content().type(APPLICATION_JSON_UTF8))
        .andExpect(content().string(jsonMatcher(expectedResponse)));

    verify(cmsLiteService).getAllContents();
  }
Exemplo n.º 2
0
  @Test
  public void shouldReturn404WhenStringResourceNotFound() throws Exception {

    when(cmsLiteService.getStringContent(anyString(), anyString()))
        .thenThrow(new ContentNotFoundException());

    controller.perform(get("/string/fooLanguage/fooName")).andExpect(status().isNotFound());
  }
Exemplo n.º 3
0
  @Test
  public void shouldReturn404WhenEditingNonExistentStringResource() throws Exception {

    when(cmsLiteService.getStringContent(anyString(), anyString()))
        .thenThrow(new ContentNotFoundException());

    controller
        .perform(post("/resource/string/fooLanguage/fooName").param("value", "fooValue"))
        .andExpect(status().isNotFound());
  }
Exemplo n.º 4
0
  @Test
  public void shouldReturnAllResourcesLanguages() throws Exception {
    StringContent stringContent = new StringContent(STRING_LANGUAGE, STRING_NAME, STRING_VALUE);
    StreamContent streamContent =
        new StreamContent(STREAM_LANGUAGE, STREAM_NAME, null, STREAM_CHECKSUM, STREAM_CONTENT_TYPE);

    when(cmsLiteService.getAllContents()).thenReturn(asList(streamContent, stringContent));

    Set<String> actual = resourceController.getAllLanguages();
    assertThat(actual, hasItems(STREAM_LANGUAGE, STRING_LANGUAGE));
  }
Exemplo n.º 5
0
  @Test
  public void shouldRemoveStringContent() throws Exception {
    StringContent stringContent = new StringContent(STRING_LANGUAGE, STRING_NAME, STRING_VALUE);
    when(cmsLiteService.getStringContent(STRING_LANGUAGE, STRING_NAME)).thenReturn(stringContent);

    controller
        .perform(
            delete("/resource/{type}/{language}/{name}", STRING_TYPE, STRING_LANGUAGE, STRING_NAME))
        .andExpect(status().is(HttpStatus.OK.value()));

    verify(cmsLiteService).removeStringContent(STRING_LANGUAGE, STRING_NAME);
  }
Exemplo n.º 6
0
  @Test
  public void shouldReturnStringContent() throws Exception {
    StringContent stringContent = new StringContent(STRING_LANGUAGE, STRING_NAME, STRING_VALUE);
    String expectedResponse = createResponse(stringContent);

    when(cmsLiteService.getStringContent(STRING_LANGUAGE, STRING_NAME)).thenReturn(stringContent);

    controller
        .perform(
            get("/resource/{type}/{language}/{name}", STRING_TYPE, STRING_LANGUAGE, STRING_NAME))
        .andExpect(status().is(HttpStatus.OK.value()))
        .andExpect(content().type(APPLICATION_JSON_UTF8))
        .andExpect(content().string(jsonMatcher(expectedResponse)));

    verify(cmsLiteService).getStringContent(STRING_LANGUAGE, STRING_NAME);
  }
Exemplo n.º 7
0
  @Test
  public void shouldReturnNamesStartedWithGivenTerm() throws Exception {
    StringContent stringContent = new StringContent(STRING_LANGUAGE, STRING_NAME, STRING_VALUE);
    StreamContent streamContent =
        new StreamContent(STREAM_LANGUAGE, STREAM_NAME, null, STREAM_CHECKSUM, STREAM_CONTENT_TYPE);
    String expectedResponse = createResponse(asList(STRING_NAME));

    when(cmsLiteService.getAllContents()).thenReturn(asList(streamContent, stringContent));

    controller
        .perform(get("/resource/available/{field}?term={term}", "name", "valid-stri"))
        .andExpect(status().is(HttpStatus.OK.value()))
        .andExpect(content().type(APPLICATION_JSON_UTF8))
        .andExpect(content().string(jsonMatcher(expectedResponse)));

    verify(cmsLiteService).getAllContents();
  }
Exemplo n.º 8
0
  @Test
  public void shouldEditStringContent() throws Exception {
    StringContent stringContent = new StringContent(STRING_LANGUAGE, STRING_NAME, STRING_VALUE);

    when(cmsLiteService.getStringContent(STRING_LANGUAGE, STRING_NAME)).thenReturn(stringContent);

    controller
        .perform(
            post("/resource/string/{language}/{name}", STRING_LANGUAGE, STRING_NAME)
                .param("value", "new value"))
        .andExpect(status().is(HttpStatus.OK.value()));

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

    verify(cmsLiteService).addContent(captor.capture());
    stringContent.setValue("new value");

    assertEquals(stringContent, captor.getValue());
  }
Exemplo n.º 9
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());
  }