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

Fix bug when parsing AssetKind with Registry Integration Feature #509

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
import org.eclipse.digitaltwin.basyx.aasenvironment.AasEnvironment;
import org.eclipse.digitaltwin.basyx.aasenvironment.environmentloader.CompleteEnvironment;
import org.eclipse.digitaltwin.basyx.aasenvironment.environmentloader.CompleteEnvironment.EnvironmentType;
import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException;
import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor;
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository;
import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.AasRepositoryRegistryLink;
import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryLinkException;
import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo;
import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository;
import org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.SubmodelRepositoryRegistryLink;
Expand All @@ -57,7 +60,7 @@
*/
public class TestEnvironmentWithRegistryIntegration {

static final String FAULTY_AAS_PATH = "faulty_aas_reginteg.aasx";
static final String ENV_PATH = "testEnvironment.json";

static ConfigurableApplicationContext appContext;

Expand Down Expand Up @@ -92,14 +95,23 @@ public static void clearRegistries() throws Exception {
}

@Test
public void whenUploadDescriptorToRegistryFails_thenNoAasOrSmAreAddedToRepository() throws InvalidFormatException, DeserializationException, IOException {
CompleteEnvironment completeEnvironment = CompleteEnvironment.fromInputStream(getIsFromClasspath(FAULTY_AAS_PATH), EnvironmentType.AASX);
public void whenUploadDescriptorToRegistryFails_thenNoAasOrSmAreAddedToRepository() throws InvalidFormatException, DeserializationException, IOException, ApiException {
// simulate descriptor already being in registry
aasRepositoryRegistryLink.getRegistryApi().postAssetAdministrationShellDescriptor(buildTestAasDescriptor());

assertThrows(IllegalArgumentException.class, () -> aasEnvironment.loadEnvironment(completeEnvironment));
CompleteEnvironment completeEnvironment = CompleteEnvironment.fromInputStream(getIsFromClasspath(ENV_PATH), EnvironmentType.JSON);

assertThrows(RepositoryRegistryLinkException.class, () -> aasEnvironment.loadEnvironment(completeEnvironment));

assertRepositoriesAreEmpty();
}

private static AssetAdministrationShellDescriptor buildTestAasDescriptor() {
AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor();
descriptor.setId("https://acplt.test/Test_AssetAdministrationShell");
return descriptor;
}

private static InputStream getIsFromClasspath(String fileName) throws IOException {
return new ClassPathResource(fileName).getInputStream();
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,16 @@ public AdministrativeInformation mapAdministration(org.eclipse.digitaltwin.aas4j
* @return the mapped assetKind
*/
public AssetKind mapAssetKind(org.eclipse.digitaltwin.aas4j.v3.model.AssetKind assetKind) {

return AssetKind.valueOf(AssetKind.class, assetKind.name());
switch (assetKind) {
case INSTANCE:
return AssetKind.INSTANCE;
case NOT_APPLICABLE:
return AssetKind.NOTAPPLICABLE;
case TYPE:
return AssetKind.TYPE;
default:
throw new IllegalArgumentException("Unknown AssetKind: " + assetKind);
}
}

}