Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit e8f895d

Browse files
SynapticloopSynapticloop
authored andcommitted
added in (en/de)code tests
1 parent d77bdcc commit e8f895d

File tree

3 files changed

+144
-9
lines changed

3 files changed

+144
-9
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ And now for the dependency
156156
<dependency>
157157
<groupId>synapticloop</groupId>
158158
<artifactId>backblaze-b2-java-api</artifactId>
159-
<version>v1.1.2</version>
159+
<version>v1.1.3</version>
160160
<type>jar</type>
161161
</dependency>
162162

@@ -179,15 +179,15 @@ Repository
179179

180180
and then include the dependency:
181181

182-
runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: 'v1.1.2', ext: 'jar')
182+
runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: 'v1.1.3', ext: 'jar')
183183

184-
compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: 'v1.1.2', ext: 'jar')
184+
compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: 'v1.1.3', ext: 'jar')
185185

186186
or, more simply for later versions of gradle
187187

188-
runtime 'synapticloop:backblaze-b2-java-api:v1.1.2'
188+
runtime 'synapticloop:backblaze-b2-java-api:v1.1.3'
189189

190-
compile 'synapticloop:backblaze-b2-java-api:v1.1.2'
190+
compile 'synapticloop:backblaze-b2-java-api:v1.1.3'
191191

192192
## Other packages
193193

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ group = 'synapticloop'
1212
archivesBaseName = 'backblaze-b2-java-api'
1313
description = """An api for backblaze b2 storage in java"""
1414

15-
version = 'v1.1.2'
15+
version = 'v1.1.3'
1616

1717
description = """backblaze-b2-java-api"""
1818

@@ -41,9 +41,11 @@ dependencies {
4141
testCompile 'junit:junit:4.7'
4242
testCompile 'org.apache.logging.log4j:log4j-slf4j-impl:2.4.1'
4343
testCompile 'org.apache.logging.log4j:log4j-core:2.4.1'
44+
testCompile 'org.json:json:20090211'
4445

4546
testRuntime 'org.apache.logging.log4j:log4j-slf4j-impl:2.4.1'
4647
testRuntime 'org.apache.logging.log4j:log4j-core:2.4.1'
48+
testRuntime 'org.json:json:20090211'
4749
}
4850

