or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

collection-assertions.mddata-assertions.mdindex.mdlookup-cache-assertions.mdtype-assertions.md

collection-assertions.mddocs/

0

# Collection Assertions

1

2

Specialized assertions for collections of RowData with bulk operations and type-safe comparisons. These assertions enable efficient testing of multiple rows with automatic type conversion and flexible comparison modes.

3

4

## RowData List Assertions

5

6

Comprehensive assertions for collections of RowData objects supporting various collection types and bulk operations.

7

8

```java { .api }

9

public class RowDataListAssert extends AbstractListAssert<RowDataListAssert, List<RowData>, RowData, RowDataAssert> {

10

public RowDataListAssert(List<RowData> rowDataList);

11

12

// Type conversion for bulk comparison

13

public RowDataListAssert asGeneric(DataType dataType);

14

public RowDataListAssert asGeneric(LogicalType logicalType);

15

/** Requires flink-table-runtime in classpath */

16

public ListAssert<Row> asRows(DataType dataType);

17

}

18

```

19

20

### Factory Methods

21

22

Multiple factory methods support different collection types:

23

24

```java { .api }

25

// From TableAssertions class

26

public static RowDataListAssert assertThatRows(Iterator<RowData> actual);

27

public static RowDataListAssert assertThatRows(Iterable<RowData> actual);

28

public static RowDataListAssert assertThatRows(Stream<RowData> actual);

29

public static RowDataListAssert assertThatRows(RowData... rows);

30

```

31

32

### Usage Examples

33

34

#### Basic Collection Assertions

35

36

```java

37

import static org.apache.flink.table.test.TableAssertions.assertThatRows;

38

import org.apache.flink.table.data.RowData;

39

import org.apache.flink.table.data.GenericRowData;

40

41

List<RowData> rows = Arrays.asList(

42

GenericRowData.of(1, "Alice"),

43

GenericRowData.of(2, "Bob"),

44

GenericRowData.of(3, "Charlie")

45

);

46

47

// Basic collection validation

48

assertThatRows(rows)

49

.hasSize(3)

50

.isNotEmpty()

51

.doesNotContainNull();

52

53

// Using inherited AssertJ list assertions

54

assertThatRows(rows)

55

.extracting(row -> row.getArity())

56

.containsOnly(2);

57

```

58

59

#### Type Conversion for Comparison

60

61

```java

62

import org.apache.flink.table.types.DataType;

63

import org.apache.flink.table.api.DataTypes;

64

65

DataType rowType = DataTypes.ROW(

66

DataTypes.FIELD("id", DataTypes.INT()),

67

DataTypes.FIELD("name", DataTypes.STRING())

68

);

69

70

List<RowData> actualRows = /* ... from table operation */;

71

List<RowData> expectedRows = Arrays.asList(

72

GenericRowData.of(1, StringData.fromString("Alice")),

73

GenericRowData.of(2, StringData.fromString("Bob"))

74

);

75

76

// Convert to generic format for comparison

77

assertThatRows(actualRows)

78

.asGeneric(rowType)

79

.containsExactly(expectedRows.toArray(new RowData[0]));

80

81

// Using logical type

82

LogicalType logicalType = rowType.getLogicalType();

83

assertThatRows(actualRows)

84

.asGeneric(logicalType)

85

.containsOnly(expectedRows.toArray(new RowData[0]));

86

```

87

88

#### External Row Conversion

89

90

```java

91

import org.apache.flink.types.Row;

92

93

// Convert to external Row objects for comparison

94

List<Row> expectedExternalRows = Arrays.asList(

95

Row.of(1, "Alice"),

96

Row.of(2, "Bob")

97

);

98

99

assertThatRows(actualRows)

100

.asRows(rowType)

101

.containsExactly(expectedExternalRows.toArray(new Row[0]));

102

```

103

104

#### Working with Different Collection Types

105

106

```java

107

// From Iterator

108

Iterator<RowData> iterator = rows.iterator();

109

assertThatRows(iterator)

110

.hasSize(3);

111

112

// From Stream

113

Stream<RowData> stream = rows.stream();

114

assertThatRows(stream)

115

.allSatisfy(row -> assertThat(row).hasArity(2));

116

117

// From varargs

118

RowData row1 = GenericRowData.of(1, "Alice");

119

RowData row2 = GenericRowData.of(2, "Bob");

120

assertThatRows(row1, row2)

121

.hasSize(2);

122

123

// From Iterable (Set, etc.)

124

Set<RowData> rowSet = new HashSet<>(rows);

125

assertThatRows(rowSet)

126

.hasSizeGreaterThan(0);

127

```

