How to test some kind of class in local testcase, Not on server

Hi experts,
I have a question about invoke “com.webMethods.portal.service.sql.DataManager.getConnection();” in main method, java.lang.NullPointerException occurs, and I want to know how to test this kind of class like “com.webMethods.portal.service.sql.DataManager.getConnection();”, It works fine when I deployed on server,but not in local testcase.


public final Map<String, String> getDBSelect() throws SQLException{
		logger.info("???????");
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = "SELECT * FROM RL_ATTACHMENT WHERE ATTACHMENTID=?";
		Map<String, String> descMap = new LinkedHashMap<String, String>();
		try {
			conn = com.webmethods.portal.service.sql.DataManager.getConnection();
			logger.info("conn:" + conn.toString());
			System.out.println("conn:" + conn.toString());
			
			ps = conn.prepareStatement(sql);
			ps.setString(1, "123");
			rs = ps.executeQuery();
			while (rs.next()) {
				String item = rs.getString(1).toUpperCase();
				descMap.put(item, rs.getString(2));
				logger.info(item + " = " + rs.getString(2));
				System.out.println(item + " = " + rs.getString(2));
			}
		} catch (Exception e) {
			logger.info(e.getMessage());
			e.printStackTrace();
		} finally {
			rs.close();
			ps.close();
			conn.close();
		}
		descMap = Collections.synchronizedMap(descMap);
		return descMap;
	}

public static void main(String[] args) throws SQLException {
		TestJavaBean testJavaBean = new TestJavaBean();

		testJavaBean.getDBSelect();
	}

thanks in advance.

best regards,
felix

1 Like

Hi,

This is because this gets the connection from the Portal Server but it cannot get the connection when you run it on JVM container alone.

1 Like

Hi Srikanth,
thanks for your reply, Is there some way to solve this problem?

best regards,
felix

Hello Felix,

Can you please explain your use case? This might help to suggest you on this case.

Thank you.

Hi,
I just wanna test my first segment java code in main method.

best regards,
felix

I am afraid you cannot do that in JVM container alone. May be you should try to cover this in an Integration Test perspective than Unit testing perspective.

Hi,
all right.thanks.

best regards,
felix