Skip to content

Commit 6c8e9ee

Browse files
authored
Merge pull request #255 from bci-oss/#197_#254_Fix_and_test_AbstractProperty
[#254] [#197] Fix java code generation when an abstract entity contains only abstract properties
2 parents 53bc3f0 + 94d3cb1 commit 6c8e9ee

File tree

5 files changed

+89
-5
lines changed

5 files changed

+89
-5
lines changed

core/sds-aspect-model-document-generators/src/test/java/io/openmanufacturing/sds/aspectmodel/generator/jsonschema/AspectModelJsonSchemaGeneratorTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,28 @@ public void testAspectWithAbstractEntity( final KnownVersion metaModelVersion )
996996
.isEqualTo( "#/components/schemas/urn_bamm_io.openmanufacturing.test_1.0.0_ExtendingTestEntity" );
997997
}
998998

999+
/**
1000+
* Test to validate the json schema generated from the given aspect model containing an abstract property.
1001+
*
1002+
* @param metaModelVersion the used meta model version.
1003+
*/
1004+
@ParameterizedTest
1005+
@MethodSource( value = "versionsStartingWith2_0_0" )
1006+
public void testAspectWithAbstractProperty( final KnownVersion metaModelVersion ) {
1007+
final Aspect aspect = loadAspect( TestAspect.ASPECT_WITH_ABSTRACT_PROPERTY, metaModelVersion );
1008+
final JsonNode schema = buildJsonSchema( aspect );
1009+
1010+
assertThat( schema.at( "/components/schemas/urn_bamm_io.openmanufacturing.test_1.0.0_ExtendingTestEntity/"
1011+
+ "description" ).asText() )
1012+
.isEqualTo( "This is a test entity" );
1013+
assertThat( schema.at( "/components/schemas/urn_bamm_io.openmanufacturing.test_1.0.0_ExtendingTestEntity/"
1014+
+ "properties/abstractTestProperty/description" ).asText() )
1015+
.isEqualTo( "This is an abstract test property" );
1016+
assertThat( schema.at( "/components/schemas/urn_bamm_io.openmanufacturing.test_1.0.0_ExtendingTestEntity/"
1017+
+ "properties/abstractTestProperty/$ref" ).asText() )
1018+
.isEqualTo( "#/components/schemas/urn_bamm_io.openmanufacturing_characteristic_2.0.0_Text" );
1019+
}
1020+
9991021
@ParameterizedTest
10001022
@MethodSource( value = "versionsStartingWith2_0_0" )
10011023
public void testAspectWithCollectionWithAbstractEntity( final KnownVersion metaModelVersion ) {

core/sds-aspect-model-java-generator/src/main/resources/java-pojo-equals-method-lib.vm

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ if (o == null || getClass() != o.getClass()) {
2727
}
2828
#end
2929
#end
30-
final $element.getName() that = ($element.getName())o;
31-
return
32-
#if( $element.getProperties().isEmpty() ) true
30+
31+
#if( $element.getProperties().isEmpty() ) return true
3332
#else
34-
${util.objectEqualsExpression( $element )}
33+
#set( $objectEqualsExpression = $util.objectEqualsExpression( $element ) )
34+
#if( $objectEqualsExpression && !$objectEqualsExpression.empty )
35+
final $element.getName() that = ($element.getName())o;
36+
return $objectEqualsExpression
37+
#else
38+
return true
39+
#end
3540
#end;
3641
}
3742
#end

core/sds-aspect-model-serializer/src/test/java/io/openmanufacturing/sds/aspectmodel/serializer/RdfModelCreatorVisitorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public class RdfModelCreatorVisitorTest extends MetaModelVersions {
5656
"ASPECT_WITHOUT_PROPERTIES_AND_OPERATIONS",
5757
"ASPECT_WITH_ENUM_ONLY_ONE_SEE",
5858
"ASPECT_WITH_COLLECTION_WITH_ABSTRACT_ENTITY",
59-
"ASPECT_WITH_ABSTRACT_SINGLE_ENTITY"
59+
"ASPECT_WITH_ABSTRACT_SINGLE_ENTITY",
60+
"ASPECT_WITH_ABSTRACT_PROPERTY"
6061
} )
6162
public void testRdfModelCreatorVisitor( final TestAspect aspect ) {
6263
testRdfCreation( aspect, KnownVersion.getLatest() );

core/sds-test-aspect-models/src/main/java/io/openmanufacturing/sds/test/TestAspect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public enum TestAspect implements TestModel {
2121
ASPECT_WITHOUT_PROPERTIES_AND_OPERATIONS,
2222
ASPECT_WITHOUT_SEE_ATTRIBUTE,
2323
ASPECT_WITH_ABSTRACT_ENTITY,
24+
ASPECT_WITH_ABSTRACT_PROPERTY,
2425
ASPECT_WITH_ABSTRACT_SINGLE_ENTITY,
2526
ASPECT_WITH_ALL_BASE_ATTRIBUTES,
2627
ASPECT_WITH_BINARY,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# Copyright (c) 2022 Robert Bosch Manufacturing Solutions GmbH
3+
#
4+
# See the AUTHORS file(s) distributed with this work for additional
5+
# information regarding authorship.
6+
#
7+
# This Source Code Form is subject to the terms of the Mozilla Public
8+
# License, v. 2.0. If a copy of the MPL was not distributed with this
9+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
10+
#
11+
# SPDX-License-Identifier: MPL-2.0
12+
#
13+
@prefix : <urn:bamm:io.openmanufacturing.test:1.0.0#> .
14+
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:2.0.0#> .
15+
@prefix bamm-c: <urn:bamm:io.openmanufacturing:characteristic:2.0.0#> .
16+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
17+
18+
:AspectWithAbstractProperty a bamm:Aspect ;
19+
bamm:preferredName "Test Aspect"@en ;
20+
bamm:description "This is a test description"@en ;
21+
bamm:see <http://example.com/omp> ;
22+
bamm:properties ( :testProperty ) ;
23+
bamm:operations ( ) .
24+
25+
:testProperty a bamm:Property ;
26+
bamm:preferredName "Test Property"@en ;
27+
bamm:description "This is a test property."@en ;
28+
bamm:see <http://example.com/omp> ;
29+
bamm:see <http://example.com/me> ;
30+
bamm:characteristic :EntityCharacteristic .
31+
32+
:EntityCharacteristic a bamm-c:SingleEntity ;
33+
bamm:preferredName "Test Entity Characteristic"@en ;
34+
bamm:description "This is a test entity"@en ;
35+
bamm:see <http://example.com/omp> ;
36+
bamm:dataType :ExtendingTestEntity .
37+
38+
:AbstractTestEntity a bamm:AbstractEntity ;
39+
bamm:preferredName "Abstract Test Entity"@en ;
40+
bamm:description "This is a abstract test entity"@en ;
41+
bamm:properties ( :abstractTestProperty ).
42+
43+
:abstractTestProperty a bamm:AbstractProperty ;
44+
bamm:description "This is an abstract test property"@en .
45+
46+
:ExtendingTestEntity a bamm:Entity ;
47+
bamm:extends :AbstractTestEntity ;
48+
bamm:preferredName "Test Entity"@en ;
49+
bamm:description "This is a test entity"@en ;
50+
bamm:properties (
51+
[ bamm:extends :abstractTestProperty ; bamm:characteristic bamm-c:Text ]
52+
) .
53+
54+
55+

0 commit comments

Comments
 (0)