Skip to content

Commit 1bb0468

Browse files
authored
feat(java, info): Add more java info tests (#739)
Add more java info tests to cover our code uder `maven-project/info`.
1 parent 1b9c1cc commit 1bb0468

19 files changed

+1784
-137
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,6 @@ venv.bak/
7979
target/
8080
maven-projects/proto/src/main/java
8181
dependency-reduced-pom.xml
82+
83+
# Vibe coding
84+
CLAUDE.md

maven-projects/info/pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
<maven.compiler.source>11</maven.compiler.source>
4343
<maven.compiler.target>11</maven.compiler.target>
4444
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
45+
<!-- Default test data path relative to info module -->
46+
<gar.test.data>../../testing</gar.test.data>
4547
</properties>
4648

4749
<dependencies>
@@ -101,6 +103,15 @@
101103
<groupId>org.jacoco</groupId>
102104
<artifactId>jacoco-maven-plugin</artifactId>
103105
<version>0.8.8</version>
106+
<configuration>
107+
<excludes>
108+
<exclude>java/**</exclude>
109+
<exclude>javax/**</exclude>
110+
<exclude>sun/**</exclude>
111+
<exclude>com/sun/**</exclude>
112+
<exclude>org/yaml/snakeyaml/**</exclude>
113+
</excludes>
114+
</configuration>
104115
<executions>
105116
<execution>
106117
<goals>
@@ -116,6 +127,19 @@
116127
</execution>
117128
</executions>
118129
</plugin>
130+
131+
<plugin>
132+
<groupId>org.apache.maven.plugins</groupId>
133+
<artifactId>maven-surefire-plugin</artifactId>
134+
<version>3.2.2</version>
135+
<configuration>
136+
<!-- Set default test data path to project root testing directory -->
137+
<systemPropertyVariables>
138+
<gar.test.data>${gar.test.data}</gar.test.data>
139+
<test.output.dir>${project.build.directory}/test-output</test.output.dir>
140+
</systemPropertyVariables>
141+
</configuration>
142+
</plugin>
119143
</plugins>
120144
</build>
121145

maven-projects/info/src/main/java/org/apache/graphar/info/AdjacentList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public AdjacentList(AdjListType type, FileType fileType, URI baseUri) {
3535
}
3636

3737
public AdjacentList(AdjListType type, FileType fileType, String prefix) {
38-
this(type, fileType, URI.create(prefix));
38+
this(type, fileType, prefix == null ? null : URI.create(prefix));
3939
}
4040

4141
public AdjListType getType() {
@@ -47,7 +47,7 @@ public FileType getFileType() {
4747
}
4848

4949
public String getPrefix() {
50-
return baseUri.toString();
50+
return baseUri == null ? null : baseUri.toString();
5151
}
5252

5353
public URI getBaseUri() {

maven-projects/info/src/main/java/org/apache/graphar/info/GraphInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public GraphInfo(
4444
List<EdgeInfo> edgeInfos,
4545
String prefix,
4646
String version) {
47-
this(name, vertexInfos, edgeInfos, URI.create(prefix), version);
47+
this(name, vertexInfos, edgeInfos, prefix == null ? null : URI.create(prefix), version);
4848
}
4949

5050
public GraphInfo(
@@ -201,7 +201,7 @@ public List<EdgeInfo> getEdgeInfos() {
201201
}
202202

203203
public String getPrefix() {
204-
return baseUri.toString();
204+
return baseUri == null ? null : baseUri.toString();
205205
}
206206

207207
public URI getBaseUri() {

maven-projects/info/src/main/java/org/apache/graphar/info/PropertyGroup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class PropertyGroup implements Iterable<Property> {
3939
private final URI baseUri;
4040

4141
public PropertyGroup(List<Property> propertyMap, FileType fileType, String prefix) {
42-
this(propertyMap, fileType, URI.create(prefix));
42+
this(propertyMap, fileType, prefix == null ? null : URI.create(prefix));
4343
}
4444

4545
public PropertyGroup(List<Property> propertyMap, FileType fileType, URI baseUri) {
@@ -92,7 +92,7 @@ public FileType getFileType() {
9292
}
9393

9494
public String getPrefix() {
95-
return baseUri.toString();
95+
return baseUri == null ? null : baseUri.toString();
9696
}
9797

9898
public URI getBaseUri() {

maven-projects/info/src/main/java/org/apache/graphar/info/VersionInfo.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@
2424
import java.util.StringJoiner;
2525

2626
public class VersionInfo {
27-
private int version;
28-
private List<String> userDefinedTypes;
29-
private final Map<Integer, List<String>> version2types =
27+
private final int version;
28+
private final List<String> userDefinedTypes;
29+
private static final Map<Integer, List<String>> version2types =
3030
Map.of(1, List.of("bool", "int32", "int64", "float", "double", "string"));
3131

32-
public VersionInfo(Integer version, List<String> userDefinedTypes) {
32+
public VersionInfo(int version, List<String> userDefinedTypes) {
33+
if (version <= 0) {
34+
throw new IllegalArgumentException(
35+
"Version must be a supported positive integer: " + version);
36+
}
3337
this.version = version;
34-
this.userDefinedTypes = userDefinedTypes;
38+
this.userDefinedTypes =
39+
userDefinedTypes == null || userDefinedTypes.isEmpty()
40+
? new java.util.ArrayList<>()
41+
: List.copyOf(userDefinedTypes);
3542
}
3643

3744
public int getVersion() {

maven-projects/info/src/main/java/org/apache/graphar/info/VertexInfo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public VertexInfo(
5858
List<PropertyGroup> propertyGroups,
5959
URI baseUri,
6060
VersionInfo version) {
61+
if (chunkSize < 0) {
62+
throw new IllegalArgumentException("Chunk size cannot be negative: " + chunkSize);
63+
}
6164
this.type = type;
6265
this.chunkSize = chunkSize;
6366
this.propertyGroups = new PropertyGroups(propertyGroups);
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.graphar.info;
21+
22+
import org.apache.graphar.info.type.AdjListType;
23+
import org.apache.graphar.info.type.FileType;
24+
import org.junit.Assert;
25+
import org.junit.Test;
26+
27+
public class AdjacentListTest {
28+
29+
@Test
30+
public void testAdjacentListBasicConstruction() {
31+
AdjacentList adjList =
32+
new AdjacentList(AdjListType.unordered_by_source, FileType.CSV, "adj_list/");
33+
34+
Assert.assertEquals(AdjListType.unordered_by_source, adjList.getType());
35+
Assert.assertEquals(FileType.CSV, adjList.getFileType());
36+
Assert.assertEquals("adj_list/", adjList.getPrefix());
37+
}
38+
39+
@Test
40+
public void testAdjacentListWithAllAdjListTypes() {
41+
AdjacentList unorderedBySource =
42+
new AdjacentList(AdjListType.unordered_by_source, FileType.CSV, "unordered_src/");
43+
Assert.assertEquals(AdjListType.unordered_by_source, unorderedBySource.getType());
44+
45+
AdjacentList unorderedByDest =
46+
new AdjacentList(AdjListType.unordered_by_dest, FileType.CSV, "unordered_dst/");
47+
Assert.assertEquals(AdjListType.unordered_by_dest, unorderedByDest.getType());
48+
49+
AdjacentList orderedBySource =
50+
new AdjacentList(AdjListType.ordered_by_source, FileType.CSV, "ordered_src/");
51+
Assert.assertEquals(AdjListType.ordered_by_source, orderedBySource.getType());
52+
53+
AdjacentList orderedByDest =
54+
new AdjacentList(AdjListType.ordered_by_dest, FileType.CSV, "ordered_dst/");
55+
Assert.assertEquals(AdjListType.ordered_by_dest, orderedByDest.getType());
56+
}
57+
58+
@Test
59+
public void testAdjacentListWithAllFileTypes() {
60+
AdjacentList csvList =
61+
new AdjacentList(AdjListType.unordered_by_source, FileType.CSV, "csv/");
62+
Assert.assertEquals(FileType.CSV, csvList.getFileType());
63+
64+
AdjacentList parquetList =
65+
new AdjacentList(AdjListType.unordered_by_source, FileType.PARQUET, "parquet/");
66+
Assert.assertEquals(FileType.PARQUET, parquetList.getFileType());
67+
68+
AdjacentList orcList =
69+
new AdjacentList(AdjListType.unordered_by_source, FileType.ORC, "orc/");
70+
Assert.assertEquals(FileType.ORC, orcList.getFileType());
71+
}
72+
73+
@Test
74+
public void testAdjacentListTypeAndFormatCombinations() {
75+
// Test unordered by source with PARQUET (COO format)
76+
AdjacentList cooList =
77+
new AdjacentList(AdjListType.unordered_by_source, FileType.PARQUET, "coo/");
78+
Assert.assertEquals(AdjListType.unordered_by_source, cooList.getType());
79+
Assert.assertEquals(FileType.PARQUET, cooList.getFileType());
80+
81+
// Test ordered by source with CSV (CSR format)
82+
AdjacentList csrList =
83+
new AdjacentList(AdjListType.ordered_by_source, FileType.CSV, "csr/");
84+
Assert.assertEquals(AdjListType.ordered_by_source, csrList.getType());
85+
Assert.assertEquals(FileType.CSV, csrList.getFileType());
86+
87+
// Test ordered by dest with ORC (CSC format)
88+
AdjacentList cscList = new AdjacentList(AdjListType.ordered_by_dest, FileType.ORC, "csc/");
89+
Assert.assertEquals(AdjListType.ordered_by_dest, cscList.getType());
90+
Assert.assertEquals(FileType.ORC, cscList.getFileType());
91+
}
92+
93+
@Test
94+
public void testAdjacentListWithNullPrefix() {
95+
AdjacentList adjList =
96+
new AdjacentList(AdjListType.unordered_by_source, FileType.CSV, (String) null);
97+
98+
Assert.assertEquals(AdjListType.unordered_by_source, adjList.getType());
99+
Assert.assertEquals(FileType.CSV, adjList.getFileType());
100+
Assert.assertNull(adjList.getPrefix());
101+
}
102+
103+
@Test
104+
public void testAdjacentListWithEmptyPrefix() {
105+
AdjacentList adjList =
106+
new AdjacentList(AdjListType.ordered_by_source, FileType.PARQUET, "");
107+
108+
Assert.assertEquals(AdjListType.ordered_by_source, adjList.getType());
109+
Assert.assertEquals(FileType.PARQUET, adjList.getFileType());
110+
Assert.assertEquals("", adjList.getPrefix());
111+
}
112+
113+
@Test
114+
public void testAdjacentListWithNullType() {
115+
AdjacentList adjList = new AdjacentList(null, FileType.CSV, "test/");
116+
117+
Assert.assertNull(adjList.getType());
118+
Assert.assertEquals(FileType.CSV, adjList.getFileType());
119+
Assert.assertEquals("test/", adjList.getPrefix());
120+
}
121+
122+
@Test
123+
public void testAdjacentListWithNullFileType() {
124+
AdjacentList adjList = new AdjacentList(AdjListType.unordered_by_source, null, "test/");
125+
126+
Assert.assertEquals(AdjListType.unordered_by_source, adjList.getType());
127+
Assert.assertNull(adjList.getFileType());
128+
Assert.assertEquals("test/", adjList.getPrefix());
129+
}
130+
131+
@Test
132+
public void testAdjacentListImmutability() {
133+
AdjListType originalType = AdjListType.ordered_by_source;
134+
FileType originalFileType = FileType.PARQUET;
135+
String originalPrefix = "original/";
136+
137+
AdjacentList adjList = new AdjacentList(originalType, originalFileType, originalPrefix);
138+
139+
// Values should remain the same after construction
140+
Assert.assertEquals(originalType, adjList.getType());
141+
Assert.assertEquals(originalFileType, adjList.getFileType());
142+
Assert.assertEquals(originalPrefix, adjList.getPrefix());
143+
144+
// References should be the same (since they're immutable)
145+
Assert.assertSame(originalType, adjList.getType());
146+
Assert.assertSame(originalFileType, adjList.getFileType());
147+
Assert.assertEquals(originalPrefix, adjList.getPrefix()); // String comparison
148+
}
149+
150+
@Test
151+
public void testAdjacentListEquality() {
152+
AdjacentList adjList1 =
153+
new AdjacentList(AdjListType.unordered_by_source, FileType.CSV, "test/");
154+
AdjacentList adjList2 =
155+
new AdjacentList(AdjListType.unordered_by_source, FileType.CSV, "test/");
156+
AdjacentList adjList3 =
157+
new AdjacentList(AdjListType.ordered_by_source, FileType.CSV, "test/");
158+
159+
// Note: AdjacentList doesn't override equals(), so this tests object identity
160+
Assert.assertNotEquals(adjList1, adjList2); // Different objects
161+
Assert.assertNotEquals(adjList1, adjList3); // Different types
162+
163+
// Same object reference
164+
AdjacentList sameRef = adjList1;
165+
Assert.assertEquals(adjList1, sameRef);
166+
}
167+
168+
@Test
169+
public void testAdjacentListDefaultPrefixBehavior() {
170+
// Test behavior that might generate default prefixes based on type
171+
AdjacentList unorderedSrc =
172+
new AdjacentList(
173+
AdjListType.unordered_by_source, FileType.CSV, "unordered_by_source/");
174+
Assert.assertEquals("unordered_by_source/", unorderedSrc.getPrefix());
175+
176+
AdjacentList orderedSrc =
177+
new AdjacentList(
178+
AdjListType.ordered_by_source, FileType.PARQUET, "ordered_by_source/");
179+
Assert.assertEquals("ordered_by_source/", orderedSrc.getPrefix());
180+
181+
AdjacentList unorderedDst =
182+
new AdjacentList(AdjListType.unordered_by_dest, FileType.ORC, "unordered_by_dest/");
183+
Assert.assertEquals("unordered_by_dest/", unorderedDst.getPrefix());
184+
185+
AdjacentList orderedDst =
186+
new AdjacentList(AdjListType.ordered_by_dest, FileType.CSV, "ordered_by_dest/");
187+
Assert.assertEquals("ordered_by_dest/", orderedDst.getPrefix());
188+
}
189+
190+
@Test
191+
public void testAdjacentListFieldAccess() {
192+
AdjListType type = AdjListType.ordered_by_source;
193+
FileType fileType = FileType.PARQUET;
194+
String prefix = "edge_data/";
195+
196+
AdjacentList adjList = new AdjacentList(type, fileType, prefix);
197+
198+
// Test that getters return the correct values
199+
Assert.assertEquals(type, adjList.getType());
200+
Assert.assertEquals(fileType, adjList.getFileType());
201+
Assert.assertEquals(prefix, adjList.getPrefix());
202+
203+
// Test multiple calls return consistent values
204+
Assert.assertEquals(type, adjList.getType());
205+
Assert.assertEquals(fileType, adjList.getFileType());
206+
Assert.assertEquals(prefix, adjList.getPrefix());
207+
}
208+
}

0 commit comments

Comments
 (0)