Skip to content

Commit

Permalink
Fix cannot change version of Aspect Model (#185)
Browse files Browse the repository at this point in the history
* Fixing changing namespace and version of models

* Fix caching problem on current loaded model

* Fix Github findings

* Fix update title information

* Fix cypress tests

* Add testing for changing namespace and version

* Fix dependencies should not update on changed file

* Update sidebar-state.service.ts
  • Loading branch information
michelu89 authored Apr 8, 2024
1 parent 412f666 commit ccccf94
Show file tree
Hide file tree
Showing 51 changed files with 576 additions and 432 deletions.
2 changes: 1 addition & 1 deletion core/apps/ame-e2e/src/fixtures/anonymous-elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
:property3 a samm:Property ;
samm:characteristic [
a samm-c:Trait ;
samm-c:baseCharacteristic [ a samm:Characteristic ] ;
samm-c:baseCharacteristic [ a samm:Characteristic; samm:dataType xsd:string ] ;
samm-c:constraint [ a samm:Constraint ] ;
samm-c:constraint [ a samm:Constraint ]
] .
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
#
# See the AUTHORS file(s) distributed with this work for
# additional information regarding authorship.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0

@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
@prefix samm-e: <urn:samm:org.eclipse.esmf.samm:entity:2.1.0#> .
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <urn:samm:org.eclipse.examples.one:1.0.0#> .

:AspectDefault a samm:Aspect ;
samm:properties (:property1) ;
samm:operations ();
samm:events () .

:property1 a samm:Property;
samm:characteristic :Characteristic1 .

:Characteristic1 a samm:Characteristic ;
samm:dataType xsd:string .
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
#
# See the AUTHORS file(s) distributed with this work for
# additional information regarding authorship.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0

@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
@prefix samm-e: <urn:samm:org.eclipse.esmf.samm:entity:2.1.0#> .
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <urn:samm:org.eclipse.examples.two:2.0.0#> .

:NewName a samm:Aspect ;
samm:properties (:property1) ;
samm:operations ();
samm:events () .

:property1 a samm:Property;
samm:characteristic :Characteristic1 .

:Characteristic1 a samm:Characteristic ;
samm:dataType xsd:string .
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
#
# See the AUTHORS file(s) distributed with this work for
# additional information regarding authorship.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0

@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
@prefix samm-e: <urn:samm:org.eclipse.esmf.samm:entity:2.1.0#> .
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <urn:samm:org.eclipse.examples.two:2.0.0#> .

:AspectDefault a samm:Aspect ;
samm:properties (:property1) ;
samm:operations ();
samm:events () .

:property1 a samm:Property;
samm:characteristic :Characteristic1 .

:Characteristic1 a samm:Characteristic ;
samm:dataType xsd:string .
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import {cyHelp} from '../../../support/helpers';
import {
SELECTOR_ecProperty,
SELECTOR_fileMenuFindElements,
SELECTOR_namespaceFileMenuButton,
SELECTOR_openNamespacesButton,
SELECTOR_searchElementsInp,
SELECTOR_workspaceBtn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import {cyHelp} from '../../../support/helpers';
import {
SELECTOR_ecProperty,
SELECTOR_fileMenuFindElements,
SELECTOR_namespaceFileMenuButton,
SELECTOR_openNamespacesButton,
SELECTOR_searchElementsInp,
SELECTOR_workspaceBtn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import {cyHelp} from '../../../support/helpers';
import {
SELECTOR_ecProperty,
SELECTOR_fileMenuFindElements,
SELECTOR_namespaceFileMenuButton,
SELECTOR_openNamespacesButton,
SELECTOR_searchElementsInp,
SELECTOR_workspaceBtn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ describe('Test loading aspect with extended external Entity', () => {
.wait(500)
.get('.mat-mdc-cell')
.contains(
' The Aspect model contains an external reference that is not included in the namespace file structure or is invalid'
' The Aspect model contains an external reference that is not included in the namespace file structure or is invalid',
)
.should('exist')
.should('exist'),
)
.then(() => cy.wait(500).get(SELECTOR_notificationsDialogCloseButton).click({force: true}));
});
Expand All @@ -54,7 +54,7 @@ describe('Test loading aspect with extended external Entity', () => {
},
{
fixture: '/external-reference/same-namespace/model-with-entity.txt',
}
},
);

cy.visitDefault();
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('Test loading aspect with extended external Entity', () => {
},
{
fixture: '/external-reference/different-namespace/model-with-entity.txt',
}
},
);

cy.visitDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ describe('Test load aspect model with anonymous elements', () => {
':Trait1 a samm-c:Trait;\n' +
' samm-c:baseCharacteristic :Characteristic3;\n' +
' samm-c:constraint :Constraint1, :Constraint2.\n' +
':Characteristic3 a samm:Characteristic.\n' +
':Characteristic3 a samm:Characteristic;\n' +
' samm:dataType xsd:string.\n' +
':Constraint1 a samm:Constraint.\n' +
':Constraint2 a samm:Constraint.\n',
':Constraint2 a samm:Constraint.',
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import {SELECTOR_settingsButton, SettingsDialogSelectors} from '../../support/constants';

describe('Auto Validate', () => {
it('should open settings dialog', () => {
it('should open editor settings dialog', () => {
cy.visitDefault()
.then(() => cy.startModelling())
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/* eslint-disable cypress/no-unnecessary-waiting */
/*
* Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
*
* See the AUTHORS file(s) distributed with this work for
* additional information regarding authorship.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

/// <reference types="Cypress" />

import 'cypress-real-events';
import {
ACTION_dialogButton,
FIELD_name,
SELECTOR_namespaceTabValueInput,
SELECTOR_namespaceTabVersionInput,
SELECTOR_settingsButton,
SELECTOR_workspaceBtn,
SettingsDialogSelectors,
} from '../../support/constants';
import {cyHelp} from '../../support/helpers';

describe('Test namespace settings dialog', () => {
describe('Test changing model namespace version', () => {
it('should open namespace settings', () => {
cy.visitDefault();
cy.startModelling();
openNamespaceSettings().then(() => verifyNamespaceSettings('org.eclipse.examples.aspect', '1.0.0'));
});

it('change namespace and version on settings', () => {
changeNamespaceSettings('org.eclipse.examples.test', '2.0.0')
.then(() => openNamespaceSettings())
.then(() => verifyNamespaceSettings('org.eclipse.examples.test', '2.0.0'))
.then(() => cy.get(SettingsDialogSelectors.settingsDialogCancelButton).click());
});
});

describe('Test changing model namespace version', () => {
it('should change namespace and version and save aspect model', () => {
cy.intercept('GET', 'http://localhost:9091/ame/api/models/namespaces?shouldRefresh=true', {});

cy.visitDefault();
cy.fixture('/change-namespace/aspect-workspace-one')
.as('rdfString')
.then(rdfString => cy.loadModel(rdfString));

cy.intercept('GET', 'http://localhost:9091/ame/api/models/namespaces?shouldRefresh=true', {
'org.eclipse.examples.one:1.0.0': ['AspectDefault.ttl'],
});

cy.intercept(
{
method: 'POST',
url: 'http://localhost:9091/ame/api/models',
headers: {namespace: 'org.eclipse.examples.one:1.0.0', 'file-name': 'AspectDefault.ttl'},
},
{
fixture: '/change-namespace/aspect-workspace-one.txt',
},
);

cy.saveAspectModelToWorkspace().then(() => cy.get(SELECTOR_workspaceBtn).click());

cy.intercept('GET', 'http://localhost:9091/ame/api/models/namespaces?shouldRefresh=true', {
'org.eclipse.examples.one:1.0.0': ['AspectDefault.ttl'],
'org.eclipse.examples.two:2.0.0': ['AspectDefault.ttl'],
});

cy.intercept(
{
method: 'POST',
url: 'http://localhost:9091/ame/api/models',
headers: {namespace: 'org.eclipse.examples.two:2.0.0', 'file-name': 'AspectDefault.ttl'},
},
{
fixture: '/change-namespace/aspect-workspace-two.txt',
},
);

openNamespaceSettings()
.then(() => changeNamespaceSettings('org.eclipse.examples.two', '2.0.0'))
.then(() => cy.saveAspectModelToWorkspace())
.then(() => cy.get(ACTION_dialogButton).click())
.then(() => openNamespaceSettings())
.then(() => verifyNamespaceSettings('org.eclipse.examples.two', '2.0.0'))
.then(() => cy.get(SettingsDialogSelectors.settingsDialogCancelButton).click())
.then(() => cy.get('.namespaces').invoke('html'))
.then(html => {
expect(html).contain('org.eclipse.examples.two:2.0.0');
expect((html.match(/AspectDefault.ttl/g) || []).length).to.equal(2);
})
.then(() => cy.get('[ng-reflect-message="This file is currently opened "]').invoke('html'))
.then(html => expect(html).contain('AspectDefault.ttl'));
});

it('should change name of aspect element and save to workspace', () => {
cy.intercept('GET', 'http://localhost:9091/ame/api/models/namespaces?shouldRefresh=true', {
'org.eclipse.examples.one:1.0.0': ['AspectDefault.ttl'],
'org.eclipse.examples.two:2.0.0': ['AspectDefault.ttl', 'NewName.ttl'],
});

cy.intercept(
{
method: 'POST',
url: 'http://localhost:9091/ame/api/models',
headers: {namespace: 'org.eclipse.examples.one:1.0.0', 'file-name': 'AspectDefault.ttl'},
},
{
fixture: '/change-namespace/aspect-workspace-one.txt',
},
);

cy.intercept(
{
method: 'POST',
url: 'http://localhost:9091/ame/api/models',
headers: {namespace: 'org.eclipse.examples.two:2.0.0', 'file-name': 'AspectDefault.ttl'},
},
{
fixture: '/change-namespace/aspect-workspace-two.txt',
},
);

cy.intercept(
{
method: 'POST',
url: 'http://localhost:9091/ame/api/models',
headers: {namespace: 'org.eclipse.examples.two:2.0.0', 'file-name': 'NewName.ttl'},
},
{
fixture: '/change-namespace/aspect-workspace-three.txt',
},
);

cy.dbClickShape('AspectDefault')
.then(() => cy.get(FIELD_name).clear({force: true}).type('NewName'))
.then(() => cyHelp.clickSaveButton())
.then(() => cy.saveAspectModelToWorkspace())
.then(() => openNamespaceSettings())
.then(() => verifyNamespaceSettings('org.eclipse.examples.two', '2.0.0'))
.then(() => cy.get(SettingsDialogSelectors.settingsDialogCancelButton).click())
.then(() => cy.get('.namespaces').invoke('html'))
.then(html => {
expect(html).contain('org.eclipse.examples.two:2.0.0');
expect((html.match(/AspectDefault.ttl/g) || []).length).to.equal(2);
})
.then(() => cy.get('[ng-reflect-message="This file is currently opened "]').invoke('html'))
.then(html => expect(html).contain('NewName.ttl'));
});
});

function openNamespaceSettings() {
return cy.get(SELECTOR_settingsButton).click().wait(1000).get(':nth-child(6) > .settings__node').click();
}

function verifyNamespaceSettings(namespace: string, version: string): void {
cy.get(SELECTOR_namespaceTabValueInput).should('have.value', namespace);
cy.get(SELECTOR_namespaceTabVersionInput).should('have.value', version);
}

function changeNamespaceSettings(namespace: string, version: string) {
return cy
.get(SELECTOR_namespaceTabValueInput)
.clear()
.type(namespace)
.then(() => cy.get(SELECTOR_namespaceTabVersionInput).clear().type(version))
.then(() => cy.get(SettingsDialogSelectors.settingsDialogOkButton).click());
}
});

This file was deleted.

2 changes: 1 addition & 1 deletion core/apps/ame-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ Cypress.Commands.add('loadModel', (rdfString: string) => {

Cypress.Commands.add('saveAspectModelToWorkspace', () => {
cy.intercept('POST', 'http://localhost:9091/ame/api/models/validate', {fixture: 'model-validation-response.json'});
cy.intercept('POST', 'http://localhost:9091/ame/api/models/format', () => {});
cy.intercept('POST', 'http://localhost:9091/ame/api/models/format', {fixture: '/default-models/aspect-default.txt'});

return cy.window().then(win => {
const fileHandlingService: FileHandlingService = win['angular.fileHandlingService'];
Expand Down
Loading

0 comments on commit ccccf94

Please sign in to comment.