Search in sources :

Example 1 with GeoLocation

use of org.jivesoftware.smackx.geoloc.packet.GeoLocation in project Smack by igniterealtime.

the class GeoLocationProviderTest method testGeoLocationWithAccuracySetAndWithoutErrorSet.

@Test
public void testGeoLocationWithAccuracySetAndWithoutErrorSet() throws Exception {
    // @formatter:off
    final String geoLocationString = "<message from='portia@merchantofvenice.lit'" + " to='bassanio@merchantofvenice.lit'>" + "<geoloc xmlns='http://jabber.org/protocol/geoloc'>" + "<accuracy>90</accuracy>" + "</geoloc>" + "</message>";
    // @formatter:on
    Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationString);
    GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class);
    assertEquals((Double) 90d, geoLocation.getAccuracy());
}
Also used : Message(org.jivesoftware.smack.packet.Message) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) Test(org.junit.jupiter.api.Test)

Example 2 with GeoLocation

use of org.jivesoftware.smackx.geoloc.packet.GeoLocation in project Smack by igniterealtime.

the class GeoLocationProviderTest method testGeoLocationProviderWithNoDatumSet.

@Test
public void testGeoLocationProviderWithNoDatumSet() throws Exception {
    // @formatter:off
    final String geoLocationString = "<message from='portia@merchantofvenice.lit'" + " to='bassanio@merchantofvenice.lit'>" + "<geoloc xmlns='http://jabber.org/protocol/geoloc'>" + "<accuracy>23</accuracy>" + "<alt>1000</alt>" + "<altaccuracy>10</altaccuracy>" + "<area>Delhi</area>" + "<bearing>10</bearing>" + "<building>Small Building</building>" + "<country>India</country>" + "<countrycode>IN</countrycode>" + "<description>My Description</description>" + "<error>90</error>" + "<floor>top</floor>" + "<lat>25.098345</lat>" + "<locality>awesome</locality>" + "<lon>77.992034</lon>" + "<postalcode>110085</postalcode>" + "<region>North</region>" + "<room>small</room>" + "<speed>250.0</speed>" + "<street>Wall Street</street>" + "<text>Unit Testing GeoLocation</text>" + "<timestamp>2004-02-19</timestamp>" + "<tzo>+5:30</tzo>" + "<uri>http://xmpp.org</uri>" + "</geoloc>" + "</message>";
    // @formatter:on
    Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationString);
    assertNotNull(messageWithGeoLocation);
    GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class);
    assertNotNull(geoLocation);
    assertEquals((Double) 23d, geoLocation.getAccuracy());
    assertEquals((Double) 1000d, geoLocation.getAlt());
    assertEquals((Double) 10d, geoLocation.getAltAccuracy());
    assertEquals("Delhi", geoLocation.getArea());
    assertEquals((Double) 10d, geoLocation.getBearing());
    assertEquals("Small Building", geoLocation.getBuilding());
    assertEquals("India", geoLocation.getCountry());
    assertEquals("IN", geoLocation.getCountryCode());
    assertEquals("WGS84", geoLocation.getDatum());
    assertEquals("My Description", geoLocation.getDescription());
    @SuppressWarnings("deprecation") Double error = geoLocation.getError();
    assertEquals(90, error);
    assertEquals("top", geoLocation.getFloor());
    assertEquals((Double) 25.098345d, geoLocation.getLat());
    assertEquals("awesome", geoLocation.getLocality());
    assertEquals((Double) 77.992034d, geoLocation.getLon());
    assertEquals("110085", geoLocation.getPostalcode());
    assertEquals("North", geoLocation.getRegion());
    assertEquals("small", geoLocation.getRoom());
    assertEquals((Double) 250d, geoLocation.getSpeed());
    assertEquals("Wall Street", geoLocation.getStreet());
    assertEquals("Unit Testing GeoLocation", geoLocation.getText());
    assertEquals(XmppDateTime.parseDate("2004-02-19"), geoLocation.getTimestamp());
    assertEquals("+5:30", geoLocation.getTzo());
    assertEquals(new URI("http://xmpp.org"), geoLocation.getUri());
}
Also used : Message(org.jivesoftware.smack.packet.Message) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 3 with GeoLocation

use of org.jivesoftware.smackx.geoloc.packet.GeoLocation in project Smack by igniterealtime.

the class GeoLocationProviderTest method testGeoLocationWithAccuracySetAndErrorSet.

@Test
public void testGeoLocationWithAccuracySetAndErrorSet() throws Exception {
    // @formatter:off
    final String geoLocationString = "<message from='portia@merchantofvenice.lit'" + " to='bassanio@merchantofvenice.lit'>" + "<geoloc xmlns='http://jabber.org/protocol/geoloc'>" + "<accuracy>90</accuracy>" + "<error>100</error>" + "</geoloc>" + "</message>";
    // @formatter:on
    Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationString);
    GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class);
    assertEquals((Double) 90d, geoLocation.getAccuracy());
    @SuppressWarnings("deprecation") Double error = geoLocation.getError();
    assertEquals(100, error);
}
Also used : Message(org.jivesoftware.smack.packet.Message) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) Test(org.junit.jupiter.api.Test)

