Skip to content

Commit 18ff779

Browse files
Splitting out Mask tests to a new file.
1 parent be56b0d commit 18ff779

File tree

2 files changed

+109
-77
lines changed

2 files changed

+109
-77
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.softlayer.api;
2+
3+
import static org.junit.Assert.*;
4+
5+
6+
import java.io.ByteArrayOutputStream;
7+
import java.io.PrintStream;
8+
import java.lang.reflect.Proxy;
9+
import java.net.URLEncoder;
10+
import java.util.Collections;
11+
import java.util.GregorianCalendar;
12+
import java.util.List;
13+
import java.util.concurrent.Callable;
14+
import java.util.concurrent.ExecutionException;
15+
import java.util.concurrent.atomic.AtomicBoolean;
16+
17+
import org.junit.Test;
18+
19+
import com.softlayer.api.http.FakeHttpClientFactory;
20+
import com.softlayer.api.http.HttpBasicAuthCredentials;
21+
import com.softlayer.api.json.GsonJsonMarshallerFactoryTest;
22+
import com.softlayer.api.service.TestEntity;
23+
24+
25+
26+
public class MaskTest {
27+
static {
28+
GsonJsonMarshallerFactoryTest.addTestEntityToGson();
29+
}
30+
@Test
31+
public void testWithMask() throws Exception {
32+
FakeHttpClientFactory http = new FakeHttpClientFactory(200,
33+
Collections.emptyMap(), "\"some response\"");
34+
RestApiClient client = new RestApiClient("http://example.com/")
35+
.withCredentials("user", "key");
36+
client.setHttpClientFactory(http);
37+
38+
TestEntity entity = new TestEntity();
39+
entity.setFoo("blah");
40+
TestEntity.Service service = TestEntity.service(client);
41+
service.withMask().foo().child().date();
42+
service.withMask().child().baz();
43+
44+
assertEquals("some response", service.doSomethingStatic(123L, entity));
45+
assertEquals("http://example.com/SoftLayer_TestEntity/doSomethingStatic.json"
46+
+ "?objectMask=" + URLEncoder.encode(service.withMask().getMask(), "UTF-8"), http.fullUrl);
47+
assertTrue(http.invokeSyncCalled);
48+
}
49+
50+
@Test
51+
public void testSetObjectMask() throws Exception {
52+
FakeHttpClientFactory http = new FakeHttpClientFactory(200,
53+
Collections.emptyMap(), "\"some response\"");
54+
RestApiClient client = new RestApiClient("http://example.com/")
55+
.withCredentials("user", "key");
56+
client.setHttpClientFactory(http);
57+
58+
TestEntity entity = new TestEntity();
59+
entity.setFoo("blah");
60+
TestEntity.Service service = TestEntity.service(client);
61+
TestEntity.Mask mask = new TestEntity.Mask();
62+
mask.foo().child().date();
63+
mask.child().baz();
64+
service.setMask(mask);
65+
66+
assertEquals("some response", service.doSomethingStatic(123L, entity));
67+
assertEquals("http://example.com/SoftLayer_TestEntity/doSomethingStatic.json"
68+
+ "?objectMask=" + URLEncoder.encode(mask.getMask(), "UTF-8"), http.fullUrl);
69+
assertTrue(http.invokeSyncCalled);
70+
}
71+
72+
@Test
73+
public void testSetStringMask() throws Exception {
74+
FakeHttpClientFactory http = new FakeHttpClientFactory(200,
75+
Collections.emptyMap(), "\"some response\"");
76+
RestApiClient client = new RestApiClient("http://example.com/")
77+
.withCredentials("user", "key");
78+
client.setHttpClientFactory(http);
79+
80+
TestEntity entity = new TestEntity();
81+
entity.setFoo("blah");
82+
TestEntity.Service service = TestEntity.service(client);
83+
service.setMask("yay-a-mask");
84+
85+
assertEquals("some response", service.doSomethingStatic(123L, entity));
86+
assertEquals("http://example.com/SoftLayer_TestEntity/doSomethingStatic.json"
87+
+ "?objectMask=yay-a-mask", http.fullUrl);
88+
assertTrue(http.invokeSyncCalled);
89+
}
90+
91+
@Test(expected = IllegalArgumentException.class)
92+
public void testMaskMustNotBeNull() {
93+
RestApiClient client = new RestApiClient("http://example.com/");
94+
TestEntity.Service service = TestEntity.service(client);
95+
service.setMask((Mask) null);
96+
}
97+
98+
@Test
99+
public void testMaskRemoval() {
100+
RestApiClient client = new RestApiClient("http://example.com/");
101+
TestEntity.Service service = TestEntity.service(client);
102+
service.withMask().baz();
103+
assertEquals("baz", service.withMask().toString());
104+
service.clearMask();
105+
assertEquals("", service.withMask().toString());
106+
}
107+
}
108+

