Skip to content

Commit b3154af

Browse files
committed
Test, test y más tests.
1 parent 07e0902 commit b3154af

File tree

55 files changed

+1179
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1179
-257
lines changed

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@
9494
<artifactId>spring-dotenv</artifactId>
9595
<version>3.0.0</version>
9696
</dependency>
97+
<dependency>
98+
<groupId>junit</groupId>
99+
<artifactId>junit</artifactId>
100+
<version>4.13.2</version>
101+
<scope>test</scope>
102+
</dependency>
103+
97104
</dependencies>
98105

99106
<build>
@@ -121,6 +128,9 @@
121128
<groupId>org.springframework.boot</groupId>
122129
<artifactId>spring-boot-maven-plugin</artifactId>
123130
</plugin>
131+
132+
133+
124134
</plugins>
125135
</build>
126136

src/main/java/com/outfitlab/project/domain/model/TripoModel.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,19 @@ public TripoModel(String taskId, String imageToken, String originalFilename, Str
3030
this.errorMessage = errorMessage;
3131
}
3232

33+
public TripoModel() {}
34+
3335
public TripoModel(String taskId, String imageToken, String originalFilename, String fileExtension, String minioImagePath, ModelStatus modelStatus) {
36+
this.taskId = taskId;
37+
this.imageToken = imageToken;
38+
this.originalFilename = originalFilename;
39+
this.fileExtension = fileExtension;
40+
this.status = modelStatus;
41+
this.minioImagePath = minioImagePath;
42+
this.minioModelPath = minioModelPath;
43+
this.tripoModelUrl = tripoModelUrl;
44+
this.createdAt = LocalDateTime.now();
45+
this.updatedAt = LocalDateTime.now();
3446
}
3547

3648
public enum ModelStatus {

src/main/java/com/outfitlab/project/domain/service/TrippoService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public TripoModel procesarYEnviarATripo(MultipartFile imageFile) throws FileEmpt
5353
String glbUrlGenerated = this.checkTaskStatus.execute(taskId);
5454

5555
tripoModel.setStatus(TripoModel.ModelStatus.COMPLETED);
56+
tripoModel.setTripoModelUrl(glbUrlGenerated);
5657

5758
return this.updateTripoModel.execute(tripoModel);
5859
}

