For doing Tests in Spring Boot you have to know the next things:
- You need a java test and resources test directories in your project. In the resources directory you put the files for the src/test/java and the src/test/resources directory the test you want to pass when you do the maven build.
- You need am application-TEST.yml file in your resources directory for configure the test calls.
- When you implements a Test you have to use the next anotations before the class name:
@org.junit.runner.RunWith(SpringJUnit4ClassRunner.class)
@org.springframework.boot.test.SpringApplicationConfiguration(classes = ClassName.class)
@org.springframework.test.context.ActiveProfiles(value = "TEST")
- For test a Service implemented in you src/main/java directory you have to indicate this way:
@org.springframework.beans.factory.annotation.Autowired
MyService service;
- At last, you need to indicate the method that test one call like:
@org.junit.Test
public void test() {
... do the test and finally verify the result of the test
assertThat(result).isEqualTo("OK");
}
Here you have implemented your first test.
For call it, you have to run the maven test option.
For skip one test, you can indicate @org.junit.Ignore and the test don't will be executed.
For skip all test, you can indicate to maven that don't want to execute test this way:
Go to run configuration and check the option skip tests.
Any question of this tip, don't doubt ask me!
Try it and have fun!
Posts about Angular, Ionic, Java, Artificial Intelligence and Unity written by David Martinez Ros @davidnezan.
Mostrando entradas con la etiqueta learn. Mostrar todas las entradas
Mostrando entradas con la etiqueta learn. Mostrar todas las entradas
miércoles, 24 de mayo de 2017
The way to implements Unit Tests in Spring Boot
miércoles, 26 de abril de 2017
How to configure MongoDB with Spring Boot in Windows 7
Hi, everyone!
Today we are going to show the steps for configuring MongoDB 3.3.4 with Spring Boot 1.5 in Windows 7.
First you have to download the MongoDB:
Here you have the official link: https://docs.mongodb.com/manual/installation/
Now here is the most important think, that don't tells the manual of mongodb:
You have to download the Windows parche: Windows6.1-KB2999226-x64.msu and it will add a dll file that is necessary for running MongoDB.
Then, you have to create the directory C:/db/data.
Then, when MongoDB is installed and you have create the directory, you have to run the file C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe.
This file will open the MongoDB connection.
Here you have MongoDB running!
For the other side, you have to configure your mongoDB database connectio and driver in Spring Boot configuration.
You have to create a file named application-{environment}.yml with the next content:
spring:
datasource:
url: jdbc:oracle:thin:@//localhost:27017/howdyl
driver-class-name: mongodb.jdbc.MongoDriver
jpa:
show-sql: true
hibernate:
showSql: true
dialect: org.hibernate.dialect.Oracle10gDialect
And the magic, you run your application a mongoDB is running.
For any question, ask me!
Try it and have fun!
Today we are going to show the steps for configuring MongoDB 3.3.4 with Spring Boot 1.5 in Windows 7.
First you have to download the MongoDB:
Here you have the official link: https://docs.mongodb.com/manual/installation/
Now here is the most important think, that don't tells the manual of mongodb:
You have to download the Windows parche: Windows6.1-KB2999226-x64.msu and it will add a dll file that is necessary for running MongoDB.
Then, you have to create the directory C:/db/data.
Then, when MongoDB is installed and you have create the directory, you have to run the file C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe.
This file will open the MongoDB connection.
Here you have MongoDB running!
For the other side, you have to configure your mongoDB database connectio and driver in Spring Boot configuration.
You have to create a file named application-{environment}.yml with the next content:
spring:
datasource:
url: jdbc:oracle:thin:@//localhost:27017/howdyl
driver-class-name: mongodb.jdbc.MongoDriver
jpa:
show-sql: true
hibernate:
showSql: true
dialect: org.hibernate.dialect.Oracle10gDialect
And the magic, you run your application a mongoDB is running.
For any question, ask me!
Try it and have fun!
martes, 18 de abril de 2017
Keys for configure Bootstrap 3 in Angular 4 Project!
Hi,
Today, I'm going to explain the steps for configure Bootstrap in an Angular application.
First of all, we have to add Bootstrap in our application with:
> npm install --save ngx-bootstrap@latest
Then, we have to open the index.html file and add:
You have to know that any div with class col-**-** need a parent div with class row.
Today, I'm going to explain the steps for configure Bootstrap in an Angular application.
First of all, we have to add Bootstrap in our application with:
> npm install --save ngx-bootstrap@latest
Then, we have to open the index.html file and add:
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
Then, we have all we need for use Bootstrap 3 in Angular 4.
Now, we have to configure all the html files following the structure:
<div class="row">
<div class="col-xs-12 col-sm-6 col-lg-3">
...
</div>
... (any repeations you need)
</div>
You have to know that any div with class col-**-** need a parent div with class row.
Also, you have to know that col-xs is for mobiles dispositive, col-sm for tablets dispositives and col-lg for computer dispositive.
Here you have the documentation of the Bootstrap 3 style; All you need is here:
When you domain all this css styles, you can improve new approach for your develops.
Try it and have fun!
viernes, 31 de marzo de 2017
How to generate a Method with Generic Classes in Java?
Wellcome again,
Today I'm going to explain how to generate methods with generic classes in the call in Java.
First of all, I'm going to show you an example:
public <T> T convertirDesdeXml(Class<T> c, byte[] xml) {
XStream xStream = new XStream();
xStream.alias(c.getSimpleName(), c);
T objecte = (T)xStream.fromXML(new String(xml));
return objecte;
}
This example converts an xml in byte[] format to a generic object.
We have to use a placeholder that is presented with <T> syntax. A placeholder is a String name that represents any object type that you will use in the context (the class, a method, an static call, etc.).
The placeholder <T> indicates that you can use the class T like a generic type in the method.
You can complicate the call like <T extends java.util,Map>. This new example indicates that the placeholder T extends the interface Map or, what is the same, the operator instanceof returns true.
You can complicate the call like <T, K>. In this example you use two placeholder and you can you the number of placeholder you want.
With the placeholder you have your first generic method with generic classes.
Thanks for the read!
Try it and have fun!
Suscribirse a:
Entradas (Atom)