diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-11 20:23:56 (GMT) |
---|---|---|
committer | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-16 19:14:39 (GMT) |
commit | e868c966e23716d8a0261b222cccbeb04616e235 (patch) | |
tree | 2e26cc205e671f54bc5de527917913f8de47e0f4 /test/com/isode | |
parent | b2a8ac9a0387a9a5e75e31f7704e62ac077faba4 (diff) | |
download | stroke-e868c966e23716d8a0261b222cccbeb04616e235.zip stroke-e868c966e23716d8a0261b222cccbeb04616e235.tar.bz2 |
Add the UserLocation Element.
Adds UserLocation Element, its parser and Serializer.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Tests added for UserLocation Parser and UserLocation Serializer, which passes.
Change-Id: Ia1d57f4233351e755770f06fdc8e292db1acf521
Diffstat (limited to 'test/com/isode')
-rw-r--r-- | test/com/isode/stroke/parser/payloadparsers/UserLocationParserTest.java | 102 | ||||
-rw-r--r-- | test/com/isode/stroke/serializer/payloadserializers/UserLocationSerializerTest.java | 91 |
2 files changed, 193 insertions, 0 deletions
diff --git a/test/com/isode/stroke/parser/payloadparsers/UserLocationParserTest.java b/test/com/isode/stroke/parser/payloadparsers/UserLocationParserTest.java new file mode 100644 index 0000000..015fab3 --- /dev/null +++ b/test/com/isode/stroke/parser/payloadparsers/UserLocationParserTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.parser.payloadparsers; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import org.junit.Test; +import com.isode.stroke.elements.UserLocation; +import com.isode.stroke.parser.payloadparsers.UserLocationParser; +import com.isode.stroke.parser.payloadparsers.PayloadsParserTester; +import com.isode.stroke.eventloop.DummyEventLoop; +import java.util.Date; +import com.isode.stroke.base.DateTime; +import java.util.TimeZone; + +public class UserLocationParserTest { + + public UserLocationParserTest() { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + } + + @Test + public void testParse_with_all_variables() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" + + "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" + + "<lat>1.67</lat><accuracy>0.95</accuracy><description>Nice</description>" + + "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" + + "<building>First</building><room>E315</room><country>USA</country>" + + "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" + + "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text>" + + "<datum>Datee</datum><street>Highway</street><speed>56.77</speed></geoloc>")); + + UserLocation payload = (UserLocation)parser.getPayload(); + + assertEquals ("Barbaric", payload.getArea()); + assertEquals (Float.valueOf(5.75F), payload.getAltitude()); + assertEquals ("Near", payload.getLocality()); + assertEquals (Float.valueOf(1.670F), payload.getLatitude()); + assertEquals (Float.valueOf(0.95F), payload.getAccuracy()); + assertEquals ("Nice", payload.getDescription()); + assertEquals ("+91", payload.getCountryCode()); + assertEquals (DateTime.dateToString(new Date(1434056150620L)), DateTime.dateToString(payload.getTimestamp())); + assertEquals ("3", payload.getFloor()); + assertEquals ("First", payload.getBuilding()); + assertEquals ("E315", payload.getRoom()); + assertEquals ("USA", payload.getCountry()); + assertEquals ("NewSode", payload.getRegion()); + assertEquals ("URIs", payload.getURI()); + assertEquals (Float.valueOf(6.7578F), payload.getLongitude()); + assertEquals (Float.valueOf(5.66F), payload.getError()); + assertEquals ("67", payload.getPostalCode()); + assertEquals (Float.valueOf(12.89F), payload.getBearing()); + assertEquals ("Hello", payload.getText()); + assertEquals ("Datee", payload.getDatum()); + assertEquals ("Highway", payload.getStreet()); + assertEquals (Float.valueOf(56.77F), payload.getSpeed()); + } + + @Test + public void testParse_with_Some_variables() { + DummyEventLoop eventLoop = new DummyEventLoop(); + PayloadsParserTester parser = new PayloadsParserTester(eventLoop); + assertNotNull(parser.parse("<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" + + "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" + + "<accuracy>0.95</accuracy><description>Nice</description>" + + "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" + + "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" + + "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text></geoloc>")); + + UserLocation payload = (UserLocation)parser.getPayload(); + + assertEquals ("Barbaric", payload.getArea()); + assertEquals (Float.valueOf(5.75F), payload.getAltitude()); + assertEquals ("Near", payload.getLocality()); + assertNull(payload.getLatitude()); + assertEquals (Float.valueOf(0.95F), payload.getAccuracy()); + assertEquals ("Nice", payload.getDescription()); + assertEquals ("+91", payload.getCountryCode()); + assertEquals (DateTime.dateToString(new Date(1434056150620L)), DateTime.dateToString(payload.getTimestamp())); + assertEquals ("3", payload.getFloor()); + assertNull(payload.getBuilding()); + assertNull(payload.getRoom()); + assertNull(payload.getCountry()); + assertEquals ("NewSode", payload.getRegion()); + assertEquals ("URIs", payload.getURI()); + assertEquals (Float.valueOf(6.7578F), payload.getLongitude()); + assertEquals (Float.valueOf(5.66F), payload.getError()); + assertEquals ("67", payload.getPostalCode()); + assertEquals (Float.valueOf(12.89F), payload.getBearing()); + assertEquals ("Hello", payload.getText()); + assertNull(payload.getDatum()); + assertNull(payload.getStreet()); + assertNull(payload.getSpeed()); + } +}
\ No newline at end of file diff --git a/test/com/isode/stroke/serializer/payloadserializers/UserLocationSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/UserLocationSerializerTest.java new file mode 100644 index 0000000..1bd07c1 --- /dev/null +++ b/test/com/isode/stroke/serializer/payloadserializers/UserLocationSerializerTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.serializer.payloadserializers; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import com.isode.stroke.serializer.payloadserializers.UserLocationSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.elements.UserLocation; +import java.util.Date; +import java.util.TimeZone; + +public class UserLocationSerializerTest { + + public UserLocationSerializerTest() { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + } + + @Test + public void testSerialize_withAllVariablesSet() { + PayloadSerializerCollection serializerCollection = new PayloadSerializerCollection(); + UserLocationSerializer testling = new UserLocationSerializer(serializerCollection); + UserLocation userLocation = new UserLocation(); + userLocation.setArea("Barbaric"); + userLocation.setAltitude(5.75F); + userLocation.setLocality("Near"); + userLocation.setLatitude(1.670F); + userLocation.setAccuracy(0.95F); + userLocation.setDescription("Nice"); + userLocation.setCountryCode("+91"); + userLocation.setTimestamp(new Date(1434056150620L)); + userLocation.setFloor("3"); + userLocation.setBuilding("First"); + userLocation.setRoom("E315"); + userLocation.setCountry("USA"); + userLocation.setRegion("NewSode"); + userLocation.setURI("URIs"); + userLocation.setLongitude(6.7578F); + userLocation.setError(5.66F); + userLocation.setPostalCode("67"); + userLocation.setBearing(12.89F); + userLocation.setText("Hello"); + userLocation.setDatum("Datee"); + userLocation.setStreet("Highway"); + userLocation.setSpeed(56.77F); + + String expectedResult = "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" + + "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" + + "<lat>1.67</lat><accuracy>0.95</accuracy><description>Nice</description>" + + "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" + + "<building>First</building><room>E315</room><country>USA</country>" + + "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" + + "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text>" + + "<datum>Datee</datum><street>Highway</street><speed>56.77</speed></geoloc>"; + assertEquals(expectedResult, testling.serialize(userLocation)); + } + + @Test + public void testSerialize_withSomeVariablesSet() { + PayloadSerializerCollection serializerCollection = new PayloadSerializerCollection(); + UserLocationSerializer testling = new UserLocationSerializer(serializerCollection); + UserLocation userLocation = new UserLocation(); + userLocation.setArea("Barbaric"); + userLocation.setAltitude(5.75F); + userLocation.setLocality("Near"); + userLocation.setAccuracy(0.95F); + userLocation.setDescription("Nice"); + userLocation.setCountryCode("+91"); + userLocation.setTimestamp(new Date(1434056150620L)); + userLocation.setFloor("3"); + userLocation.setRegion("NewSode"); + userLocation.setURI("URIs"); + userLocation.setLongitude(6.7578F); + userLocation.setError(5.66F); + userLocation.setPostalCode("67"); + userLocation.setBearing(12.89F); + userLocation.setText("Hello"); + + String expectedResult = "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" + + "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" + + "<accuracy>0.95</accuracy><description>Nice</description>" + + "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" + + "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" + + "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text></geoloc>"; + assertEquals(expectedResult, testling.serialize(userLocation)); + } +}
\ No newline at end of file |