src/main/java/com/outfitlab/project/domain/useCases/tripo/ValidateExtension.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public class ValidateExtension {
44

55
public boolean execute(String extension) {
6+
if (extension == null || extension.equals("")) return false;
67
return extension.equals("jpg") ||
78
extension.equals("jpeg") ||
89
extension.equals("png") ||
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package com.outfitlab.project.domain.service;
2+
3+
import com.outfitlab.project.domain.exceptions.MarcasNotFoundException;
4+
import com.outfitlab.project.domain.model.MarcaModel;
5+
import com.outfitlab.project.domain.useCases.marca.GetAllMarcas;
6+
import com.outfitlab.project.domain.useCases.marca.GetMarcaByCodigoMarca;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
10+
import java.util.Arrays;
11+
import java.util.List;
12+
13+
import static org.junit.Assert.*;
14+
import static org.mockito.Mockito.*;
15+
16+
public class MarcaServiceTest {
17+
18+
private GetAllMarcas getAllMarcasMock;
19+
private GetMarcaByCodigoMarca getMarcaByCodigoMarcaMock;
20+
private MarcaService marcaService;
21+
22+
@Before
23+
public void setUp() {
24+
getAllMarcasMock = mock(GetAllMarcas.class);
25+
getMarcaByCodigoMarcaMock = mock(GetMarcaByCodigoMarca.class);
26+
marcaService = new MarcaService(getAllMarcasMock, getMarcaByCodigoMarcaMock);
27+
}
28+
29+
@Test
30+
public void getAllMarcasDeberiaDevolverListaDeMarcas_cuandoExistenMarcas() throws Exception, MarcasNotFoundException {
31+
MarcaModel marca1 = new MarcaModel();
32+
marca1.setNombre("Marca1");
33+
MarcaModel marca2 = new MarcaModel();
34+
marca2.setNombre("Marca2");
35+
36+
when(getAllMarcasMock.execute()).thenReturn(Arrays.asList(marca1, marca2));
37+
38+
List<MarcaModel> resultado = null;
39+
try {
40+
resultado = marcaService.getAllMarcas();
41+
} catch (MarcasNotFoundException e) {
42+
fail("No se esperaba excepción");
43+
}
44+
45+
assertNotNull(resultado);
46+
assertEquals(2, resultado.size());
47+
verify(getAllMarcasMock, times(1)).execute();
48+
}
49+
50+
@Test
51+
public void getAllMarcasDeberiaLanzarMarcasNotFoundException_cuandoUseCaseLanzaExcepcion() throws Exception, MarcasNotFoundException {
52+
when(getAllMarcasMock.execute()).thenThrow(new MarcasNotFoundException("No marcas"));
53+
54+
try {
55+
marcaService.getAllMarcas();
56+
fail("Se esperaba MarcasNotFoundException");
57+
} catch (MarcasNotFoundException e) {
58+
assertEquals("No marcas", e.getMessage());
59+
}
60+
}
61+
62+
@Test
63+
public void getAllMarcasDeberiaLanzarMarcasNotFoundException_cuandoUseCaseLanzaExceptionGenerica() throws Exception, MarcasNotFoundException {
64+
when(getAllMarcasMock.execute()).thenThrow(new RuntimeException("Error genérico"));
65+
66+
try {
67+
marcaService.getAllMarcas();
68+
fail("Se esperaba MarcasNotFoundException");
69+
} catch (MarcasNotFoundException e) {
70+
assertEquals("Error genérico", e.getMessage());
71+
}
72+
}
73+
74+
@Test
75+
public void getMarcaByCodigoMarcaDeberiaDevolverMarca_cuandoExiste() throws Exception, MarcasNotFoundException {
76+
String codigo = "MAR001";
77+
MarcaModel marca = new MarcaModel();
78+
marca.setNombre("Marca1");
79+
80+
when(getMarcaByCodigoMarcaMock.execute(codigo)).thenReturn(marca);
81+
82+
MarcaModel resultado = null;
83+
try {
84+
resultado = marcaService.getMarcaByCodigoMarca(codigo);
85+
} catch (MarcasNotFoundException e) {
86+
fail("No se esperaba excepción");
87+
}
88+
89+
assertNotNull(resultado);
90+
assertEquals("Marca1", resultado.getNombre());
91+
verify(getMarcaByCodigoMarcaMock, times(1)).execute(codigo);
92+
}
93+
94+
@Test
95+
public void getMarcaByCodigoMarcaDeberiaLanzarMarcasNotFoundException_cuandoUseCaseLanzaExcepcion() throws Exception, MarcasNotFoundException {
96+
String codigo = "MAR002";
97+
when(getMarcaByCodigoMarcaMock.execute(codigo)).thenThrow(new MarcasNotFoundException("No encontramos la marca: MAR002"));
98+
99+
try {
100+
marcaService.getMarcaByCodigoMarca(codigo);
101+
fail("Se esperaba MarcasNotFoundException");
102+
} catch (MarcasNotFoundException e) {
103+
assertEquals("No encontramos la marca: " + codigo, e.getMessage());
104+
}
105+
}
106+
107+
@Test
108+
public void getMarcaByCodigoMarcaDeberiaLanzarMarcasNotFoundException_cuandoUseCaseLanzaExceptionGenerica() throws Exception, MarcasNotFoundException {
109+
String codigo = "MAR003";
110+
when(getMarcaByCodigoMarcaMock.execute(codigo)).thenThrow(new RuntimeException("Error genérico"));
111+
112+
try {
113+
marcaService.getMarcaByCodigoMarca(codigo);
114+
fail("Se esperaba MarcasNotFoundException");
115+
} catch (MarcasNotFoundException e) {
116+
assertEquals("No encontramos la marca: " + codigo, e.getMessage());
117+
}
118+
}
119+
}
120+

0 commit comments

Comments
 (0)