Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FUSETOOLS2-2201: Testing with productized versions of Camel #1611

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions .github/workflows/camel_version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Camel Version CI

on:
pull_request:
branches: [ main ]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
camel:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-13, windows-latest ]
camel-version: [ "4.0.0", "4.0.0.redhat-00031" ]

env:
CODE_VERSION: max
CODE_TYPE: stable
TEST_RESOURCES: test-resources
CAMEL_VERSION: ${{ matrix.camel-version }}

runs-on: ${{ matrix.os }}
name: ${{ matrix.camel-version }} / ${{ matrix.os }}

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: "temurin"

- name: Test java
run: java --version

- name: Install JBang (ubuntu, macOS)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-13'
run: |
curl -Ls https://sh.jbang.dev | bash -s - app setup
echo "$HOME/.jbang/bin" >> $GITHUB_PATH

- name: Install JBang (windows)
if: matrix.os == 'windows-latest'
run: choco install jbang

- name: Setup JBang (trusted sources)
run: jbang trust add https://github.com/apache/

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18.15.x
cache: npm

- name: Setup vsce
run: |
npm install -g typescript @vscode/vsce
vsce --version

- name: npm-ci
run: npm ci

- name: ui test (ubuntu)
id: uiTest_Ubuntu
if: matrix.os == 'ubuntu-latest'
run: xvfb-run --auto-servernum npm run ui-test

- name: ui test (macos, windows)
id: uiTest_MacOS_Windows
if: matrix.os != 'ubuntu-latest'
run: npm run ui-test

- name: vsce-package
run: vsce package

- name: Store Camel Language Server log
uses: actions/upload-artifact@v3
if: failure() && matrix.os != 'windows-latest'
with:
name: ${{ matrix.os }}-${{ matrix.camel-version }}-camel-lsp-log
path: |
/tmp/log-camel-lsp.log
/tmp/log-camel*.log.gz

