Skip to content

Commit cebe8f0

Browse files
authored
Fix bug when parsing AssetKind with Registry Integration Feature (#509)
* fix: AssetKind mapping failing during Registry Integration * test: fix invalid test due to bugfix
1 parent 8ad7727 commit cebe8f0

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

basyx.aasenvironment/basyx.aasenvironment.component/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/component/TestEnvironmentWithRegistryIntegration.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@
3636
import org.eclipse.digitaltwin.basyx.aasenvironment.AasEnvironment;
3737
import org.eclipse.digitaltwin.basyx.aasenvironment.environmentloader.CompleteEnvironment;
3838
import org.eclipse.digitaltwin.basyx.aasenvironment.environmentloader.CompleteEnvironment.EnvironmentType;
39+
import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException;
40+
import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor;
3941
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository;
4042
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AasRepositoryRegistryLink;
43+
import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryLinkException;
4144
import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo;
4245
import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository;
4346
import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.SubmodelRepositoryRegistryLink;
@@ -57,7 +60,7 @@
5760
*/
5861
public class TestEnvironmentWithRegistryIntegration {
5962

60-
static final String FAULTY_AAS_PATH = "faulty_aas_reginteg.aasx";
63+
static final String ENV_PATH = "testEnvironment.json";
6164

6265
static ConfigurableApplicationContext appContext;
6366

@@ -92,14 +95,23 @@ public static void clearRegistries() throws Exception {
9295
}
9396

9497
@Test
95-
public void whenUploadDescriptorToRegistryFails_thenNoAasOrSmAreAddedToRepository() throws InvalidFormatException, DeserializationException, IOException {
96-
CompleteEnvironment completeEnvironment = CompleteEnvironment.fromInputStream(getIsFromClasspath(FAULTY_AAS_PATH), EnvironmentType.AASX);
98+
public void whenUploadDescriptorToRegistryFails_thenNoAasOrSmAreAddedToRepository() throws InvalidFormatException, DeserializationException, IOException, ApiException {
99+
// simulate descriptor already being in registry
100+
aasRepositoryRegistryLink.getRegistryApi().postAssetAdministrationShellDescriptor(buildTestAasDescriptor());
97101

98-
assertThrows(IllegalArgumentException.class, () -> aasEnvironment.loadEnvironment(completeEnvironment));
102+
CompleteEnvironment completeEnvironment = CompleteEnvironment.fromInputStream(getIsFromClasspath(ENV_PATH), EnvironmentType.JSON);
103+
104+
assertThrows(RepositoryRegistryLinkException.class, () -> aasEnvironment.loadEnvironment(completeEnvironment));
99105

100106
assertRepositoriesAreEmpty();
101107
}
102108

109+
private static AssetAdministrationShellDescriptor buildTestAasDescriptor() {
110+
AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor();
111+
descriptor.setId("https://acplt.test/Test_AssetAdministrationShell");
112+
return descriptor;
113+
}
114+
103115
private static InputStream getIsFromClasspath(String fileName) throws IOException {
104116
return new ClassPathResource(fileName).getInputStream();
105117
}
Binary file not shown.

basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/mapper/AttributeMapper.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,16 @@ public AdministrativeInformation mapAdministration(org.eclipse.digitaltwin.aas4j
134134
* @return the mapped assetKind
135135
*/
136136
public AssetKind mapAssetKind(org.eclipse.digitaltwin.aas4j.v3.model.AssetKind assetKind) {
137-
138-
return AssetKind.valueOf(AssetKind.class, assetKind.name());
137+
switch (assetKind) {
138+
case INSTANCE:
139+
return AssetKind.INSTANCE;
140+
case NOT_APPLICABLE:
141+
return AssetKind.NOTAPPLICABLE;
142+
case TYPE:
143+
return AssetKind.TYPE;
144+
default:
145+
throw new IllegalArgumentException("Unknown AssetKind: " + assetKind);
146+
}
139147
}
140148

141149
}

0 commit comments

Comments
 (0)