@Override public ListResult<Extension> list(UriInfo uriInfo) { // Defaulting to display only Installed extensions String query = uriInfo.getQueryParameters().getFirst("query"); if (query == null) { query = "status=" + Extension.Status.Installed; } ListResult<Extension> extensions = getDataManager().fetchAll( Extension.class, new ReflectiveFilterer<>(Extension.class, FilterOptionsParser.fromString(query)), new ReflectiveSorter<>(Extension.class, new SortOptionsFromQueryParams(uriInfo)), new PaginationFilter<>(new PaginationOptionsFromQueryParams(uriInfo)) ); List<Extension> enhanced = extensions.getItems().stream() .map(this::enhance) .collect(Collectors.toList()); return new ListResult.Builder<Extension>() .items(enhanced) .totalCount(extensions.getTotalCount()) .build(); }
@Test public void testDeletedIntegrationsCurator() throws IOException, ParseException { String integrationId = "intId1"; Set<String> livePodIds = new HashSet<String>( Arrays.asList("pod1", "pod2")); Map<String,RawMetrics> metrics = jsondbRM.getRawMetrics(integrationId); IntegrationMetricsSummary summary = intMH.compute(integrationId, metrics, livePodIds); dataManager.create(summary); assertThat(metrics.size()).isEqualTo(3); assertThat(dataManager.fetchAll(IntegrationMetricsSummary.class).getTotalCount()).isEqualTo(1); //Now pretend to delete the integration itself and //run the curator with no active integrations jsondbRM.curate(new HashSet<String>()); intMH.curate(new HashSet<String>()); //expect all metrics to be deleted Map<String,RawMetrics> metricsAfter = jsondbRM.getRawMetrics(integrationId); assertThat(metricsAfter.size()).isEqualTo(0); assertThat(dataManager.fetchAll(IntegrationMetricsSummary.class).getTotalCount()).isEqualTo(0); } }
@Test public void getConnectors() { @SuppressWarnings("unchecked") ListResult<Connector> connectors = dataManager.fetchAll(Connector.class); assertThat(connectors.getItems().stream().map(Connector::getId).map(Optional::get)) .containsExactlyInAnyOrder("activemq", "amqp", "ftp","sftp", "sql", "salesforce", "twitter", "aws-s3", "mqtt"); Assert.assertTrue(connectors.getTotalCount() > 1); Assert.assertTrue(connectors.getItems().size() > 1); Assert.assertEquals(connectors.getTotalCount(), connectors.getItems().size()); }
@Test public void getConnections() { ListResult<Connection> connections = dataManager.fetchAll(Connection.class); assertThat(connections.getItems().stream().map(Connection::getId).map(Optional::get)).containsOnly("5"); Assert.assertEquals(1, connections.getTotalCount()); Assert.assertEquals(1, connections.getItems().size()); Assert.assertEquals(connections.getTotalCount(), connections.getItems().size()); }
@Test public void getConnectorsWithFilterFunction() { @SuppressWarnings("unchecked") ListResult<Connector> connectors = dataManager.fetchAll( Connector.class, resultList -> new ListResult.Builder<Connector>() .createFrom(resultList) .items(resultList.getItems().stream() .filter(connector -> connector.getId().get().equals("twitter") || connector.getId().get().equals("activemq")) .collect(Collectors.toList())) .build() ); assertThat(connectors.getItems().stream().map(Connector::getId).map(Optional::get)).containsExactlyInAnyOrder("twitter", "activemq"); Assert.assertEquals(9, connectors.getTotalCount()); Assert.assertEquals(2, connectors.getItems().size()); }
@Test public void noParams() { ListResult<TestPersonInterface> toSort = new ListResult.Builder<TestPersonInterface>().items(getTestData()).totalCount(getTestData().size()).build(); Function<ListResult<TestPersonInterface>, ListResult<TestPersonInterface>> operator = new ReflectiveSorter<>(TestPersonInterface.class, getOptions(null, null)); ListResult<TestPersonInterface> sorted = operator.apply(toSort); String[] expectedNames = { "Schrödinger", "Heisenberg", "Feynman", "Maxwell", }; for (int i = 0; i < expectedNames.length; i++) { assertEquals(sorted.getItems().get(i).getLastName(), expectedNames[i]); } assertEquals(getTestData().size(), sorted.getTotalCount()); }
@Test public void noParams() { ListResult<TestPersonInterface> toSort = new ListResult.Builder<TestPersonInterface>().items(getTestData()).totalCount(getTestData().size()).build(); Function<ListResult<TestPersonInterface>, ListResult<TestPersonInterface>> operator = new ReflectiveSorter<>(TestPersonInterface.class, getOptions(null, null)); ListResult<TestPersonInterface> sorted = operator.apply(toSort); String[] expectedNames = { "Schrödinger", "Heisenberg", "Feynman", "Maxwell", }; for (int i = 0; i < expectedNames.length; i++) { assertEquals(sorted.getItems().get(i).getLastName(), expectedNames[i]); } assertEquals(getTestData().size(), sorted.getTotalCount()); }
@Test public void apply() throws Exception { try { ListResult<Integer> filtered = new PaginationFilter<Integer>(new PaginationOptions() { @Override public int getPage() { return PaginationFilterTest.this.parameter.page; } @Override public int getPerPage() { return PaginationFilterTest.this.parameter.perPage; } }).apply(new ListResult.Builder<Integer>().items(parameter.inputList).totalCount(parameter.inputList.size()).build()); assertEquals(parameter.outputList, filtered.getItems()); assertEquals(parameter.inputList.size(), filtered.getTotalCount()); } catch (Exception e) { if (parameter.expectedException == null) { throw e; } assertEquals(parameter.expectedException, e.getClass()); return; } if (parameter.expectedException != null) { fail("Expected exception " + parameter.expectedException); } }
@Test public void apply() throws Exception { try { ListResult<Integer> filtered = new PaginationFilter<Integer>(new PaginationOptions() { @Override public int getPage() { return PaginationFilterTest.this.parameter.page; } @Override public int getPerPage() { return PaginationFilterTest.this.parameter.perPage; } }).apply(new ListResult.Builder<Integer>().items(parameter.inputList).totalCount(parameter.inputList.size()).build()); assertEquals(parameter.outputList, filtered.getItems()); assertEquals(parameter.inputList.size(), filtered.getTotalCount()); } catch (Exception e) { if (parameter.expectedException == null) { throw e; } assertEquals(parameter.expectedException, e.getClass()); return; } if (parameter.expectedException != null) { fail("Expected exception " + parameter.expectedException); } }
@Test public void findTags() { Integration integration = new Integration.Builder() .addTag("tag1") .addTag("tag2") .build(); Connection connection = new Connection.Builder() .addTag("tag2") .addTag("tag3") .build(); ListResult<String> allTags = new TagFinder() .add(ListResult.of(integration)) .add(ListResult.of(connection)) .getResult(); Assert.assertEquals( 3, allTags.getTotalCount()); Assert.assertTrue(allTags.getItems().contains("tag1") ); Assert.assertTrue(allTags.getItems().contains("tag2") ); Assert.assertTrue(allTags.getItems().contains("tag3") ); }