- name: Store UI test logs
uses: actions/upload-artifact@v3
if: |
(failure() || cancelled()) &&
(steps.uiTest_Ubuntu.outcome == 'failure' ||
steps.uiTest_MacOS_Windows.outcome == 'failure' ||
steps.uiTest_Ubuntu.outcome == 'cancelled' ||
steps.uiTest_MacOS_Windows.outcome == 'cancelled')
with:
name: ${{ matrix.os }}-${{ matrix.camel-version }}-ui-test-logs
path: test-resources/settings/logs/*

- name: Store UI Test Screenshots
uses: actions/upload-artifact@v3
if: |
(failure() || cancelled()) &&
(steps.uiTest_Ubuntu.outcome == 'failure' ||
steps.uiTest_MacOS_Windows.outcome == 'failure' ||
steps.uiTest_Ubuntu.outcome == 'cancelled' ||
steps.uiTest_MacOS_Windows.outcome == 'cancelled')
with:
name: ${{ matrix.os }}-${{ matrix.camel-version }}-ui-test-screenshots
path: test-resources/screenshots/*.png

check:
if: always()
runs-on: ubuntu-latest
name: Status Check
needs: [ camel ]
steps:
- name: Test Matrix Result
run: |
echo result = ${{ needs.camel.result }}
- name: Status Check - success
if: ${{ needs.camel.result == 'success' }}
run: |
echo "All tests successfully completed!"
exit 0
- name: Status Check - failure
if: ${{ needs.camel.result != 'success' }}
run: |
echo "Status Check failed!"
exit 1
17 changes: 13 additions & 4 deletions src/ui-test/tests/camel.settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
initXMLFileWithJBang,
JBANG_VERSION_ID,
killTerminal,
readUserSetting,
resetUserSettings,
RESOURCES,
setAdditionalComponents,
Expand Down Expand Up @@ -121,7 +122,15 @@ describe('User preferences', function () {

after(async function () {
await new EditorView().closeAllEditors();
resetUserSettings(CATALOG_VERSION_ID);
if(process.env.CAMEL_VERSION != null){
await setCamelCatalogVersion(process.env.CAMEL_VERSION);
await driver.wait(async function () {
return readUserSetting(CATALOG_VERSION_ID) === process.env.CAMEL_VERSION;
}, 15000, `Camel Version - '${process.env.CAMEL_VERSION}' not set in time limit.`, 1500);

} else {
resetUserSettings(CATALOG_VERSION_ID);
}
});

afterEach(async function () {
Expand All @@ -136,7 +145,7 @@ describe('User preferences', function () {
// add component
const editor = new TextEditor();
await editor.isDisplayed();
await editor.typeTextAt(3, XML_URI_POSITION, 'file-watch');
await editor.typeTextAt(3, XML_URI_POSITION, 'knative');

// open ca
contentAssist = await editor.toggleContentAssist(true) as ContentAssist;
Expand All @@ -145,7 +154,7 @@ describe('User preferences', function () {
assert.equal(items.length, 1);

// check if content is expected
const expectedContentAssist = 'file-watch:path';
const expectedContentAssist = 'knative:type/typeId';
const timer = await contentAssist.getItem(expectedContentAssist);
assert.equal(await getTextExt(timer), expectedContentAssist);
});
Expand All @@ -160,7 +169,7 @@ describe('User preferences', function () {
// add component
const editor = new TextEditor();
await editor.isDisplayed();
await editor.typeTextAt(3, XML_URI_POSITION, 'file-watch');
await editor.typeTextAt(3, XML_URI_POSITION, 'knative');

// open ca
contentAssist = await editor.toggleContentAssist(true) as ContentAssist;
Expand Down
33 changes: 33 additions & 0 deletions src/ui-test/tests/env/check.camel.version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License", destination); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { assert } from "chai";
import { CATALOG_VERSION_ID, readUserSetting } from "../../utils/testUtils";

describe('Camel version', function () {
this.timeout(15000);

const testDescription = process.env.CAMEL_VERSION ? `Check actual version is ${process.env.CAMEL_VERSION}` : 'Nothing to check';

it(testDescription, async function () {

if (process.env.CAMEL_VERSION == null || process.env.CAMEL_VERSION.length == 0) {
this.skip();
}

assert.equal(readUserSetting(CATALOG_VERSION_ID), process.env.CAMEL_VERSION);
});
});
41 changes: 41 additions & 0 deletions src/ui-test/tests/env/set.camel.version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License", destination); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
CATALOG_VERSION_ID,
readUserSetting,
setUserSettingsDirectly,
} from '../../utils/testUtils';
import { assert } from 'chai';

describe('Camel version', function () {
this.timeout(15000);

const testDescription = process.env.CAMEL_VERSION ? `Set ${process.env.CAMEL_VERSION}` : 'Use default';

it(testDescription, async function () {
// no env variable set or is empty
if (process.env.CAMEL_VERSION == null || process.env.CAMEL_VERSION.length == 0) {
this.skip();
}

// set version directly
setUserSettingsDirectly(CATALOG_VERSION_ID, process.env.CAMEL_VERSION);

// check if version was set
assert.equal(readUserSetting(CATALOG_VERSION_ID), process.env.CAMEL_VERSION)
});
});
4 changes: 2 additions & 2 deletions src/ui-test/tests/modelines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ describe('Camel-K modelines support', function () {
editor = await activateEditor(driver, TESTFILE);
await selectFromCA('dependency');
await editor.typeText('=');
await selectFromCA('camel-activemq');
assert.equal((await editor.getTextAtLine(1)).trim(), '// camel-k: dependency=camel-activemq');
await selectFromCA('camel-amqp');
assert.equal((await editor.getTextAtLine(1)).trim(), '// camel-k: dependency=camel-amqp');
});

it('mvn dependency', async function () {
Expand Down
30 changes: 22 additions & 8 deletions src/ui-test/tests/properties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,22 @@ describe('Camel properties auto-completion support', function () {
editor = await activateEditor(driver, TEST_FILE);
await editor.typeText('camel.');
await selectFromCA('component');
await selectFromCA('activemq');
assert.equal((await editor.getTextAtLine(1)).trim(), 'camel.component.activemq');
await selectFromCA('amqp');
assert.equal((await editor.getTextAtLine(1)).trim(), 'camel.component.amqp');
});

it('the default values are automatically added when auto-completing Camel component properties', async function () {
editor = await activateEditor(driver, TEST_FILE);
await editor.typeText('camel.component.activemq.');
await editor.typeText('camel.component.amqp.');
await selectFromCA('acceptMessagesWhileStopping');
assert.equal((await editor.getTextAtLine(1)).trim(), 'camel.component.activemq.acceptMessagesWhileStopping=false'); // defualt value 'false' is added
assert.equal((await editor.getTextAtLine(1)).trim(), 'camel.component.amqp.acceptMessagesWhileStopping=false'); // defualt value 'false' is added
});

it('provide filtered completion when in middle of a component id, component property or value', async function () {
editor = await activateEditor(driver, TEST_FILE);
await editor.typeText('camel.component.n');

contentAssist = await editor.toggleContentAssist(true) as ContentAssist;
await ca.waitUntilContentAssistContains('nats'); // wait until one of expected filtered options is available
const size = (await contentAssist.getItems()).length; // get count of fitlered options
assert.equal(Number(size), 4);
assert.isTrue(await testFilteredCompletion('nats', 'amqp'));
});

it('support insert-and-replace completion', async function () {
Expand Down Expand Up @@ -132,4 +129,21 @@ describe('Camel properties auto-completion support', function () {
assert.equal(await getTextExt(item), expectedItem);
await item.click();
}

/**
* Test for filtration of values in content assist.
*
* @param availableItem Item which must be available in CA.
* @param notAvailableItem Item which should NOT be available in CA.
* @returns true/false
*/
async function testFilteredCompletion(availableItem: string, notAvailableItem: string): Promise<boolean> {
try {
contentAssist = await ca.waitUntilContentAssistContains(availableItem);
await contentAssist.getItem(notAvailableItem);
return false;
} catch (error) {
return true;
}
}
});
7 changes: 6 additions & 1 deletion src/ui-test/uitest_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ const extensionFolder = path.join(projectPath, '.test-extensions');