128

129

#### Complex Validation Scenarios

130

131

```java

132

// Validate rows with mixed operations

133

assertThatRows(actualRows)

134

.hasSize(expectedCount)

135

.asGeneric(rowType)

136

.satisfies(genericRows -> {

137

// All rows should be INSERT kind

138

assertThat(genericRows)

139

.allSatisfy(row -> assertThat(row).hasKind(RowKind.INSERT));

140

141

// Specific field validations

142

assertThat(genericRows)

143

.extracting(row -> row.getInt(0))

144

.containsExactly(1, 2, 3);

145

});

146

```

147

148

#### Streaming Data Validation

149

150

```java

151

// For streaming table results

152

CloseableIterator<Row> streamingResults = /* ... */;

153

154

// Convert to list for comprehensive testing

155

List<RowData> collectedRows = new ArrayList<>();

156

while (streamingResults.hasNext()) {

157

Row row = streamingResults.next();

158

collectedRows.add(/* convert row to RowData */);

159

}

160

161

assertThatRows(collectedRows)

162

.asGeneric(resultType)

163

.satisfies(rows -> {

164

// Validate streaming-specific properties

165

assertThat(rows)

166

.hasSize(expectedStreamingCount)

167

.allSatisfy(row ->

168

assertThat(row).isNotNullAt(0) // timestamp field

169

);

170

});

171

```

172

173

#### Bulk Row Kind Validation

174

175

```java

176

import org.apache.flink.types.RowKind;

177

178

// Validate change stream results

179

List<RowData> changeStreamRows = /* ... */;

180

181

assertThatRows(changeStreamRows)

182

.asGeneric(rowType)

183

.satisfies(rows -> {

184

// Count different row kinds

185

long insertCount = rows.stream()

186

.filter(row -> row.getRowKind() == RowKind.INSERT)

187

.count();

188

189

long deleteCount = rows.stream()

190

.filter(row -> row.getRowKind() == RowKind.DELETE)

191

.count();

192

193

assertThat(insertCount).isEqualTo(expectedInserts);

194

assertThat(deleteCount).isEqualTo(expectedDeletes);

195

});

196

```

197

198

#### Advanced Collection Comparisons

199

200

```java

201

// Partial matching with flexible ordering

202

List<RowData> subset = Arrays.asList(

203

GenericRowData.of(1, StringData.fromString("Alice")),

204

GenericRowData.of(3, StringData.fromString("Charlie"))

205

);

206

207

assertThatRows(actualRows)

208

.asGeneric(rowType)

209

.containsAll(subset);

210

211

// Exclusive content validation

212

assertThatRows(actualRows)

213

.asGeneric(rowType)

214

.doesNotContainAnyElementsOf(forbiddenRows);

215

216

// Size-based validation with content sampling

217

assertThatRows(actualRows)

218

.hasSizeGreaterThan(1000)

219

.satisfies(rows -> {

220

// Sample validation for performance

221

List<RowData> sample = rows.subList(0, Math.min(100, rows.size()));

222

assertThatRows(sample)

223

.asGeneric(rowType)

224

.allSatisfy(row ->

225

assertThat(row)

226

.hasArity(expectedArity)

227

.isNotNullAt(keyFieldIndex)

228

);

229

});

230

```

231

232

## Inherited List Assertions

233

234

Since `RowDataListAssert` extends AssertJ's `AbstractListAssert`, all standard list assertions are available:

235

236

```java

237

// Standard AssertJ list operations

238

assertThatRows(rows)

239

.hasSize(3)

240

.isNotEmpty()

241

.doesNotContainNull()

242

.startsWith(firstExpectedRow)

243

.endsWith(lastExpectedRow)

244

.contains(middleExpectedRow)

245

.doesNotHaveDuplicates();

246

247

// Element extraction and mapping

248

assertThatRows(rows)

249

.extracting(RowData::getArity)

250

.containsOnly(2);

251

252

assertThatRows(rows)

253

.extracting(row -> row.getString(1))

254

.contains("Alice", "Bob");

255

```