Skip to content

Commit

Permalink
chore: bump spring boot version to 2.7.18
Browse files Browse the repository at this point in the history
  • Loading branch information
64ArthurAraujo committed Jan 4, 2024
1 parent 414cb65 commit abadd71
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 271 deletions.
27 changes: 9 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.18.RELEASE</version>
<version>2.7.18</version>
<relativePath/>
</parent>

Expand All @@ -35,7 +35,6 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
<version>42.3.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -46,19 +45,12 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.30</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.16.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand All @@ -69,6 +61,12 @@
<groupId>com.mercadopago</groupId>
<artifactId>sdk-java</artifactId>
<version>2.1.11</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand All @@ -91,19 +89,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<version>2.22.2</version>
<configuration>
<includes>
<include>**/*RequestTest.java</include>
<!-- <include>**/*RequestTest.java</include> -->
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.22.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/cc/wordview/api/service/Servicer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cc.wordview.api.service;

import java.util.ArrayList;
import java.util.Optional;

import cc.wordview.api.exception.NoSuchEntryException;
Expand All @@ -13,9 +14,14 @@ public abstract class Servicer {
public <T, T2> T evaluatePresenceAndReturn(Optional<T> optional, String fieldName,
T2 fieldValue) throws NoSuchEntryException {

if (!optional.isPresent())
T optionalValue = optional
.orElseThrow(() -> noSuchEntry(fieldName, fieldValue));

if (optionalValue instanceof ArrayList
&& ((ArrayList<?>) optionalValue).isEmpty()) {
throw noSuchEntry(fieldName, fieldValue);
}

return optional.get();
return optionalValue;
}
}
16 changes: 6 additions & 10 deletions src/main/java/cc/wordview/api/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ public NoCredentialsResponse getByIdWithoutCredentials(Long id)

@Override
public User getByEmail(String email) throws NoSuchEntryException {
return evaluatePresenceAndReturn(
repository.findByEmail(email),
"email", email
);
return evaluatePresenceAndReturn(repository.findByEmail(email), "email",
email);
}

@Override
public User getByToken(String token) throws NoSuchEntryException {
return evaluatePresenceAndReturn(
repository.findByToken(token),
"token", token
);
return evaluatePresenceAndReturn(repository.findByToken(token), "token",
token);
}