4951
configurations.all {

src/test/java/synapticloop/b2/util/HelperTest.java

Lines changed: 136 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,148 @@
22

33
import static org.junit.Assert.*;
44

5+
import org.json.JSONArray;
6+
import org.json.JSONException;
7+
import org.json.JSONObject;
58
import org.junit.Test;
69

7-
810
public class HelperTest {
11+
// this is taken from the URL https://www.backblaze.com/b2/docs/string_encoding.html
12+
13+
private static final String ENCODING_TEST_JSON = "[\n" +
14+
" {\"fullyEncoded\": \"%20\", \"minimallyEncoded\": \"+\", \"string\": \" \"},\n" +
15+
" {\"fullyEncoded\": \"%21\", \"minimallyEncoded\": \"!\", \"string\": \"!\"},\n" +
16+
" {\"fullyEncoded\": \"%22\", \"minimallyEncoded\": \"%22\", \"string\": \"\\\"\"},\n" +
17+
" {\"fullyEncoded\": \"%23\", \"minimallyEncoded\": \"%23\", \"string\": \"#\"},\n" +
18+
" {\"fullyEncoded\": \"%24\", \"minimallyEncoded\": \"$\", \"string\": \"$\"},\n" +
19+
" {\"fullyEncoded\": \"%25\", \"minimallyEncoded\": \"%25\", \"string\": \"%\"},\n" +
20+
" {\"fullyEncoded\": \"%26\", \"minimallyEncoded\": \"%26\", \"string\": \"&\"},\n" +
21+
" {\"fullyEncoded\": \"%27\", \"minimallyEncoded\": \"'\", \"string\": \"'\"},\n" +
22+
" {\"fullyEncoded\": \"%28\", \"minimallyEncoded\": \"(\", \"string\": \"(\"},\n" +
23+
" {\"fullyEncoded\": \"%29\", \"minimallyEncoded\": \")\", \"string\": \")\"},\n" +
24+
" {\"fullyEncoded\": \"%2A\", \"minimallyEncoded\": \"*\", \"string\": \"*\"},\n" +
25+
" {\"fullyEncoded\": \"%2B\", \"minimallyEncoded\": \"%2B\", \"string\": \"+\"},\n" +
26+
" {\"fullyEncoded\": \"%2C\", \"minimallyEncoded\": \"%2C\", \"string\": \",\"},\n" +
27+
" {\"fullyEncoded\": \"%2D\", \"minimallyEncoded\": \"-\", \"string\": \"-\"},\n" +
28+
" {\"fullyEncoded\": \"%2E\", \"minimallyEncoded\": \".\", \"string\": \".\"},\n" +
29+
" {\"fullyEncoded\": \"/\", \"minimallyEncoded\": \"/\", \"string\": \"/\"},\n" +
30+
" {\"fullyEncoded\": \"%30\", \"minimallyEncoded\": \"0\", \"string\": \"0\"},\n" +
31+
" {\"fullyEncoded\": \"%31\", \"minimallyEncoded\": \"1\", \"string\": \"1\"},\n" +
32+
" {\"fullyEncoded\": \"%32\", \"minimallyEncoded\": \"2\", \"string\": \"2\"},\n" +
33+
" {\"fullyEncoded\": \"%33\", \"minimallyEncoded\": \"3\", \"string\": \"3\"},\n" +
34+
" {\"fullyEncoded\": \"%34\", \"minimallyEncoded\": \"4\", \"string\": \"4\"},\n" +
35+
" {\"fullyEncoded\": \"%35\", \"minimallyEncoded\": \"5\", \"string\": \"5\"},\n" +
36+
" {\"fullyEncoded\": \"%36\", \"minimallyEncoded\": \"6\", \"string\": \"6\"},\n" +
37+
" {\"fullyEncoded\": \"%37\", \"minimallyEncoded\": \"7\", \"string\": \"7\"},\n" +
38+
" {\"fullyEncoded\": \"%38\", \"minimallyEncoded\": \"8\", \"string\": \"8\"},\n" +
39+
" {\"fullyEncoded\": \"%39\", \"minimallyEncoded\": \"9\", \"string\": \"9\"},\n" +
40+
" {\"fullyEncoded\": \"%3A\", \"minimallyEncoded\": \":\", \"string\": \":\"},\n" +
41+
" {\"fullyEncoded\": \"%3B\", \"minimallyEncoded\": \";\", \"string\": \";\"},\n" +
42+
" {\"fullyEncoded\": \"%3C\", \"minimallyEncoded\": \"%3C\", \"string\": \"<\"},\n" +
43+
" {\"fullyEncoded\": \"%3D\", \"minimallyEncoded\": \"=\", \"string\": \"=\"},\n" +
44+
" {\"fullyEncoded\": \"%3E\", \"minimallyEncoded\": \"%3E\", \"string\": \">\"},\n" +
45+
" {\"fullyEncoded\": \"%3F\", \"minimallyEncoded\": \"%3F\", \"string\": \"?\"},\n" +
46+
" {\"fullyEncoded\": \"%40\", \"minimallyEncoded\": \"@\", \"string\": \"@\"},\n" +
47+
" {\"fullyEncoded\": \"%41\", \"minimallyEncoded\": \"A\", \"string\": \"A\"},\n" +
48+
" {\"fullyEncoded\": \"%42\", \"minimallyEncoded\": \"B\", \"string\": \"B\"},\n" +
49+
" {\"fullyEncoded\": \"%43\", \"minimallyEncoded\": \"C\", \"string\": \"C\"},\n" +
50+
" {\"fullyEncoded\": \"%44\", \"minimallyEncoded\": \"D\", \"string\": \"D\"},\n" +
51+
" {\"fullyEncoded\": \"%45\", \"minimallyEncoded\": \"E\", \"string\": \"E\"},\n" +
52+
" {\"fullyEncoded\": \"%46\", \"minimallyEncoded\": \"F\", \"string\": \"F\"},\n" +
53+
" {\"fullyEncoded\": \"%47\", \"minimallyEncoded\": \"G\", \"string\": \"G\"},\n" +
54+
" {\"fullyEncoded\": \"%48\", \"minimallyEncoded\": \"H\", \"string\": \"H\"},\n" +
55+
" {\"fullyEncoded\": \"%49\", \"minimallyEncoded\": \"I\", \"string\": \"I\"},\n" +
56+
" {\"fullyEncoded\": \"%4A\", \"minimallyEncoded\": \"J\", \"string\": \"J\"},\n" +
57+
" {\"fullyEncoded\": \"%4B\", \"minimallyEncoded\": \"K\", \"string\": \"K\"},\n" +
58+
" {\"fullyEncoded\": \"%4C\", \"minimallyEncoded\": \"L\", \"string\": \"L\"},\n" +
59+
" {\"fullyEncoded\": \"%4D\", \"minimallyEncoded\": \"M\", \"string\": \"M\"},\n" +
60+
" {\"fullyEncoded\": \"%4E\", \"minimallyEncoded\": \"N\", \"string\": \"N\"},\n" +
61+
" {\"fullyEncoded\": \"%4F\", \"minimallyEncoded\": \"O\", \"string\": \"O\"},\n" +
62+
" {\"fullyEncoded\": \"%50\", \"minimallyEncoded\": \"P\", \"string\": \"P\"},\n" +
63+
" {\"fullyEncoded\": \"%51\", \"minimallyEncoded\": \"Q\", \"string\": \"Q\"},\n" +
64+
" {\"fullyEncoded\": \"%52\", \"minimallyEncoded\": \"R\", \"string\": \"R\"},\n" +
65+
" {\"fullyEncoded\": \"%53\", \"minimallyEncoded\": \"S\", \"string\": \"S\"},\n" +
66+
" {\"fullyEncoded\": \"%54\", \"minimallyEncoded\": \"T\", \"string\": \"T\"},\n" +
67+
" {\"fullyEncoded\": \"%55\", \"minimallyEncoded\": \"U\", \"string\": \"U\"},\n" +
68+
" {\"fullyEncoded\": \"%56\", \"minimallyEncoded\": \"V\", \"string\": \"V\"},\n" +
69+
" {\"fullyEncoded\": \"%57\", \"minimallyEncoded\": \"W\", \"string\": \"W\"},\n" +
70+
" {\"fullyEncoded\": \"%58\", \"minimallyEncoded\": \"X\", \"string\": \"X\"},\n" +
71+
" {\"fullyEncoded\": \"%59\", \"minimallyEncoded\": \"Y\", \"string\": \"Y\"},\n" +
72+
" {\"fullyEncoded\": \"%5A\", \"minimallyEncoded\": \"Z\", \"string\": \"Z\"},\n" +
73+
" {\"fullyEncoded\": \"%5B\", \"minimallyEncoded\": \"%5B\", \"string\": \"[\"},\n" +
74+
" {\"fullyEncoded\": \"%5C\", \"minimallyEncoded\": \"%5C\", \"string\": \"\\\\\"},\n" +
75+
" {\"fullyEncoded\": \"%5D\", \"minimallyEncoded\": \"%5D\", \"string\": \"]\"},\n" +
76+
" {\"fullyEncoded\": \"%5E\", \"minimallyEncoded\": \"%5E\", \"string\": \"^\"},\n" +
77+
" {\"fullyEncoded\": \"%5F\", \"minimallyEncoded\": \"_\", \"string\": \"_\"},\n" +
78+
" {\"fullyEncoded\": \"%60\", \"minimallyEncoded\": \"%60\", \"string\": \"`\"},\n" +
79+
" {\"fullyEncoded\": \"%61\", \"minimallyEncoded\": \"a\", \"string\": \"a\"},\n" +
80+
" {\"fullyEncoded\": \"%62\", \"minimallyEncoded\": \"b\", \"string\": \"b\"},\n" +
81+
" {\"fullyEncoded\": \"%63\", \"minimallyEncoded\": \"c\", \"string\": \"c\"},\n" +
82+
" {\"fullyEncoded\": \"%64\", \"minimallyEncoded\": \"d\", \"string\": \"d\"},\n" +
83+
" {\"fullyEncoded\": \"%65\", \"minimallyEncoded\": \"e\", \"string\": \"e\"},\n" +
84+
" {\"fullyEncoded\": \"%66\", \"minimallyEncoded\": \"f\", \"string\": \"f\"},\n" +
85+
" {\"fullyEncoded\": \"%67\", \"minimallyEncoded\": \"g\", \"string\": \"g\"},\n" +
86+
" {\"fullyEncoded\": \"%68\", \"minimallyEncoded\": \"h\", \"string\": \"h\"},\n" +
87+
" {\"fullyEncoded\": \"%69\", \"minimallyEncoded\": \"i\", \"string\": \"i\"},\n" +
88+
" {\"fullyEncoded\": \"%6A\", \"minimallyEncoded\": \"j\", \"string\": \"j\"},\n" +
89+
" {\"fullyEncoded\": \"%6B\", \"minimallyEncoded\": \"k\", \"string\": \"k\"},\n" +
90+
" {\"fullyEncoded\": \"%6C\", \"minimallyEncoded\": \"l\", \"string\": \"l\"},\n" +
91+
" {\"fullyEncoded\": \"%6D\", \"minimallyEncoded\": \"m\", \"string\": \"m\"},\n" +
92+
" {\"fullyEncoded\": \"%6E\", \"minimallyEncoded\": \"n\", \"string\": \"n\"},\n" +
93+
" {\"fullyEncoded\": \"%6F\", \"minimallyEncoded\": \"o\", \"string\": \"o\"},\n" +
94+
" {\"fullyEncoded\": \"%70\", \"minimallyEncoded\": \"p\", \"string\": \"p\"},\n" +
95+
" {\"fullyEncoded\": \"%71\", \"minimallyEncoded\": \"q\", \"string\": \"q\"},\n" +
96+
" {\"fullyEncoded\": \"%72\", \"minimallyEncoded\": \"r\", \"string\": \"r\"},\n" +
97+
" {\"fullyEncoded\": \"%73\", \"minimallyEncoded\": \"s\", \"string\": \"s\"},\n" +
98+
" {\"fullyEncoded\": \"%74\", \"minimallyEncoded\": \"t\", \"string\": \"t\"},\n" +
99+
" {\"fullyEncoded\": \"%75\", \"minimallyEncoded\": \"u\", \"string\": \"u\"},\n" +
100+
" {\"fullyEncoded\": \"%76\", \"minimallyEncoded\": \"v\", \"string\": \"v\"},\n" +
101+
" {\"fullyEncoded\": \"%77\", \"minimallyEncoded\": \"w\", \"string\": \"w\"},\n" +
102+
" {\"fullyEncoded\": \"%78\", \"minimallyEncoded\": \"x\", \"string\": \"x\"},\n" +
103+
" {\"fullyEncoded\": \"%79\", \"minimallyEncoded\": \"y\", \"string\": \"y\"},\n" +
104+
" {\"fullyEncoded\": \"%7A\", \"minimallyEncoded\": \"z\", \"string\": \"z\"},\n" +
105+
" {\"fullyEncoded\": \"%7B\", \"minimallyEncoded\": \"%7B\", \"string\": \"{\"},\n" +
106+
" {\"fullyEncoded\": \"%7C\", \"minimallyEncoded\": \"%7C\", \"string\": \"|\"},\n" +
107+
" {\"fullyEncoded\": \"%7D\", \"minimallyEncoded\": \"%7D\", \"string\": \"}\"},\n" +
108+
" {\"fullyEncoded\": \"%7E\", \"minimallyEncoded\": \"~\", \"string\": \"~\"},\n" +
109+
" {\"fullyEncoded\": \"%7F\", \"minimallyEncoded\": \"%7F\", \"string\": \"\\u007f\"},\n" +
110+
" {\"fullyEncoded\": \"%E8%87%AA%E7%94%B1\", \"minimallyEncoded\": \"%E8%87%AA%E7%94%B1\", \"string\": \"\\u81ea\\u7531\"},\n" +
111+
" {\"fullyEncoded\": \"%F0%90%90%80\", \"minimallyEncoded\": \"%F0%90%90%80\", \"string\": \"\\ud801\\udc00\"}\n" +
112+
"]";
9113

10114
@Test
11-
public void testEncoding() {
115+
public void testEncoding() throws JSONException {
12116
Helper.urlEncode("");
13-
assertNull(null);
117+
JSONArray jsonArray = new JSONArray(ENCODING_TEST_JSON);
118+
int length = jsonArray.length();
119+
for(int i = 0; i< length; i++) {
120+
JSONObject jsonObject = jsonArray.getJSONObject(i);
121+
122+
String fullyEncoded = jsonObject.getString("fullyEncoded");
123+
String minimallyEncoded = jsonObject.getString("minimallyEncoded");
124+
String string = jsonObject.getString("string");
125+
126+
// assert encoding
127+
String urlEncode = Helper.urlEncode(string);
128+
if(!(minimallyEncoded.equals(urlEncode) || fullyEncoded.equals(urlEncode))) {
129+
assertTrue("Invalid encoding, could not encode '" +
130+
string +
131+
"' to either '" +
132+
minimallyEncoded +
133+
"' or '" +
134+
fullyEncoded +
135+
"'. The encoded output was '" +
136+
"'" +
137+
urlEncode +
138+
"'.",
139+
false);
140+
}
141+
142+
// assert decoding
143+
assertEquals(string, Helper.urlDecode(fullyEncoded));
144+
assertEquals(string, Helper.urlDecode(minimallyEncoded));
145+
146+
}
14147
}
15148

16149
}

0 commit comments

Comments
 (0)