Few weeks ago I started to work with JHipster - Java Framework for rapid development.I am not going to write a review of this framework - I hope, I will find time to do it later, but today I am going to write some useful information about pitfalls, that you can reach during your work with JHipster. #####Jhipster project unable to start itself on digitalocean Just FYI, Jhipster is built on top of Spring Boot Framework + Angular JS, so to start application, you need just to execute single command mvn spring-boot:run That’s a convenient way for deploying application - no separate application servers, only embedded, only hardcore. That’s why Spring Boot stores some embedded tomcat server, which contains all properties. So, the problem is that sometimes, when you deploy your application on Digital Ocean cloud server - you need to wait for a long time to finish deploying process. In my case, the problem with long deploy is that Tomcat loves to use /dev/random function, instead of /dev/urandom. To get a good example of how random and urandom works, just go to terminal and type cat /dev/random Then try to move your mouse, you will receive additional values. Then...
Agenda
</br>
Description of rules
@Rule vs @ClassRule
Some useful rules
Writing your own rule
Description of rules
Rules allow very flexible addition or redefinition of the behavior of each test method in a test class. Testers can reuse or extend one of the provided Rules below, or write their own.
This mean, that you can controll the behavior of your test case, you can catch exceptions, write before-after methods, etc.
I would recommend to read more about rules here
https://github.com/junit-team/junit/wiki/Rules
@Rule vs @ClassRule
There is a difference between @Rule and @ClassRule in JUnit.We can differ them similiar as @Before and @BeforeClass. If you will annotate field ,that implements org.junit.rules.TestRule with @Rule annotation, then it will run in each method. But, if you will annotate this field as @ClassRule, then it will run once.
Useful rules examples
Writing your own rule
We will write custom TestRule, that will log actions. We will have two
We will get
before: global
before: local
after: local
after: global
Today I had a problem with Tomcat encoding with query params.I have solution for search entities.It was working with latin words. But when I tried to add query params in cyrillic, tomcat treat them as unreadable symbols, despite the fact, that I have URLEncodingFilter in my web application, that encodes everything in UTF-8,
So, request like this turns to be invalid.
http://{HOST}:8080/is-lnu-rest-api/api/specoffers/types?name=Молодший
So, as usual, I started investigation of this issue. First, I scanned my project, especially web.xml deployment descriptor for some unusual encoding thing, but I failed, I found nothing. So I delegated all the investigation to google, and found that I should edit my
tomcat/conf/server.xml
You need to find Connector with port=”8080” and add two lines.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
useBodyEncodingForURI="true" <!-- This line -->
URIEncoding="UTF-8" <!-- This line -->
redirectPort="8443" />
Restart your tomcat, and now everythig will be okay
How many times did you have to use java enums in your JPA/Hubernate entities ? Yes, instead of having some relations with reference-tables, which are some sort of dictionaries, you wrote simple field with varchar type Something like class Model with RowStatus enum RowStatus is used to detemine whether row is deleted from the system, or row is active.It seems, that this should be enough to have no problems while using this functionality. But there is one potential problem: When we set enum in our system, we made a contract, that we will send only values from RowStatus enum. But how about updating data outside our system ? For example, system administrator of your database made some critical update and committed some critical bug - instead of values from RowStatus - ACTIVE, DELETED he updated row with syntax error - DELITED. From now on, when Hibernate will try to map such row - he will throw an exception. That’s an issue. Possible solutions ? The only solution that I can offer you is that you will controll adding your data on database. You can use database enums, constraints, triggers, etc… I choosed postgres enums. To add such, you simply need...
How many times did you experienced issue, when you need to clean your database from unused data ?For example, you have a qa server with thousands of rows, which you don’t need anymore, so it’s time to delete them. To clean up your database, someone call separate scripts for each table, someone create-drops database.I decided to delete all tables. To remove all rows, you can use maven sql plugin, which has powerful possibilities for doing work with sql. First of all, if you have your maven application, I would reccomend to create separate module for sql. If you don’t want to do this, just leave it as it is in your root pom.xml. You will need to add Maven Sql Plugin. Then, you need to map execution to install goal. You will need to create resource folder.This will be the place, where you will store your scripts. Before we start I don’t want anyone to think, that such module is the best place for storing your database schemas creation.For this purposes there is a good framework called liquibase - it saves migration history and can surely know, what should be updated, and what should not. Such module is always good...