@Override
Expand All @@ -58,13 +54,13 @@ public User insert(User entity) throws ValueTakenException {
entity.setPassword(hashedPasswd);
entity.setToken(new Token(128).getValue());


// Check email is taken;
Optional<User> user = repository.findByEmail(entity.getEmail());

if (user.isPresent()) {
throw valueTaken(entity.getEmail());
} else {
}
else {
return repository.save(entity);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package cc.wordview.api.test.api.controller;

import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import cc.wordview.api.Application;
Expand All @@ -16,40 +12,38 @@

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@AutoConfigureMockMvc
public class CategoryControllerTest {
class CategoryControllerTest {
@Autowired
private MockMvc request;

@Test
public void create() throws Exception {
void create() throws Exception {
TestRequest.post(request, "/category",
new MockCategory("TestCategory", MockValues.ADMIN_TOKEN)
.toJson(),
status().isCreated());
}

@Test
public void createByNonAdmin() throws Exception {
void createByNonAdmin() throws Exception {
TestRequest.post(request, "/category",
new MockCategory("TestCategory", MockValues.NON_ADMIN_TOKEN)
.toJson(),
status().isForbidden());
}

@Test
public void createByNonExistentUser() throws Exception {
void createByNonExistentUser() throws Exception {
TestRequest.post(request, "/category",
new MockCategory("TestCategory", MockValues.INEXISTENT_TOKEN)
.toJson(),
status().isNotFound());
}

@Test
public void getAll() throws Exception {
void getAll() throws Exception {
TestRequest.get(request, "/category", status().isOk());
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package cc.wordview.api.test.api.controller;

import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import cc.wordview.api.Application;
Expand All @@ -17,60 +13,40 @@

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@AutoConfigureMockMvc
public class LangWordControllerTest {
class LangWordControllerTest {
@Autowired
private MockMvc request;

@Test
public void create() throws Exception {
TestRequest.post(
request,
"/langword/",
new MockLangWord(
"Carro", "pt_BR", 1L,
MockValues.ADMIN_TOKEN
).toJson(),
status().isCreated()
);
void create() throws Exception {
TestRequest.post(request, "/langword/",
new MockLangWord("Carro", "pt_BR", 1L, MockValues.ADMIN_TOKEN)
.toJson(),
status().isCreated());
}

@Test
public void createByNonExistentUser() throws Exception {
TestRequest.post(
request,
"/langword/",
new MockLangWord(
"Carro", "pt_BR", 2L,
MockValues.INEXISTENT_TOKEN
).toJson(),
status().isNotFound()
);
void createByNonExistentUser() throws Exception {
TestRequest.post(request, "/langword/",
new MockLangWord("Carro", "pt_BR", 2L,
MockValues.INEXISTENT_TOKEN).toJson(),
status().isNotFound());
}

@Test
public void createByNonAdmin() throws Exception {
TestRequest.post(
request,
"/langword/",
new MockLangWord(
"Carro", "pt_BR", 2L,
MockValues.NON_ADMIN_TOKEN
).toJson(),
status().isForbidden()
);
void createByNonAdmin() throws Exception {
TestRequest.post(request, "/langword/",
new MockLangWord("Carro", "pt_BR", 2L,
MockValues.NON_ADMIN_TOKEN).toJson(),
status().isForbidden());
}

@Test
public void getByIdLesson() throws Exception {
TestRequest.post(
request,
"/langword/search?lessonid=1&lang=pt-br",
new MockAuthorizationBody(MockValues.NON_ADMIN_TOKEN).toJson(),
status().isOk()
);
void getByIdLesson() throws Exception {
TestRequest.post(request, "/langword/search?lessonid=1&lang=pt-br",
new MockAuthorizationBody(MockValues.NON_ADMIN_TOKEN).toJson(),
status().isOk());
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package cc.wordview.api.test.api.controller;

import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import cc.wordview.api.Application;
Expand All @@ -17,33 +15,32 @@

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@AutoConfigureMockMvc
public class LessonControllerTest {
@TestMethodOrder(MethodOrderer.MethodName.class)
class LessonControllerTest {
@Autowired
private MockMvc request;

// CREATE
@Test
public void create() throws Exception {
void create() throws Exception {
TestRequest.post(request, "/lesson/",
new MockLesson("lesson1", LessonDifficulty.STARTER,
MockValues.ADMIN_TOKEN).toJson(),
status().isCreated());
}

@Test
public void createByNonExistentUser() throws Exception {
void createByNonExistentUser() throws Exception {
TestRequest.post(request, "/lesson/",
new MockLesson("lesson1", LessonDifficulty.STARTER,
MockValues.INEXISTENT_TOKEN).toJson(),
status().isNotFound());
}

@Test
public void createByNonAdmin() throws Exception {
void createByNonAdmin() throws Exception {
TestRequest.post(request, "/lesson/",
new MockLesson("lesson1", LessonDifficulty.STARTER,
MockValues.NON_ADMIN_TOKEN).toJson(),
Expand All @@ -52,37 +49,37 @@ public void createByNonAdmin() throws Exception {

// READ
@Test
public void getByTitle() throws Exception {
void getByTitle() throws Exception {
TestRequest.get(request, "/lesson/search?title=lesson", status().isOk());
}

@Test
public void getByNonExistentTitle() throws Exception {
void getByNonExistentTitle() throws Exception {
TestRequest.get(request, "/lesson/search?title=sd", status().isNotFound());
}

@Test
public void getByDifficulty() throws Exception {
void getByDifficulty() throws Exception {
TestRequest.get(request, "/lesson/search?diffi=starter", status().isOk());
}

@Test
public void getByNonExistentDifficulty() throws Exception {
TestRequest.get(request, "/lesson/search?diffi=sd", status().isNotFound());
void getByNonExistentDifficulty() throws Exception {
TestRequest.get(request, "/lesson/search?diffi=w", status().isNotFound());
}

@Test
public void getByCategory() throws Exception {
void getByCategory() throws Exception {
TestRequest.get(request, "/lesson/search?category=1", status().isOk());
}

@Test
public void getByZeroCategory() throws Exception {
void getByZeroCategory() throws Exception {
TestRequest.get(request, "/lesson/search?category=0", status().isBadRequest());
}

@Test
public void getByNonExistentCategory() throws Exception {
void getByNonExistentCategory() throws Exception {
TestRequest.get(request, "/lesson/search?category=2", status().isNotFound());
}
}
Loading

0 comments on commit abadd71

Please sign in to comment.