forked from community/device-mgt-core
Merge pull request #1053 from sinthuja/origin-wso2-master
Adding more negative testcase for operation management4.x.x
commit
e7319c5ac8
@ -0,0 +1,316 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
* WSO2 Inc. licenses this file to you 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 org.wso2.carbon.device.mgt.core.mock;
|
||||||
|
|
||||||
|
import java.sql.Array;
|
||||||
|
import java.sql.Blob;
|
||||||
|
import java.sql.CallableStatement;
|
||||||
|
import java.sql.Clob;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
|
import java.sql.NClob;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLClientInfoException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.SQLWarning;
|
||||||
|
import java.sql.SQLXML;
|
||||||
|
import java.sql.Savepoint;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.sql.Struct;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is mock class which provides mock database connection.
|
||||||
|
*/
|
||||||
|
public class MockConnection implements Connection {
|
||||||
|
@Override
|
||||||
|
public Statement createStatement() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String nativeSQL(String sql) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getAutoCommit() throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void commit() throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rollback() throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClosed() throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseMetaData getMetaData() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReadOnly() throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCatalog(String catalog) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCatalog() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTransactionIsolation(int level) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTransactionIsolation() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SQLWarning getWarnings() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearWarnings() throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
|
||||||
|
throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
|
||||||
|
throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHoldability(int holdability) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHoldability() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Savepoint setSavepoint() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Savepoint setSavepoint(String name) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rollback(Savepoint savepoint) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
|
||||||
|
int resultSetHoldability) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
|
||||||
|
int resultSetHoldability) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Clob createClob() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Blob createBlob() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NClob createNClob() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SQLXML createSQLXML() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(int timeout) throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setClientInfo(Properties properties) throws SQLClientInfoException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClientInfo(String name) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Properties getClientInfo() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSchema(String schema) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSchema() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void abort(Executor executor) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNetworkTimeout() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
* WSO2 Inc. licenses this file to you 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 org.wso2.carbon.device.mgt.core.mock;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.SQLFeatureNotSupportedException;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the mock data source implementation that will be used in the test cases.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MockDataSource implements DataSource {
|
||||||
|
private boolean throwException = false;
|
||||||
|
private Connection connection;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Connection getConnection() throws SQLException {
|
||||||
|
if (throwException) {
|
||||||
|
throw new SQLException("Cannot created test connection.");
|
||||||
|
} else {
|
||||||
|
if (connection != null) {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
return new MockConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Connection getConnection(String username, String password) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PrintWriter getLogWriter() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLogWriter(PrintWriter out) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLoginTimeout(int seconds) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLoginTimeout() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThrowException(boolean throwException) {
|
||||||
|
this.throwException = throwException;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
this.throwException = false;
|
||||||
|
this.connection = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setConnection(Connection connection) {
|
||||||
|
this.connection = connection;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
* WSO2 Inc. licenses this file to you 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 org.wso2.carbon.device.mgt.core.mock;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.Driver;
|
||||||
|
import java.sql.DriverPropertyInfo;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.SQLFeatureNotSupportedException;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the mock JDBC driver which is used in the testcases to mock other database operations.
|
||||||
|
*/
|
||||||
|
public class MockJDBCDriver implements Driver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Connection connect(String url, Properties info) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean acceptsURL(String url) throws SQLException {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||||
|
return new DriverPropertyInfo[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMajorVersion() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMinorVersion() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean jdbcCompliant() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,250 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
* WSO2 Inc. licenses this file to you 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 org.wso2.carbon.device.mgt.core.mock;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.SQLWarning;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the mock statement for the testcases.
|
||||||
|
*/
|
||||||
|
public class MockStatement implements Statement {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResultSet executeQuery(String sql) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int executeUpdate(String sql) throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxFieldSize() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMaxFieldSize(int max) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxRows() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMaxRows(int max) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEscapeProcessing(boolean enable) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getQueryTimeout() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setQueryTimeout(int seconds) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancel() throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SQLWarning getWarnings() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearWarnings() throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCursorName(String name) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(String sql) throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResultSet getResultSet() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getUpdateCount() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getMoreResults() throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFetchDirection(int direction) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFetchDirection() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFetchSize(int rows) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFetchSize() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getResultSetConcurrency() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getResultSetType() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addBatch(String sql) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearBatch() throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] executeBatch() throws SQLException {
|
||||||
|
return new int[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Connection getConnection() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getMoreResults(int current) throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResultSet getGeneratedKeys() throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(String sql, String[] columnNames) throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getResultSetHoldability() throws SQLException {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClosed() throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPoolable(boolean poolable) throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPoolable() throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeOnCompletion() throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCloseOnCompletion() throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,228 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
* WSO2 Inc. licenses this file to you 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 org.wso2.carbon.device.mgt.core.operation;
|
||||||
|
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||||
|
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.mock.MockDataSource;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Negative testcases for {@link OperationManagerImpl}
|
||||||
|
* regarding the database connectivity.
|
||||||
|
*/
|
||||||
|
public class OperationManagementNegativeDBOperationTest extends BaseDeviceManagementTest {
|
||||||
|
|
||||||
|
private static final String DEVICE_TYPE = "NEGDB_OP_TEST_TYPE";
|
||||||
|
private static final String DEVICE_ID_PREFIX = "NEGDB_OP-TEST-DEVICE-ID-";
|
||||||
|
private static final int NO_OF_DEVICES = 5;
|
||||||
|
private static final String ADMIN_USER = "admin";
|
||||||
|
|
||||||
|
private List<DeviceIdentifier> deviceIds = new ArrayList<>();
|
||||||
|
private OperationManager operationMgtService;
|
||||||
|
private MockDataSource dataSource;
|
||||||
|
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@Override
|
||||||
|
public void init() throws Exception {
|
||||||
|
DataSource datasource = this.getDataSource(this.
|
||||||
|
readDataSourceConfig("src/test/resources/config/datasource/mock-data-source-config.xml"));
|
||||||
|
OperationManagementDAOFactory.init(datasource);
|
||||||
|
for (int i = 0; i < NO_OF_DEVICES; i++) {
|
||||||
|
deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
|
||||||
|
}
|
||||||
|
List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
|
||||||
|
DeviceManagementProviderService deviceMgtService = DeviceManagementDataHolder.getInstance().
|
||||||
|
getDeviceManagementProvider();
|
||||||
|
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
||||||
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
||||||
|
for (Device device : devices) {
|
||||||
|
deviceMgtService.enrollDevice(device);
|
||||||
|
}
|
||||||
|
List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE);
|
||||||
|
for (Device device : returnedDevices) {
|
||||||
|
if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
|
||||||
|
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NotificationStrategy notificationStrategy = new TestNotificationStrategy();
|
||||||
|
this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy);
|
||||||
|
this.setMockDataSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operation by device id", expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperations() throws OperationManagementException {
|
||||||
|
this.dataSource.setThrowException(true);
|
||||||
|
try {
|
||||||
|
this.operationMgtService.getOperations(this.deviceIds.get(0));
|
||||||
|
} finally {
|
||||||
|
this.dataSource.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operations with paginated request",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperationsPaginatedRequest() throws OperationManagementException {
|
||||||
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
|
||||||
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
|
||||||
|
PaginationRequest request = new PaginationRequest(1, 2);
|
||||||
|
request.setDeviceType(DEVICE_TYPE);
|
||||||
|
request.setOwner(ADMIN_USER);
|
||||||
|
this.dataSource.setThrowException(true);
|
||||||
|
try {
|
||||||
|
this.operationMgtService.getOperations(this.deviceIds.get(0), request);
|
||||||
|
} finally {
|
||||||
|
PrivilegedCarbonContext.endTenantFlow();
|
||||||
|
this.dataSource.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get pending operations", expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getPendingOperations() throws OperationManagementException {
|
||||||
|
this.dataSource.setThrowException(true);
|
||||||
|
try {
|
||||||
|
this.operationMgtService.getPendingOperations(this.deviceIds.get(0));
|
||||||
|
} finally {
|
||||||
|
this.dataSource.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get next pending operations", expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getNextPendingOperations() throws OperationManagementException {
|
||||||
|
this.dataSource.setThrowException(true);
|
||||||
|
try {
|
||||||
|
this.operationMgtService.getNextPendingOperation(this.deviceIds.get(0));
|
||||||
|
} finally {
|
||||||
|
this.dataSource.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operation by device and operation id",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperationByDeviceAndOperationId() throws OperationManagementException {
|
||||||
|
this.dataSource.setThrowException(true);
|
||||||
|
try {
|
||||||
|
this.operationMgtService.getOperationByDeviceAndOperationId(this.deviceIds.get(0), 1);
|
||||||
|
} finally {
|
||||||
|
this.dataSource.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operation by device and status",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperationByDeviceAndStatus() throws OperationManagementException, DeviceManagementException {
|
||||||
|
this.dataSource.setThrowException(true);
|
||||||
|
try {
|
||||||
|
this.operationMgtService.getOperationsByDeviceAndStatus(this.deviceIds.get(0), Operation.Status.PENDING);
|
||||||
|
} finally {
|
||||||
|
this.dataSource.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operation by operation id",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperationByOperationId() throws OperationManagementException, DeviceManagementException {
|
||||||
|
this.dataSource.setThrowException(true);
|
||||||
|
try {
|
||||||
|
this.operationMgtService.getOperation(1);
|
||||||
|
} finally {
|
||||||
|
this.dataSource.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operation by activity id",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperationByActivityId() throws OperationManagementException, DeviceManagementException {
|
||||||
|
this.dataSource.setThrowException(true);
|
||||||
|
try {
|
||||||
|
this.operationMgtService.getOperationByActivityId("ACTIVITY_1");
|
||||||
|
} finally {
|
||||||
|
this.dataSource.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operation by activity id and device id",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperationByActivityAndDeviceID() throws OperationManagementException, DeviceManagementException {
|
||||||
|
this.dataSource.setThrowException(true);
|
||||||
|
try {
|
||||||
|
this.operationMgtService.getOperationByActivityIdAndDevice("ACTIVITY_1", deviceIds.get(0));
|
||||||
|
} finally {
|
||||||
|
this.dataSource.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get activities updated after some timestamp",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getActivitiesUpdatedAfter() throws OperationManagementException, DeviceManagementException {
|
||||||
|
this.dataSource.setThrowException(true);
|
||||||
|
try {
|
||||||
|
this.operationMgtService.getActivitiesUpdatedAfter(System.currentTimeMillis() / 1000, 10, 0);
|
||||||
|
} finally {
|
||||||
|
this.dataSource.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get activities count updated after some timestamp",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getActivityCountUpdatedAfter() throws OperationManagementException, DeviceManagementException {
|
||||||
|
this.dataSource.setThrowException(true);
|
||||||
|
try {
|
||||||
|
this.operationMgtService.getActivityCountUpdatedAfter(System.currentTimeMillis() / 1000);
|
||||||
|
} finally {
|
||||||
|
this.dataSource.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMockDataSource() throws NoSuchFieldException, IllegalAccessException {
|
||||||
|
Field datasource = OperationManagementDAOFactory.class.getDeclaredField("dataSource");
|
||||||
|
datasource.setAccessible(true);
|
||||||
|
this.dataSource = new MockDataSource();
|
||||||
|
datasource.set(datasource, this.dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public void resetDatabase() throws DeviceManagementException {
|
||||||
|
OperationManagementDAOFactory.init(this.getDataSource(this.
|
||||||
|
readDataSourceConfig("src/test/resources/config/datasource/data-source-config.xml")));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,196 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
* WSO2 Inc. licenses this file to you 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 org.wso2.carbon.device.mgt.core.operation;
|
||||||
|
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
|
||||||
|
import org.wso2.carbon.device.mgt.core.common.TestDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the testcase which covers the methods from {@link OperationManager}
|
||||||
|
*/
|
||||||
|
public class OperationManagementNoDBSchemaTests extends BaseDeviceManagementTest {
|
||||||
|
|
||||||
|
private static final String DEVICE_TYPE = "NEG_OP_TEST_TYPE";
|
||||||
|
private static final String DEVICE_ID_PREFIX = "NEG_OP-TEST-DEVICE-ID-";
|
||||||
|
private static final String COMMAND_OPERATON_CODE = "COMMAND-TEST";
|
||||||
|
private static final int NO_OF_DEVICES = 5;
|
||||||
|
private static final String ADMIN_USER = "admin";
|
||||||
|
|
||||||
|
private List<DeviceIdentifier> deviceIds = new ArrayList<>();
|
||||||
|
private OperationManager operationMgtService;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void init() throws Exception {
|
||||||
|
DataSource datasource = this.getDataSource(this.
|
||||||
|
readDataSourceConfig("src/test/resources/config/datasource/no-table-data-source-config.xml"));
|
||||||
|
OperationManagementDAOFactory.init(datasource);
|
||||||
|
for (int i = 0; i < NO_OF_DEVICES; i++) {
|
||||||
|
deviceIds.add(new DeviceIdentifier(DEVICE_ID_PREFIX + i, DEVICE_TYPE));
|
||||||
|
}
|
||||||
|
List<Device> devices = TestDataHolder.generateDummyDeviceData(this.deviceIds);
|
||||||
|
DeviceManagementProviderService deviceMgtService = DeviceManagementDataHolder.getInstance().
|
||||||
|
getDeviceManagementProvider();
|
||||||
|
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
|
||||||
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
||||||
|
for (Device device : devices) {
|
||||||
|
deviceMgtService.enrollDevice(device);
|
||||||
|
}
|
||||||
|
List<Device> returnedDevices = deviceMgtService.getAllDevices(DEVICE_TYPE);
|
||||||
|
for (Device device : returnedDevices) {
|
||||||
|
if (!device.getDeviceIdentifier().startsWith(DEVICE_ID_PREFIX)) {
|
||||||
|
throw new Exception("Incorrect device with ID - " + device.getDeviceIdentifier() + " returned!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NotificationStrategy notificationStrategy = new TestNotificationStrategy();
|
||||||
|
this.operationMgtService = new OperationManagerImpl(DEVICE_TYPE, notificationStrategy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "add operation", expectedExceptions = OperationManagementException.class)
|
||||||
|
public void addCommandOperation() throws DeviceManagementException, OperationManagementException,
|
||||||
|
InvalidDeviceException {
|
||||||
|
this.operationMgtService.addOperation(
|
||||||
|
OperationManagementTests.getOperation(new CommandOperation(),
|
||||||
|
Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
|
||||||
|
this.deviceIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operations", expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperations() throws DeviceManagementException, OperationManagementException,
|
||||||
|
InvalidDeviceException {
|
||||||
|
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||||
|
this.operationMgtService.getOperations(deviceIdentifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(description = "Get Pending operations", expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getPendingOperations() throws DeviceManagementException, OperationManagementException,
|
||||||
|
InvalidDeviceException {
|
||||||
|
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||||
|
this.operationMgtService.getPendingOperations(deviceIdentifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get paginated request", expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getPaginatedRequestAsAdmin() throws OperationManagementException {
|
||||||
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
|
||||||
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
|
||||||
|
PaginationRequest request = new PaginationRequest(1, 2);
|
||||||
|
request.setDeviceType(DEVICE_TYPE);
|
||||||
|
request.setOwner(ADMIN_USER);
|
||||||
|
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||||
|
this.operationMgtService.getOperations(deviceIdentifier, request);
|
||||||
|
}
|
||||||
|
PrivilegedCarbonContext.endTenantFlow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Update operation", expectedExceptions = OperationManagementException.class)
|
||||||
|
public void updateOperation() throws OperationManagementException {
|
||||||
|
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||||
|
Operation operation = OperationManagementTests.getOperation(new CommandOperation(), Operation.Type.COMMAND,
|
||||||
|
COMMAND_OPERATON_CODE);
|
||||||
|
operation.setStatus(Operation.Status.COMPLETED);
|
||||||
|
operation.setOperationResponse("The operation is successfully completed");
|
||||||
|
this.operationMgtService.updateOperation(deviceIdentifier, operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get next pending operation", expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getNextPendingOperation() throws OperationManagementException {
|
||||||
|
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||||
|
this.operationMgtService.getNextPendingOperation(deviceIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(description = "get operation by device and operation id",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperationByDeviceAndOperationId() throws OperationManagementException {
|
||||||
|
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||||
|
this.operationMgtService.getOperationByDeviceAndOperationId(deviceIdentifier, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operation by device and status",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperationsByDeviceAndStatus() throws OperationManagementException, DeviceManagementException {
|
||||||
|
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
|
||||||
|
this.operationMgtService.getOperationsByDeviceAndStatus(deviceIdentifier,
|
||||||
|
Operation.Status.PENDING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operation by operation id", expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperation() throws OperationManagementException, DeviceManagementException {
|
||||||
|
this.operationMgtService.getOperation(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operation activity", expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperationActivity() throws OperationManagementException {
|
||||||
|
this.operationMgtService.getOperationByActivityId
|
||||||
|
(DeviceManagementConstants.OperationAttributes.ACTIVITY + "1");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get operation by activity id and device",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperationByActivityIdAndDevice() throws OperationManagementException {
|
||||||
|
this.operationMgtService.getOperationByActivityIdAndDevice(
|
||||||
|
DeviceManagementConstants.OperationAttributes.ACTIVITY + "1", this.deviceIds.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get activities updated after some time",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getOperationUpdatedAfterWithLimitAndOffset() throws OperationManagementException {
|
||||||
|
this.operationMgtService.getActivitiesUpdatedAfter(System.currentTimeMillis() / 1000, 10, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "Get activity count updated after",
|
||||||
|
expectedExceptions = OperationManagementException.class)
|
||||||
|
public void getActivityCountUpdatedAfter() throws OperationManagementException {
|
||||||
|
this.operationMgtService.getActivityCountUpdatedAfter(System.currentTimeMillis() / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public void resetDatabase() throws DeviceManagementException {
|
||||||
|
OperationManagementDAOFactory.init(this.getDataSource(this.
|
||||||
|
readDataSourceConfig("src/test/resources/config/datasource/data-source-config.xml")));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ WSO2 Inc. licenses this file to you 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<DataSourceConfig>
|
||||||
|
<Url>jdbc:h2:mem:cdm-test-db;DB_CLOSE_ON_EXIT=FALSE;MVCC=true</Url>
|
||||||
|
<DriverClassName>org.wso2.carbon.device.mgt.core.mock.MockJDBCDriver</DriverClassName>
|
||||||
|
<User>wso2carbon</User>
|
||||||
|
<Password>wso2carbon</Password>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- For MySql -->
|
||||||
|
|
||||||
|
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
|
||||||
|
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
|
||||||
|
<!--<User>root</User>-->
|
||||||
|
<!--<Password></Password>-->
|
||||||
|
</DataSourceConfig>
|
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ WSO2 Inc. licenses this file to you 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<DataSourceConfig>
|
||||||
|
<Url>jdbc:h2:mem:nodb-test-db;DB_CLOSE_ON_EXIT=FALSE;MVCC=true</Url>
|
||||||
|
<DriverClassName>org.h2.Driver</DriverClassName>
|
||||||
|
<User>wso2carbon</User>
|
||||||
|
<Password>wso2carbon</Password>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- For MySql -->
|
||||||
|
|
||||||
|
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
|
||||||
|
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
|
||||||
|
<!--<User>root</User>-->
|
||||||
|
<!--<Password></Password>-->
|
||||||
|
</DataSourceConfig>
|
Loading…
Reference in new issue