Skip to content

Commit 21494f7

Browse files
fixed some unit tests
1 parent 1e6ea34 commit 21494f7

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

src/main/java/com/softlayer/api/RestApiClient.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,10 @@ class ServiceProxy<S extends Service> implements InvocationHandler {
225225

226226
final Class<S> serviceClass;
227227
final String id;
228-
public Mask mask;
228+
Mask mask;
229229
String maskString;
230230
ResultLimit resultLimit;
231231
Integer lastResponseTotalItemCount;
232-
233232

234233
public ServiceProxy(Class<S> serviceClass, String id) {
235234
this.serviceClass = serviceClass;
@@ -305,7 +304,6 @@ public Object logAndHandleResponse(HttpResponse response, String url,
305304
}
306305

307306
public Object invokeService(Method method, final Object[] args) throws Throwable {
308-
309307
ApiMethod methodInfo = method.getAnnotation(ApiMethod.class);
310308
// Must have ID if instance is required
311309
if (methodInfo.instanceRequired() && id == null) {
@@ -442,6 +440,7 @@ public boolean isDone() {
442440
@Override
443441
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
444442
boolean noParams = args == null || args.length == 0;
443+
445444
if ("asAsync".equals(method.getName()) && noParams) {
446445
ServiceProxy<S> asyncProxy = new ServiceProxy<>(serviceClass, id);
447446
asyncProxy.mask = mask;

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ public void testSetStringMask() {
9090

9191
@Test(expected = IllegalArgumentException.class)
9292
public void testMaskMustNotBeNull() {
93-
RestApiClient client = new RestApiClient("http://example.com/");
93+
RestApiClient client = new TestApiClient("http://example.com/");
9494
TestEntity.Service service = TestEntity.service(client);
9595
service.setMask((Mask) null);
9696
}
9797

9898
@Test
9999
public void testMaskRemoval() {
100-
RestApiClient client = new RestApiClient("http://example.com/");
100+
RestApiClient client = new TestApiClient("http://example.com/");
101101
TestEntity.Service service = TestEntity.service(client);
102102
service.withMask().baz();
103103
assertEquals("baz", service.withMask().toString());
@@ -107,7 +107,7 @@ public void testMaskRemoval() {
107107

108108
@Test
109109
public void testRecursiveMaskAndLocal() {
110-
RestApiClient client = new RestApiClient("http://example.com/");
110+
RestApiClient client = new TestApiClient("http://example.com/");
111111
TestEntity.Service service = TestEntity.service(client);
112112
service.withMask().recursiveProperty().recursiveProperty().baz();
113113
service.withMask().recursiveProperty().recursiveProperty().foo();
@@ -118,7 +118,7 @@ public void testRecursiveMaskAndLocal() {
118118

119119
@Test
120120
public void testRecursiveMask() {
121-
RestApiClient client = new RestApiClient("http://example.com/");
121+
RestApiClient client = new TestApiClient("http://example.com/");
122122
TestEntity.Service service = TestEntity.service(client);
123123
service.withMask().recursiveProperty().baz();
124124
service.withMask().recursiveProperty().foo();
@@ -130,7 +130,7 @@ public void testRecursiveMask() {
130130

131131
@Test
132132
public void testMultiLevelMask() {
133-
RestApiClient client = new RestApiClient("http://example.com/");
133+
RestApiClient client = new TestApiClient("http://example.com/");
134134
TestEntity.Service service = TestEntity.service(client);
135135
service.withMask().recursiveProperty().baz();
136136
service.withMask().recursiveProperty().foo();
@@ -149,12 +149,13 @@ public void testNoChangeMaskScope() {
149149

150150
TestApiClient client = new TestApiClient("http://example.com/");
151151

152-
client.setLoggingEnabled(true);
152+
// client.setLoggingEnabled(true);
153153

154154
TestEntity.Service service = TestEntity.service(client);
155155
service.withMask().testThing().id();
156156
service.withMask().testThing().first();
157157

158+
158159
TestEntity result = service.getObject();
159160
assertEquals("testThing[id,first]", service.withMask().toString());
160161
String expected = "http://example.com/SoftLayer_TestEntity.json?objectMask=mask%5BtestThing%5Bid%2Cfirst%5D%5D";
@@ -165,20 +166,17 @@ public void testNoChangeMaskScope() {
165166

166167
@Test
167168
public void testChangeMaskScope() {
169+
// https://github.com/softlayer/softlayer-java/issues/19
170+
168171
TestApiClient client = new TestApiClient("http://example.com/");
169-
client.setLoggingEnabled(true);
172+
// client.setLoggingEnabled(true);
170173

171174
TestEntity.Service service = TestEntity.service(client);
172175
service.withMask().recursiveProperty().baz();
173176
service.withMask().recursiveProperty().foo();
174177

175178
String result = service.getRecursiveProperty();
176-
System.out.print(result);
177-
// RestApiClient.ServiceProxy serviceProxy = client.createService(TestEntity, 1234);
178-
// serviceProxy.invoke(service, service.getRecursiveProperty(),null);
179-
// assertEquals("http://example.com/SomeService/1234/someMethod.json?objectMask=someMask%26%26",
180-
// client.ServiceProxy.
181-
// )
179+
// assertEquals("baz,foo", service.withMask());
182180
}
183181
}
184182

src/test/java/com/softlayer/api/http/FakeHttpClientFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ public OutputStream getBodyStream() {
8181
@Override
8282
public HttpResponse invokeSync(Callable<?> setupBody) {
8383
invokeSyncCalled = true;
84-
// try {
85-
// setupBody.call();
86-
// } catch (Exception e) {
87-
// throw new RuntimeException(e);
88-
// }
84+
try {
85+
setupBody.call();
86+
} catch (Exception e) {
87+
throw new RuntimeException(e);
88+
}
8989
return this;
9090
}
9191

src/test/java/com/softlayer/api/service/TestEntity.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,6 @@ public Void doSomethingNonStatic(GregorianCalendar param1) {
278278

279279
@Override
280280
public String getRecursiveProperty() {
281-
System.out.print("getRecursiveProperty\n");
282-
System.out.print("MASK: " + withMask().toString() +"\n");
283-
284281
return "Hello World";
285282
}
286283

0 commit comments

Comments
 (0)