1   /*
2    * Copyright (C) 2010 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.atlassian.jira.rest.client.internal.jersey;
18  
19  import com.atlassian.jira.rest.client.IterableMatcher;
20  import com.atlassian.jira.rest.client.internal.json.ResourceUtil;
21  import org.codehaus.jettison.json.JSONException;
22  import org.junit.Assert;
23  import org.junit.Test;
24  
25  import java.util.Collection;
26  
27  public class AbstractJerseyRestClientTest {
28  	@Test
29  	public void testExtractErrors() throws JSONException {
30  		final String str = ResourceUtil.getStringFromResource("/json/error/valid.json");
31  		final Collection<String> stringCollection = AbstractJerseyRestClient.extractErrors(str);
32  		Assert.assertThat(stringCollection, IterableMatcher.hasOnlyElements("abcfsd"));
33  	}
34  
35  	@Test
36  	public void testExtractErrors2() throws JSONException {
37  		final String str = ResourceUtil.getStringFromResource("/json/error/valid2.json");
38  		final Collection<String> stringCollection = AbstractJerseyRestClient.extractErrors(str);
39  		Assert.assertThat(stringCollection, IterableMatcher.hasOnlyElements("a", "b", "xxx"));
40  	}
41  
42  	@Test
43  	public void testExtractErrors3() throws JSONException {
44  		final String str = ResourceUtil.getStringFromResource("/json/error/valid3.json");
45  		final Collection<String> stringCollection = AbstractJerseyRestClient.extractErrors(str);
46  		Assert.assertThat(stringCollection, IterableMatcher.hasOnlyElements("aa", "bb"));
47  	}
48  
49  	@Test
50  	public void testExtractErrors4() throws JSONException {
51  		final String str = ResourceUtil.getStringFromResource("/json/error/valid4.json");
52  		final Collection<String> stringCollection = AbstractJerseyRestClient.extractErrors(str);
53  		Assert.assertThat(stringCollection, IterableMatcher.hasOnlyElements("a", "b", "y", "z"));
54  	}
55  
56  }