@Test public void refresh() throws Exception { final Reddit reddit = new Reddit(); PublishSubject<Reddit> subject = PublishSubject.create(); Mockito.doReturn(subject.asObservable().toList()) .when(mRepository) .getReddits(Mockito.anyString()); mViewModel.refresh(); Mockito.verify(mRepository).getReddits("test"); Assert.assertThat(mViewModel.errorText.get(), IsNull.nullValue()); Assert.assertThat(mViewModel.isLoading.get(), Is.is(true)); subject.onNext(reddit); subject.onCompleted(); Assert.assertThat(mViewModel.isLoading.get(), Is.is(false)); Assert.assertThat(mViewModel.reddits, IsCollectionContaining.hasItems(reddit)); }
@Test public void searchQueryChange() throws Exception { final Subreddit subreddit = new Subreddit(); PublishSubject<Subreddit> subject = PublishSubject.create(); Mockito.doReturn(subject.asObservable().toList()) .when(mRepository) .searchSubreddits(Mockito.anyString()); mViewModel.subscribeOnSearchQueryChange(); mViewModel.mSearchQuery.onNext("test"); Mockito.verify(mRepository).searchSubreddits("test"); Assert.assertThat(mViewModel.isLoading.get(), Is.is(true)); subject.onNext(subreddit); subject.onCompleted(); Assert.assertThat(mViewModel.isLoading.get(), Is.is(false)); Assert.assertThat(mViewModel.subreddits, IsCollectionContaining.hasItems(subreddit)); }
private void verifyResults(final CloseableIterable<? extends Element> resultsItr) { final Edge[] expectedResults = { new Edge.Builder() .group("RoadUse") .source("10") .dest("11") .directed(true) .property("visibility", "public") .property("count", 3L) .build(), new Edge.Builder() .group("RoadUse") .source("11") .dest("10") .directed(true) .property("visibility", "public") .property("count", 1L) .build() }; final List<Element> results = Lists.newArrayList(resultsItr); assertEquals(expectedResults.length, results.size()); assertThat(results, IsCollectionContaining.hasItems(expectedResults)); }
private void verifyResults(final CloseableIterable<? extends Element> resultsItr) { final Edge[] expectedResults = { new Edge.Builder() .group("RoadUse") .source("10") .dest("11") .directed(true) .property("count", 3L) .build(), new Edge.Builder() .group("RoadUse") .source("11") .dest("10") .directed(true) .property("count", 1L) .build() }; final List<Element> results = Lists.newArrayList(resultsItr); assertEquals(expectedResults.length, results.size()); assertThat(results, IsCollectionContaining.hasItems(expectedResults)); }
private void verifyResults(final CloseableIterable<? extends Element> resultsItr) { final Edge[] expectedResults = { new Edge.Builder() .source("10") .dest("11") .directed(true) .group("RoadUse") .property("count", 1L) .property("startDate", Aggregation.MAY_01_2000) .property("endDate", new Date(Aggregation.MAY_03_2000.getTime() - 1)) .build() }; final List<Element> results = Lists.newArrayList(resultsItr); assertEquals(expectedResults.length, results.size()); assertThat(results, IsCollectionContaining.hasItems(expectedResults)); }
private void verifyResults(final CloseableIterable<? extends Element> resultsItr) { final Edge[] expectedResults = { new Edge.Builder() .group("RoadUse") .source("10") .dest("11") .directed(true) .property("description", "3 vehicles have travelled between junction 10 and junction 11") .build(), new Edge.Builder() .group("RoadUse") .source("11") .dest("10") .directed(true) .property("description", "1 vehicles have travelled between junction 11 and junction 10") .build() }; final List<Element> results = Lists.newArrayList(resultsItr); assertEquals(expectedResults.length, results.size()); assertThat(results, IsCollectionContaining.hasItems(expectedResults)); }
@Test public void shouldReturnSubclasses() throws IOException { // When final Set<Class> subclasses = ReflectionUtil.getSubTypes(Number.class); // Then assertThat(subclasses, Matchers.allOf( IsCollectionContaining.hasItems( TestCustomNumber.class, uk.gov.gchq.koryphe.serialisation.json.obj.second.TestCustomNumber.class ), Matchers.not(IsCollectionContaining.hasItems(UnsignedLong.class)) ) ); }
@Test public void shouldGetStringArrayWhenParsingArrayNode() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); List<JsonNode> subNodes = new ArrayList<>(); TextNode textNode1 = new TextNode("one"); TextNode textNode2 = new TextNode("two"); subNodes.add(textNode1); subNodes.add(textNode2); ArrayNode arrNode = new ArrayNode(JsonNodeFactory.instance, subNodes); tree.put("key", arrNode); List<String> values = deserializer.getStringOrArray(tree, "key"); assertThat(values, is(notNullValue())); assertThat(values, is(IsCollectionWithSize.hasSize(2))); assertThat(values, is(IsCollectionContaining.hasItems("one", "two"))); }
@Test public void testSplittingDrivers() { final List<InputDriver> subDriverList = createSubInputDrivers("test"); final InputDriver subDriver = new GroupDriver("sub1", subDriverList); final List<InputDriver> drivers = new ArrayList<>(2); drivers.add(subDriver); drivers.add(new StringDriver("string1")); drivers.add(new RegexDriver("regex.?")); final GroupDriver group = new GroupDriver("group", drivers); assertNotNull(group); assertThat(group.convertDrivers(), IsCollectionContaining.hasItems("string1", "regex.?", "VG:sub1:test1:test2:test3:tes.?4")); final List<String> nonGroupDrivers = new ArrayList<>(); final List<String> groupDrivers = new ArrayList<>(); GroupDriver.convertDriversIntoDriversAndGroups(Arrays.asList(group.getSubDrivers(false)), nonGroupDrivers, groupDrivers); assertEquals("VG:sub1:test1:test2:test3:tes.?4", groupDrivers.get(0)); assertThat(nonGroupDrivers, IsCollectionContaining.hasItems("string1", "regex.?")); }
@Test public void testEvaluatorWithRegexMultipleRules() { final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = CommisionRuleSetSupplier.getCommissionRuleSetWithRegex(); final DecisionTreeRuleSet ruleSet = ruleSetBuilder.build(); final TreeNode node = constructTree(ruleSet); final List<EvaluationResult> results = Evaluator.evaluateAllResults(Arrays.asList("ELECTRONIC", "CME", "S&P", "US", "INDEX"), null, node); assertNotNull(results); assertEquals(3, results.size()); final List<UUID> idResults = results.stream().map(EvaluationResult::getRuleIdentifier) .collect(Collectors.toList()); assertThat(idResults, IsCollectionContaining.hasItems(new UUID(0, 0), new UUID(0, 1), new UUID(0, 7))); final Optional<UUID> result = Evaluator.singleEvaluate(Arrays.asList("ELECTRONIC", "CME", "S&P", "US", "INDEX"), null, node); assertTrue(result.isPresent()); assertEquals(new UUID(0, 7), result.get()); }
@Test public void testFindByType() { final DriverCache cache = new DriverCache(); final InputDriver stringDriver = new StringDriver("testString1"); final InputDriver stringDriver2 = new StringDriver("testString2"); final InputDriver regexDriver = new RegexDriver("tes.?"); final InputDriver groupDriver = new GroupDriver("testGroup", Arrays.asList( new StringDriver("testSub1"), new StringDriver("testSub2"))); cache.put(stringDriver); cache.put(stringDriver2); cache.put(regexDriver); cache.put(groupDriver); final List<InputDriver> regexResults = cache.findByInputDriverType(InputValueType.REGEX); assertNotNull(regexResults); assertEquals(regexDriver, regexResults.get(0)); final List<InputDriver> groupDrivers = cache.findByInputDriverType(InputValueType.VALUE_GROUP); assertEquals(groupDriver, groupDrivers.get(0)); final List<InputDriver> stringDrivers = cache.findByInputDriverType(InputValueType.STRING); assertThat(stringDrivers, IsCollectionContaining.hasItems(stringDriver, stringDriver2)); }
@Test public void testFindingInputDrivers() { final DecisionTreeRuleSet commisssionRuleSet = CommisionRuleSetSupplier.getCommissionRuleSetWithRegex().build(); List<InputDriver> driversByType = commisssionRuleSet.getDriversByType(InputValueType.STRING); assertNotNull(driversByType); assertEquals(11, driversByType.size()); assertThat(driversByType, IsCollectionContaining.hasItems(new StringDriver("VOICE"), new StringDriver("RATE"), new StringDriver("UK"), new StringDriver("*"), new StringDriver("CME"), new StringDriver("INDEX"), new StringDriver("S&P"), new StringDriver("US"), new StringDriver("ED"), new StringDriver("NDK"))); driversByType = commisssionRuleSet.getDriversByType(InputValueType.REGEX); assertNotNull(driversByType); assertEquals(3, driversByType.size()); assertThat(driversByType, IsCollectionContaining.hasItems(new RegexDriver("AP.?C"), new RegexDriver("C.?E"), new RegexDriver("^[A-Z]{1,2}[A-Z][0-9]{1,2}$"))); }
@Test public void convertStringToGroupDriver() { final DriverCache cache = new DriverCache(); final String testString = "VG:TestGroup:Test1:Test2:Test3"; final Supplier<InputDriver> groupSupplier = DomainSerialiser.createInputDriver(testString, cache); final InputDriver groupDriver = groupSupplier.get(); assertNotNull(groupDriver); assertEquals("TestGroup", groupDriver.getValue()); assertEquals(InputValueType.VALUE_GROUP, groupDriver.getType()); assertEquals(groupDriver, cache.get("TestGroup", InputValueType.VALUE_GROUP)); final InputDriver[] drivers = ((GroupDriver) groupDriver).getSubDrivers(false); final InputDriver[] expected = {new StringDriver("Test1"), new StringDriver("Test2"), new StringDriver("Test3")}; assertThat(Arrays.asList(drivers), IsCollectionContaining.hasItems(expected)); List<String> serialisedDrivers = DomainSerialiser.convertDriversWithSubGroups(Arrays.asList(groupDriver)); assertNotNull(serialisedDrivers); assertEquals(1, serialisedDrivers.size()); assertEquals(testString, serialisedDrivers.get(0)); serialisedDrivers = DomainSerialiser.convertDrivers(new InputDriver[]{groupDriver}); assertNotNull(serialisedDrivers); assertEquals(1, serialisedDrivers.size()); assertEquals(groupDriver.toString(), serialisedDrivers.get(0)); }
@Test @Ignore("The support for a blank token at the end is not working. Putting in test and will return to it.") public void testEmptyTokensAtEndOfGroupDriver() { final DriverCache cache = new DriverCache(); final String testString = "VG:TestGroup:Test1:Test2:Test3::VG:SubGroup:Test4:Test5:"; final Supplier<InputDriver> groupSupplier = DomainSerialiser.createInputDriver(testString, cache); final InputDriver groupDriver = groupSupplier.get(); assertNotNull(groupDriver); final InputDriver[] drivers = ((GroupDriver) groupDriver).getSubDrivers(false); final InputDriver[] expectedList = new InputDriver[]{ new StringDriver("Test1"), new StringDriver("Test2"), new StringDriver("Test3"), new StringDriver(""), new GroupDriver("SubGroup", Arrays.asList(new StringDriver("Test4"), new StringDriver("Test5"), new StringDriver("")))}; assertEquals(expectedList.length, drivers.length); assertThat(Arrays.asList(drivers), IsCollectionContaining.hasItems(expectedList)); final List<String> serialisedDrivers = DomainSerialiser.convertDrivers(new InputDriver[]{groupDriver}); assertEquals(testString, serialisedDrivers.get(0)); }
@Test public void testConvertGroupDrivers() { final Builder<RuleBuilder, DecisionTreeRule> ruleBuilder = RuleBuilder.creator(); final DriverCache cache = new DriverCache(); final List<String> testInputs = Arrays.asList("VG:VG1:test1:test2:test3:test4", "singleTest", "VG:VG2:test10:test20:test30:test40:VG:VG3:test50:test9.?:test200.*"); ruleBuilder.with(RuleBuilder::input, testInputs); ruleBuilder.with(RuleBuilder::cache, cache); ruleBuilder.with(RuleBuilder::setDriverCount, 3L); ruleBuilder.with(RuleBuilder::setId, new UUID(0, 1)); ruleBuilder.with(RuleBuilder::output, Collections.singletonMap("outputDriver", "result")); final DecisionTreeRule rule = ruleBuilder.build(); assertNotNull(rule); final InputDriver[] derivedInputDrivers = rule.getDrivers(); List<String> result = DomainSerialiser.convertDriversWithSubGroups(Arrays.asList(derivedInputDrivers)); assertNotNull(result); assertEquals(testInputs, result); result = DomainSerialiser.convertDrivers(derivedInputDrivers); assertNotNull(result); assertThat(result, IsCollectionContaining.hasItems("VG:VG1", "singleTest", "VG:VG2")); }
@Test public void shouldNotRemoveKnownPublicClaimsFromTree() throws Exception { JWT jwt = new JWT("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCIsInN1YiI6ImVtYWlscyIsImF1ZCI6InVzZXJzIiwiaWF0IjoxMDEwMTAxMCwiZXhwIjoxMTExMTExMSwibmJmIjoxMDEwMTAxMSwianRpIjoiaWRpZCIsInJvbGVzIjoiYWRtaW4ifQ.jCchxb-mdMTq5EpeVMSQyTp6zSwByKnfl9U-Zc9kg_w"); assertThat(jwt, is(notNullValue())); assertThat(jwt.getIssuer(), is("auth0")); assertThat(jwt.getSubject(), is("emails")); assertThat(jwt.getAudience(), is(IsCollectionContaining.hasItem("users"))); assertThat(jwt.getIssuedAt().getTime(), is(10101010L * 1000)); assertThat(jwt.getExpiresAt().getTime(), is(11111111L * 1000)); assertThat(jwt.getNotBefore().getTime(), is(10101011L * 1000)); assertThat(jwt.getId(), is("idid")); assertThat(jwt.getClaim("roles").asString(), is("admin")); assertThat(jwt.getClaim("iss").asString(), is("auth0")); assertThat(jwt.getClaim("sub").asString(), is("emails")); assertThat(jwt.getClaim("aud").asString(), is("users")); assertThat(jwt.getClaim("iat").asDouble(), is(10101010D)); assertThat(jwt.getClaim("exp").asDouble(), is(11111111D)); assertThat(jwt.getClaim("nbf").asDouble(), is(10101011D)); assertThat(jwt.getClaim("jti").asString(), is("idid")); }
@Test public void shouldFetchAllProgressCodes() throws Exception { //Given final ProgressDao dao = Mockito.mock(ProgressDao.class); final ProgressService service = new JujacoreProgressService( "", dao, Mockito.mock(SlackSession.class) ); Mockito.when(dao.fetchProgressCodes()).thenReturn(Arrays.asList( "+code1", "+code2", "+code1" )); //When final Set<String> codes = service.codes(); //Then MatcherAssert.assertThat( codes, IsCollectionWithSize.hasSize(2) ); MatcherAssert.assertThat( codes, IsCollectionContaining.hasItems( "+code1", "+code2" ) ); }
@Test public void shouldExcludeBlackListedCodes() throws Exception { //Given final ProgressDao dao = Mockito.mock(ProgressDao.class); final ProgressService service = new JujacoreProgressService( "+blackListCode1;+blackListCode2", dao, Mockito.mock(SlackSession.class) ); Mockito.when(dao.fetchProgressCodes()).thenReturn(Arrays.asList( "+code1", "+blackListCode1", "+blackListCode2", "+code2" )); //When final Set<String> actualProgressCodes = service.codes(); //Then MatcherAssert.assertThat( actualProgressCodes, IsCollectionWithSize.hasSize(2) ); MatcherAssert.assertThat( actualProgressCodes, IsCollectionContaining.hasItems( "+code1", "+code2" ) ); }
@Test public void shouldConvertToDomainObjects() throws OperationException, UnsupportedEncodingException { // Given final OperationChain<Iterable<? extends DomainObject>> opChain = new OperationChain.Builder() .first(new GetElements.Builder() .input(new EntitySeed(SOURCE_1)) .build()) .then(new GenerateObjects.Builder<DomainObject>() .generator(new BasicObjectGenerator()) .build()) .build(); // When final List<DomainObject> results = Lists.newArrayList(graph.execute(opChain, getUser())); final EntityDomainObject entityDomainObject = new EntityDomainObject(SOURCE_1, "3", null); final EdgeDomainObject edgeDomainObject = new EdgeDomainObject(SOURCE_1, DEST_1, false, 1, 1L); // Then assertNotNull(results); assertEquals(2, results.size()); assertThat(results, IsCollectionContaining.hasItems( entityDomainObject, edgeDomainObject)); }
private void shouldSummarise(final AccumuloStore store) throws OperationException { final View view = new View.Builder(defaultView) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .groupBy() .build()) .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .groupBy() .build()) .edge(TestGroups.EDGE_2, new ViewElementDefinition.Builder() .groupBy() .build()) .build(); final GetElementsWithinSet operation = new GetElementsWithinSet.Builder().view(view).input(seeds).build(); final GetElementsWithinSetHandler handler = new GetElementsWithinSetHandler(); final CloseableIterable<? extends Element> elements = handler.doOperation(operation, user, store); //After query compaction the result size should be 3 assertEquals(3, Iterables.size(elements)); assertThat((CloseableIterable<Element>) elements, IsCollectionContaining.hasItems(expectedSummarisedEdge, expectedEntity1, expectedEntity2)); elements.close(); }
private void shouldReturnOnlyEdgesWhenViewContainsNoEntities(final AccumuloStore store) throws OperationException { final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .groupBy() .build()) .edge(TestGroups.EDGE_2, new ViewElementDefinition.Builder() .groupBy() .build()) .build(); final GetElementsWithinSet operation = new GetElementsWithinSet.Builder().view(view).input(seeds).build(); final GetElementsWithinSetHandler handler = new GetElementsWithinSetHandler(); final CloseableIterable<? extends Element> elements = handler.doOperation(operation, user, store); final Collection<Element> forTest = new LinkedList<>(); Iterables.addAll(forTest, elements); //After query compaction the result size should be 1 assertEquals(1, Iterables.size(elements)); assertThat((CloseableIterable<Element>) elements, IsCollectionContaining.hasItem(expectedSummarisedEdge)); elements.close(); }
private void shouldReturnOnlyEntitiesWhenViewContainsNoEdges(final AccumuloStore store) throws OperationException { final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .groupBy() .build()) .build(); final GetElementsWithinSet operation = new GetElementsWithinSet.Builder().view(view).input(seeds).build(); final GetElementsWithinSetHandler handler = new GetElementsWithinSetHandler(); final CloseableIterable<? extends Element> elements = handler.doOperation(operation, user, store); //The result size should be 2 assertEquals(2, Iterables.size(elements)); assertThat((CloseableIterable<Element>) elements, IsCollectionContaining.hasItems(expectedEntity1, expectedEntity2)); elements.close(); }
private void shouldLoadElementsWhenMoreElementsThanFitInBatchScanner(final boolean loadIntoMemory, final AccumuloStore store) throws StoreException { store.getProperties().setMaxEntriesForBatchScanner("1"); // Query for all edges between the set {A0} and the set {A23} final GetElementsBetweenSets op = new GetElementsBetweenSets.Builder().input(AccumuloTestData.SEED_A0_SET).inputB(AccumuloTestData.SEED_A23_SET).view(defaultView).build(); final Set<Element> betweenA0A23results = returnElementsFromOperation(store, op, new User(), loadIntoMemory); assertEquals(2, betweenA0A23results.size()); assertThat(betweenA0A23results, IsCollectionContaining.hasItems(AccumuloTestData.EDGE_A0_A23, AccumuloTestData.A0_ENTITY)); // Query for all edges between set {A1} and the set {notpresent} - there shouldn't be any, but // we will get the entity for A1 final GetElementsBetweenSets secondOp = new GetElementsBetweenSets.Builder().input(AccumuloTestData.SEED_A1_SET).inputB(AccumuloTestData.NOT_PRESENT_ENTITY_SEED_SET).view(defaultView).build(); final Set<Element> betweenA1andNotPresentResults = returnElementsFromOperation(store, secondOp, new User(), loadIntoMemory); assertEquals(1, betweenA1andNotPresentResults.size()); assertThat(betweenA1andNotPresentResults, IsCollectionContaining.hasItem(AccumuloTestData.A1_ENTITY)); // Query for all edges between set {A1} and the set {A2} - there shouldn't be any edges but will // get the entity for A1 final GetElementsBetweenSets thirdOp = new GetElementsBetweenSets.Builder().input(AccumuloTestData.SEED_A1_SET).inputB(AccumuloTestData.SEED_A2_SET).view(defaultView).build(); final Set<Element> betweenA1A2Results = returnElementsFromOperation(store, thirdOp, new User(), loadIntoMemory); assertEquals(1, betweenA1A2Results.size()); assertThat(betweenA1A2Results, IsCollectionContaining.hasItem(AccumuloTestData.A1_ENTITY)); }
public static <T> Matcher<Iterable<? super T>> exactlyNItems(final int n, Matcher<? super T> elementMatcher) { return new IsCollectionContaining<T>(elementMatcher) { @Override protected boolean matchesSafely(Iterable<? super T> collection, Description mismatchDescription) { int count = 0; boolean isPastFirst = false; for (Object item : collection) { if (elementMatcher.matches(item)) { count++; } if (isPastFirst) { mismatchDescription.appendText(", "); } elementMatcher.describeMismatch(item, mismatchDescription); isPastFirst = true; } if (count != n) { mismatchDescription.appendText(". Expected exactly " + n + " but got " + count); } return count == n; } }; }
@Test public void testWriteBehind() throws Exception { final URL resource = XmlConfigurationTest.class.getResource("/configs/writebehind-cache.xml"); XmlConfiguration xmlConfig = new XmlConfiguration(resource); Collection<ServiceConfiguration<?>> serviceConfiguration = xmlConfig.getCacheConfigurations().get("bar").getServiceConfigurations(); assertThat(serviceConfiguration, IsCollectionContaining.<ServiceConfiguration<?>>hasItem(instanceOf(WriteBehindConfiguration.class))); serviceConfiguration = xmlConfig.newCacheConfigurationBuilderFromTemplate("example", Number.class, String.class).build().getServiceConfigurations(); assertThat(serviceConfiguration, IsCollectionContaining.<ServiceConfiguration<?>>hasItem(instanceOf(WriteBehindConfiguration.class))); for (ServiceConfiguration<?> configuration : serviceConfiguration) { if(configuration instanceof WriteBehindConfiguration) { BatchingConfiguration batchingConfig = ((WriteBehindConfiguration) configuration).getBatchingConfiguration(); assertThat(batchingConfig.getMaxDelay(), is(10L)); assertThat(batchingConfig.getMaxDelayUnit(), is(SECONDS)); assertThat(batchingConfig.isCoalescing(), is(false)); assertThat(batchingConfig.getBatchSize(), is(2)); assertThat(((WriteBehindConfiguration) configuration).getConcurrency(), is(1)); assertThat(((WriteBehindConfiguration) configuration).getMaxQueueSize(), is(10)); break; } } }
@SuppressWarnings("unchecked") @Test public void testAddingWriteBehindConfigurationAtCacheLevel() { CacheManagerBuilder<CacheManager> cacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder(); WriteBehindConfiguration writeBehindConfiguration = WriteBehindConfigurationBuilder.newBatchedWriteBehindConfiguration(Long.MAX_VALUE, SECONDS, 1) .concurrencyLevel(3) .queueSize(10) .build(); Class<CacheLoaderWriter<?, ?>> klazz = (Class<CacheLoaderWriter<?, ?>>) (Class) (SampleLoaderWriter.class); CacheManager cacheManager = cacheManagerBuilder.build(true); final Cache<Long, String> cache = cacheManager.createCache("cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, heap(100)) .add(writeBehindConfiguration) .add(new DefaultCacheLoaderWriterConfiguration(klazz)) .build()); Collection<ServiceConfiguration<?>> serviceConfiguration = cache.getRuntimeConfiguration() .getServiceConfigurations(); assertThat(serviceConfiguration, IsCollectionContaining.<ServiceConfiguration<?>>hasItem(instanceOf(WriteBehindConfiguration.class))); cacheManager.close(); }
@Test public void testSupportsMultipleAuthoritativeTierProviders() throws Exception { ServiceLocator.DependencySet dependencySet = dependencySet(); OnHeapStore.Provider cachingTierProvider = new OnHeapStore.Provider(); OffHeapStore.Provider authoritativeTierProvider = new OffHeapStore.Provider(); OffHeapDiskStore.Provider diskStoreProvider = new OffHeapDiskStore.Provider(); dependencySet.with(cachingTierProvider); dependencySet.with(authoritativeTierProvider); dependencySet.with(diskStoreProvider); dependencySet.with(mock(DiskResourceService.class)); ServiceLocator serviceLocator = dependencySet.build(); serviceLocator.startAllServices(); assertThat(serviceLocator.getServicesOfType(CachingTier.Provider.class), IsCollectionContaining.<CachingTier.Provider>hasItem(IsSame.<CachingTier.Provider>sameInstance(cachingTierProvider))); assertThat(serviceLocator.getServicesOfType(AuthoritativeTier.Provider.class), IsCollectionContaining.<AuthoritativeTier.Provider>hasItem(IsSame.<AuthoritativeTier.Provider>sameInstance(authoritativeTierProvider))); assertThat(serviceLocator.getServicesOfType(OffHeapDiskStore.Provider.class), IsCollectionContaining.<OffHeapDiskStore.Provider>hasItem(IsSame.<OffHeapDiskStore.Provider>sameInstance(diskStoreProvider))); }
@Test public void shouldShowAllRevisionsWhenFanInIsOff() { GitMaterial g1 = u.wf(new GitMaterial("g1"), "f1"); u.checkinInOrder(g1, "g1-1"); u.checkinInOrder(g1, "g1-2"); ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWithGroup("g1", "p1", u.m(g1)); ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWithGroup("g1", "p2", u.m(g1)); ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWithGroup("g2", "p3", u.m(p1), u.m(p2)); String p1_1 = u.runAndPass(p1, "g1-1"); String p2_1 = u.runAndPass(p2, "g1-2"); String p3_1 = u.runAndPass(p3, p1_1, p2_1); ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap("p3", 1, username, result); Node nodeForGit = graph.getNodesAtEachLevel().get(0).get(0); assertThat(nodeForGit.revisions().size(), is(2)); Collection<String> revisionStrings = collect(nodeForGit.revisions(), new Transformer() { @Override public String transform(Object o) { Revision revision = (Revision) o; return revision.getRevisionString(); } }); assertThat(revisionStrings, IsCollectionContaining.hasItems("g1-1", "g1-2")); }
public static <T> Matcher<Iterable<? super T>> exactlyNItems(final int n, final Matcher<? super T> elementMatcher) { return new IsCollectionContaining<T>(elementMatcher) { @Override protected boolean matchesSafely(Iterable<? super T> collection, Description mismatchDescription) { int count = 0; boolean isPastFirst = false; for (Object item : collection) { if (elementMatcher.matches(item)) { count++; } if (isPastFirst) { mismatchDescription.appendText(", "); } elementMatcher.describeMismatch(item, mismatchDescription); isPastFirst = true; } if (count != n) { mismatchDescription.appendText(". Expected exactly " + n + " but got " + count); } return count == n; } }; }
@Test public void testGetAccountTimesheets() throws Exception { Config userConfig = DbTemplate.getList("users").get(0); int userId = userConfig.getInt("id"); List<Timesheet> result = getResult(getResource().getAccountTimesheets(userId)); List<Integer> expectedIds = new ArrayList<Integer>(); for (Config config : timesheetsConfig) { if (config.getString("account_username").equals(userConfig.getString("username"))) { expectedIds.add(config.getInt("id")); } } List<Integer> ids = getIdsForObjects(result); assertThat(ids, IsCollectionContaining.hasItems(expectedIds.toArray(new Integer[expectedIds.size()]))); }
@Test public void testGetOrgTimesheets() throws Exception { Config portalConfig = DbTemplate.getList("portals").get(1); List<Timesheet> result = getResult(getResource().getOrgTimesheets(portalConfig.getInt("id"))); List<Integer> expectedIds = new ArrayList<Integer>(); for (Config config : timesheetsConfig) { if (config.getString("portal_short_name").equals(portalConfig.getString("short_name"))) { expectedIds.add(config.getInt("id")); } } List<Integer> ids = getIdsForObjects(result); assertThat(ids, IsCollectionContaining.hasItems(expectedIds.toArray(new Integer[expectedIds.size()]))); }
@Test public void testGetEventTimesheets() throws Exception { List<? extends Config> eventsConfig = DbTemplate.getList("events"); Config eventConfig = eventsConfig.get(eventsConfig.size() - 1); String dateString = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); List<Timesheet> result = getResult(getResource().getEventTimesheets(eventConfig.getInt("id"), dateString)); List<Integer> expectedIds = new ArrayList<Integer>(); for (Config config : timesheetsConfig) { if (config.hasPath("event_title") && config.getString("event_title").equals(eventConfig.getString("title"))) { expectedIds.add(config.getInt("id")); } } List<Integer> ids = getIdsForObjects(result); assertThat(ids, IsCollectionContaining.hasItems(expectedIds.toArray(new Integer[expectedIds.size()]))); }
@Test public void testGetCustomProfileFields() throws Exception { List<? extends Config> profileFieldsConfig = DbTemplate.getList("custom_profile"); List<CustomProfileField> result = getResult(getResource().getCustomProfileFields()); List<String> configNames = new ArrayList<String>(); for (Config fieldConfig : profileFieldsConfig) { configNames.add(fieldConfig.getString("name")); } List<String> resultNames = new ArrayList<String>(); for (CustomProfileField field : result) { resultNames.add(field.getName()); } assertThat(resultNames, IsCollectionContaining.hasItems(configNames.toArray(new String[configNames.size()]))); }
@Test public void testGetOrgEvents() throws Exception { Config portalConfig = DbTemplate.getList("portals").get(1); List<Event> result = getResult(getResource().getOrgEvents(portalConfig.getInt("id"), new EventQueryParams())); List<Integer> expectedIds = new ArrayList<Integer>(); for (Config config : eventsConfig) { if (config.getString("portal_short_name").equals(portalConfig.getString("short_name"))) { expectedIds.add(config.getInt("id")); } } List<Integer> ids = getIdsForObjects(result); assertThat(ids, IsCollectionContaining.hasItems(expectedIds.toArray(new Integer[expectedIds.size()]))); }
@Test public void testGetOrgGroups() throws Exception { List<Group> result = getResult(getResource().getOrgGroups(orgId)); Group foundGroup = null; for (Group group : result) { if (group.getName().equals(defaultGroup)) { foundGroup = group; } } assertNotNull(foundGroup); assertEquals(defaultGroup, foundGroup.getName()); List<Integer> configIds = getIdsForConfigs(DbTemplate.getList("users")); assertThat(foundGroup.getAccountIds(), IsCollectionContaining.hasItems(configIds.toArray(new Integer[configIds.size()]))); }
private void verifyResults(final CloseableIterable<? extends Element> resultsItr) { final Edge[] expectedResults = { new Edge.Builder() .group("RoadUse") .source("11") .dest("10") .directed(true) .property("startDate", getDate("2000-05-03")) .property("endDate", DateUtils.addMilliseconds(getDate("2000-05-04"), -1)) .property("count", 1L) .build(), new Edge.Builder() .group("RoadUse") .source("10") .dest("11") .directed(true) .property("count", 1L) .property("startDate", getDate("2000-05-02")) .property("endDate", DateUtils.addMilliseconds(getDate("2000-05-03"), -1)) .build(), new Edge.Builder() .group("RoadUse") .source("10") .dest("11") .directed(true) .property("count", 2L) .property("startDate", getDate("2000-05-01")) .property("endDate", DateUtils.addMilliseconds(getDate("2000-05-02"), -1)) .build() }; final List<Element> results = Lists.newArrayList(resultsItr); assertEquals(expectedResults.length, results.size()); assertThat(results, IsCollectionContaining.hasItems(expectedResults)); }
private void verifyResults(final CloseableIterable<? extends Element> resultsItr) { final Edge[] expectedResults = { new Edge.Builder() .group("RoadUse") .source("10") .dest("11") .directed(true) .property("count", 3L) .build() }; final List<Element> results = Lists.newArrayList(resultsItr); assertEquals(expectedResults.length, results.size()); assertThat(results, IsCollectionContaining.hasItems(expectedResults)); }
private void verifyResults(final Iterable<? extends String> resultsItr) { final String[] expectedResults = { "10,11,3", "11,10,1", "23,24,2", "28,27,1" }; final List<String> results = Lists.newArrayList(resultsItr); assertEquals(expectedResults.length, results.size()); assertThat(results, IsCollectionContaining.hasItems(expectedResults)); }
private void verifyResults(final Iterable<? extends String> resultsItr) { final String[] expectedResults = { "Junction,Bus Count", "M5:LA Boundary,1067", "M4:LA Boundary,1958", "M32:2,1411" }; final List<String> results = Lists.newArrayList(resultsItr); assertEquals(expectedResults.length, results.size()); assertThat(results, IsCollectionContaining.hasItems(expectedResults)); }