Exemplo n.º 1
0
 /** @return the expected value */
 private String setMetadataValueQuery(final String givenQuery) {
   when(dsf.getMetadataValueQuery()).thenReturn(givenQuery);
   DataSearchQueryBuilder uut = new DataSearchQueryBuilder(dsf, userInfoMock);
   return "{\"nested\":{\"query\":"
       + uut.getSimpleQuery(DataSearchQueryBuilder.METADATA_VALUE, givenQuery).getPayload()
       + ",\"path\":\"metadata\"}}";
 }
Exemplo n.º 2
0
  @Test
  public void testTaggedWith() {
    when(dsf.isIncludeTrashItems()).thenReturn(false);
    Set<Tag> tags = new LinkedHashSet<>();

    final String expectedValue = setTaggedWithQuery(tags, dsf);
    assertEquals("", expectedValue);

    Tag mock1 = mock(Tag.class);
    mock1.setId("id1");
    mock1.setValue("tag1");

    when(mock1.getId()).thenReturn("id1");

    Tag mock2 = mock(Tag.class);
    mock1.setId("id2");
    mock1.setValue("tag2");

    when(mock2.getId()).thenReturn("id2");

    tags.add(mock1);
    final String expectedValue1 = setTaggedWithQuery(tags, dsf);
    assertEquals("id1", expectedValue1);

    tags.add(mock2);

    final String expectedValue2 = setTaggedWithQuery(tags, dsf);
    assertEquals("id1,id2", expectedValue2);
  }
Exemplo n.º 3
0
 /** @return the expected value */
 private String setSharedWith(final String givenValue) {
   when(dsf.getSharedWith()).thenReturn(givenValue);
   return "{\"bool\":{\"must\":[{\"nested\":{\"query\":{\"bool\":{\"must\":[{\"term\":{\"permission\":\"own\"}},{\"wildcard\":{\"user\":\""
       + userInfoMock.getUsername()
       + "#*\"}}]}},\"path\":\"userPermissions\"}},{\"nested\":{\"query\":{\"wildcard\":{\"user\":\""
       + givenValue
       + "#*\"}},\"path\":\"userPermissions\"}}]}}";
 }
Exemplo n.º 4
0
  @Test
  public void testFileExcludingTrash() {
    when(dsf.isIncludeTrashItems()).thenReturn(false);

    final String expectedValue = setFileQuery("*query*");

    String result = new DataSearchQueryBuilder(dsf, userInfoMock).file().toString();
    assertEquals(wrappedQueryExcludingTrash(expectedValue), result);
  }
Exemplo n.º 5
0
  /** @return the expected value */
  private String setModifiedWithin(final Date from, final Date to) {
    DateInterval di = mock(DateInterval.class);
    when(di.getFrom()).thenReturn(from);
    when(di.getTo()).thenReturn(to);

    when(dsf.getModifiedWithin()).thenReturn(di);
    if (from == null && to == null) {
      return null;
    }
    if (from == null) {
      return "{\"range\":{\"dateModified\":{\"lte\":\"" + to.getTime() + "\"}}}";
    } else if (to == null) {
      return "{\"range\":{\"dateModified\":{\"gte\":\"" + from.getTime() + "\"}}}";
    }
    return "{\"range\":{\"dateModified\":{\"gte\":\""
        + from.getTime()
        + "\",\"lte\":\""
        + to.getTime()
        + "\"}}}";
  }
Exemplo n.º 6
0
  /** @return the expected value */
  private String setFileSizeRange(final Double min, final Double max) {
    FileSizeRange fsr = mock(FileSizeRange.class);
    when(fsr.getMin()).thenReturn(min);
    when(fsr.getMax()).thenReturn(max);

    when(dsf.getFileSizeRange()).thenReturn(fsr);
    if (min == null && max == null) {
      return null;
    }
    if (min == null) {
      return "{\"range\":{\"fileSize\":{\"lte\":\"" + max.longValue() + "\"}}}";
    } else if (max == null) {
      return "{\"range\":{\"fileSize\":{\"gte\":\"" + min.longValue() + "\"}}}";
    }
    return "{\"range\":{\"fileSize\":{\"gte\":\""
        + min.longValue()
        + "\",\"lte\":\""
        + max.longValue()
        + "\"}}}";
  }
Exemplo n.º 7
0
 private String setTaggedWithQuery(final Set<Tag> tags, final DiskResourceQueryTemplate drqt) {
   when(dsf.getTagQuery()).thenReturn(tags);
   DataSearchQueryBuilder uut = new DataSearchQueryBuilder(dsf, userInfoMock);
   return uut.taggedWith();
 }
Exemplo n.º 8
0
  /** @return the expected value */
  private String setNegatedFileQuery(final String givenSearchTerms) {
    when(dsf.getNegatedFileQuery()).thenReturn(givenSearchTerms);

    DataSearchQueryBuilder uut = new DataSearchQueryBuilder(dsf, userInfoMock);
    return uut.getSimpleQuery(DataSearchQueryBuilder.LABEL, givenSearchTerms).getPayload();
  }
Exemplo n.º 9
0
 @Before
 public void setUp() {
   when(dsf.isIncludeTrashItems()).thenReturn(true);
   when(userInfoMock.getBaseTrashPath()).thenReturn("/iplant/trash");
   when(userInfoMock.getUsername()).thenReturn("test_user");
 }
Exemplo n.º 10
0
 /** @return the expected value */
 private String setOwnedBy(final String givenValue) {
   when(dsf.getOwnedBy()).thenReturn(givenValue);
   return "{\"nested\":{\"query\":{\"bool\":{\"must\":[{\"term\":{\"permission\":\"own\"}},{\"wildcard\":{\"user\":\""
       + givenValue
       + "#*\"}}]}},\"path\":\"userPermissions\"}}";
 }