|
1 | 1 | package org.zendesk.client.v2; |
2 | 2 |
|
| 3 | +import org.hamcrest.core.IsCollectionContaining; |
3 | 4 | import org.junit.After; |
4 | 5 | import org.junit.BeforeClass; |
5 | 6 | import org.junit.Ignore; |
|
42 | 43 | import java.util.Collections; |
43 | 44 | import java.util.Date; |
44 | 45 | import java.util.HashMap; |
| 46 | +import java.util.HashSet; |
45 | 47 | import java.util.List; |
46 | 48 | import java.util.Properties; |
| 49 | +import java.util.Set; |
47 | 50 | import java.util.UUID; |
48 | 51 | import java.util.stream.StreamSupport; |
49 | 52 |
|
@@ -848,6 +851,47 @@ public void getArticles() throws Exception { |
848 | 851 | } |
849 | 852 | } |
850 | 853 |
|
| 854 | + @Test |
| 855 | + public void getArticlesFromAnyLabels() throws Exception { |
| 856 | + createClientWithTokenOrPassword(); |
| 857 | + /* |
| 858 | + Given 3 articles |
| 859 | + Article 1 with title "SomeLabelOne" and label "SomeLabelA" |
| 860 | + Article 2 with title "SomeLabelTwo" and labels "SomeLabelB" and "SomeLabelC" |
| 861 | + Article 3 with title "SomeLabelThree" and label "SomeLabelD" |
| 862 | + When a search by labels "SomeLabelA", "SomeLabelB" |
| 863 | + Then we get Article 1 and Article 2 but not Article 3 |
| 864 | + because Article 1 and 2 have at least one of the labels, Article 3 has none |
| 865 | + */ |
| 866 | + Iterable<Article> result = instance.getArticlesFromAnyLabels(Arrays.asList("SomeLabelA", "SomeLabelB")); |
| 867 | + Set<String> actualTitles = extractTitles(result); |
| 868 | + assertThat(actualTitles.size(), is(2)); |
| 869 | + assertThat(actualTitles, IsCollectionContaining.hasItems("SomeLabelOne", "SomeLabelTwo")); |
| 870 | + } |
| 871 | + |
| 872 | + @Test |
| 873 | + public void getArticlesFromAllLabels() throws Exception { |
| 874 | + createClientWithTokenOrPassword(); |
| 875 | + /* |
| 876 | + Given 2 articles |
| 877 | + Article 1 with title "AllLabelOne" and label "AllLabelA" |
| 878 | + Article 2 with title "AllLabelTwo" and labels "AllLabelA" and "AllLabelB" |
| 879 | + When a search by labels "AllLabelA", "AllLabelB" |
| 880 | + Then we get Article 2 but not Article 1 |
| 881 | + because Article 2 has both labels and Article 1 has only one |
| 882 | + */ |
| 883 | + Iterable<Article> result = instance.getArticlesFromAllLabels(Arrays.asList("AllLabelA", "AllLabelB")); |
| 884 | + Set<String> actualTitles = extractTitles(result); |
| 885 | + assertThat(actualTitles.size(), is(1)); |
| 886 | + assertThat(actualTitles, IsCollectionContaining.hasItems("AllLabelTwo")); |
| 887 | + } |
| 888 | + |
| 889 | + private Set<String> extractTitles(Iterable<Article> iter) { |
| 890 | + Set<String> result = new HashSet<>(); |
| 891 | + iter.forEach(article -> result.add(article.getTitle())); |
| 892 | + return result; |
| 893 | + } |
| 894 | + |
851 | 895 | @Test |
852 | 896 | public void getArticleSubscriptions() throws Exception { |
853 | 897 | createClientWithTokenOrPassword(); |
|
0 commit comments