Skip to content

Commit 26acba7

Browse files
committed
Merge remote-tracking branch 'remotes/upstream/master' into issue-10
Conflicts: src/test/java/com/softlayer/api/RestApiClientTest.java
2 parents 1dab059 + 8bd202d commit 26acba7

4 files changed

Lines changed: 32 additions & 5 deletions

File tree

gen/src/main/java/com/softlayer/api/gen/ClassWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ public ClassWriter emitServiceMethod(TypeClass.Property property, boolean async)
324324

325325
// Instance is only required if it's not an account property
326326
if ("SoftLayer_Account".equals(type.meta.name)) {
327-
emitAnnotation(TYPE_API_METHOD);
327+
emitAnnotation(TYPE_API_METHOD);
328328
} else {
329-
emitAnnotationWithAttrs(TYPE_API_METHOD, "instanceRequired", true);
329+
emitAnnotationWithAttrs(TYPE_API_METHOD, "instanceRequired", true);
330330
}
331331
} else {
332332
// Otherwise, just a javadoc link

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,25 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
466466
return invokeService(method, args);
467467
} else if (ServiceAsync.class.isAssignableFrom(method.getDeclaringClass())) {
468468
return invokeServiceAsync(method, args);
469+
} else if (method.getDeclaringClass() == Object.class) {
470+
return method.invoke(this, args);
469471
} else {
470472
// Should not be possible
471473
throw new RuntimeException("Unrecognized method: " + method);
472474
}
473475
}
476+
477+
@Override
478+
public boolean equals(Object obj) {
479+
return Proxy.isProxyClass(obj.getClass()) && obj.hashCode() == hashCode();
480+
}
481+
482+
@Override
483+
public String toString() {
484+
if (id == null) {
485+
return "Service: " + serviceClass.getAnnotation(ApiService.class).value();
486+
}
487+
return "Service: " + serviceClass.getAnnotation(ApiService.class).value() + " with ID " + id;
488+
}
474489
}
475490
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.io.ByteArrayOutputStream;
66
import java.io.PrintStream;
7+
import java.lang.reflect.Proxy;
78
import java.net.URLEncoder;
89
import java.util.Collections;
910
import java.util.GregorianCalendar;
@@ -428,7 +429,7 @@ public void onSuccess(String value) {
428429
assertTrue(http.invokeAsyncCallbackCalled);
429430
assertTrue(successCalled.get());
430431
}
431-
432+
432433
@Test(expected = IllegalArgumentException.class)
433434
public void testMaskMustNotBeNull() {
434435
RestApiClient client = new RestApiClient("http://example.com/");
@@ -445,4 +446,15 @@ public void testMaskRemoval() {
445446
service.clearMask();
446447
assertEquals("", service.withMask().toString());
447448
}
449+
450+
@Test
451+
public void testNormalObjectMethodsOnService() {
452+
RestApiClient client = new RestApiClient("http://example.com/");
453+
TestEntity.Service service = TestEntity.service(client);
454+
assertEquals("Service: SoftLayer_TestEntity", service.toString());
455+
assertEquals("Service: SoftLayer_TestEntity with ID 5", TestEntity.service(client, 5L).toString());
456+
assertTrue(Proxy.isProxyClass(service.getClass()));
457+
assertEquals(service.hashCode(), service.hashCode());
458+
assertTrue(service.equals(service));
459+
}
448460
}

src/test/java/com/softlayer/api/json/GsonJsonMarshallerFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public void testWrite() throws Exception {
105105
expected.put("baz", null);
106106
int offsetMinutes = TimeZone.getDefault().getOffset(obj.getDate().getTimeInMillis()) / 60000;
107107
String expectedTimeZone =
108-
(offsetMinutes < 0 ? '-' : '+') +
109-
String.format("%1$02d:%2$02d", Math.abs(offsetMinutes / 60), Math.abs(offsetMinutes % 60));
108+
(offsetMinutes < 0 ? '-' : '+') +
109+
String.format("%1$02d:%2$02d", Math.abs(offsetMinutes / 60), Math.abs(offsetMinutes % 60));
110110
expected.put("date", "1984-02-25T20:15:25" + expectedTimeZone);
111111
Map<String, Object> childMap = new HashMap<String, Object>();
112112
childMap.put("complexType", "SoftLayer_TestEntity");

0 commit comments

Comments
 (0)