Permalink
Browse files

add new some api and test for GetCustomField.

  • Loading branch information...
hakurai committed Nov 8, 2012
1 parent 855d0cf commit bfd69c67f6c4dc47436655ef2802d305ff7f1d32
View
@@ -8,3 +8,4 @@ target/
immutable.properties
mutable.properties
normalUser.properties
+custom.properties
@@ -59,16 +59,12 @@ public String getName() {
return (String) map.get(NAME);
}
- public UpdateCustomField addIssueType(Integer issueTypeId) {
- List<Integer> issueTypes = getIssueTypes();
- if (issueTypes == null) {
- issueTypes = new ArrayList<Integer>();
- map.put(ISSUE_TYPES, issueTypes);
- }
-
- issueTypes.add(issueTypeId);
+ public UpdateCustomField setIssueType(Integer issueTypeId) {
+ return setValue(ISSUE_TYPES, issueTypeId);
+ }
- return this;
+ public UpdateCustomField addIssueType(Integer issueTypeId) {
+ return addValue(ISSUE_TYPES, issueTypeId);
}
public List<Integer> getIssueTypes() {
@@ -175,16 +171,12 @@ public String getInitialDate() {
return (String) map.get(INITIAL_DATE);
}
- public UpdateCustomField addItem(String item) {
- List<String> items = getItems();
- if (items == null) {
- items = new ArrayList<String>();
- map.put(ITEMS, items);
- }
-
- items.add(item);
+ public UpdateCustomField setItem(String item) {
+ return setValue(ITEMS, item);
+ }
- return this;
+ public UpdateCustomField addItem(String item) {
+ return addValue(ITEMS, item);
}
public List<String> getItems() {
@@ -221,4 +213,25 @@ public CustomField execute() {
return CustomFieldParser.parse((Map<String, Object>) res);
}
+
+ protected <V> UpdateCustomField setValue(String name, V value) {
+ List<V> list = (List<V>) map.get(name);
+ if (list != null && !list.isEmpty()) {
+ list.clear();
+ }
+ addValue(name, value);
+
+ return this;
+ }
+
+ protected <V> UpdateCustomField addValue(String name, V value) {
+ List<V> list = (List<V>) map.get(name);
+ if (list == null) {
+ list = new ArrayList<V>();
+ map.put(name, list);
+ }
+ list.add(value);
+
+ return this;
+ }
}
@@ -17,7 +17,7 @@
public ListCustomFieldImpl(Map<String, Object> map) {
super(map);
- items = XmlRpcUtil.<Item>toList(ItemImpl.class, map);
+ items = XmlRpcUtil.<Item>toList(ItemImpl.class, map.get("items"));
}
@Override
@@ -18,7 +18,7 @@
public SelectCustomFieldImpl(Map<String, Object> map) {
super(map);
- items = XmlRpcUtil.<Item>toList(ItemImpl.class, map);
+ items = XmlRpcUtil.<Item>toList(ItemImpl.class, map.get("items"));
allowInput = (Boolean) map.get("allow_input");
}
@@ -0,0 +1,35 @@
+package backlog4j.api;
+
+import backlog4j.BacklogClient;
+import backlog4j.BacklogClientFactory;
+import backlog4j.CustomField;
+import backlog4j.conf.CustomConfigure;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author eguchi
+ */
+public class GetCustomFieldsTest {
+
+ protected BacklogClient customClient;
+
+
+ @Before
+ public void setUp() throws Exception {
+ customClient = new BacklogClientFactory(CustomConfigure.getInstance()).newBacklogClient();
+ }
+
+ @Test
+ public void testExecute() throws Exception {
+ List<CustomField> customFieldList = customClient.getCustomFields().setProjectId(151).execute();
+
+ assertThat(customFieldList.size(),is(5));
+
+ }
+}
@@ -0,0 +1,67 @@
+package backlog4j.conf;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+
+/**
+ * @author eguchi
+ */
+public class CustomConfigure implements BacklogConfigure {
+
+ private static final BacklogConfigure BACKLOG_CONFIGURE = new CustomConfigure();
+ private final BacklogConfigure delegate;
+
+
+ private CustomConfigure() {
+ Properties properties = new Properties();
+ try {
+ properties.loadFromXML(new FileInputStream("custom.properties"));
+ } catch (IOException e) {
+ }
+
+ String spaceId = properties.getProperty("spaceId", "");
+ String username = properties.getProperty("username", "");
+ String password = properties.getProperty("password", "");
+
+ try {
+ delegate = new BacklogConfigureImpl(spaceId, username, password, 10000, 10000);
+ } catch (MalformedURLException e) {
+ throw new IllegalStateException("failed to write TestuserConfigure");
+ }
+
+ }
+
+
+ public static BacklogConfigure getInstance() {
+ return BACKLOG_CONFIGURE;
+ }
+
+
+ @Override
+ public String getUsername() {
+ return delegate.getUsername();
+ }
+
+ @Override
+ public String getPassword() {
+ return delegate.getPassword();
+ }
+
+ @Override
+ public URL getXmlRpcUrl() {
+ return delegate.getXmlRpcUrl();
+ }
+
+ @Override
+ public int getReadTimeout() {
+ return delegate.getReadTimeout();
+ }
+
+ @Override
+ public int getConnectTimeout() {
+ return delegate.getConnectTimeout();
+ }
+}

0 comments on commit bfd69c6

Please sign in to comment.