Skip to content

Commit

Permalink
#231 add test-suit for basic features
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorsten Marx committed Sep 10, 2024
1 parent 92658bc commit e0d7182
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 23 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ see wiki for more information: [wiki](https://github.com/thmarx/cms/wiki)

## 5.3.0

* **MAINTENANCE** Refactoring packages [#228](https://github.com/thmarx/cms/issues/228)
* **BUG** CMSRequestContext is empty in HookSystemRegisterExtentionPoint [#232](https://github.com/thmarx/cms/issues/232)
* **FEATURE** Add HttpRequest to RequestFeature [#230](https://github.com/thmarx/cms/issues/230)
* **FEATURE** Automatic load lof4j config from app directory [#229](https://github.com/thmarx/cms/issues/229)
* **FEATURE** Make ShortCodes callable from template code [#219](https://github.com/thmarx/cms/issues/219)
* **MAINTENANCE** Refactoring packages [#228](https://github.com/thmarx/cms/issues/228)
* **MAINTENANCE** Performance optimizations [#234](https://github.com/thmarx/cms/issues/234)
* **MAINTENANCE** Update jetty dependency [#233](https://github.com/thmarx/cms/issues/233)
* **MAINTENANCE** Test suite [#231](https://github.com/thmarx/cms/issues/231)


## 5.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import com.github.thmarx.cms.content.views.model.View;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,6 @@ public RequestExtensions newContext(Theme theme, RequestContext requestContext)
.fileSystem(new ExtensionFileSystem(db.getFileSystem().resolve("extensions/"), theme.extensionsPath()))
.build())
.engine(engine).build();
/*
Context themeContext = null;
if (!theme.empty()) {
themeContext = Context.newBuilder()
.allowAllAccess(true)
.allowHostClassLookup(className -> true)
.allowHostAccess(HostAccess.ALL)
.allowValueSharing(true)
.hostClassLoader(getClassLoader())
.allowIO(IOAccess.newBuilder()
.fileSystem(new ExtensionFileSystem(theme.extensionsPath()))
.build())
.engine(engine).build();
}
*/

RequestExtensions requestExtensions = new RequestExtensions(context);

Expand Down
2 changes: 1 addition & 1 deletion cms-server/hosts/features/extensions/http.extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $hooks.registerAction("system/server/http/extension", (context) => {
"/test2",
(request, response) => {
response.addHeader("Content-Type", "text/html; charset=utf-8")
response.write("ich bin einen test extension, registered via hook!", UTF_8)
response.write("http extension via hook!", UTF_8)
}
)
return null;
Expand Down
2 changes: 1 addition & 1 deletion cms-server/hosts/features/extensions/template.extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $template.registerTemplateSupplier(
$hooks.registerAction("system/template/supplier", (context) => {
context.arguments().get("suppliers").add(
"myName",
() => "My name is Thorsten"
() => "My name is CondationCMS"
)
return null;
})
Expand Down
4 changes: 2 additions & 2 deletions cms-server/hosts/features/templates/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ <h2>
<p th:text="${name}"></p>
<!-- Thorsten -->
</div>
<div th:with="hello = ${getHello.apply('Thorsten')}">
<div th:with="hello = ${getHello.apply('CondationCMS')}">
<p th:text="${hello}"></p>
<!-- Hello Thorsten -->
<!-- Hello CondationCMS -->
</div>
</div>

Expand Down
File renamed without changes.
27 changes: 27 additions & 0 deletions distribution/test-suite/http-extensions.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { check } from 'k6';
import http from 'k6/http';

export const options = {
thresholds: {
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
http_req_duration: ['p(95)<250'], // 95% of requests should be below 200ms
},
};

export default function () {


var res = http.get("http://localhost2:1010/extension/test2");
check(res, {
'is status 200': (r) => r.status === 200,
'verify content': (r) =>
r.body.includes('http extension via hook!'),
});
res = http.get("http://localhost2:1010/hello-route");
check(res, {
'is status 200': (r) => r.status === 200,
'verify content': (r) =>
r.body.includes('route via hook!'),
});

}
File renamed without changes.
37 changes: 37 additions & 0 deletions distribution/test-suite/module.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { check } from 'k6';
import http from 'k6/http';

export const options = {
thresholds: {
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
http_req_duration: ['p(95)<250'], // 95% of requests should be below 200ms
},
};

export default function () {

let res = http.get("http://localhost2:1010/example/route");
check(res, {
'is status 200': (r) => r.status === 200,
});

res = http.get("http://localhost2:1010/module/example-module/world");
check(res, {
'is status 200': (r) => r.status === 200,
'verify content': (r) =>
r.body.includes('Hello world!'),
});

res = http.get("http://localhost2:1010/example/route");
check(res, {
'is status 200': (r) => r.status === 200,
'verify content': (r) =>
r.body.includes('example route\nHELlO: NO-NAME'),
});
res = http.get("http://localhost2:1010/example/route?name=test-suite");
check(res, {
'is status 200': (r) => r.status === 200,
'verify content': (r) =>
r.body.includes('example route\nHELlO: test-suite'),
});
}
35 changes: 35 additions & 0 deletions distribution/test-suite/template.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { check } from 'k6';
import http from 'k6/http';

export const options = {
thresholds: {
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
http_req_duration: ['p(95)<250'], // 95% of requests should be below 200ms
},
};

export default function () {


var res = http.get("http://localhost2:1010");
check(res, {
'is status 200': (r) => r.status === 200,
'template supplier via extension hook': (r) =>
r.body.includes('My name is CondationCMS'),
});
res = http.get("http://localhost2:1010");
check(res, {
'is status 200': (r) => r.status === 200,
'template function via extension hook': (r) =>
r.body.includes('Hello CondationCMS'),
});

res = http.get("http://localhost2:1010");
check(res, {
'is status 200': (r) => r.status === 200,
'template calling a shortcode': (r) =>
r.body.includes("Hello CondationCMS, I'm a TAG!"),
});


}

0 comments on commit e0d7182

Please sign in to comment.