/* * Copyright <2021> Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://www.apache.org/licenses/LICENSE-2.0 * * or in the "license" file accompanying this file. This file 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 software.amazon.documentdb.jdbc.query; import com.mongodb.client.MongoClient; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.bson.BsonDocument; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import software.amazon.documentdb.jdbc.DocumentDbConnectionProperties; import software.amazon.documentdb.jdbc.common.test.DocumentDbFlapDoodleTest; import software.amazon.documentdb.jdbc.metadata.DocumentDbDatabaseSchemaMetadata; import software.amazon.documentdb.jdbc.persist.DocumentDbSchemaWriter; import java.sql.SQLException; import static software.amazon.documentdb.jdbc.metadata.DocumentDbDatabaseSchemaMetadata.VERSION_NEW; public class DocumentDbQueryMappingServiceTest extends DocumentDbFlapDoodleTest { private static final String DATABASE_NAME = "database"; private static final String USER = "user"; private static final String PASSWORD = "password"; private DocumentDbConnectionProperties connectionProperties; private MongoClient client; @BeforeAll @SuppressFBWarnings(value = "HARD_CODE_PASSWORD", justification = "Hardcoded for test purposes only") void setup() { connectionProperties = new DocumentDbConnectionProperties(); createUser(DATABASE_NAME, USER, PASSWORD); connectionProperties.setUser(USER); connectionProperties.setPassword(PASSWORD); connectionProperties.setDatabase(DATABASE_NAME); connectionProperties.setTlsEnabled("false"); connectionProperties.setHostname("localhost:" + getMongoPort()); client = createMongoClient(ADMIN_DATABASE, USER, PASSWORD); } @AfterAll void teardown() throws Exception { try (DocumentDbSchemaWriter schemaWriter = new DocumentDbSchemaWriter(connectionProperties, client)) { schemaWriter.remove("id"); } client.close(); } protected void insertBsonDocuments(final String collectionName, final BsonDocument[] documents) { insertBsonDocuments(collectionName, DATABASE_NAME, documents, client); } protected DocumentDbQueryMappingService getQueryMappingService() throws SQLException { final DocumentDbDatabaseSchemaMetadata databaseMetadata = DocumentDbDatabaseSchemaMetadata.get(connectionProperties, "id", VERSION_NEW, client); return new DocumentDbQueryMappingService(connectionProperties, databaseMetadata); } protected static String getDatabaseName() { return DATABASE_NAME; } }