|
| 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