Skip to content

Commit 9f30641

Browse files
committed
component - health check
1 parent dfb8fd0 commit 9f30641

File tree

52 files changed

+492
-139
lines changed

Some content is hidden

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

52 files changed

+492
-139
lines changed

component/pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@
3737

3838
<artifactId>component</artifactId>
3939
<dependencies>
40+
<dependency>
41+
<groupId>org.slf4j</groupId>
42+
<artifactId>slf4j-api</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>ch.qos.logback</groupId>
46+
<artifactId>logback-classic</artifactId>
47+
</dependency>
4048
<dependency>
4149
<groupId>org.junit.jupiter</groupId>
42-
<artifactId>junit-jupiter-api</artifactId>
50+
<artifactId>junit-jupiter-engine</artifactId>
4351
<scope>test</scope>
4452
</dependency>
4553
</dependencies>

composite-entity/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
<modelVersion>4.0.0</modelVersion>
3535
<artifactId>composite-entity</artifactId>
3636
<dependencies>
37+
<dependency>
38+
<groupId>org.slf4j</groupId>
39+
<artifactId>slf4j-api</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>ch.qos.logback</groupId>
43+
<artifactId>logback-classic</artifactId>
44+
</dependency>
3745
<dependency>
3846
<groupId>org.junit.jupiter</groupId>
3947
<artifactId>junit-jupiter-engine</artifactId>

composite-view/pom.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@
3737
<artifactId>composite-view</artifactId>
3838
<dependencies>
3939
<dependency>
40-
<groupId>org.junit.jupiter</groupId>
41-
<artifactId>junit-jupiter-engine</artifactId>
42-
<scope>test</scope>
40+
<groupId>org.slf4j</groupId>
41+
<artifactId>slf4j-api</artifactId>
4342
</dependency>
4443
<dependency>
45-
<groupId>junit</groupId>
46-
<artifactId>junit</artifactId>
44+
<groupId>ch.qos.logback</groupId>
45+
<artifactId>logback-classic</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.junit.jupiter</groupId>
49+
<artifactId>junit-jupiter-engine</artifactId>
4750
<scope>test</scope>
4851
</dependency>
4952
<dependency>

composite-view/src/test/java/com/iluwatar/compositeview/AppServletTest.java

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,88 +24,93 @@
2424
*/
2525
package com.iluwatar.compositeview;
2626

27+
import org.junit.jupiter.api.Test;
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
29+
import static org.mockito.Mockito.*;
30+
2731
import jakarta.servlet.RequestDispatcher;
2832
import jakarta.servlet.http.HttpServletRequest;
2933
import jakarta.servlet.http.HttpServletResponse;
30-
import org.junit.jupiter.api.Test;
31-
import org.mockito.Mockito;
34+
3235
import java.io.PrintWriter;
3336
import java.io.StringWriter;
3437

35-
import static org.junit.Assert.*;
38+
class AppServletTest {
3639

37-
/* Written with reference from https://stackoverflow.com/questions/5434419/how-to-test-my-servlet-using-junit
38-
and https://stackoverflow.com/questions/50211433/servlets-unit-testing
39-
*/
40-
41-
class AppServletTest extends Mockito{
42-
private String msgPartOne = "<h1>This Server Doesn't Support";
43-
private String msgPartTwo = """
44-
Requests</h1>
45-
<h2>Use a GET request with boolean values for the following parameters<h2>
46-
<h3>'name'</h3>
47-
<h3>'bus'</h3>
48-
<h3>'sports'</h3>
49-
<h3>'sci'</h3>
50-
<h3>'world'</h3>""";
51-
private String destination = "newsDisplay.jsp";
40+
private final String msgPartOne = "<h1>This Server Doesn't Support";
41+
private final String msgPartTwo = """
42+
Requests</h1>
43+
<h2>Use a GET request with boolean values for the following parameters<h2>
44+
<h3>'name'</h3>
45+
<h3>'bus'</h3>
46+
<h3>'sports'</h3>
47+
<h3>'sci'</h3>
48+
<h3>'world'</h3>""";
49+
private final String destination = "newsDisplay.jsp";
5250

5351
@Test
5452
void testDoGet() throws Exception {
55-
HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class);
56-
HttpServletResponse mockResp = Mockito.mock(HttpServletResponse.class);
57-
RequestDispatcher mockDispatcher = Mockito.mock(RequestDispatcher.class);
53+
HttpServletRequest mockReq = mock(HttpServletRequest.class);
54+
HttpServletResponse mockResp = mock(HttpServletResponse.class);
55+
RequestDispatcher mockDispatcher = mock(RequestDispatcher.class);
5856
StringWriter stringWriter = new StringWriter();
5957
PrintWriter printWriter = new PrintWriter(stringWriter);
58+
6059
when(mockResp.getWriter()).thenReturn(printWriter);
6160
when(mockReq.getRequestDispatcher(destination)).thenReturn(mockDispatcher);
61+
6262
AppServlet curServlet = new AppServlet();
6363
curServlet.doGet(mockReq, mockResp);
64+
6465
verify(mockReq, times(1)).getRequestDispatcher(destination);
6566
verify(mockDispatcher).forward(mockReq, mockResp);
66-
67-
6867
}
6968

7069
@Test
7170
void testDoPost() throws Exception {
72-
HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class);
73-
HttpServletResponse mockResp = Mockito.mock(HttpServletResponse.class);
71+
HttpServletRequest mockReq = mock(HttpServletRequest.class);
72+
HttpServletResponse mockResp = mock(HttpServletResponse.class);
7473
StringWriter stringWriter = new StringWriter();
7574
PrintWriter printWriter = new PrintWriter(stringWriter);
75+
7676
when(mockResp.getWriter()).thenReturn(printWriter);
7777

7878
AppServlet curServlet = new AppServlet();
7979
curServlet.doPost(mockReq, mockResp);
8080
printWriter.flush();
81+
8182
assertTrue(stringWriter.toString().contains(msgPartOne + " Post " + msgPartTwo));
8283
}
8384

8485
@Test
8586
void testDoPut() throws Exception {
86-
HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class);
87-
HttpServletResponse mockResp = Mockito.mock(HttpServletResponse.class);
87+
HttpServletRequest mockReq = mock(HttpServletRequest.class);
88+
HttpServletResponse mockResp = mock(HttpServletResponse.class);
8889
StringWriter stringWriter = new StringWriter();
8990
PrintWriter printWriter = new PrintWriter(stringWriter);
91+
9092
when(mockResp.getWriter()).thenReturn(printWriter);
9193

9294
AppServlet curServlet = new AppServlet();
9395
curServlet.doPut(mockReq, mockResp);
9496
printWriter.flush();
97+
9598
assertTrue(stringWriter.toString().contains(msgPartOne + " Put " + msgPartTwo));
9699
}
97100

98101
@Test
99102
void testDoDelete() throws Exception {
100-
HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class);
101-
HttpServletResponse mockResp = Mockito.mock(HttpServletResponse.class);
103+
HttpServletRequest mockReq = mock(HttpServletRequest.class);
104+
HttpServletResponse mockResp = mock(HttpServletResponse.class);
102105
StringWriter stringWriter = new StringWriter();
103106
PrintWriter printWriter = new PrintWriter(stringWriter);
107+
104108
when(mockResp.getWriter()).thenReturn(printWriter);
105109

106110
AppServlet curServlet = new AppServlet();
107111
curServlet.doDelete(mockReq, mockResp);
108112
printWriter.flush();
113+
109114
assertTrue(stringWriter.toString().contains(msgPartOne + " Delete " + msgPartTwo));
110115
}
111116
}

composite-view/src/test/java/com/iluwatar/compositeview/JavaBeansTest.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
*/
2525
package com.iluwatar.compositeview;
2626

27-
import jakarta.servlet.http.HttpServletRequest;
2827
import org.junit.jupiter.api.Test;
29-
import org.mockito.Mockito;
28+
import static org.junit.jupiter.api.Assertions.*;
29+
import static org.mockito.Mockito.*;
3030

31-
import static org.junit.Assert.*;
31+
import jakarta.servlet.http.HttpServletRequest;
3232

3333
class JavaBeansTest {
34+
3435
@Test
3536
void testDefaultConstructor() {
3637
ClientPropertiesBean newBean = new ClientPropertiesBean();
@@ -39,13 +40,13 @@ void testDefaultConstructor() {
3940
assertTrue(newBean.isScienceNewsInterest());
4041
assertTrue(newBean.isSportsInterest());
4142
assertTrue(newBean.isWorldNewsInterest());
42-
4343
}
4444

4545
@Test
4646
void testNameGetterSetter() {
4747
ClientPropertiesBean newBean = new ClientPropertiesBean();
4848
assertEquals("DEFAULT_NAME", newBean.getName());
49+
4950
newBean.setName("TEST_NAME_ONE");
5051
assertEquals("TEST_NAME_ONE", newBean.getName());
5152
}
@@ -54,6 +55,7 @@ void testNameGetterSetter() {
5455
void testBusinessSetterGetter() {
5556
ClientPropertiesBean newBean = new ClientPropertiesBean();
5657
assertTrue(newBean.isBusinessInterest());
58+
5759
newBean.setBusinessInterest(false);
5860
assertFalse(newBean.isBusinessInterest());
5961
}
@@ -62,6 +64,7 @@ void testBusinessSetterGetter() {
6264
void testScienceSetterGetter() {
6365
ClientPropertiesBean newBean = new ClientPropertiesBean();
6466
assertTrue(newBean.isScienceNewsInterest());
67+
6568
newBean.setScienceNewsInterest(false);
6669
assertFalse(newBean.isScienceNewsInterest());
6770
}
@@ -70,6 +73,7 @@ void testScienceSetterGetter() {
7073
void testSportsSetterGetter() {
7174
ClientPropertiesBean newBean = new ClientPropertiesBean();
7275
assertTrue(newBean.isSportsInterest());
76+
7377
newBean.setSportsInterest(false);
7478
assertFalse(newBean.isSportsInterest());
7579
}
@@ -78,14 +82,16 @@ void testSportsSetterGetter() {
7882
void testWorldSetterGetter() {
7983
ClientPropertiesBean newBean = new ClientPropertiesBean();
8084
assertTrue(newBean.isWorldNewsInterest());
85+
8186
newBean.setWorldNewsInterest(false);
8287
assertFalse(newBean.isWorldNewsInterest());
8388
}
8489

8590
@Test
86-
void testRequestConstructor(){
87-
HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class);
88-
ClientPropertiesBean newBean = new ClientPropertiesBean((mockReq));
91+
void testRequestConstructor() {
92+
HttpServletRequest mockReq = mock(HttpServletRequest.class);
93+
ClientPropertiesBean newBean = new ClientPropertiesBean(mockReq);
94+
8995
assertEquals("DEFAULT_NAME", newBean.getName());
9096
assertFalse(newBean.isWorldNewsInterest());
9197
assertFalse(newBean.isBusinessInterest());

composite/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
</parent>
3535
<artifactId>composite</artifactId>
3636
<dependencies>
37+
<dependency>
38+
<groupId>org.slf4j</groupId>
39+
<artifactId>slf4j-api</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>ch.qos.logback</groupId>
43+
<artifactId>logback-classic</artifactId>
44+
</dependency>
3745
<dependency>
3846
<groupId>org.junit.jupiter</groupId>
3947
<artifactId>junit-jupiter-engine</artifactId>

context-object/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
</parent>
3535
<artifactId>context-object</artifactId>
3636
<dependencies>
37+
<dependency>
38+
<groupId>org.slf4j</groupId>
39+
<artifactId>slf4j-api</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>ch.qos.logback</groupId>
43+
<artifactId>logback-classic</artifactId>
44+
</dependency>
3745
<dependency>
3846
<groupId>org.junit.jupiter</groupId>
3947
<artifactId>junit-jupiter-engine</artifactId>

converter/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
<artifactId>converter</artifactId>
3535
<modelVersion>4.0.0</modelVersion>
3636
<dependencies>
37+
<dependency>
38+
<groupId>org.slf4j</groupId>
39+
<artifactId>slf4j-api</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>ch.qos.logback</groupId>
43+
<artifactId>logback-classic</artifactId>
44+
</dependency>
3745
<dependency>
3846
<groupId>org.junit.jupiter</groupId>
3947
<artifactId>junit-jupiter-engine</artifactId>

curiously-recurring-template-pattern/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
</parent>
3737
<artifactId>curiously-recurring-template-pattern</artifactId>
3838
<dependencies>
39+
<dependency>
40+
<groupId>org.slf4j</groupId>
41+
<artifactId>slf4j-api</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>ch.qos.logback</groupId>
45+
<artifactId>logback-classic</artifactId>
46+
</dependency>
3947
<dependency>
4048
<groupId>org.junit.jupiter</groupId>
4149
<artifactId>junit-jupiter-engine</artifactId>

currying/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
</parent>
3737
<artifactId>currying</artifactId>
3838
<dependencies>
39+
<dependency>
40+
<groupId>org.slf4j</groupId>
41+
<artifactId>slf4j-api</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>ch.qos.logback</groupId>
45+
<artifactId>logback-classic</artifactId>
46+
</dependency>
3947
<dependency>
4048
<groupId>org.junit.jupiter</groupId>
4149
<artifactId>junit-jupiter-engine</artifactId>

0 commit comments

Comments
 (0)