io.stargate.it.http.graphql.cqlfirst.ScalarsTest Maven / Gradle / Ivy
/*
* Copyright The Stargate Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.stargate.it.http.graphql.cqlfirst;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.uuid.Uuids;
import com.jayway.jsonpath.JsonPath;
import io.stargate.db.schema.Column;
import io.stargate.it.BaseIntegrationTest;
import io.stargate.it.driver.CqlSessionExtension;
import io.stargate.it.driver.CqlSessionSpec;
import io.stargate.it.driver.TestKeyspace;
import io.stargate.it.http.RestUtils;
import io.stargate.it.storage.StargateConnectionInfo;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.ZoneId;
import java.util.Date;
import java.util.Map;
import java.util.TimeZone;
import java.util.UUID;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@ExtendWith(CqlSessionExtension.class)
@CqlSessionSpec(
initQueries = {
"CREATE TABLE IF NOT EXISTS \"Scalars\" (\n"
+ " id uuid PRIMARY KEY,\n"
+ " asciivalue ascii,\n"
+ " bigintvalue bigint,\n"
+ " blobvalue blob,\n"
+ " booleanvalue boolean,\n"
+ " datevalue date,\n"
+ " decimalvalue decimal,\n"
+ " doublevalue double,\n"
+ " durationvalue duration,\n"
+ " floatvalue float,\n"
+ " inetvalue inet,\n"
+ " intvalue int,\n"
+ " smallintvalue smallint,\n"
+ " textvalue text,\n"
+ " timevalue time,\n"
+ " timestampvalue timestamp,\n"
+ " timeuuidvalue timeuuid,\n"
+ " tinyintvalue tinyint,\n"
+ " uuidvalue uuid,\n"
+ " varcharvalue varchar,\n"
+ " varintvalue varint\n"
+ ")"
})
public class ScalarsTest extends BaseIntegrationTest {
private static CqlFirstClient CLIENT;
private static CqlIdentifier KEYSPACE_ID;
@BeforeAll
public static void setup(StargateConnectionInfo cluster, @TestKeyspace CqlIdentifier keyspaceId) {
KEYSPACE_ID = keyspaceId;
String host = cluster.seedAddress();
CLIENT = new CqlFirstClient(host, RestUtils.getAuthToken(host));
}
@ParameterizedTest
@MethodSource("getScalarValues")
public void shouldSupportScalar(Column.Type type, Object value) {
UUID id = UUID.randomUUID();
String fieldName = type.name().toLowerCase() + "value";
String graphqlValue =
(value instanceof String) ? String.format("\"%s\"", value) : value.toString();
// When writing a value of this type:
Map response =
CLIENT.executeDmlQuery(
KEYSPACE_ID,
String.format(
"mutation { updateScalars(value: {id: \"%s\", %s: %s}) { applied } }",
id, fieldName, graphqlValue));
assertThat(JsonPath.read(response, "$.updateScalars.applied")).isTrue();
// Should read back the same value:
response =
CLIENT.executeDmlQuery(
KEYSPACE_ID,
String.format("{ Scalars(value: {id: \"%s\"}) { values { %s } } }", id, fieldName));
String fieldPath = String.format("$.Scalars.values[0].%s", fieldName);
assertThat(JsonPath.
© 2015 - 2024 Weber Informatics LLC | Privacy Policy