Skip to content

Commit dc02c84

Browse files
Tests green
1 parent 24231d1 commit dc02c84

File tree

9 files changed

+94
-10
lines changed

9 files changed

+94
-10
lines changed

core/src/main/java/dev/vml/es/acm/core/script/ScriptScheduler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public void onEvent(Event event) {
177177

178178
public void bootOnDemand() {
179179
LOG.info("Automatic scripts booting on demand - job scheduling");
180+
bootedScripts.clear();
180181
unscheduleBoot();
181182
scheduleBoot();
182183
LOG.info("Automatic scripts booting on demand - job scheduled");
@@ -319,8 +320,10 @@ private void queueBootScript(Script script, ResourceResolver resourceResolver) {
319320
bootedScripts.put(script.getId(), checksum);
320321
LOG.info("Boot script '{}' queued", script.getId());
321322
} else {
322-
LOG.info("Boot script '{}' not eligible for queueing!", script.getId());
323+
LOG.info("Boot script '{}' not queued - check failed", script.getId());
323324
}
325+
} else {
326+
LOG.info("Boot script '{}' not queued - checksum unchanged", script.getId());
324327
}
325328
}
326329

test/e2e/001-general.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
11
import { test, expect } from '@playwright/test';
22
import { expectCodeExecutorStatus, expectHealthyStatus } from './utils/expect';
3+
import { testOnEnv, apiHeaders } from './utils/env';
34

45
test.describe('General', () => {
56
test('Tool is accessible', async ({ page }) => {
67
await page.goto('/acm');
78

89
const title = page.locator('.granite-title', { hasText: 'Content Manager' });
910
await expect(title).toBeVisible();
11+
12+
await page.screenshot();
13+
});
14+
15+
testOnEnv('local')('Tool state is reset', async ({ page }) => {
16+
const clearResponse = await page.request.post('/apps/acm/api/event.json?name=HISTORY_CLEAR', { headers: await apiHeaders(page) });
17+
expect(clearResponse.ok()).toBeTruthy();
18+
const clearJson = await clearResponse.json();
19+
expect(clearJson).toEqual({ status: 200, message: "Event 'HISTORY_CLEAR' dispatched successfully!", data: null });
20+
await page.waitForTimeout(3000);
21+
22+
const bootResponse = await page.request.post('/apps/acm/api/event.json?name=SCRIPT_SCHEDULER_BOOT', { headers: await apiHeaders(page) });
23+
expect(bootResponse.ok()).toBeTruthy();
24+
const bootJson = await bootResponse.json();
25+
expect(bootJson).toEqual({ status: 200, message: "Event 'SCRIPT_SCHEDULER_BOOT' dispatched successfully!", data: null });
26+
await page.waitForTimeout(10000);
1027
});
1128

1229
test('System is healthy', async ({ page }) => {
1330
await page.goto('/acm#/maintenance?tab=health-checker');
1431

1532
await expectHealthyStatus(page);
33+
await page.screenshot();
1634
});
1735

1836
test('Code executor is idle', async ({ page }) => {
1937
await page.goto('/acm#/maintenance?tab=code-executor');
2038

2139
await expectCodeExecutorStatus(page);
40+
await page.screenshot();
2241
});
2342

2443
});

test/e2e/002-console.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ test.describe('Console', () => {
2222
await expect(page.getByRole('button', { name: 'Execute' })).toBeEnabled();
2323
await page.getByRole('button', { name: 'Execute' }).click();
2424

25-
await page.getByRole('tab', { name: 'Output' }).click();
25+
await expect(page.getByRole('tab', { name: 'Output' })).toHaveAttribute('aria-selected', 'true');
2626
await expectExecutionProgressBarSucceeded(page);
2727

2828
const output = await readFromCodeEditor(page, 'Console Output');
2929
expectToHaveMultilineText(output, `
3030
Hello World!
3131
`);
32+
await page.screenshot();
3233
});
3334
});
3435

test/e2e/003-tool-access.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ test.describe('Tool Access', () => {
1818
await page.goto('/acm#/console');
1919
await expectCompilationSucceeded(page);
2020
await expect(page.getByRole('button', { name: 'Execute' })).toBeEnabled();
21+
22+
await page.screenshot();
2123
});
2224

