@Test public void testContainsValue() { assertThat(new UnionMap<>(of("1", "a"), of("2", "b"))).containsValue("a"); assertThat(new UnionMap<>(of("1", "a"), of("2", "b"))).containsValue("b"); }
@Test public void sendReturnsResultsForLocalMember() throws Exception { HashSet<PersistentID> persistentIdsForSender = new HashSet<>(); persistentIdsForSender.add(mock(PersistentID.class)); when(prepareBackup.run()).thenReturn(persistentIdsForSender); assertThat(prepareBackupStep.send()).containsOnlyKeys(sender) .containsValue(persistentIdsForSender); }
@Test public void sendReturnsResultsForLocalMember() throws Exception { HashSet<PersistentID> persistentIdsForSender = new HashSet<>(); persistentIdsForSender.add(mock(PersistentID.class)); when(finishBackup.run()).thenReturn(persistentIdsForSender); assertThat(finishBackupStep.send()).containsOnlyKeys(sender) .containsValue(persistentIdsForSender); }
@Test public void addToResultsShouldShowUpInGetResults() throws Exception { HashSet<PersistentID> persistentIdsForMember1 = new HashSet<>(); persistentIdsForMember1.add(mock(PersistentID.class)); prepareBackupStep.addToResults(member1, persistentIdsForMember1); assertThat(prepareBackupStep.getResults()).containsOnlyKeys(member1) .containsValue(persistentIdsForMember1); }
@Test public void addToResultsShouldShowUpInGetResults() throws Exception { HashSet<PersistentID> persistentIdsForMember1 = new HashSet<>(); persistentIdsForMember1.add(mock(PersistentID.class)); finishBackupStep.addToResults(member1, persistentIdsForMember1); assertThat(finishBackupStep.getResults()).containsOnlyKeys(member1) .containsValue(persistentIdsForMember1); }
@Test public void should_keep_existing_organization() throws SQLException { String otherOrg = "existing uuid"; db.executeInsert("RULES_PROFILES", "NAME", "java", "kee", PROFILE_KEY, "organization_uuid", otherOrg); underTest.execute(); Assertions.assertThat(db.selectFirst("SELECT ORGANIZATION_UUID FROM RULES_PROFILES WHERE KEE = '" + PROFILE_KEY + "'")).containsValue(otherOrg); } }
@Test public void should_change_profile_without_organization() throws SQLException { db.executeInsert("RULES_PROFILES", "NAME", "java", "kee", PROFILE_KEY); underTest.execute(); Assertions.assertThat(db.selectFirst("SELECT ORGANIZATION_UUID FROM RULES_PROFILES WHERE KEE = '" + PROFILE_KEY + "'")).containsValue(DEFAULT_ORG); }
@Test public void passwordShouldBeRedacted() { MemberConfigurationInfo info = new MemberConfigurationInfo(); Map<String, String> properties = new HashMap<>(); properties.put(ConfigurationProperties.SSL_KEYSTORE, "somewhere/something"); properties.put(ConfigurationProperties.SSL_KEYSTORE_PASSWORD, "mySecretPassword"); info.setGfePropsSetFromFile(properties); CliFunctionResult functionResult = mock(CliFunctionResult.class); when(functionResult.getResultObject()).thenReturn(info); doReturn(mock(DistributedMember.class)).when(command).getMember(any()); doReturn(functionResult).when(command).executeFunctionAndGetFunctionResult(any(), any(), any()); parser.executeAndAssertThat(command, "describe config --member=test").statusIsSuccess() .hasDataSection("file-properties") .hasContent() .doesNotContainValue("mySecretPassword") .containsValue("********"); } }
@Test public void testListEnvironmentsWithEnvironmentNamePrefix() throws Exception { final String environmentNamePrefix = "environmentNamePrefix"; when(environmentDDBRecords.stream()).thenReturn(Stream.of(environmentDDBRecord)); doReturn(environmentDDBRecords) .when(dynamoDBMapper) .query(eq(EnvironmentDDBRecord.class), any()); when(environmentMapper.toEnvironment(environmentDDBRecord)).thenReturn(environment); final List<Environment> result = environmentRepositoryDDB.listEnvironments(cluster, environmentNamePrefix); verify(dynamoDBMapper) .query(eq(EnvironmentDDBRecord.class), ddbQueryExpressionCaptor.capture()); verify(environmentMapper).toEnvironment(environmentDDBRecord); final EnvironmentDDBRecord queriedEnvironmentDDBRecord = ddbQueryExpressionCaptor.getValue().getHashKeyValues(); final Map<String, Condition> queryConditions = ddbQueryExpressionCaptor.getValue().getRangeKeyConditions(); assertThat(queriedEnvironmentDDBRecord.getAccountIdCluster()) .isEqualTo(cluster.generateAccountIdCluster()); assertThat(queryConditions).isNotEmpty().hasSize(1); assertThat(queryConditions).containsKey(ENVIRONMENT_NAME_RANGE_KEY); assertThat(queryConditions) .containsValue( new Condition() .withComparisonOperator(ComparisonOperator.BEGINS_WITH) .withAttributeValueList(new AttributeValue().withS(environmentNamePrefix))); assertThat(result.size()).isEqualTo(1); assertThat(result.get(0)).isEqualTo(environment); }
@Test public void testMutabilityAndImmutability() { final AttributeKey<Object> someAttr = AttributeKey.valueOf(RequestContextExportingAppenderTest.class, "SOME_ATTR"); final RequestContextExportingAppender a = new RequestContextExportingAppender(); // Ensure mutability before start. a.addBuiltIn(BuiltInProperty.ELAPSED_NANOS); assertThat(a.getBuiltIns()).containsExactly(BuiltInProperty.ELAPSED_NANOS); a.addAttribute("some-attr", someAttr); assertThat(a.getAttributes()).containsOnlyKeys("some-attr") .containsValue(someAttr); a.addHttpRequestHeader(HttpHeaderNames.USER_AGENT); assertThat(a.getHttpRequestHeaders()).containsExactly(HttpHeaderNames.USER_AGENT); a.addHttpResponseHeader(HttpHeaderNames.SET_COOKIE); assertThat(a.getHttpResponseHeaders()).containsExactly(HttpHeaderNames.SET_COOKIE); final ListAppender<ILoggingEvent> la = new ListAppender<>(); a.addAppender(la); a.start(); la.start(); // Ensure immutability after start. assertThatThrownBy(() -> a.addBuiltIn(BuiltInProperty.REQ_PATH)) .isExactlyInstanceOf(IllegalStateException.class); assertThatThrownBy(() -> a.addAttribute("my-attr", MY_ATTR)) .isExactlyInstanceOf(IllegalStateException.class); assertThatThrownBy(() -> a.addHttpRequestHeader(HttpHeaderNames.ACCEPT)) .isExactlyInstanceOf(IllegalStateException.class); assertThatThrownBy(() -> a.addHttpResponseHeader(HttpHeaderNames.DATE)) .isExactlyInstanceOf(IllegalStateException.class); }
@Test public void doNotSweepAnythingAfterEntryWithCommitTsAfterSweepTs() { immutableTs = 1000L; // put 4 writes committed at the same timestamp as start timestamp, and put one committed at sweep timestamp enqueueWriteCommitted(TABLE_CONS, 900); enqueueWriteCommitted(TABLE_CONS, 910); enqueueWriteCommitted(TABLE_CONS, 920); enqueueWriteCommitedAt(TABLE_CONS, 950, immutableTs); enqueueWriteCommitted(TABLE_CONS, 970); sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(CONS_SHARD)); assertThat(progress.getLastSweptTimestamp(ShardAndStrategy.conservative(CONS_SHARD))).isEqualTo(920L); ArgumentCaptor<Map> argument = ArgumentCaptor.forClass(Map.class); verify(spiedKvs, times(1)).deleteAllTimestamps(eq(TABLE_CONS), argument.capture(), eq(false)); assertThat(argument.getValue()).containsValue(920L); sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(CONS_SHARD)); assertThat(progress.getLastSweptTimestamp(ShardAndStrategy.conservative(CONS_SHARD))).isEqualTo(920L); verify(spiedKvs, times(1)).deleteAllTimestamps(any(TableReference.class), anyMap(), eq(false)); immutableTs = 1001L; sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(CONS_SHARD)); assertThat(progress.getLastSweptTimestamp(ShardAndStrategy.conservative(CONS_SHARD))).isEqualTo(1001L - 1L); // we have now had a total of 2 calls to deleteAllTimestamps, 1 from before and one new verify(spiedKvs, times(2)).deleteAllTimestamps(eq(TABLE_CONS), argument.capture(), eq(false)); assertThat(argument.getValue()).containsValue(970L); }
@Test public void doNotDeleteAnythingAfterEntryWithCommitTsAfterSweepTs() { immutableTs = 1000L; enqueueWriteUncommitted(TABLE_CONS, 900); enqueueWriteUncommitted(TABLE_CONS, 920); enqueueWriteCommitedAt(TABLE_CONS, 950, 2000); enqueueWriteUncommitted(TABLE_CONS, 970); enqueueWriteUncommitted(TABLE_CONS, 1110); sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(CONS_SHARD)); assertThat(progress.getLastSweptTimestamp(ShardAndStrategy.conservative(CONS_SHARD))).isEqualTo(920L); verify(spiedKvs, never()).deleteAllTimestamps(any(TableReference.class), anyMap(), eq(false)); ArgumentCaptor<Multimap> multimap = ArgumentCaptor.forClass(Multimap.class); verify(spiedKvs, times(1)).delete(eq(TABLE_CONS), multimap.capture()); assertThat(multimap.getValue().keySet()).containsExactly(DEFAULT_CELL); assertThat(multimap.getValue().values()).containsExactly(900L, 920L); sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(CONS_SHARD)); assertThat(progress.getLastSweptTimestamp(ShardAndStrategy.conservative(CONS_SHARD))).isEqualTo(920L); verify(spiedKvs, never()).deleteAllTimestamps(any(TableReference.class), anyMap(), eq(false)); verify(spiedKvs, times(1)).delete(any(TableReference.class), any(Multimap.class)); assertReadAtTimestampReturnsValue(TABLE_CONS, 1500L, 1110L); immutableTs = 2009L; sweepQueue.sweepNextBatch(ShardAndStrategy.conservative(CONS_SHARD)); assertThat(progress.getLastSweptTimestamp(ShardAndStrategy.conservative(CONS_SHARD))).isEqualTo(2009L - 1L); ArgumentCaptor<Map> map = ArgumentCaptor.forClass(Map.class); verify(spiedKvs, times(1)).deleteAllTimestamps(eq(TABLE_CONS), map.capture(), eq(false)); assertThat(map.getValue()).containsValue(950L); assertReadAtTimestampReturnsValue(TABLE_CONS, 1500L, 950L); }
@Test public void crawl() { Crawler crawler = new Crawler(db, config); crawler.crawl(); Assert.assertEquals(4, db.getDocumentCount("post")); Assert.assertEquals(3, db.getDocumentCount("page")); DocumentList results = db.getPublishedPosts(); assertThat(results.size()).isEqualTo(3); for (Map<String, Object> content : results) { assertThat(content) .containsKey(Crawler.Attributes.ROOTPATH) .containsValue("../../../"); } DocumentList allPosts = db.getAllContent("post"); assertThat(allPosts.size()).isEqualTo(4); for (Map<String, Object> content : allPosts) { if (content.get(Crawler.Attributes.TITLE).equals("Draft Post")) { assertThat(content).containsKey(Crawler.Attributes.DATE); } } // covers bug #213 DocumentList publishedPostsByTag = db.getPublishedPostsByTag("blog"); Assert.assertEquals(3, publishedPostsByTag.size()); }
@Test void objectShouldContainValue() { assertThatJson("{\"a\":1, \"b\": 2}").isObject().containsValue(valueOf(2)); }
@Override public MapAssert<String, Object> containsValue(Object expected) { if (expected instanceof Node) { if (!contains(expected)) { throw failures.failure(info, shouldContainValue(actual, expected)); } return this; } else { return super.containsValue(expected); } }
@Test void objectShouldContainComplexValueError() { assertThatThrownBy(() -> assertThatJson("{\"root\":{\"a\":1, \"b\": {\"c\" :3}}}") .node("root") .isObject() .containsValue(json("{\"c\" :5}"))) .hasMessage("[Different value found in node \"root\"] \n" + "Expecting:\n" + " <{\"a\":1,\"b\":{\"c\":3}}>\n" + "to contain value:\n" + " <{\"c\":5}>"); }
@Test public void testCreateBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); when( this.commandClient.createBoard() ).thenReturn( ResponseEntity.created( URI.create( "http://localhost/boards/" + boardUuid.toString() ) ).build() ); ResponseEntity response = this.service.createBoard(); assertThat( response.getStatusCode() ).isEqualTo( HttpStatus.CREATED ); assertThat( response.getHeaders() ) .containsKey( HttpHeaders.LOCATION ) .containsValue( singletonList( "http://localhost/boards/" + boardUuid.toString() ) ); verify( this.commandClient, times( 1 ) ).createBoard(); }
@Test public void testAddStoryToBoard() throws Exception { UUID boardUuid = UUID.randomUUID(); Board board = createTestBoard( boardUuid ); when( this.client.find( any( UUID.class ) ) ).thenReturn( board ); UUID storyUuid = this.service.addStory( boardUuid, "Test Story" ); assertThat( storyUuid ).isNotNull(); assertThat( board.getStories() ).hasSize( 1 ) .containsKey( storyUuid ) .containsValue( createTestStory( "Test Story" ) ); assertThat( board.changes() ).hasSize( 2 ); verify( this.client, times( 1 ) ).find( any( UUID.class ) ); verify( this.client, times( 1 ) ).save( any( Board.class ) ); }
@Test public void noParent() { ScopeMap<String, String> map = new ScopeMap<>(); map.put("a", "v"); assertThat(map).contains(entry("a", "v")); assertThat(map).containsKeys("a"); assertThat(map).containsValue("v"); }
@Test public void noParent() { ScopeMap<String, String> map = new ScopeMap<>(); map.put("a", "v"); assertThat(map).contains(entry("a", "v")); assertThat(map).containsKeys("a"); assertThat(map).containsValue("v"); }