/** * Retrieves the meta information object from the connection. * * @param connectionClass * the connection class. * @param connection * the connection instance. * @return the meta information object from the connection or <code>null</code> in case of * problems. */ private Object getMetaData(Class<?> connectionClass, Object connection) { return cache.invokeMethod(connectionClass, GET_META_DATA, null, connection, null, null, JAVA_SQL_CONNECTION_FQN); }
@Test public void getStaticField() { String field = (String) cache.getField(TestClass.class, "staticField", null, null); assertThat(field, is(equalTo("S"))); }
/** * {@inheritDoc} */ @Override public void beforeBody(long methodId, long sensorTypeId, Object object, Object[] parameters, RegisteredSensorConfig rsc) { Object httpContext = REFLECTION_CACHE.getField(object.getClass(), "localContext", object, null); if (httpContext != null) { SpanStoreAdapter spanStoreAdapter = new ApacheHttpContextSpanStoreAdapter(httpContext); SpanStore spanStore = spanStoreAdapter.getSpanStore(); if (spanStore != null) { spanStore.startSpan(); } } }
/** * Retrieves the version of the database. * * @param databaseMetaDataClass * the meta information class. * @param databaseMetaData * the meta information instance of the connection. * @return the version of the database. */ private String parseVersion(Class<?> databaseMetaDataClass, Object databaseMetaData) { return (String) cache.invokeMethod(databaseMetaDataClass, GET_DATABASE_PRODUCT_VERSION, null, databaseMetaData, null, null, JAVA_SQL_DATABASE_META_DATA_FQN); }
@Test public void normalUsage() { TestClass testInstance = new TestClass(); String field = (String) cache.getField(TestClass.class, "field", testInstance, null); assertThat(field, is(equalTo("X"))); }
/** * Checks if the connection is closed. * * @param connectionClass * the connection class. * @param connection * the connection instance. * @return the result of calling isClosed on the connection object or <code>true</code> any * exception occurs during method invocation */ private boolean isClosed(Class<?> connectionClass, Object connection) { return (Boolean) cache.invokeMethod(connectionClass, IS_CLOSED, null, connection, null, true, JAVA_SQL_CONNECTION_FQN); }
@Test public void normalUsageJavaClass() { Exception testCause = new Exception(); Exception testInstance = new Exception(testCause); Exception cause = (Exception) cache.getField(testInstance.getClass(), "cause", testInstance, null); assertThat(cause, is(sameInstance(testCause))); }
/** * Retrieves the product name of the database. * * @param databaseMetaDataClass * the meta information class. * @param databaseMetaData * the meta information instance of the connection. * @return the product name of the database. */ private String parseProduct(Class<?> databaseMetaDataClass, Object databaseMetaData) { return (String) cache.invokeMethod(databaseMetaDataClass, GET_DATABASE_PRODUCT_NAME, null, databaseMetaData, null, null, JAVA_SQL_DATABASE_META_DATA_FQN); } }
@Test public void nullClass() { Object errorvalue = "errorvalue"; Object result = cache.getField(null, "field", "instance", errorvalue); assertThat(result, is(theInstance(errorvalue))); }
/** * {@inheritDoc} */ @Override public void setSpanStore(SpanStore spanStore) { cache.invokeMethod(httpContext.getClass(), "setAttribute", new Class<?>[] { String.class, Object.class }, httpContext, new Object[] { SpanStoreAdapter.Constants.ID, spanStore }, null); } }
@Test public void getFieldInSuperSuperClass() { TestClass testInstance = new TestClass(); String field = (String) cache.getField(TestClass.class, "superSuperField", testInstance, null); assertThat(field, is(equalTo("Z"))); }
/** * {@inheritDoc} */ @Override public SpanStore getSpanStore() { Object spanStore = cache.invokeMethod(httpContext.getClass(), "getAttribute", new Class<?>[] { String.class }, httpContext, new Object[] { SpanStoreAdapter.Constants.ID }, null); if (spanStore instanceof SpanStore) { return (SpanStore) spanStore; } return null; }
@Test public void getFieldInSuperClass() { TestClass testInstance = new TestClass(); String field = (String) cache.getField(TestClass.class, "superField", testInstance, null); assertThat(field, is(equalTo("Y"))); }
/** * {@inheritDoc} */ @Override public void put(String key, String value) { cache.invokeMethod(message.getClass(), "setStringProperty", new Class<?>[] { String.class, String.class }, message, new Object[] { key, value }, null, JAVAX_JMS_MESSAGE); }
@Test public void nullField() { Object errorvalue = "errorvalue"; Object result = cache.getField(TestClass.class, null, "instance", errorvalue); assertThat(result, is(theInstance(errorvalue))); }
/** * {@inheritDoc} */ @Override public void setSpanContext(SpanContext spanContext) { cache.invokeMethod(httpServletRequest.getClass(), "setAttribute", new Class<?>[] { String.class, Object.class }, httpServletRequest, new Object[] { SpanContextStore.Constants.ID, spanContext }, null, JAVAX_SERVLET_HTTP_SERVLET_REQUEST_CLASS); }
@Test public void noSuchField() { TestClass testInstance = new TestClass(); Object errorValue = "errorValue"; Object field = cache.getField(TestClass.class, "notExisting", testInstance, errorValue); assertThat(field, is(theInstance(errorValue))); } }
/** * {@inheritDoc} */ @Override public String getHttpMethod() { return (String) cache.invokeMethod(jettyHttpExchange.getClass(), "getMethod", new Class<?>[] {}, jettyHttpExchange, new Object[] {}, null); }
/** * {@inheritDoc} */ @Override public int getStatus() { return (Integer) cache.invokeMethod(httpServletResponse.getClass(), "getStatus", new Class<?>[] {}, httpServletResponse, new Object[] {}, 0, JAVAX_SERVLET_HTTP_SERVLET_RESPONSE_FQN); }
/** * {@inheritDoc} */ @Override public String getHttpMethod() { return (String) cache.invokeMethod(httpServletRequest.getClass(), "getMethod", new Class<?>[] {}, httpServletRequest, new Object[] {}, null, JAVAX_SERVLET_HTTP_SERVLET_REQUEST_CLASS); }