use of org.igniterealtime.smack.inttest.SmackIntegrationTest in project Smack by igniterealtime.
the class HttpFileUploadIntegrationTest method httpFileUploadTest.
@SmackIntegrationTest
public void httpFileUploadTest() throws FileNotFoundException, 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.SmackIntegrationTest in project Smack by igniterealtime.
the class IoTDataIntegrationTest method dataTest.
/**
* Connection one provides a thing, which momentary value is read out by connection two.
*
* @throws Exception
* @throws TimeoutException
*/
@SmackIntegrationTest
public void dataTest() throws TimeoutException, Exception {
final String key = StringUtils.randomString(12);
final String sn = StringUtils.randomString(12);
final int value = INSECURE_RANDOM.nextInt();
Thing dataThing = Thing.builder().setKey(key).setSerialNumber(sn).setMomentaryReadOutRequestHandler(new ThingMomentaryReadOutRequest() {
@Override
public void momentaryReadOutRequest(ThingMomentaryReadOutResult callback) {
IoTDataField.IntField field = new IntField(testRunId, value);
callback.momentaryReadOut(Collections.singletonList(field));
}
}).build();
iotDataManagerOne.installThing(dataThing);
List<IoTFieldsExtension> values;
try {
RosterIntegrationTest.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
values = iotDataManagerTwo.requestMomentaryValuesReadOut(conOne.getUser());
} finally {
iotDataManagerOne.uninstallThing(dataThing);
RosterIntegrationTest.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
}
assertEquals(1, values.size());
IoTFieldsExtension iotFieldsExtension = values.get(0);
List<NodeElement> nodes = iotFieldsExtension.getNodes();
assertEquals(1, nodes.size());
NodeElement node = nodes.get(0);
List<TimestampElement> timestamps = node.getTimestampElements();
assertEquals(1, timestamps.size());
TimestampElement timestamp = timestamps.get(0);
List<? extends IoTDataField> fields = timestamp.getDataFields();
assertEquals(1, fields.size());
IoTDataField dataField = fields.get(0);
assertTrue(dataField instanceof IoTDataField.IntField);
IoTDataField.IntField intDataField = (IoTDataField.IntField) dataField;
assertEquals(testRunId, intDataField.getName());
assertEquals(value, intDataField.getValue());
}
use of org.igniterealtime.smack.inttest.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.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.SmackIntegrationTest in project Smack by igniterealtime.
the class MultiUserChatIntegrationTest method mucTest.
@SmackIntegrationTest
public void mucTest() throws TimeoutException, Exception {
EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from("smack-inttest-" + randomString), mucService.getDomain());
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
final String mucMessage = "Smack Integration Test MUC Test Message " + randomString;
final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
mucAsSeenByTwo.addMessageListener(new MessageListener() {
@Override
public void processMessage(Message message) {
String body = message.getBody();
if (mucMessage.equals(body)) {
resultSyncPoint.signal(body);
}
}
});
MucCreateConfigFormHandle handle = mucAsSeenByOne.createOrJoin(Resourcepart.from("one-" + randomString));
if (handle != null) {
handle.makeInstant();
}
mucAsSeenByTwo.join(Resourcepart.from("two-" + randomString));
mucAsSeenByOne.sendMessage(mucMessage);
resultSyncPoint.waitForResult(timeout);
mucAsSeenByOne.leave();
mucAsSeenByTwo.leave();
}
Aggregations