xstream_field_order 1. XMLSequence : annotation which will be used for TestXml class 2. TestXml : Class for xstream fields 3. PartialSeqFieldKeySorter: customize the sort fields, defined fields which you will display in XML import com.thoughtworks.xstream.converters.reflection.FieldKey; import com.thoughtworks.xstream.converters.reflection.FieldKeySorter; import com.thoughtworks.xstream.core.util.OrderRetainingMap; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; public class PartialSeqFieldKeySorter implements FieldKeySorter { […]
Read MoreMockito for JUnit5 test cases
1. One of NPE solutions for mock SomeClass someclass = mock(SomeClass.class,Mockito.RETURNS_DEEP_STUBS); 2. Assert Any Exceptions assertThrows(RunTimeException.class, ()->{ //logic code }); 3. Mock/Test private method @InjectMocks PrivateInClass privateInClass; ReflectionTestUtils.invokeMethod(privateInClass, “privateMethodName”, param1, param2, …); 4. Mock final class Add below file in test path …/test/resources/mockkito-extensions/org.mockito.plugins.MockMaker MockMaker content mock-maker-inline
Read MoreBloomRPC cant import proto files issue and solutions
1. Try to import path which includes all files are needed as class and resources 2. When shows “boolmrpc e is not a construtor, error construct request” need to check proto files whether are correct 1) one or more proto files are not necessary 2) grammar errors in porto 3) related files in the import […]
Read MoreForify fix for DocumentBuilderFactory : XML External Entity Injection
Reference code: DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); documentBuilderFactory.setFeature(“http://xml.org/sax/features/external-general-entities”, false); documentBuilderFactory.setFeature(“http://xml.org/sax/features/external-parameter-entities”, false); documentBuilderFactory.setFeature(“http://apache.org/xml/features/disallow-doctype-decl”, true); documentBuilderFactory.setXIncludeAware(false); documentBuilderFactory.setExpandEntityReferences(false); ……
Read MoreJava code for output jpa sql with EclipseLink
Below is java code : TypedQuery outputSql = entityManager.createQuery(query); org.eclipse.persistence.sessions.Session session = communityEm.unwrap(org.eclipse.persistence.jpa.JpaEntityManager.class).getActiveSession(); org.eclipse.persistence.queries.DatabaseQuery databaseQuery = outputSql.unwrap(org.eclipse.persistence.jpa.JpaQuery.class).getDatabaseQuery(); databaseQuery.prepareCall(session, new org.eclipse.persistence.sessions.DatabaseRecord()); System.out.println(“databaseQuery.getSQLString()”+databaseQuery.getSQLString());
Read MoreIdea tool short cut on Mac
1. Optimize import java classes //use this short cut can remove redundant/unused classes Shift+Command + A , then Enter 2. Find java file Control + Shift + O 3. Find keyword in projects Control + Shift + F
Read MoreJAVA JPA Join relations for multiple tables
E.g. we have sql below select A.id, A.name, B.name2, C.name2 from A,B,C where A.id=B.bid and B.name3 = C.id We use join to connect JPA tables // Root rootpath Entity A,B,C in B has relasionship B.name3 = C Join b_path = rootpath.join(“id”); Join c_path = b_path.join(“name3”);
Read MoreJava code knowledge
1. Get client timezone Calendar.getInstance().getTimeZone() 2. JPA sql output //queryType:TypedQuery System.out.println(queryType.unwrap(org.eclipse.persistence.jpa.JpaQuery.class).getDatabaseQuery().getSQLString()); 3. LocalDateTime to Date //local_time : LocalDateTime Date.from( local_time.atZone( ZoneId.systemDefault()).toInstant()),
Read MoreConnect Hana with Java
Please see below code for getting hana kernel info and license info Please also search ‘ngdbc jar’ or use directly attached jar zipped ngdbc-2-3-58.jar import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; static void query_info(String ip, String port, String tename, String user, String password) { String perline = “”; Connection connection = null; String hostname […]
Read MoreRemote to call selenium server
Server end: We need to prepare to install firefox and selenium jar and gecko packages. 1) start selenium server, e.g. java -jar selenium-server-standalone-3.141.5.jar -role hub 2) start geckodriver with firefox browser, e.g. java -Dwebdriver.gecko.driver=/path/to/geckodriver -Dwebdriver.firefox.bin=/path/to/firefox-bin -jar /path/to/selenium-server-standalone-3.141.5.jar -role node -port 6666 -hub http://serverIP:4444/grid/register -browser browserName=firefox Until now, the selenium server will be listening on remote […]
Read More