change
This commit is contained in:
parent
5f80b8e78d
commit
bbf6640d6d
|
@ -10,6 +10,7 @@ import java.util.Properties;
|
||||||
|
|
||||||
public class AuthenticationTest {
|
public class AuthenticationTest {
|
||||||
|
|
||||||
|
// private static final String host = "127.0.0.1";
|
||||||
private static final String host = "master";
|
private static final String host = "master";
|
||||||
private static final String user = "root";
|
private static final String user = "root";
|
||||||
private static final String password = "123456";
|
private static final String password = "123456";
|
||||||
|
@ -17,7 +18,20 @@ public class AuthenticationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
try (Statement stmt = conn.createStatement()) {
|
// change password
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=taosdata");
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
stmt.execute("alter user " + user + " pass '" + password + "'");
|
||||||
|
stmt.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// use new to login and execute query
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password);
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
stmt.execute("show databases");
|
stmt.execute("show databases");
|
||||||
ResultSet rs = stmt.getResultSet();
|
ResultSet rs = stmt.getResultSet();
|
||||||
ResultSetMetaData meta = rs.getMetaData();
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
|
@ -30,28 +44,24 @@ public class AuthenticationTest {
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
// change password back
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password);
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
stmt.execute("alter user " + user + " pass 'taosdata'");
|
||||||
|
stmt.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||||
Properties props = new Properties();
|
} catch (ClassNotFoundException e) {
|
||||||
props.setProperty(TSDBDriver.PROPERTY_KEY_USER, user);
|
|
||||||
props.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, password);
|
|
||||||
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test", props);
|
|
||||||
} catch (SQLException | ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void after() {
|
|
||||||
try {
|
|
||||||
if (conn != null) {
|
|
||||||
conn.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue