Package com.streamreduce.core.model

Examples of com.streamreduce.core.model.Connection$Builder


    public void testSendInsightMessageDoesNotAppearInS3() throws Exception {
        //If SobaMessage does not have a type of NODEBELLY, it shouldn't be sent as an insight message to
        //outbound

        JSONObject imgPayload = TestUtils.createValidSampleIMGPayload();
        Connection testIMGConnection =
                TestUtils.createIMGConnectionWithSpecificOutboundDatatypes(
                        OutboundDataType.INSIGHT);
        SobaMessage sobaMessage = new SobaMessage.Builder()
                .connection(testIMGConnection)
                .dateGenerated(System.currentTimeMillis())
                .hashtags(Sets.newHashSet("#foo"))
                .sender(testIMGConnection)
                .transformedMessage(imgPayload.getString("message"))
                .type(MessageType.GATEWAY)
                .visibility(SobaObject.Visibility.ACCOUNT)
                .build();
        sobaMessage.setId(new ObjectId());

        outboundStorageService.sendSobaMessage(sobaMessage, testIMGConnection);

        ConnectionCredentials creds = new ArrayList<>(
                testIMGConnection.getOutboundConfigurations()).get(0).getCredentials();
        s3TestUtils = new S3TestUtils(creds);

        String expectedBucketName = "com.streamreduce." + testIMGConnection.getAccount().getId();
        String prefix = "insight/" + sobaMessage.getConnectionId() + "/";
        List<Blob> payloads = s3TestUtils.getBlobsFromS3(expectedBucketName, prefix);

        Assert.assertEquals(0, payloads.size());
    }
View Full Code Here


        client.validateConnection();
    }

    @Test(expected = IllegalArgumentException.class)
    public void testValidateFeedConnectionNonFeedProvider() throws Exception {
        Connection feedConnection = TestUtils.createTestFeedConnection();

        feedConnection.setProviderId("nonFeedProviderId");

        FeedClient client = new FeedClient(feedConnection);

        client.validateConnection();
    }
View Full Code Here

        Assert.assertEquals(0, payloads.size());
    }

    @Test
    public void testEndToEndForProcessedMessages() throws Exception {
        Connection feedConnection =
                TestUtils.createTestFeedConnection(OutboundDataType.PROCESSED);

        //Let ConnectionService take care of creating the Id
        feedConnection.setId(null);
        //Make sure user/account are set to persisted values on the connections
        feedConnection.setUser(testUser);
        feedConnection.setAccount(testAccount);

        //Make the feed connection have a last_activity_poll from before the feed messages
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String feb282012TimeStamp = Long.toString(sdf.parse("2012-02-28").getTime());
        Map<String, String> metadata = new HashMap<>();
        metadata.put("last_activity_poll", feb282012TimeStamp);
        feedConnection.setMetadata(metadata);

        //Create the feed connection and fire the job to create messages
        Connection createdFeedConnection = connectionService.createConnection(feedConnection);
        connectionService.fireOneTimeHighPriorityJobForConnection(feedConnection);

        //Chill a few seconds and let the job and outbound service do their work.
        //It's not very fast...
        Thread.sleep(TimeUnit.SECONDS.toMillis(10));

        s3TestUtils = new S3TestUtils(TestUtils.createConnectionCredentialsForAWS());

        String expectedBucketName = "com.streamreduce." + createdFeedConnection.getAccount().getId();
        String prefix = "processed/" + feedConnection.getId() + "/";

        List<Blob> blobs = s3TestUtils.getBlobsFromS3(expectedBucketName, prefix);
        Assert.assertEquals(3, blobs.size());
    }
View Full Code Here

        client.validateConnection();
    }

    @Test(expected = MalformedURLException.class)
    public void testValidateFeedConnectionMalformedUrl() throws Exception {
        Connection feedConnection = TestUtils.createTestFeedConnection();

        feedConnection.setUrl("abc123");

        FeedClient client = new FeedClient(feedConnection);

        client.validateConnection();
    }
View Full Code Here

    }

    @Test
    public void testSendProcessedMessageAppearsInS3WithDifferentRegion() throws Exception {
        JSONObject imgPayload = TestUtils.createValidSampleIMGPayload();
        Connection testIMGConnection = TestUtils.createIMGConnectionWithSpecificOutboundDatatypes();

        OutboundConfiguration outboundConfiguration = new OutboundConfiguration.Builder()
                .credentials(TestUtils.createCloudConnection().getCredentials())
                .dataTypes(OutboundDataType.PROCESSED)
                .protocol("s3")
                .destination("eu-west-1")
                .build();
        testIMGConnection.setOutboundConfigurations(Sets.newHashSet(outboundConfiguration));
        testIMGConnection.setAccount(testAccount);
        testIMGConnection.setUser(testUser);
        testIMGConnection = connectionService.createConnection(testIMGConnection);


        SobaMessage sobaMessage = new SobaMessage.Builder()
                .connection(testIMGConnection)
                .dateGenerated(System.currentTimeMillis())
                .hashtags(Sets.newHashSet("#foo"))
                .sender(testIMGConnection)
                .transformedMessage(imgPayload.getString("message"))
                .type(MessageType.GATEWAY)
                .visibility(SobaObject.Visibility.ACCOUNT)
                .build();
        sobaMessage.setId(new ObjectId());

        outboundStorageService.sendSobaMessage(sobaMessage, testIMGConnection);
        Thread.sleep(TimeUnit.SECONDS.toMillis(10));

        String expectedBucketName = "com.streamreduce." + testIMGConnection.getAccount().getId();
        String key = "processed/" + sobaMessage.getConnectionId() + "/" + sobaMessage.getId();

        ConnectionCredentials credentials = new ArrayList<>(
                testIMGConnection.getOutboundConfigurations()).get(0).getCredentials();
        s3TestUtils = new S3TestUtils(credentials);

        Blob payload = s3TestUtils.getExpectedBlob(expectedBucketName, key);

        //Test that what made it to S3 is the same thing we get when we turn the sobaMessage into a dto
View Full Code Here

        client.validateConnection();
    }

    @Test(expected = RuntimeException.class)
    public void testValidateFeedConnectionUnavailableUrl() throws Exception {
        Connection feedConnection = TestUtils.createTestFeedConnection();
        feedConnection.setUrl("http://foo.bar.ham.eggs.com");
        FeedClient client = new FeedClient(feedConnection);
        client.validateConnection();
    }
View Full Code Here

        client.validateConnection();
    }

    @Test(expected = RuntimeException.class)
    public void testValidateFeedConnectionNonFeedUrl() throws Exception {
        Connection feedConnection = TestUtils.createTestFeedConnection();
        feedConnection.setUrl("http://www.google.com");
        FeedClient client = new FeedClient(feedConnection);
        client.validateConnection();
    }
View Full Code Here

    }

    @Override
    public int sendSobaMessage(SobaMessage sobaMessage) throws OutboundStorageException {
        try {
            Connection c = connectionService.getConnection(sobaMessage.getConnectionId());
            return sendSobaMessage(sobaMessage, c);
        } catch (ConnectionNotFoundException e) {
            throw new OutboundStorageException("Unable to retrieve Connection for sobaMessage with Id of "
                    + sobaMessage.getId(), e);
        }
View Full Code Here

TOP

Related Classes of com.streamreduce.core.model.Connection$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.