Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
thuytm committed Dec 14, 2021
1 parent 1ddf419 commit 07afe44
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,37 @@

@Service
public class MyService {
// @Retryable(
// value = ArithmeticException.class,
// maxAttempts = 2,
// backoff = @Backoff(delay = 5001))
int doSomething1(int a) {
try {
System.out.println("---------------- Doing");
int i = a/0;
return i;
} catch (ArithmeticException ex) {
throw ex;
}
}

// @Retryable(
// value = Exception.class,
// maxAttempts = 2,
// backoff = @Backoff(delay = 1001))
int doSomething(int a) {
try {
System.out.println("---------------- Doing");
int i = a/0;
return i;
} catch (Exception ex) {
throw ex;
}
}

@Recover
public int recover(Exception ex, int a) {
System.out.println("---------------- Recovering for ex " + ex.getMessage());
return a;
}
}
27 changes: 27 additions & 0 deletions user-management-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>3.0.8</version>
</dependency>
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
Expand All @@ -63,6 +68,28 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>1.0.23</version>
</dependency>
<dependency>
<groupId>com.adaptavist</groupId>
<artifactId>tm4j-junit-integration</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.demo;

import com.example.demo.model.dto.UserDto;
import net.thucydides.core.annotations.Title;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.test.context.junit4.SpringRunner;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = UserManagementTestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class IntegrationTest {
@LocalServerPort
private int port;

TestRestTemplate restTemplate = new TestRestTemplate();

HttpHeaders headers = new HttpHeaders();

@Test
@Title("Verify api create user")
public void createUserTest() {
headers.add("Content-Type", "application/json");
HttpEntity<String> entity = new HttpEntity<String>("{ \"full_name\": \"Nguyen Van A\", \"email\": \"\", \"password\": \"abc123\", \"phone\": \"0942362001\" }", headers);
ResponseEntity<UserDto> response = restTemplate.exchange(createURLWithPort("/users"), HttpMethod.POST, entity, UserDto.class);

assertEquals(response.getStatusCode(), is(400));
}

private String createURLWithPort(String uri) {
return "http://localhost:" + port + uri;
}

}


0 comments on commit 07afe44

Please sign in to comment.