1 | |
package org.jbehave.core.io.rest.redmine; |
2 | |
|
3 | |
import static java.text.MessageFormat.format; |
4 | |
|
5 | |
import org.jbehave.core.io.rest.RESTClient.Type; |
6 | |
import org.jbehave.core.io.rest.Resource; |
7 | |
import org.jbehave.core.io.rest.UploadToREST; |
8 | |
|
9 | |
import com.google.gson.Gson; |
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
public class UploadToRedmine extends UploadToREST { |
15 | |
|
16 | |
private static final String REDMINE_URI = "{0}.{1}"; |
17 | |
|
18 | |
public UploadToRedmine(Type type) { |
19 | 2 | this(type, null, null); |
20 | 2 | } |
21 | |
|
22 | |
public UploadToRedmine(Type type, String username, String password) { |
23 | 2 | super(type, username, password); |
24 | 2 | } |
25 | |
|
26 | |
protected String uri(String resourcePath, Type type) { |
27 | 1 | return format(REDMINE_URI, resourcePath, type.name().toLowerCase()); |
28 | |
} |
29 | |
|
30 | |
protected String entity(Resource resource, Type type) { |
31 | 1 | Page page = new Page(); |
32 | 1 | page.title = resource.getName(); |
33 | 1 | page.text = resource.getContent(); |
34 | 1 | Entity entity = new Entity(); |
35 | 1 | entity.wiki_page = page; |
36 | 1 | switch (type) { |
37 | |
case JSON: |
38 | 1 | Gson gson = new Gson(); |
39 | 1 | return gson.toJson(entity); |
40 | |
case XML: |
41 | |
default: |
42 | 0 | return resource.getContent(); |
43 | |
} |
44 | |
} |
45 | |
|
46 | 3 | private static class Entity { |
47 | |
private Page wiki_page; |
48 | |
} |
49 | |
|
50 | 4 | private static class Page { |
51 | |
private String title; |
52 | |
private String text; |
53 | |
} |
54 | |
|
55 | |
} |