Package com.streamreduce.core.model

Examples of com.streamreduce.core.model.Connection


    @Ignore("Integration Tests depended on sensitive account keys, ignoring until better harness is in place.")
    public void testRefreshFeedMessagesSavesFeedEntryDetails() throws Exception {
        //Integration test that ensures that a SobaMessage saved from a feed entry persists its FeedEntryDetails and
        //that those same FeedEntryDetails are retrievable from the MessageService.

        Connection sampleFeedConnection = testService.createSampleRssFeedPrivateConnectionAndRefresh(testUser);

        //Attempt to retrieve these messages, and filter out only those from our connection and that have MessageDetails
        //of type FEED_ENTRY.
        List<SobaMessage> messages = messageService.getAllMessages(testUser,null,null,0,false,null,null,sampleFeedConnection.getId().toString(),false);
        List onlyFeedEntries = Lists.newArrayList(Iterables.filter(messages, new Predicate<SobaMessage>() {
            @Override
            public boolean apply(@Nullable SobaMessage message) {
                return (message != null && message.getDetails() != null) &&
                    message.getDetails().getMessageDetailsType() == MessageDetailsType.FEED_ENTRY;
View Full Code Here


public class OutboundStorageServiceImplTest {

    @Test
    public void testSendRawMessageNullPayload() throws Exception {
        //Tests that sending a Null payload as a raw message does not write to any outbound connections.
        Connection connection = TestUtils.createTestFeedConnection(OutboundDataType.RAW);
        OutboundStorageServiceImpl outboundStorageService = new OutboundStorageServiceImpl();
        Assert.assertEquals(0,outboundStorageService.sendRawMessage(null, connection));
    }
View Full Code Here

        Assert.assertEquals(0,outboundStorageService.sendRawMessage(null, connection));
    }

    @Test
    public void testSendRawMessage_noOutbound() throws Exception {
        Connection connection = Mockito.mock(Connection.class);
        Account account = Mockito.mock(Account.class);
        Mockito.when(connection.getAccount()).thenReturn(account);
        HashSet<OutboundConfiguration> outboundConfigurations = Sets.newHashSet(Mockito.mock(OutboundConfiguration.class));
        Mockito.when(connection.getOutboundConfigurations()).thenReturn(outboundConfigurations);

        OutboundStorageServiceImpl outboundStorageService = new OutboundStorageServiceImpl();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("test", "foo");
        Assert.assertEquals(0,outboundStorageService.sendRawMessage(jsonObject, connection));
View Full Code Here

    }

    @Test
    public void testSendRawMessage_toConnectionWithNoOutboundConfigs() throws Exception {
        //sendRawMessage should return 0 for the number of messages that were actually sent.
        Connection connection = TestUtils.createTestFeedConnection();
        OutboundStorageServiceImpl outboundStorageService = new OutboundStorageServiceImpl();
        Assert.assertEquals(0,outboundStorageService.sendRawMessage(TestUtils.createValidSampleIMGPayload(), connection));
    }
View Full Code Here

    }

    @Test
    public void testSendRawMessageConnectionRawNotInOutbounds() throws Exception {
        //Tests that sending a Null payload as a raw message does not write to any outbound connections.
        Connection connection = TestUtils.createTestFeedConnection(OutboundDataType.PROCESSED);
        OutboundStorageServiceImpl outboundStorageService = new OutboundStorageServiceImpl();
        Assert.assertEquals(0,outboundStorageService.sendRawMessage(TestUtils.createValidSampleIMGPayload(), connection));
    }
View Full Code Here

        super.setUp();

        // we know this user has inventory items right now...
        // just grab the first one we find.
        User user = userService.getUser(Constants.NODEABLE_SUPER_USERNAME);
        Connection cloud = connectionService.getConnections(CloudProvider.TYPE, user).get(0);
        List<InventoryItem> inventoryItems = inventoryService.getInventoryItems(cloud);
        int retry = 0;

        while (inventoryItems.size() == 0 && retry < 3) {
            Thread.sleep(30000);
View Full Code Here

        Mockito.verify(mockAmazonSimpleEmailServiceClient, never()).sendEmail(null);
    }

    @Test
    public void testConnectionBrokenEmail() throws Exception {
        Connection mockConnection = mock(Connection.class);
        when(mockConnection.getId()).thenReturn(new ObjectId());
        when(mockConnection.getAccount()).thenReturn(testAccount);
        when(mockConnection.getAlias()).thenReturn("My Test Connection");

        when(mockUserService.getAccountAdmin(testAccount)).thenReturn(testUser);

        testSenderUser.setId(new ObjectId());
        emailService.sendConnectionBrokenEmail(mockConnection);
View Full Code Here

        when(mockSecurityService.getCurrentUser()).thenThrow(new AuthenticationException());
        ReflectionTestUtils.setField(eventService, "securityService", mockSecurityService);


        // Test creating a SobaObject event with no logged in user
        Connection connection = new Connection.Builder()
                .provider(connectionProviderFactory.connectionProviderFromId(ProviderIdConstants.GITHUB_PROVIDER_ID))
                .account(testAccount)
                .alias("Test GitHub Connection")
                .description("This is a test GitHub connection.")
                .user(testUser)
View Full Code Here

                expectedObjectMetadata.put("targetFuid", tAccount.getFuid());
                expectedObjectMetadata.put("targetName", tAccount.getName());
            } else if (expectedTarget instanceof InventoryItem) {
                InventoryItem tInventoryItem = (InventoryItem) expectedTarget;
                Connection tConnection = tInventoryItem.getConnection();
                ConnectionProvider tConnectionProvider =
                        applicationManager.getConnectionProviderFactory()
                                .connectionProviderFromId(tConnection.getProviderId());
                Map<String, Object> expectedInventoryItemMetadata = new HashMap<>();
                InventoryService inventoryService = applicationManager.getInventoryService();

                expectedObjectMetadata.put("targetExternalId", tInventoryItem.getExternalId());

                expectedInventoryItemMetadata.put("targetConnectionId", tConnection.getId());
                expectedInventoryItemMetadata.put("targetConnectionAlias", tConnection.getAlias());
                expectedInventoryItemMetadata.put("targetConnectionHashtags", tConnection.getHashtags());
                expectedInventoryItemMetadata.put("targetConnectionVersion", tConnection.getVersion());
                expectedInventoryItemMetadata.put("targetProviderId", tConnectionProvider.getId());
                expectedInventoryItemMetadata.put("targetProviderDisplayName", tConnectionProvider.getDisplayName());
                expectedInventoryItemMetadata.put("targetProviderType", tConnectionProvider.getType());

                if (tInventoryItem.getConnection().getProviderId().equals(ProviderIdConstants.AWS_PROVIDER_ID)) {
                    Location zone = inventoryService.getLocationByScope(tInventoryItem, LocationScope.ZONE);
                    Location region = inventoryService.getLocationByScope(tInventoryItem, LocationScope.REGION);
                    Set<String> iso3166Codes = zone != null ? zone.getIso3166Codes() : null;
                    String iso3166Code = iso3166Codes != null && iso3166Codes.size() >= 1 ?
                            iso3166Codes.iterator().next() :
                            null;

                    if (tInventoryItem.getType().equals(Constants.COMPUTE_INSTANCE_TYPE)) {
                        expectedObjectMetadata.put("targetIP",
                                inventoryService.getComputeInstanceIPAddress(tInventoryItem));
                        expectedObjectMetadata.put("targetOS",
                                inventoryService.getComputeInstanceOSName(tInventoryItem));
                    }

                    if (iso3166Code != null) {
                        expectedObjectMetadata.put("targetISO3166Code", iso3166Code);
                    }
                    if (zone != null) {
                        expectedObjectMetadata.put("targetZone", zone.getId());
                    }
                    if (region != null) {
                        expectedObjectMetadata.put("targetRegion", region.getId());
                    }
                }

                validateEventMetadata(eventMetadata, expectedInventoryItemMetadata, true);
            } else if (expectedTarget instanceof Connection) {
                Connection tConnection = (Connection) expectedTarget;
                ConnectionProvider tConnectionProvider = applicationManager.getConnectionProviderFactory()
                        .connectionProviderFromId(
                                tConnection.getProviderId());

                expectedObjectMetadata.put("targetProviderId", tConnectionProvider.getId());
                expectedObjectMetadata.put("targetProviderDisplayName", tConnectionProvider.getDisplayName());
                expectedObjectMetadata.put("targetProviderType", tConnectionProvider.getType());
            } else if (expectedTarget instanceof User) {
View Full Code Here

    @Autowired
    ConnectionProviderFactory connectionProviderFactory;

    @Test
    public void testGitHubConnectionCRUD() throws Exception {
        Connection tmpConnection = new Connection.Builder()
                .alias("Nodeable GitHub")
                .description("Nodeable's GitHub instance.")
                .credentials(new ConnectionCredentials("fakeusername", "fakepassword"))
                .provider(connectionProviderFactory.connectionProviderFromId(ProviderIdConstants.GITHUB_PROVIDER_ID))
                .user(testUser)
                .authType(AuthType.USERNAME_PASSWORD)
                .build();

        /* Test creating an invalid connection (invalid credentials) */
        try {
            connectionService.createConnection(tmpConnection);
            fail("Should not be able to create a Jira connection with invalid credentials.");
        } catch (InvalidCredentialsException e) {
            // Expected
        }

        tmpConnection.setCredentials(new ConnectionCredentials(gitHubProperties.getString("nodeable.github.username"),
                gitHubProperties.getString("nodeable.github.password")));

        /* Test creating a valid connection */
        Connection connection = connectionService.createConnection(tmpConnection);

        assertNotNull(connection.getId());

        /* Verify the projects returned look like what we expect.  (This is fragile and depends on us knowing
           the projects the GitHub user we're testing with watches, owns and has access to as part of an org.
         */
        validateGitHubProjectHostingInventoryItems(connection);
        pollForProjectHostingActivity(connection);

        /* Test reading a connection (invalid id) */
        try {
            connectionService.getConnection(new ObjectId());
            fail("Should not be able to find a GitHub connection with an invalid id.");
        } catch (ConnectionNotFoundException e) {
            // Expected
        }

        /* Test reading a connection */
        connection = connectionService.getConnection(connection.getId());

        assertNotNull(connection);

        /* Test reading all GitHub connections */
        assertEquals(1, connectionService.getConnections(ProjectHostingProvider.TYPE, testUser).size());

        /* Test updating a connection (invalid credentials) */
        connection.setCredentials(new ConnectionCredentials("fakeusername", "fakepassword"));

        try {
            connectionService.createConnection(connection);
            fail("Should not be able to create a GitHub connection with invalid credentials.");
        } catch (InvalidCredentialsException e) {
            // Expected
        }

        /* Test updating a connection */
        connection.setCredentials(new ConnectionCredentials(gitHubProperties.getString("nodeable.github.username"),
                gitHubProperties.getString("nodeable.github.password")));
        connection.setDescription("Updated description.");

        connection = connectionService.updateConnection(connection);

        assertEquals("Updated description.", connectionService.getConnection(connection.getId()).getDescription());

        /* Test deleting a connection */
        connectionService.deleteConnection(connection);

        try {
            connectionService.getConnection(connection.getId());
            fail("Should not be able to find a GitHub connection with a deleted id.");
        } catch (ConnectionNotFoundException e) {
            // Expected
        }
    }
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.