Example 4 with GeoLocation

use of org.jivesoftware.smackx.geoloc.packet.GeoLocation in project Smack by igniterealtime.

the class GeolocationIntegrationTest method testNotification.

/**
 * Verifies that a notification is sent when a publication is received, assuming that notification filtering
 * has been adjusted to allow for the notification to be delivered.
 *
 * @throws Exception if the test fails
 */
@SmackIntegrationTest
public void testNotification() throws Exception {
    GeoLocation.Builder builder = GeoLocation.builder();
    GeoLocation data = builder.setAccuracy(23d).setAlt(1000d).setAltAccuracy(10d).setArea("Delhi").setBearing(10d).setBuilding("Small Building").setCountry("India").setCountryCode("IN").setDescription("My Description").setFloor("top").setLat(25.098345d).setLocality("awesome").setLon(77.992034).setPostalcode("110085").setRegion("North").setRoom("small").setSpeed(250.0d).setStreet("Wall Street").setText("Unit Testing GeoLocation").setTimestamp(XmppDateTime.parseDate("2004-02-19")).setTzo("+5:30").setUri(new URI("http://xmpp.org")).build();
    IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
    final SimpleResultSyncPoint geoLocationReceived = new SimpleResultSyncPoint();
    final PepEventListener<GeoLocation> geoLocationListener = (jid, geoLocation, id, message) -> {
        if (geoLocation.equals(data)) {
            geoLocationReceived.signal();
        }
    };
    try {
        // Register ConTwo's interest in receiving geolocation notifications, and wait for that interest to have been propagated.
        registerListenerAndWait(glm2, ServiceDiscoveryManager.getInstanceFor(conTwo), geoLocationListener);
        // Publish the data.
        // for the purpose of this test, this needs not be blocking/use publishAndWait();
        glm1.publishGeoLocation(data);
        // Wait for the data to be received.
        try {
            Object result = geoLocationReceived.waitForResult(timeout);
            // Explicitly assert the success case.
            Assertions.assertNotNull(result, "Expected to receive a PEP notification, but did not.");
        } catch (TimeoutException e) {
            Assertions.fail("Expected to receive a PEP notification, but did not.");
        }
    } finally {
        unregisterListener(glm2, geoLocationListener);
    }
}
Also used : SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) GeoLocationManager(org.jivesoftware.smackx.geoloc.GeoLocationManager) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) XmppDateTime(org.jxmpp.util.XmppDateTime) URI(java.net.URI) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) URI(java.net.URI) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) TimeoutException(java.util.concurrent.TimeoutException) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 5 with GeoLocation

use of org.jivesoftware.smackx.geoloc.packet.GeoLocation in project Smack by igniterealtime.

the class GeolocationIntegrationTest method publishAndWait.

/**
 * Publish data using PEP, and block until the server has echoed the publication back to the publishing user.
 *
 * @param geoManager The GeoLocationManager instance for the connection that is expected to publish data.
 * @param discoManager The ServiceDiscoveryManager instance for the connection that is expected to publish data.
 * @param data The data to be published.
 *
 * @throws Exception if the test fails
 */
public void publishAndWait(GeoLocationManager geoManager, ServiceDiscoveryManager discoManager, GeoLocation data) throws Exception {
    final SimpleResultSyncPoint publicationEchoReceived = new SimpleResultSyncPoint();
    final PepEventListener<GeoLocation> publicationEchoListener = (jid, geoLocation, id, message) -> {
        if (geoLocation.equals(data)) {
            publicationEchoReceived.signal();
        }
    };
    try {
        registerListenerAndWait(geoManager, discoManager, publicationEchoListener);
        geoManager.addGeoLocationListener(publicationEchoListener);
        geoManager.publishGeoLocation(data);
    } finally {
        geoManager.removeGeoLocationListener(publicationEchoListener);
    }
}
Also used : SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) GeoLocationManager(org.jivesoftware.smackx.geoloc.GeoLocationManager) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) XmppDateTime(org.jxmpp.util.XmppDateTime) URI(java.net.URI) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)

Aggregations

GeoLocation (org.jivesoftware.smackx.geoloc.packet.GeoLocation)9 URI (java.net.URI)6 Message (org.jivesoftware.smack.packet.Message)5 Test (org.junit.jupiter.api.Test)5 TimeoutException (java.util.concurrent.TimeoutException)4 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)4 SmackIntegrationTestEnvironment (org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment)4 AfterClass (org.igniterealtime.smack.inttest.annotations.AfterClass)4 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)4 IntegrationTestRosterUtil (org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil)4 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)4 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)4 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)4 NotLoggedInException (org.jivesoftware.smack.SmackException.NotLoggedInException)4 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)4 EntityCapabilitiesChangedListener (org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener)4 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)4 GeoLocationManager (org.jivesoftware.smackx.geoloc.GeoLocationManager)4 PepEventListener (org.jivesoftware.smackx.pep.PepEventListener)4 Assertions (org.junit.jupiter.api.Assertions)4