Package com.streamreduce.core.model

Examples of com.streamreduce.core.model.Connection


        Assert.assertEquals(imgPayload,jsonPayload);
    }

    @Test
    public void testSendRawMessageDoesNotAppearWithoutRawOutboundDataTypeInS3() throws Exception {
        Connection testIMGConnection = createAndMockForIMGConnectionWithOutboundTypes(
                OutboundDataType.EVENT, OutboundDataType.PROCESSED, OutboundDataType.INSIGHT);


        JSONObject imgPayload  = TestUtils.createValidSampleIMGPayload();
        Response response = gatewayResource.createCustomConnectionMessage(imgPayload); //magic happens here

        //Start verification
        if (response.getStatus() != 201) {
            ErrorMessage e = (ErrorMessage) response.getEntity();
            Assert.fail("Unable to verify test due to IMG failure.  Response has a status of " + response.getStatus() +
                    " and an error message of : " + e.getErrorMessage());
        }

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

        String expectedBucketName = "com.streamreduce." + testIMGConnection.getAccount().getId();
        String prefix = "raw/" + testIMGConnection.getId() + "/";
        List<Blob> blobs = s3TestUtils.getBlobsFromS3(expectedBucketName,prefix);

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


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

    private Connection createAndMockForIMGConnectionWithOutboundTypes(OutboundDataType... dataTypes)  {
        Connection testIMGConnection = TestUtils.createIMGConnectionWithSpecificOutboundDatatypes(dataTypes);

        SecurityService mockSecurityService = mock(SecurityService.class);
        when(mockSecurityService.getCurrentGatewayConnection()).thenReturn(testIMGConnection);
        ReflectionTestUtils.setField(gatewayResource,"securityService",mockSecurityService);
View Full Code Here

        RssProvider mockProvider = mock(RssProvider.class);
        when(mockProvider.getId()).thenReturn(ProviderIdConstants.FEED_PROVIDER_ID);
        when(mockProvider.getType()).thenReturn(FeedProvider.TYPE);

        Connection sampleFeedConnection = new Connection.Builder()
                .provider(mockProvider)
                .url(SAMPLE_FEED_FILE_PATH)
                .alias("EC2")
                .user(u)
                .authType(AuthType.NONE)
                .visibility(SobaObject.Visibility.SELF)
                .build();
        Map<String, String> metadata = new HashMap<>();
        metadata.put("last_activity_poll", feb282012TimeStamp);
        sampleFeedConnection.setMetadata(metadata);

        sampleFeedConnection = connectionService.createConnection(sampleFeedConnection);
        connectionService.fireOneTimeHighPriorityJobForConnection(sampleFeedConnection);
        Thread.sleep(TimeUnit.SECONDS.toMillis(1));
        return sampleFeedConnection;
View Full Code Here

    @Override
    @ManagedOperation(description = "Disables a connection.")
    @ManagedOperationParameters({
            @ManagedOperationParameter(name = "connectionObjectId", description = "Connection ObjectID.")})
    public void disableConnection(String connectionObjectId) {
        Connection connection = connectionDAO.get(new ObjectId(connectionObjectId));
        connection.setDisabled(true);
        connectionDAO.save(connection);
    }
View Full Code Here

    @Override
    @ManagedOperation(description = "Enables a connection.")
    @ManagedOperationParameters({
            @ManagedOperationParameter(name = "connectionObjectId", description = "Connection ObjectID.")})
    public void enableConnection(String connectionObjectId) {
        Connection connection = connectionDAO.get(new ObjectId(connectionObjectId));
        connection.setDisabled(false);
        connectionDAO.save(connection);
    }
View Full Code Here

        User user = applicationManager.getUserService().getUser(testUser.getUsername());
        String authnToken = login(user.getUsername(), testUser.getUsername()); // ugh

        // just get the first random one
        List<Connection> connections = applicationManager.getConnectionService().getConnections(ProjectHostingProvider.TYPE, user);
        Connection connection = connections.get(0);

        JSONObject json = new JSONObject();
        // Just to be sure, let's change the visibility to something valid
        json.put("hashtag", random);

        makeRequest(connectionsBaseUrl + "/" + connection.getId() + "/hashtag", "POST", json, authnToken);

        /// verify the connection is tagged
        connection = applicationManager.getConnectionService().getConnection(connection.getId());

        assertNotNull(connection.getHashtags());
        assertTrue(connection.getHashtags().size() > 0);
        assertTrue(connection.getHashtags().contains("#" + random));

        // now check the child items
        List<InventoryItem> items = applicationManager.getInventoryService().getInventoryItems(connection, user);
        assertNotNull(items);
        assertTrue(items.size() > 0);

        for (InventoryItem item : items) {
            assertTrue(item.getHashtags().contains("#" + random));
        }

        // now delete
        makeRequest(connectionsBaseUrl + "/" + connection.getId() + "/hashtag/" + random, "DELETE", null, authnToken);

        // get a fresh copy from the db
        connection = applicationManager.getConnectionService().getConnection(connection.getId());

        assertFalse(connection.getHashtags().contains("#" + random));

        // now check the child items
        items = applicationManager.getInventoryService().getInventoryItems(connection, user);
        for (InventoryItem item : items) {
            assertFalse(item.getHashtags().contains("#" + random));
View Full Code Here

    @Ignore
    public void testCanBlacklistPublicConnection() throws Exception {

        List<Connection> connectionList = applicationManager.getConnectionService().getPublicConnections("feed");
        // get an RSS connection bootstrapped by nodeable
        Connection connection = connectionList.get(0);
        assertNotNull(connection);

        // try and delete the connection.
        String response = makeRequest(connectionsBaseUrl + "/" + connection.getId(), "DELETE", null, authnToken);

        Assert.assertEquals("200", response);

        // make sure it's still exists
        connection = applicationManager.getConnectionService().getConnection(connection.getId());
        assertNotNull(connection);

        // make sure you account object has it in the blacklisted list
        //boolean exists =
        Account account = applicationManager.getUserService().getAccount(testUser.getAccount().getId());
        assertFalse(!account.getPublicConnectionBlacklist().contains(connection.getId()));

        // should not show up in your connection list now.
        String req = makeRequest(connectionsBaseUrl, "GET", null, authnToken);

        List<ConnectionResponseDTO> allConnections = jsonToObject(req,
                TypeFactory.defaultInstance().constructCollectionType(List.class, ConnectionResponseDTO.class));

        for(ConnectionResponseDTO connectionResponseDTO : allConnections) {
            assertFalse(connectionResponseDTO.getId().equals(connection.getId()));
        }

    }
View Full Code Here

    public void testConnectionToDTO() {
        GitHubProjectHostingProvider mockProvider = Mockito.mock(GitHubProjectHostingProvider.class);
        when(mockProvider.getId()).thenReturn(ProviderIdConstants.GITHUB_PROVIDER_ID);
        when(mockProvider.getType()).thenReturn(ProjectHostingProvider.TYPE);

        Connection c = new Connection.Builder()
                .alias("test github")
                .description("test github")
                .visibility(SobaObject.Visibility.PUBLIC)
                .provider(mockProvider)
                .user(testUser)
                .url("http://someUrl" )
                .authType(AuthType.NONE)
                .outboundConfigurations(
                        new OutboundConfiguration.Builder()
                                .credentials(new ConnectionCredentials("accessKey", "secretKey" ))
                                .protocol("s3" )
                                .destination("my.bucket.name" )
                                .namespace("/key/prefix/here/" )
                                .dataTypes(OutboundDataType.PROCESSED)
                                .build()
                )
                .build();

        when(testResource.toFullDTO(any(Connection.class))).thenCallRealMethod();
        when(testResource.toOwnerDTO(any(Connection.class),any(ConnectionResponseDTO.class))).thenCallRealMethod();
        ConnectionResponseDTO dto = testResource.toFullDTO(c);

        //Test some fields
        Assert.assertEquals(AuthType.NONE, dto.getAuthType());
        Assert.assertEquals(c.getAlias(), dto.getAlias());
        Assert.assertEquals(c.getUrl(), dto.getUrl());

        List<OutboundConfigurationResponseDTO> outboundDTOs = dto.getOutboundConfigurations();
        Assert.assertEquals(1, outboundDTOs.size());
        Assert.assertEquals("s3", outboundDTOs.get(0).getProtocol());
        Assert.assertEquals("my.bucket.name", outboundDTOs.get(0).getDestination());
View Full Code Here

public class ConnectionResourceITCase extends BaseConnectionResourceITCase {

    @Test
    @Ignore
    public void testRemoveTag() {
        Connection stubConnection = new Connection.Builder()
                .user(testUser)
                .provider(mock(ConnectionProvider.class))
                .authType(AuthType.NONE)
                .hashtags(Sets.newHashSet("foo", "bar", "baz", "github"))
                .alias("stubConnection")
                .visibility(SobaObject.Visibility.ACCOUNT)
                .build();

        connectionDAO.save(stubConnection);

        for (int i = 0; i < 100; i++) { // create 100 inventory items
            InventoryItem item = new InventoryItem.Builder()
                    .connection(stubConnection)
                    .hashtags(Sets.newHashSet("#foo", "#bar", "#baz", "#github"))
                    .alias("stubItem" + Integer.toString(i))
                    .description("stubItem:  " + Integer.toString(i))
                    .user(testUser)
                    .type("stub")
                    .visibility(SobaObject.Visibility.ACCOUNT)
                    .metadataId(new ObjectId())
                    .externalId("testKey")
                    .build();

            inventoryItemDAO.save(item);
        }

        long before = System.currentTimeMillis();
        connectionResource.removeTag(stubConnection.getId().toString(), "#baz");
        long after = System.currentTimeMillis();

        long lengthInMillis = after - before;
        Assert.assertTrue(lengthInMillis < TimeUnit.SECONDS.toMillis(1));
        logger.info("Seconds taken to remove tags is " + lengthInMillis / 1000.0);

        Set<String> expectedTags = Sets.newHashSet("#foo", "#bar", "#github");

        Connection updatedStubConnection = connectionDAO.get(stubConnection.getId());
        assertEquals(expectedTags, updatedStubConnection.getHashtags());

        List<InventoryItem> inventoryItems = inventoryItemDAO.getInventoryItems(updatedStubConnection.getId());
        for (InventoryItem updatedItem : inventoryItems) {
            assertEquals(expectedTags, updatedItem.getHashtags());
        }
    }
View Full Code Here

        }
    }

    private OutboundConfiguration createOutboundConfigurationFromDto(OutboundConfigurationServiceDTO dto) {
        try {
            Connection originatingConnection = connectionService.getConnection(dto.getOriginatingConnectionId());
            return new OutboundConfiguration.Builder()
                    .protocol(dto.getProtocol())
                    .destination(dto.getDestination())
                    .namespace(dto.getNamespace())
                    .dataTypes(dto.getDataTypes().toArray(new OutboundDataType[dto.getDataTypes().size()]))
View Full Code Here

TOP

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

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.