src/test/java/com/softlayer/api/RestApiClientTest.java

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -313,68 +313,7 @@ public void testDifferentMethodName() throws Exception {
313313
assertEquals(RestApiClient.HEADERS, http.headers);
314314
assertTrue(http.invokeSyncCalled);
315315
}
316-
317-
@Test
318-
public void testWithMask() throws Exception {
319-
FakeHttpClientFactory http = new FakeHttpClientFactory(200,
320-
Collections.emptyMap(), "\"some response\"");
321-
RestApiClient client = new RestApiClient("http://example.com/")
322-
.withCredentials("user", "key");
323-
client.setHttpClientFactory(http);
324316

325-
TestEntity entity = new TestEntity();
326-
entity.setFoo("blah");
327-
TestEntity.Service service = TestEntity.service(client);
328-
service.withMask().foo().child().date();
329-
service.withMask().child().baz();
330-
331-
assertEquals("some response", service.doSomethingStatic(123L, entity));
332-
assertEquals("http://example.com/SoftLayer_TestEntity/doSomethingStatic.json"
333-
+ "?objectMask=" + URLEncoder.encode(service.withMask().getMask(), "UTF-8"), http.fullUrl);
334-
assertTrue(http.invokeSyncCalled);
335-
}
336-
337-
@Test
338-
public void testSetObjectMask() throws Exception {
339-
FakeHttpClientFactory http = new FakeHttpClientFactory(200,
340-
Collections.emptyMap(), "\"some response\"");
341-
RestApiClient client = new RestApiClient("http://example.com/")
342-
.withCredentials("user", "key");
343-
client.setHttpClientFactory(http);
344-
345-
TestEntity entity = new TestEntity();
346-
entity.setFoo("blah");
347-
TestEntity.Service service = TestEntity.service(client);
348-
TestEntity.Mask mask = new TestEntity.Mask();
349-
mask.foo().child().date();
350-
mask.child().baz();
351-
service.setMask(mask);
352-
353-
assertEquals("some response", service.doSomethingStatic(123L, entity));
354-
assertEquals("http://example.com/SoftLayer_TestEntity/doSomethingStatic.json"
355-
+ "?objectMask=" + URLEncoder.encode(mask.getMask(), "UTF-8"), http.fullUrl);
356-
assertTrue(http.invokeSyncCalled);
357-
}
358-
359-
@Test
360-
public void testSetStringMask() throws Exception {
361-
FakeHttpClientFactory http = new FakeHttpClientFactory(200,
362-
Collections.emptyMap(), "\"some response\"");
363-
RestApiClient client = new RestApiClient("http://example.com/")
364-
.withCredentials("user", "key");
365-
client.setHttpClientFactory(http);
366-
367-
TestEntity entity = new TestEntity();
368-
entity.setFoo("blah");
369-
TestEntity.Service service = TestEntity.service(client);
370-
service.setMask("yay-a-mask");
371-
372-
assertEquals("some response", service.doSomethingStatic(123L, entity));
373-
assertEquals("http://example.com/SoftLayer_TestEntity/doSomethingStatic.json"
374-
+ "?objectMask=yay-a-mask", http.fullUrl);
375-
assertTrue(http.invokeSyncCalled);
376-
}
377-
378317
@Test
379318
public void testWithResultLimit() throws Exception {
380319
FakeHttpClientFactory http = new FakeHttpClientFactory(200,
@@ -461,22 +400,7 @@ public void onSuccess(String value) {
461400
assertTrue(successCalled.get());
462401
}
463402

464-
@Test(expected = IllegalArgumentException.class)
465-
public void testMaskMustNotBeNull() {
466-
RestApiClient client = new RestApiClient("http://example.com/");
467-
TestEntity.Service service = TestEntity.service(client);
468-
service.setMask((Mask) null);
469-
}
470-
471-
@Test
472-
public void testMaskRemoval() {
473-
RestApiClient client = new RestApiClient("http://example.com/");
474-
TestEntity.Service service = TestEntity.service(client);
475-
service.withMask().baz();
476-
assertEquals("baz", service.withMask().toString());
477-
service.clearMask();
478-
assertEquals("", service.withMask().toString());
479-
}
403+
480404

481405
@Test
482406
public void testNormalObjectMethodsOnService() {

0 commit comments

Comments
 (0)