|
16 | 16 |
|
17 | 17 | package com.google.cloud.bigquery;
|
18 | 18 |
|
| 19 | +import static org.hamcrest.CoreMatchers.allOf; |
| 20 | +import static org.hamcrest.CoreMatchers.containsString; |
| 21 | +import static org.hamcrest.MatcherAssert.assertThat; |
19 | 22 | import static org.junit.Assert.assertEquals;
|
20 | 23 | import static org.junit.Assert.assertNull;
|
21 | 24 | import static org.junit.Assert.assertTrue;
|
| 25 | +import static org.junit.Assert.fail; |
22 | 26 |
|
23 | 27 | import com.google.api.services.bigquery.model.Streamingbuffer;
|
| 28 | +import com.google.api.services.bigquery.model.Table; |
| 29 | +import com.google.api.services.bigquery.model.TableReference; |
24 | 30 | import com.google.cloud.bigquery.StandardTableDefinition.StreamingBuffer;
|
25 | 31 | import com.google.common.collect.ImmutableList;
|
26 | 32 | import org.junit.Test;
|
@@ -118,6 +124,62 @@ public void testToAndFromPb() {
|
118 | 124 | definition, TableDefinition.<StandardTableDefinition>fromPb(definition.toPb()));
|
119 | 125 | }
|
120 | 126 |
|
| 127 | + @Test |
| 128 | + public void testFromPbWithUnexpectedTimePartitioningTypeRaisesInvalidArgumentException() { |
| 129 | + Table invalidTable = |
| 130 | + new Table() |
| 131 | + .setType("TABLE") |
| 132 | + .setTableReference( |
| 133 | + new TableReference() |
| 134 | + .setProjectId("ILLEGAL_ARG_TEST_PROJECT") |
| 135 | + .setDatasetId("ILLEGAL_ARG_TEST_DATASET") |
| 136 | + .setTableId("ILLEGAL_ARG_TEST_TABLE")) |
| 137 | + .setTimePartitioning( |
| 138 | + new com.google.api.services.bigquery.model.TimePartitioning().setType("GHURRY")); |
| 139 | + try { |
| 140 | + StandardTableDefinition.fromPb(invalidTable); |
| 141 | + } catch (IllegalArgumentException ie) { |
| 142 | + assertThat( |
| 143 | + ie.getMessage(), |
| 144 | + allOf( |
| 145 | + containsString("Illegal Argument - Got unexpected time partitioning"), |
| 146 | + containsString("GHURRY"), |
| 147 | + containsString("ILLEGAL_ARG_TEST_PROJECT"), |
| 148 | + containsString("ILLEGAL_ARG_TEST_DATASET"), |
| 149 | + containsString("ILLEGAL_ARG_TEST_TABLE"))); |
| 150 | + return; |
| 151 | + } |
| 152 | + fail("testFromPb illegal argument exception did not throw!"); |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + public void testFromPbWithNullTimePartitioningTypeRaisesNullPointerException() { |
| 157 | + Table invalidTable = |
| 158 | + new Table() |
| 159 | + .setType("TABLE") |
| 160 | + .setTableReference( |
| 161 | + new TableReference() |
| 162 | + .setProjectId("NULL_PTR_TEST_PROJECT") |
| 163 | + .setDatasetId("NULL_PTR_TEST_DATASET") |
| 164 | + .setTableId("NULL_PTR_TEST_TABLE")) |
| 165 | + .setTimePartitioning( |
| 166 | + new com.google.api.services.bigquery.model.TimePartitioning().setType(null)); |
| 167 | + try { |
| 168 | + StandardTableDefinition.fromPb(invalidTable); |
| 169 | + } catch (NullPointerException ne) { |
| 170 | + assertThat( |
| 171 | + ne.getMessage(), |
| 172 | + allOf( |
| 173 | + containsString("Null pointer - Got unexpected time partitioning"), |
| 174 | + containsString("null"), |
| 175 | + containsString("NULL_PTR_TEST_PROJECT"), |
| 176 | + containsString("NULL_PTR_TEST_DATASET"), |
| 177 | + containsString("NULL_PTR_TEST_TABLE"))); |
| 178 | + return; |
| 179 | + } |
| 180 | + fail("testFromPb null pointer exception did not throw!"); |
| 181 | + } |
| 182 | + |
121 | 183 | @Test
|
122 | 184 | public void testFromPbWithNullEstimatedRowsAndBytes() {
|
123 | 185 | StandardTableDefinition.fromPb(
|
|
0 commit comments