2325
test('Setup test user and verify limited access', async ({ page, browser }) => {
@@ -59,8 +61,7 @@ test.describe('Tool Access', () => {
5961

6062
await expect(page.getByRole('button', { name: 'Execute' })).toBeEnabled();
6163
await page.getByRole('button', { name: 'Execute' }).click();
62-
63-
await page.getByRole('tab', { name: 'Output' }).click();
64+
await expect(page.getByRole('tab', { name: 'Output' })).toHaveAttribute('aria-selected', 'true');
6465
await expectExecutionProgressBarSucceeded(page);
6566

6667
const output = await readFromCodeEditor(page, 'Console Output');
@@ -77,6 +78,8 @@ test.describe('Tool Access', () => {
7778
await expect(testUserPage.getByRole('button', { name: 'Snippets' })).not.toBeVisible();
7879
await expect(testUserPage.getByRole('button', { name: 'History' })).not.toBeVisible();
7980
await expect(testUserPage.getByRole('button', { name: 'Maintenance' })).not.toBeVisible();
81+
82+
await testUserPage.screenshot();
8083

8184
await testUserPage.getByRole('button', { name: 'Scripts' }).click();
8285
await expect(testUserPage).toHaveURL(/\/acm#\/scripts/);
@@ -95,6 +98,8 @@ test.describe('Tool Access', () => {
9598

9699
await testUserPage.goto('/acm#/maintenance');
97100
await expect(testUserPage.getByRole('button', { name: 'Maintenance' })).not.toBeVisible();
101+
102+
await testUserPage.screenshot();
98103
});
99104
});
100105
});

test/e2e/004-history.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ test.describe('History', () => {
1515

1616
const firstRow = rows.nth(1);
1717
await expect(firstRow.locator('[role="rowheader"]')).toContainText('Console');
18+
await page.screenshot();
1819
await firstRow.click();
1920
await page.getByRole('tab', { name: 'Output' }).click();
2021
const firstOutput = await readFromCodeEditor(page, 'Execution Output');
2122
expect(firstOutput).toContain('Setup complete!');
23+
await page.screenshot();
2224

2325
await page.goto('/acm#/history');
2426
await expect(grid).toBeVisible();
@@ -29,6 +31,7 @@ test.describe('History', () => {
2931
await page.getByRole('tab', { name: 'Output' }).click();
3032
const secondOutput = await readFromCodeEditor(page, 'Execution Output');
3133
expect(secondOutput).toContain('Hello World!');
34+
await page.screenshot();
3235
});
3336

3437
test('Shows automatic script executions', async ({ page }) => {
@@ -42,9 +45,11 @@ test.describe('History', () => {
4245
await page.getByRole('searchbox', { name: 'Executable' }).fill('example/ACME-20_once');
4346
await expect(rows.nth(1)).toContainText('Script \'example/ACME-20_once\'');
4447
await expect(rows.nth(1)).toContainText('succeeded');
48+
await page.screenshot();
4549

4650
await page.getByRole('searchbox', { name: 'Executable' }).fill('example/ACME-21_changed');
4751
await expect(rows.nth(1)).toContainText('Script \'example/ACME-21_changed\'');
4852
await expect(rows.nth(1)).toContainText('succeeded');
53+
await page.screenshot();
4954
});
5055
});

test/e2e/005-manual-scripts.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@ test.describe('Manual Scripts', () => {
1414
test('Execute CSV Generation With I/O', async ({ page }) => {
1515
await page.goto('/acm');
1616
await page.getByRole('button', { name: 'Scripts' }).click();
17+
await page.screenshot({ path: 'test-results/screenshots/005-scripts-list.png' });
1718
await page.getByText('example/ACME-203_output-csv').click();
19+
await page.screenshot({ path: 'test-results/screenshots/005-script-details.png' });
1820
await page.getByRole('button', { name: 'Execute' }).click();
1921

2022
await page.getByRole('textbox', { name: 'Users to' }).fill('5000');
2123
await page.getByRole('textbox', { name: 'First names' }).fill('John\nJane\nJack\nAlice\nBob\nRobert');
2224
await page.getByRole('textbox', { name: 'Last names' }).fill('Doe\nSmith\nBrown\nJohnson\nWhite\nJordan');
25+
await page.screenshot({ path: 'test-results/screenshots/005-execution-inputs-filled.png' });
2326

2427
await page.getByRole('button', { name: 'Start' }).click();
2528
await expectExecutionProgressBarSucceeded(page);
29+
await page.screenshot();
2630

2731
const output = await readFromCodeEditor(page, 'Execution Output');
2832
expect(output).toContain('[SUCCESS] Users CSV report generation ended successfully');
33+
await page.screenshot({ path: 'test-results/screenshots/005-execution-output.png' });
2934

3035
await page.getByRole('tab', { name: 'Details' }).click();
3136

@@ -54,16 +59,19 @@ test.describe('Manual Scripts', () => {
5459
value: 'Processed 5000 user(s)',
5560
},
5661
]);
62+
await page.screenshot({ path: 'test-results/screenshots/005-execution-outputs.png' });
5763

5864
await page.getByRole('tab', { name: 'Output' }).click();
5965

6066
await page.getByRole('button', { name: 'Review' }).click();
6167
await page.getByRole('tab', { name: 'Texts' }).click();
6268
await expectOutputTexts(page, ['Processed 5000 user(s)']);
69+
await page.screenshot({ path: 'test-results/screenshots/005-output-review-texts.png' });
6370
await page.getByTestId('modal').getByRole('button', { name: 'Close' }).click();
6471

6572
await page.getByRole('button', { name: 'Review' }).click();
6673
await page.getByRole('tab', { name: 'Files' }).click();
74+
await page.screenshot({ path: 'test-results/screenshots/005-output-review-files.png' });
6775
await expectOutputFileDownload(page, 'Download Archive', /\.(zip)$/);
6876

6977
await page.getByRole('button', { name: 'Review' }).click();

test/e2e/playwright.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig, devices } from '@playwright/test';
2+
import { authHeader, BASE_URL } from './utils/env';
23

34
/**
45
* Read environment variables from file.
@@ -26,14 +27,15 @@ export default defineConfig({
2627
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2728
use: {
2829
/* Base URL to use in actions like `await page.goto('')`. */
29-
baseURL: 'http://localhost:5502',
30+
baseURL: BASE_URL,
3031

3132
/* Action timeout (e.g. toBeEnabled, toBeVisible) */
3233
actionTimeout: 10000,
3334

3435
/* Basic Auth for AEM */
3536
extraHTTPHeaders: {
36-
'Authorization': 'Basic ' + Buffer.from('admin:admin').toString('base64'),
37+
...authHeader(),
38+
'Origin': BASE_URL,
3739
},
3840

3941
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */

test/e2e/utils/context.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Browser, Page } from '@playwright/test';
2+
import { authHeader, BASE_URL } from './env';
23

34
export async function newAemContext(
45
browser: Browser,
@@ -7,10 +8,8 @@ export async function newAemContext(
78
callback: (page: Page) => Promise<void>
89
): Promise<void> {
910
const context = await browser.newContext({
10-
baseURL: 'http://localhost:5502',
11-
extraHTTPHeaders: {
12-
'Authorization': 'Basic ' + btoa(`${user}:${password}`),
13-
},
11+
baseURL: BASE_URL,
12+
extraHTTPHeaders: authHeader(user, password),
1413
});
1514

1615
const page = await context.newPage();

test/e2e/utils/env.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { test, Page } from '@playwright/test';
2+
3+
export const testOnEnv = (env: string) => {
4+
return process.env.AEM_ENV === env ? test : test.skip;
5+
};
6+
7+
export const BASE_URL = 'http://localhost:5502';
8+
export const ADMIN_USER = 'admin';
9+
export const ADMIN_PASSWORD = 'admin';
10+
11+
export const authHeader = (user = ADMIN_USER, password = ADMIN_PASSWORD) => ({
12+
'Authorization': 'Basic ' + Buffer.from(`${user}:${password}`).toString('base64')
13+
});
14+
15+
export const baseUrlHeaders = () => ({
16+
'Origin': BASE_URL,
17+
'Referer': BASE_URL,
18+
});
19+
20+
export const csrfHeader = (token: string) => ({
21+
'CSRF-Token': token,
22+
});
23+
24+
export const getCsrfToken = async (page: Page): Promise<string> => {
25+
const tokenResponse = await page.request.get('/libs/granite/csrf/token.json', {
26+
headers: {
27+
...authHeader(),
28+
...baseUrlHeaders(),
29+
},
30+
});
31+
const tokenData = await tokenResponse.json();
32+
return tokenData.token;
33+
};
34+
35+
export const apiHeaders = async (page: Page) => {
36+
const csrfToken = await getCsrfToken(page);
37+
return {
38+
...authHeader(),
39+
...baseUrlHeaders(),
40+
...csrfHeader(csrfToken),
41+
};
42+
};

0 commit comments

Comments
 (0)