async function main(): Promise<void> {
const tester = new ExTester(storageFolder, releaseType, extensionFolder);
await tester.setupAndRunTests('out/src/ui-test/tests/*.test.js',
await tester.setupAndRunTests(
[
'out/src/ui-test/tests/env/set.camel.version.js',
'out/src/ui-test/tests/*.test.js',
'out/src/ui-test/tests/env/check.camel.version.js'
],
process.env.CODE_VERSION,
{
'installDependencies': true
Expand Down
32 changes: 32 additions & 0 deletions src/ui-test/utils/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,38 @@ export function resetUserSettings(id: string): void {
fs.writeFileSync(settingsPath, reset, 'utf-8');
}

/**
* Read user settings value directly from settings.json
*
* @param id ID of setting to read.
*/
export function readUserSetting(id: string): string | null {
const settingsPath = path.resolve(storageFolder, 'settings', 'User', 'settings.json');
const settingsContent = fs.readFileSync(settingsPath, 'utf-8');

const regex = new RegExp(`"${id}":\\s*"(.*?)"`, 'i');
const match = settingsContent.match(regex);

if (match == null) {
return null;
} else {
return match[1];
}
}

/**
* Set user setting directly inside settings.json
*
* @param id ID of setting.
* @param value Value of setting.
*/
export function setUserSettingsDirectly(id: string, value: string): void {
const settingsPath = path.resolve(storageFolder, 'settings', 'User', 'settings.json');
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
settings[id] = value;
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 4), 'utf-8');
}

/**
* Delete file from folder.
*
Expand Down