use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest 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);
}
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class HttpFileUploadIntegrationTest method httpFileUploadTest.
@SmackIntegrationTest
public void httpFileUploadTest() throws IOException, XMPPErrorException, InterruptedException, SmackException {
final int fileSize = FILE_SIZE;
File file = createNewTempFile();
FileOutputStream fos = new FileOutputStream(file.getCanonicalPath());
byte[] upBytes;
try {
upBytes = new byte[fileSize];
INSECURE_RANDOM.nextBytes(upBytes);
fos.write(upBytes);
} finally {
fos.close();
}
URL getUrl = hfumOne.uploadFile(file, new UploadProgressListener() {
@Override
public void onUploadProgress(long uploadedBytes, long totalBytes) {
double progress = uploadedBytes / totalBytes;
LOGGER.fine("HTTP File Upload progress " + progress + "% (" + uploadedBytes + '/' + totalBytes + ')');
}
});
HttpURLConnection urlConnection = getHttpUrlConnectionFor(getUrl);
ByteArrayOutputStream baos = new ByteArrayOutputStream(fileSize);
byte[] buffer = new byte[4096];
int n;
try {
InputStream is = new BufferedInputStream(urlConnection.getInputStream());
while ((n = is.read(buffer)) != -1) {
baos.write(buffer, 0, n);
}
} finally {
urlConnection.disconnect();
}
byte[] downBytes = baos.toByteArray();
assertArrayEquals(upBytes, downBytes);
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class IoTDiscoveryIntegrationTest method registerClaimAndUnregisterThing.
@SmackIntegrationTest
public void registerClaimAndUnregisterThing() throws XMPPErrorException, InterruptedException, SmackException {
final String key = StringUtils.randomString(12);
final String sn = StringUtils.randomString(12);
final Thing thing = Thing.builder().setKey(key).setSerialNumber(sn).setManufacturer("Ignite Realtime").setModel("Smack").setVersion("0.1").build();
registerThing(discoveryManagerOne, thing);
IoTClaimed iotClaimed = discoveryManagerTwo.claimThing(thing.getMetaTags());
assertEquals(conOne.getUser().asBareJid(), iotClaimed.getJid());
discoveryManagerTwo.disownThing(iotClaimed.getJid());
discoveryManagerOne.unregister();
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class VersionIntegrationTest method testVersion.
@SmackIntegrationTest
public void testVersion() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// TODO put into @BeforeClass method
VersionManager.setAutoAppendSmackVersion(false);
VersionManager versionManagerOne = VersionManager.getInstanceFor(conOne);
VersionManager versionManagerTwo = VersionManager.getInstanceFor(conTwo);
final String versionName = "Smack Integration Test " + testRunId;
versionManagerTwo.setVersion(versionName, "1.0");
assertTrue(versionManagerOne.isSupported(conTwo.getUser()));
Version version = versionManagerOne.getVersion(conTwo.getUser());
assertEquals(versionName, version.getName());
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class MamIntegrationTest method mamPageTest.
@SmackIntegrationTest
public void mamPageTest() throws TimeoutException, Exception {
final int messagesPerPage = 10;
final int numPages = 3;
final int totalMessages = messagesPerPage * numPages;
final List<Message> outgoingMessages = new ArrayList<>(totalMessages);
final EntityBareJid userOne = conOne.getUser().asEntityBareJid();
final EntityBareJid userTwo = conTwo.getUser().asEntityBareJid();
final SimpleResultSyncPoint allMessagesReceived = new SimpleResultSyncPoint();
final String lastMessageArchiveUid = mamManagerConTwo.getMessageUidOfLatestMessage();
for (int i = 0; i < totalMessages; i++) {
String messageBody = "MAM Page Test " + testRunId + ' ' + (i + 1);
Message message = StanzaBuilder.buildMessage().to(userTwo).setBody(messageBody).build();
outgoingMessages.add(message);
}
final String lastBody = outgoingMessages.get(outgoingMessages.size() - 1).getBody();
final StanzaListener stanzaListener = new StanzaListener() {
@Override
public void processStanza(Stanza stanza) {
Message message = (Message) stanza;
if (message.getBody().equals(lastBody)) {
allMessagesReceived.signal();
}
}
};
conTwo.addAsyncStanzaListener(stanzaListener, MessageWithBodiesFilter.INSTANCE);
try {
for (Message message : outgoingMessages) {
conOne.sendStanza(message);
}
allMessagesReceived.waitForResult(timeout);
} finally {
conTwo.removeAsyncStanzaListener(stanzaListener);
}
MamQueryArgs mamQueryArgs = MamQueryArgs.builder().setResultPageSize(messagesPerPage).limitResultsToJid(userOne).afterUid(lastMessageArchiveUid).build();
MamQuery mamQuery = mamManagerConTwo.queryArchive(mamQueryArgs);
assertFalse(mamQuery.isComplete());
assertEquals(messagesPerPage, mamQuery.getMessageCount());
List<List<Message>> pages = new ArrayList<>(numPages);
pages.add(mamQuery.getMessages());
for (int additionalPageRequestNum = 0; additionalPageRequestNum < numPages - 1; additionalPageRequestNum++) {
List<Message> page = mamQuery.pageNext(messagesPerPage);
boolean isLastQuery = additionalPageRequestNum == numPages - 2;
if (isLastQuery) {
assertTrue(mamQuery.isComplete());
} else {
assertFalse(mamQuery.isComplete());
}
assertEquals(messagesPerPage, page.size());
pages.add(page);
}
List<Message> queriedMessages = new ArrayList<>(totalMessages);
for (List<Message> messages : pages) {
queriedMessages.addAll(messages);
}
assertEquals(outgoingMessages.size(), queriedMessages.size());
for (int i = 0; i < outgoingMessages.size(); i++) {
Message outgoingMessage = outgoingMessages.get(i);
Message queriedMessage = queriedMessages.get(i);
assertEquals(outgoingMessage.getBody(), queriedMessage.getBody());
}
}
Aggregations