Commit 5f7a1c14 authored by George Nash's avatar George Nash

Remove Java stringToEndpoint two parameter variant

With oc_endpoint_string_parse_path exposed to java there is
no longer a need to have the two parameter variant of the
stringToEndpoint method that uses an array to return input
parameters which is really unusual in Java.
Signed-off-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
parent 544ada95
Pipeline #779 passed with stage
in 6 minutes and 53 seconds
......@@ -7,7 +7,7 @@ import org.junit.Test;
public class OCEndpointTest {
@Test
public void testStringToEndpoint_1_param_version() {
public void testStringToEndpoint() {
// IPV4 with port and uri
OCEndpoint ep = null;
try {
......@@ -82,83 +82,7 @@ public class OCEndpointTest {
}
@Test
public void testStringToEndpoint_2_param_version() {
String[] uri = new String[1];
// IPV4 with port and uri
OCEndpoint ep = null;
try {
ep = OCEndpointUtil.stringToEndpoint("coaps://10.211.55.3:56789/a/light", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertEquals(OCTransportFlags.IPV4, ep.getFlags() & OCTransportFlags.IPV4);
assertEquals(OCTransportFlags.SECURED, ep.getFlags() & OCTransportFlags.SECURED);
assertNotEquals(OCTransportFlags.TCP, ep.getFlags() & OCTransportFlags.TCP);
assertEquals(56789, ep.getAddr().getIpv4().getPort());
assertEquals("/a/light", uri[0]);
assertArrayEquals(new short[]{10, 211, 55, 3}, ep.getAddr().getIpv4().getAddress());
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
// IPV6
try {
ep = OCEndpointUtil.stringToEndpoint("coap://[ff02::158]", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertEquals(OCTransportFlags.IPV6, (ep.getFlags() & OCTransportFlags.IPV6));
assertNotEquals(OCTransportFlags.SECURED, (ep.getFlags() & OCTransportFlags.SECURED));
assertNotEquals(OCTransportFlags.TCP, (ep.getFlags() & OCTransportFlags.TCP));
assertEquals(5683, ep.getAddr().getIpv6().getPort());
assertNull(uri[0]);
assertArrayEquals(new short[]{0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0x58},
ep.getAddr().getIpv6().getAddress());
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
// IPV6 with uri
try {
ep = OCEndpointUtil.stringToEndpoint("coaps://[ff02::158]/a/light", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertEquals(OCTransportFlags.IPV6, (ep.getFlags() & OCTransportFlags.IPV6));
assertEquals(OCTransportFlags.SECURED, (ep.getFlags() & OCTransportFlags.SECURED));
assertNotEquals(OCTransportFlags.TCP, (ep.getFlags() & OCTransportFlags.TCP));
assertEquals(5684, ep.getAddr().getIpv6().getPort());
assertEquals("/a/light", uri[0]);
assertArrayEquals(new short[]{0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0x58},
ep.getAddr().getIpv6().getAddress());
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
// IPV6 with port and uri
try {
ep = OCEndpointUtil.stringToEndpoint("coaps://[fe80::12]:2439/a/light", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertEquals(OCTransportFlags.IPV6, (ep.getFlags() & OCTransportFlags.IPV6));
assertEquals(OCTransportFlags.SECURED, (ep.getFlags() & OCTransportFlags.SECURED));
assertNotEquals(OCTransportFlags.TCP, (ep.getFlags() & OCTransportFlags.TCP));
assertEquals(2439, ep.getAddr().getIpv6().getPort());
assertEquals("/a/light", uri[0]);
assertArrayEquals(new short[]{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x12},
ep.getAddr().getIpv6().getAddress());
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
}
@Test
public void testStringToEndpoint_dns_lookup_1_param_version() {
public void testStringToEndpoint_dns_lookup() {
// dns lookup
OCEndpoint ep = null;
try {
......@@ -213,63 +137,7 @@ public class OCEndpointTest {
}
@Test
public void testStringToEndpoint_dns_lookup_2_param_version() {
String[] uri = new String[1];
// dns lookup
OCEndpoint ep = null;
try {
ep = OCEndpointUtil.stringToEndpoint("coap://openconnectivity.org", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertTrue(OCTransportFlags.IPV4 == (ep.getFlags() & OCTransportFlags.IPV4) ||
OCTransportFlags.IPV6 == (ep.getFlags() & OCTransportFlags.IPV6));
assertNotEquals(OCTransportFlags.SECURED, ep.getFlags() & OCTransportFlags.SECURED);
assertNotEquals(OCTransportFlags.TCP, ep.getFlags() & OCTransportFlags.TCP);
assertEquals(5683, ep.getAddr().getIpv4().getPort());
assertNull(uri[0]);
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
// dns lookup with uri
try {
ep = OCEndpointUtil.stringToEndpoint("coap://openconnectivity.org/alpha", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertTrue(OCTransportFlags.IPV4 == (ep.getFlags() & OCTransportFlags.IPV4) ||
OCTransportFlags.IPV6 == (ep.getFlags() & OCTransportFlags.IPV6));
assertNotEquals(OCTransportFlags.SECURED, ep.getFlags() & OCTransportFlags.SECURED);
assertNotEquals(OCTransportFlags.TCP, ep.getFlags() & OCTransportFlags.TCP);
assertEquals(5683, ep.getAddr().getIpv4().getPort());
assertEquals("/alpha", uri[0]);
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
// dns lookup with port and uri
try {
ep = OCEndpointUtil.stringToEndpoint("coaps://openconnectivity.org:3456/alpha", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertTrue(OCTransportFlags.IPV4 == (ep.getFlags() & OCTransportFlags.IPV4) ||
OCTransportFlags.IPV6 == (ep.getFlags() & OCTransportFlags.IPV6));
assertEquals(OCTransportFlags.SECURED, ep.getFlags() & OCTransportFlags.SECURED);
assertNotEquals(OCTransportFlags.TCP, ep.getFlags() & OCTransportFlags.TCP);
assertEquals(3456, ep.getAddr().getIpv4().getPort());
assertEquals("/alpha", uri[0]);
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
}
@Test
public void testStringToEndpoint_tcp_1_param_version() {
public void testStringToEndpoint_tcp() {
// IPv4 over tcp and uri
OCEndpoint ep = null;
try {
......@@ -361,100 +229,7 @@ public class OCEndpointTest {
}
@Test
public void testStringToEndpoint_tcp_2_param_version() {
String[] uri = new String[1];
// IPv4 over tcp and uri
OCEndpoint ep = null;
try {
ep = OCEndpointUtil.stringToEndpoint("coaps+tcp://10.211.55.3/a/light", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertEquals(OCTransportFlags.IPV4, ep.getFlags() & OCTransportFlags.IPV4);
assertEquals(OCTransportFlags.SECURED, ep.getFlags() & OCTransportFlags.SECURED);
assertEquals(OCTransportFlags.TCP, ep.getFlags() & OCTransportFlags.TCP);
assertEquals(5684, ep.getAddr().getIpv4().getPort());
assertEquals("/a/light", uri[0]);
assertArrayEquals(new short[]{10, 211, 55, 3}, ep.getAddr().getIpv4().getAddress());
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
// IPv4 over tcp and port
try {
ep = OCEndpointUtil.stringToEndpoint("coap+tcp://1.2.3.4:2568", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertEquals(OCTransportFlags.IPV4, (ep.getFlags() & OCTransportFlags.IPV4));
assertNotEquals(OCTransportFlags.SECURED, (ep.getFlags() & OCTransportFlags.SECURED));
assertEquals(OCTransportFlags.TCP, (ep.getFlags() & OCTransportFlags.TCP));
assertEquals(2568, ep.getAddr().getIpv4().getPort());
assertNull(uri[0]);
assertArrayEquals(new short[]{1, 2, 3, 4}, ep.getAddr().getIpv4().getAddress());
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
// IPv6 over tcp
try {
ep = OCEndpointUtil.stringToEndpoint("coap+tcp://[ff02::158]", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertEquals(OCTransportFlags.IPV6, (ep.getFlags() & OCTransportFlags.IPV6));
assertNotEquals(OCTransportFlags.SECURED, (ep.getFlags() & OCTransportFlags.SECURED));
assertEquals(OCTransportFlags.TCP, (ep.getFlags() & OCTransportFlags.TCP));
assertEquals(5683, ep.getAddr().getIpv6().getPort());
assertNull(uri[0]);
assertArrayEquals(new short[]{0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0x58},
ep.getAddr().getIpv6().getAddress());
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
// IPv6 over tcp with uri
try {
ep = OCEndpointUtil.stringToEndpoint("coaps+tcp://[ff02::158]/a/light", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertEquals(OCTransportFlags.IPV6, (ep.getFlags() & OCTransportFlags.IPV6));
assertEquals(OCTransportFlags.SECURED, (ep.getFlags() & OCTransportFlags.SECURED));
assertEquals(OCTransportFlags.TCP, (ep.getFlags() & OCTransportFlags.TCP));
assertEquals(5684, ep.getAddr().getIpv6().getPort());
assertEquals("/a/light", uri[0]);
assertArrayEquals(new short[]{0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0x58},
ep.getAddr().getIpv6().getAddress());
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
// IPv6 over tcp with port and uri
try {
ep = OCEndpointUtil.stringToEndpoint("coaps+tcp://[fe80::12]:2439/a/light", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertEquals(OCTransportFlags.IPV6, (ep.getFlags() & OCTransportFlags.IPV6));
assertEquals(OCTransportFlags.SECURED, (ep.getFlags() & OCTransportFlags.SECURED));
assertEquals(OCTransportFlags.TCP, (ep.getFlags() & OCTransportFlags.TCP));
assertEquals(2439, ep.getAddr().getIpv6().getPort());
assertEquals("/a/light", uri[0]);
assertArrayEquals(new short[]{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x12},
ep.getAddr().getIpv6().getAddress());
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
}
@Test
public void testStringToEndpoint_tcp_and_dns_lookup_1_param_version() {
public void testStringToEndpoint_tcp_and_dns_lookup() {
// dns lookup over tcp with port
OCEndpoint ep = null;
try {
......@@ -474,28 +249,6 @@ public class OCEndpointTest {
assertEquals(0, OCEndpoint.getCPtr(ep));
}
@Test
public void testStringToEndpoint_tcp_and_dns_lookup_2_param_version() {
String[] uri = new String[1];
// dns lookup over tcp with port
OCEndpoint ep = null;
try {
ep = OCEndpointUtil.stringToEndpoint("coaps+tcp://openconnectivity.org:3456", uri);
} catch (OCEndpointParseException e) {
e.printStackTrace();
fail("stringToEndpoint threw exception when it was not expected.");
}
assertNotNull(ep);
assertTrue(OCTransportFlags.IPV4 == (ep.getFlags() & OCTransportFlags.IPV4) ||
OCTransportFlags.IPV6 == (ep.getFlags() & OCTransportFlags.IPV6));
assertEquals(OCTransportFlags.SECURED, ep.getFlags() & OCTransportFlags.SECURED);
assertEquals(OCTransportFlags.TCP, ep.getFlags() & OCTransportFlags.TCP);
assertEquals(3456, ep.getAddr().getIpv4().getPort());
assertNull(uri[0]);
OCEndpointUtil.freeEndpoint(ep);
assertEquals(0, OCEndpoint.getCPtr(ep));
}
@Test
public void test_throw_exception_on_setDi_when_endpoint_null() {
// must call OCRandom.init to initialize the random number for generateUuid
......@@ -513,7 +266,7 @@ public class OCEndpointTest {
}
@Test
public void test_throw_exception_on_setDi_when_di_null_1_param_version() {
public void test_throw_exception_on_setDi_when_di_null() {
try {
// IPV4 with port and uri
OCEndpoint ep = OCEndpointUtil.stringToEndpoint("coaps://10.211.55.3:56789/a/light");
......@@ -527,22 +280,7 @@ public class OCEndpointTest {
}
@Test
public void test_throw_exception_on_setDi_when_di_null_2_param_version() {
try {
String[] uri = new String[1];
// IPV4 with port and uri
OCEndpoint ep = OCEndpointUtil.stringToEndpoint("coaps://10.211.55.3:56789/a/light", uri);
assertNotNull(ep);
OCEndpointUtil.setDi(ep, null);
fail("The call to setDi when di is null should thow an exception.");
} catch (Exception e) {
assertEquals( e.getClass(), NullPointerException.class);
assertEquals(e.getMessage(), "OCUuid cannot be null.");
}
}
@Test
public void test_throw_parse_exception_stringToEndpoint_1_param_version() {
public void test_throw_parse_exception_stringToEndpoint() {
OCEndpoint ep = null;
try {
ep = OCEndpointUtil.stringToEndpoint("");
......@@ -578,44 +316,6 @@ public class OCEndpointTest {
assertNull(ep);
}
@Test
public void test_throw_parse_exception_stringToEndpoint_2_param_version() {
String[] uri = new String[1];
OCEndpoint ep = null;
try {
ep = OCEndpointUtil.stringToEndpoint("", uri);
fail("The call stringToEndpoint should throw an exception");
} catch (Exception e) {
assertEquals(OCEndpointParseException.class, e.getClass());
assertEquals("The \"\" string cannot be parsed.", e.getMessage());
}
try {
// will fail does not have `://`
ep = OCEndpointUtil.stringToEndpoint("coaps+tcp", uri);
fail("The call stringToEndpoint should throw an exception");
} catch (Exception e) {
assertEquals(OCEndpointParseException.class, e.getClass());
assertEquals("The \"coaps+tcp\" string cannot be parsed.", e.getMessage());
}
try {
ep = OCEndpointUtil.stringToEndpoint("foobar", uri);
fail("The call stringToEndpoint should throw an exception");
} catch (Exception e) {
assertEquals(OCEndpointParseException.class, e.getClass());
assertEquals("The \"foobar\" string cannot be parsed.", e.getMessage());
}
try {
ep = OCEndpointUtil.stringToEndpoint(null, uri);
fail("The call stringToEndpoint should throw an exception");
} catch (Exception e) {
assertEquals(OCEndpointParseException.class, e.getClass());
assertEquals("The (null) string cannot be parsed.", e.getMessage());
}
assertNull(ep);
}
@Test
public void test_endpointStringParsePath() {
// coaps ipv4 endpoint with path
......
......@@ -160,8 +160,6 @@ SWIGEXPORT jobject JNICALL Java_org_iotivity_OCEndpointUtilJNI_toString(JNIEnv *
%apply oc_string_t *INPUT { oc_string_t *endpoint_str };
%apply oc_string_t *OUTPUT { oc_string_t *uri };
%javaexception("OCEndpointParseException") jni_string_to_endpoint {
if (!jarg1) {
jclass cls_OCEndpointParseException = JCALL1(FindClass, jenv, "org/iotivity/OCEndpointParseException");
......@@ -183,48 +181,10 @@ SWIGEXPORT jobject JNICALL Java_org_iotivity_OCEndpointUtilJNI_toString(JNIEnv *
oc_free_string(&exception_message);
}
}
/* TODO figure out a clean way to return the uri param not as an array value */
%ignore oc_string_to_endpoint;
%newobject jni_string_to_endpoint;
%rename(stringToEndpoint) jni_string_to_endpoint;
%inline %{
oc_endpoint_t * jni_string_to_endpoint(oc_string_t *endpoint_str, oc_string_t *uri) {
OC_DBG("JNI: %s\n", __func__);
oc_endpoint_t *ep = oc_new_endpoint();
if(oc_string_to_endpoint(endpoint_str, ep, uri) < 0) {
OC_DBG("JNI: oc_string_to_endpoint failed to parse %s\n", oc_string(*endpoint_str));
oc_free_endpoint(ep);
return NULL;
}
return ep;
}
%}
%javaexception("OCEndpointParseException") jni_string_to_endpoint_a {
if (!jarg1) {
jclass cls_OCEndpointParseException = JCALL1(FindClass, jenv, "org/iotivity/OCEndpointParseException");
assert(cls_OCEndpointParseException);
JCALL2(ThrowNew, jenv, cls_OCEndpointParseException, "The (null) string cannot be parsed.");
return $null;
}
$action
if(!result) {
OC_DBG("JNI: String can not be parsed.");
jclass cls_OCEndpointParseException = JCALL1(FindClass, jenv, "org/iotivity/OCEndpointParseException");
assert(cls_OCEndpointParseException);
oc_string_t exception_message_part1;
oc_concat_strings(&exception_message_part1, "The \"", oc_string(*arg1));
oc_string_t exception_message;
oc_concat_strings(&exception_message, oc_string(exception_message_part1), "\" string cannot be parsed.");
JCALL2(ThrowNew, jenv, cls_OCEndpointParseException, ((char *)oc_string(exception_message)));
oc_free_string(&exception_message_part1);
oc_free_string(&exception_message);
}
}
%newobject jni_string_to_endpoint_a;
%rename(stringToEndpoint) jni_string_to_endpoint_a;
%inline %{
oc_endpoint_t * jni_string_to_endpoint_a(oc_string_t *endpoint_str) {
oc_endpoint_t * jni_string_to_endpoint(oc_string_t *endpoint_str) {
OC_DBG("JNI: %s\n", __func__);
oc_endpoint_t *ep = oc_new_endpoint();
if(oc_string_to_endpoint(endpoint_str, ep, NULL) < 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment