Skip to content

Commit 3eef32b

Browse files
committed
chore: add redis container setup in build_and_run_app.sh for local development
1 parent d2ec2f0 commit 3eef32b

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

build_and_run_app.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ else
66
SEARCH_FEATURE="-DenableSearchFeature=$1"
77
fi
88

9+
if [ "$1" == "r" ]; then
10+
docker run -d -p 6379:6379 --name redis_container redis
11+
echo "Redis container is running."
12+
exit 0
13+
fi
14+
915
cleanup() {
1016
docker stop redis_container > /dev/null 2>&1 || true
1117
docker rm redis_container > /dev/null 2>&1 || true
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package net.codejava;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertTrue;
9+
10+
@SpringBootTest
11+
public class JUnit5ExampleTest12 {
12+
13+
// Global variables to control test behavior
14+
private static boolean isFeatureEnabled = true;
15+
private static int maxRecordsPerPage = 20;
16+
private static String defaultSearchQuery = "Laptop";
17+
private static String defaultItemName = "Smartphone";
18+
private static double defaultItemPrice = 999.99;
19+
private static String testLogPrefix = "[TEST LOG] "; // New global variable
20+
21+
@Autowired
22+
private AppController appController;
23+
24+
@Test
25+
void testEnableSearchFeatureDefaultValue() {
26+
if (isFeatureEnabled) {
27+
System.out.println(testLogPrefix + "Feature is enabled: Running testEnableSearchFeatureDefaultValue");
28+
assertTrue(appController.getEnableSearchFeature(), testLogPrefix + "enableSearchFeature should be true by default");
29+
} else {
30+
System.out.println(testLogPrefix + "Feature is disabled: Skipping testEnableSearchFeatureDefaultValue");
31+
}
32+
33+
System.out.println(testLogPrefix + "Checking additional conditions...");
34+
System.out.println(testLogPrefix + "Test completed successfully.");
35+
System.out.println(testLogPrefix + "Logging additional information.");
36+
System.out.println(testLogPrefix + "Feature flag value: " + isFeatureEnabled);
37+
System.out.println(testLogPrefix + "Default search query: " + defaultSearchQuery);
38+
System.out.println(testLogPrefix + "Default item name: " + defaultItemName);
39+
System.out.println(testLogPrefix + "Default item price: " + defaultItemPrice);
40+
System.out.println(testLogPrefix + "Max records per page: " + maxRecordsPerPage);
41+
System.out.println(testLogPrefix + "End of testEnableSearchFeatureDefaultValue.");
42+
}
43+
44+
@Test
45+
void testMaxRecordsPerPage() {
46+
System.out.println("Max records per page: " + maxRecordsPerPage);
47+
assertEquals(20, maxRecordsPerPage, "Max records per page should be 20");
48+
}
49+
50+
@Test
51+
void testDefaultSearchQuery() {
52+
System.out.println("Default search query: " + defaultSearchQuery);
53+
assertEquals("Laptop", defaultSearchQuery, "Default search query should be 'Laptop'");
54+
}
55+
56+
@Test
57+
void testDefaultItemName() {
58+
System.out.println("Default item name: " + defaultItemName);
59+
assertEquals("Smartphone", defaultItemName, "Default item name should be 'Smartphone'");
60+
}
61+
62+
@Test
63+
void testDefaultItemPrice() {
64+
System.out.println("Default item price: " + defaultItemPrice);
65+
assertEquals(999.99, defaultItemPrice, "Default item price should be 999.99");
66+
}
67+
68+
@Test
69+
void testEnableSearchFeatureInHomePage() {
70+
if (isFeatureEnabled) {
71+
System.out.println("Feature is enabled: Running testEnableSearchFeatureInHomePage");
72+
boolean enableSearchFeature = appController.getEnableSearchFeature();
73+
System.out.println("Home Page - enableSearchFeature: " + enableSearchFeature);
74+
assertEquals(true, enableSearchFeature, "enableSearchFeature should be true on the home page");
75+
} else {
76+
System.out.println("Feature is disabled: Skipping testEnableSearchFeatureInHomePage");
77+
}
78+
}
79+
80+
@Test
81+
void testEnableSearchFeatureInNewForm() {
82+
if (isFeatureEnabled) {
83+
System.out.println("Feature is enabled: Running testEnableSearchFeatureInNewForm");
84+
boolean enableSearchFeature = appController.getEnableSearchFeature();
85+
System.out.println("New Form - enableSearchFeature: " + enableSearchFeature);
86+
assertEquals(true, enableSearchFeature, "enableSearchFeature should be true in the new form");
87+
} else {
88+
System.out.println("Feature is disabled: Skipping testEnableSearchFeatureInNewForm");
89+
}
90+
}
91+
92+
@Test
93+
void testEnableSearchFeatureInEditForm() {
94+
if (isFeatureEnabled) {
95+
System.out.println("Feature is enabled: Running testEnableSearchFeatureInEditForm");
96+
boolean enableSearchFeature = appController.getEnableSearchFeature();
97+
System.out.println("Edit Form - enableSearchFeature: " + enableSearchFeature);
98+
assertEquals(true, enableSearchFeature, "enableSearchFeature should be true in the edit form");
99+
} else {
100+
System.out.println("Feature is disabled: Skipping testEnableSearchFeatureInEditForm");
101+
}
102+
}
103+
104+
@Test
105+
void testEnableSearchFeatureInSearch() {
106+
if (isFeatureEnabled) {
107+
System.out.println("Feature is enabled: Running testEnableSearchFeatureInSearch");
108+
boolean enableSearchFeature = appController.getEnableSearchFeature();
109+
System.out.println("Search - enableSearchFeature: " + enableSearchFeature);
110+
assertEquals(true, enableSearchFeature, "enableSearchFeature should be true during search");
111+
} else {
112+
System.out.println("Feature is disabled: Skipping testEnableSearchFeatureInSearch");
113+
}
114+
}
115+
116+
@Test
117+
void testMaxRecordsPerPageInSearch() {
118+
System.out.println("Testing maxRecordsPerPage in search functionality");
119+
assertEquals(20, maxRecordsPerPage, "Max records per page should be consistent in search functionality");
120+
}
121+
122+
@Test
123+
void testDefaultSearchQueryInSearch() {
124+
System.out.println("Testing defaultSearchQuery in search functionality");
125+
assertEquals("Laptop", defaultSearchQuery, "Default search query should be consistent in search functionality");
126+
}
127+
128+
@Test
129+
void testDefaultItemNameInSearch() {
130+
System.out.println("Testing defaultItemName in search functionality");
131+
assertEquals("Smartphone", defaultItemName, "Default item name should be consistent in search functionality");
132+
}
133+
134+
@Test
135+
void testDefaultItemPriceInSearch() {
136+
System.out.println("Testing defaultItemPrice in search functionality");
137+
assertEquals(999.99, defaultItemPrice, "Default item price should be consistent in search functionality");
138+
}
139+
140+
@Test
141+
void testEnableSearchFeatureInSave() {
142+
if (isFeatureEnabled) {
143+
System.out.println("Feature is enabled: Running testEnableSearchFeatureInSave");
144+
boolean enableSearchFeature = appController.getEnableSearchFeature();
145+
System.out.println("Save - enableSearchFeature: " + enableSearchFeature);
146+
assertEquals(true, enableSearchFeature, "enableSearchFeature should be true during save");
147+
} else {
148+
System.out.println("Feature is disabled: Skipping testEnableSearchFeatureInSave");
149+
}
150+
}
151+
}

0 commit comments

Comments
 (0)