/******************************************************************************
 *                                                                            *
 *                    Copyright 2018 Subterranean Security                    *
 *                                                                            *
 *  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 com.sandpolis.core.instance.storage.database;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.net.URISyntaxException;

import org.junit.jupiter.api.Test;

import com.sandpolis.core.instance.storage.database.Database;

class DatabaseTest {

	@Test
	void testState() throws Exception {
		try (Database db = new Database("jdbc:sqlite:file:/home/test.db")) {
			assertFalse(db.isOpen());
			assertEquals("/home/test.db", db.getFile().getAbsolutePath());
		}

		try (Database db = new Database("jdbc:mysql:192.168.1.1/database")) {
			assertFalse(db.isOpen());
			assertNull(db.getFile());
			assertNotNull(db.getUrl());
		}
	}

	@Test
	void testInvalidUrls() {
		assertThrows(URISyntaxException.class, () -> new Database("invalid url"));
	}

}

@@ -1712,16 +1712,37 @@
 hrows;%0A%0A
+import java.io.File;%0A
 import j
@@ -1770,16 +1770,58 @@
 ption;%0A%0A
+import org.junit.jupiter.api.DisplayName;%0A
 import o
@@ -1945,22 +1945,99 @@
 st%0A%09
-void testState
+@DisplayName(%22Check the state and metadata of a newly constructed Database%22)%0A%09void metadata
 () t
@@ -2053,16 +2053,29 @@
 eption %7B
+%0A%0A%09%09// SQLite
 %0A%09%09try (
@@ -2183,16 +2183,25 @@
 tEquals(
+new File(
 %22/home/t
@@ -2207,16 +2207,35 @@
 test.db%22
+).getAbsolutePath()
 , db.get
@@ -2266,16 +2266,27 @@
 );%0A%09%09%7D%0A%0A
+%09%09// MySQL%0A
 %09%09try (D
@@ -2458,18 +2458,94 @@
 st%0A%09
-void testI
+@DisplayName(%22Check that a Database cannot be constructed for an invalid URL%22)%0A%09void i
 nval
@@ -2549,17 +2549,16 @@
 validUrl
-s
 () %7B%0A%09%09a
@@ -2615,16 +2615,19 @@
 tabase(%22
+///
 invalid 
@@ -2629,16 +2629,19 @@
 alid url
+///
 %22));%0A%09%7D%0A

Fix path in database test on Windows