Skip to content

Commit 9e51119

Browse files
committed
setup for railway
1 parent 17a99e6 commit 9e51119

File tree

8 files changed

+146
-11
lines changed

8 files changed

+146
-11
lines changed

challenger/src/main/java/uk/co/compendiumdev/challenge/gui/ChallengerWebGUI.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ String getChallengesPageHtmlHeader(){
3838
"/gui/challenges");
3939
}
4040

41+
String getSponsorMessage(){
42+
String sponsorMessage = """
43+
<div class='sponsor-top'>
44+
<p>
45+
Support this site by joining our Patreon.
46+
For as little as $1 a month you receive exclusive ad-free content,
47+
ebooks and online training courses. -
48+
<a href='https://patreon.com/eviltester' target='_blank'>Learn more</a>
49+
</p>
50+
</div>
51+
""";
52+
53+
return sponsorMessage;
54+
}
55+
4156
public void setup(final Challengers challengers,
4257
final ChallengeDefinitions challengeDefinitions,
4358
final PersistenceLayer persistenceLayer,
@@ -49,7 +64,6 @@ public void setup(final Challengers challengers,
4964
guiManagement.appendMenuItem("API documentation","/docs");
5065
guiManagement.appendMenuItem("Learning", "/learning");
5166

52-
5367
String actualMenu = """
5468
<script>
5569
function setMenuNavBasedOnUrl(){
@@ -137,7 +151,7 @@ function setMenuNavBasedOnUrl(){
137151
</div>
138152
""".stripIndent();
139153

140-
guiManagement.setActualMenuHtml(actualMenu);
154+
guiManagement.setActualMenuHtml(getSponsorMessage() + actualMenu);
141155

142156
// Add the Default GUI Endpoiints for entity exploration
143157

@@ -150,7 +164,7 @@ function setMenuNavBasedOnUrl(){
150164
"""
151165
);
152166

153-
guiManagement.setFooter(getChallengesFooter());
167+
guiManagement.setFooter(getSponsorMessage() + getChallengesFooter());
154168

155169

156170

@@ -476,7 +490,7 @@ private String showPreviousGuids() {
476490

477491
private String getChallengesFooter() {
478492
return """
479-
<p>&nbsp;</p><hr/><div class='footer'><p>Copyright Compendium Developments Ltd 2020 </p>
493+
<p>&nbsp;</p><hr/><div class='footer'><p>Copyright Compendium Developments Ltd 2020 - 2025</p>
480494
<ul class='footerlinks'><li><a href='https://eviltester.com/apichallenges'>API Challenges Info</a></li>
481495
<li><a href='https://eviltester.com'>EvilTester.com</a></li>
482496
<li><a href='https://linkedin.com/in/eviltester'>Contact</a></li>

challenger/src/main/java/uk/co/compendiumdev/challenge/gui/MarkdownContentManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ public String getHtmlVersionOfMarkdownContent(String contentFolder, String conte
184184
}
185185

186186
if(mdheaders.contains("showads: true")) {
187-
headerInject = headerInject +
188-
"<script async src=\"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7132305589272099\"" +
189-
" crossorigin=\"anonymous\"></script>";
187+
// this did render google ads
188+
// headerInject = headerInject +
189+
// "<script async src=\"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7132305589272099\"" +
190+
// " crossorigin=\"anonymous\"></script>";
190191
}
191192

192193
headerInject = headerInject + youtubeHeaderInject;

challenger/src/main/resources/public/css/content.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,17 @@ div.main-text-content ul li { margin-bottom: 0.5rem;}
151151
div.main-text-content blockquote {
152152
background: #f5f5f5;
153153
padding: 0.5em;
154+
}
155+
156+
div.sponsor-top {
157+
background-color:#403f4c;
158+
color: #ffffff;
159+
text-align: center;
160+
font-size: .875em;
161+
padding-top: .5rem;
162+
padding-bottom: .5rem;
163+
}
164+
165+
div.sponsor-top a {
166+
color: #c0e0de;
154167
}

challengerAuto/src/test/java/uk/co/compendiumdev/challenger/restassured/_04_head_challenges/C008HeadTodos200Test.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ void canCheckHeadForTodos(){
3939
statusCode(200).
4040
and().extract().response();
4141

42+
int expectedCount = headresponse.headers().size();
43+
if(!headresponse.headers().hasHeaderWithName("Content-Length")){
44+
expectedCount++;
45+
}
46+
4247
// headers should be the same for get and head
43-
Assertions.assertEquals(headresponse.headers().size(),
48+
Assertions.assertEquals(expectedCount,
4449
todosgetresponse.headers().size());
4550

4651
}

challengerAuto/src/test/java/uk/co/compendiumdev/simpleapi/BasicSimpleApiCrudCoverageTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void canCreateAnItemWithPost(){
4343

4444
Item anItem = new Item();
4545
// anItem.id is auto generated
46-
anItem.isbn13 = "999-9-99-123456-1";
46+
anItem.isbn13 = TimestampToIsbn13.currentIsbn(); //"999-9-99-123456-1";
4747
anItem.numberinstock =23;
4848
anItem.type="dvd";
4949
anItem.price = new BigDecimal("51.29");
@@ -67,7 +67,7 @@ void canGetACreatedItem(){
6767

6868
Item anItem = new Item();
6969
// anItem.id is auto generated
70-
anItem.isbn13 = "999-9-99-123456-2";
70+
anItem.isbn13 = TimestampToIsbn13.currentIsbn(); //"999-9-99-123456-2";
7171
anItem.numberinstock =23;
7272
anItem.type="dvd";
7373
anItem.price = new BigDecimal("51.29");
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package uk.co.compendiumdev.simpleapi;
2+
3+
import java.time.Instant;
4+
5+
/**
6+
* Utility that generates an ISBN‑13‑style string out of the current time
7+
* (epoch milliseconds).
8+
*
9+
* <p>
10+
* The format is {@code XXX-X-XX-XXXXXX-X} (e.g.
11+
* “999‑9‑99‑123456‑2”). The digits come from the 13‑digit
12+
* representation of {@code System.currentTimeMillis()}.
13+
* </p>
14+
*
15+
* <pre>{@code
16+
* System.out.println(TimestampToIsbn13.currentIsbn());
17+
* // 1609459200000 → 160-9-45-920000-0
18+
* }</pre>
19+
*/
20+
public final class TimestampToIsbn13 {
21+
22+
private TimestampToIsbn13() {}
23+
24+
/**
25+
* Returns an ISBN‑13 style string made from the current timestamp
26+
* (epoch milliseconds).
27+
*
28+
* @return e.g. {@code 999-9-99-123456-2}
29+
*/
30+
public static String currentIsbn() {
31+
// 13‑digit string built from System.currentTimeMillis().
32+
String epoch = String.format("%013d", Instant.now().toEpochMilli());
33+
34+
// Split into the 5 groups: 3‑1‑2‑6‑1
35+
return epoch.substring(0, 3) + "-" // 999
36+
+ epoch.substring(3, 4) + "-" // 9
37+
+ epoch.substring(4, 6) + "-" // 99
38+
+ epoch.substring(6, 12) + "-" // 123456
39+
+ epoch.substring(12); // 2
40+
}
41+
42+
/**
43+
* Same as {@link #currentIsbn()}, but you can supply your own
44+
* {@code epochMillis} value. Useful for deterministic tests.
45+
*
46+
* @param epochMillis the epoch millisecond value to convert
47+
* @return ISBN‑13 style string
48+
*/
49+
public static String toIsbn(long epochMillis) {
50+
String epoch = String.format("%013d", epochMillis);
51+
return epoch.substring(0, 3) + "-" + epoch.substring(3, 4) + "-"
52+
+ epoch.substring(4, 6) + "-" + epoch.substring(6, 12) + "-"
53+
+ epoch.substring(12);
54+
}
55+
}

challengerAuto/src/test/java/uk/co/compendiumdev/simulator/SimulatorHttpTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,12 @@ void step009_headRequestReturnsHeadersFromGet() {
319319
then().
320320
statusCode(200).extract().headers();
321321

322-
Assertions.assertEquals(headHeaders.size(), getHeaders.size());
322+
int expectedCount = headHeaders.size();
323+
if(!headHeaders.hasHeaderWithName("Content-Length")){
324+
expectedCount++;
325+
}
326+
327+
Assertions.assertEquals(expectedCount, getHeaders.size());
323328

324329
// remove the variable headers that are server based rather than app based
325330
List<String> headersToSkipComparison = Arrays.asList("Report-To", "Reporting-Endpoints", "Connection", "Date");
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM eclipse-temurin:11
4+
WORKDIR /opt/app
5+
COPY ./challenger/target/apichallenges.jar .
6+
CMD ["java", "-jar", "apichallenges.jar"]
7+
EXPOSE 4567
8+
9+
10+
# === Build Stage ===
11+
FROM maven:3.9.6-eclipse-temurin-17 AS build
12+
13+
WORKDIR /app
14+
15+
# Copy pom and source code
16+
COPY ../../pom.xml .
17+
COPY ../../challenger ./challenger
18+
COPY ../../challengerAuto ./challengerAuto
19+
COPY ../../ercoremodel ./ercoremodel
20+
COPY ../../examplemodels ./examplemodels
21+
COPY ../../standAloneTodoListManagerRestApi ./standAloneTodoListManagerRestApi
22+
COPY ../../standAloneTodoListManagerRestApiAuto ./standAloneTodoListManagerRestApiAuto
23+
COPY ../../standAloneTodoListRestApi ./standAloneTodoListRestApi
24+
COPY ../../swaggerizer ./swaggerizer
25+
COPY ../../thingifier ./thingifier
26+
COPY ../../thingifierapp ./thingifierapp
27+
COPY ../../todoManagerRestAuto ./todoManagerRestAuto
28+
29+
# Build the application
30+
RUN mvn clean package -DskipTests
31+
32+
# === Runtime Stage ===
33+
FROM openjdk:26-ea-17-jdk-slim
34+
35+
WORKDIR /app
36+
37+
# Copy the jar from the build stage
38+
COPY --from=build /app/challenger/target/apichallenges.jar apichallenges.jar
39+
40+
# Run the app
41+
ENTRYPOINT ["java", "-jar", "apichallenges.jar", "-model=challengeapi", "-noshutdown", "-multiplayer" -cloudstorage"-multiuser"]
42+

0 commit comments

Comments
 (0)