Search in sources :

Example 1 with SmackIntegrationTest

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) URL(java.net.URL) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 2 with SmackIntegrationTest

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());
}
Also used : IoTFieldsExtension(org.jivesoftware.smackx.iot.data.element.IoTFieldsExtension) TimestampElement(org.jivesoftware.smackx.iot.data.element.TimestampElement) IntField(org.jivesoftware.smackx.iot.data.element.IoTDataField.IntField) IntField(org.jivesoftware.smackx.iot.data.element.IoTDataField.IntField) IoTDataField(org.jivesoftware.smackx.iot.data.element.IoTDataField) NodeElement(org.jivesoftware.smackx.iot.data.element.NodeElement) ThingMomentaryReadOutResult(org.jivesoftware.smackx.iot.data.ThingMomentaryReadOutResult) ThingMomentaryReadOutRequest(org.jivesoftware.smackx.iot.data.ThingMomentaryReadOutRequest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 3 with SmackIntegrationTest

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();
}
Also used : IoTClaimed(org.jivesoftware.smackx.iot.discovery.element.IoTClaimed) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 4 with SmackIntegrationTest

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());
}
Also used : Version(org.jivesoftware.smackx.iqversion.packet.Version) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 5 with SmackIntegrationTest

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();
}
Also used : Message(org.jivesoftware.smack.packet.Message) ResultSyncPoint(org.igniterealtime.smack.inttest.util.ResultSyncPoint) MessageListener(org.jivesoftware.smack.MessageListener) EntityBareJid(org.jxmpp.jid.EntityBareJid) MucCreateConfigFormHandle(org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle) TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) TimeoutException(java.util.concurrent.TimeoutException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Aggregations

SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)19 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)14 AndFilter (org.jivesoftware.smack.filter.AndFilter)4 Message (org.jivesoftware.smack.packet.Message)4 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)3 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)3 TimeoutException (java.util.concurrent.TimeoutException)2 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)2 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)2 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 ThreadFilter (org.jivesoftware.smack.filter.ThreadFilter)2 Presence (org.jivesoftware.smack.packet.Presence)2 MucCreateConfigFormHandle (org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle)2 EntityBareJid (org.jxmpp.jid.EntityBareJid)2 Jid (org.jxmpp.jid.Jid)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1