Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

Commit

Permalink
Fix #13 - add unit test for parsing properties from Nameplate SM.
Browse files Browse the repository at this point in the history
  • Loading branch information
farmakiG committed Oct 10, 2022
1 parent ec65279 commit d3771f6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ ISubmodel getNameplateSubmodel(IIdentifier aasIdentifier) {
Optional<ISubmodel> npm = Optional.empty();
try {
npm = AASBasyx.getNameplate(registryUrl, aasIdentifier);
} catch (IOException e) {
} catch (Exception e) {
// log
}
if (!npm.isPresent()) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/oscm/basyx/parser/AASBasyx.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package org.oscm.basyx.parser;

import java.io.IOException;
import java.util.Map;
import java.util.Optional;

Expand All @@ -26,7 +25,7 @@
public class AASBasyx {

public static Optional<ISubmodel> getNameplate(String registryUrl, IIdentifier aasIdentifier)
throws IOException {
throws Exception {

IConnectorFactory connectorFactory = new HTTPConnectorFactory();

Expand Down
58 changes: 58 additions & 0 deletions src/test/java/org/oscm/basyx/parser/NameplateBasyxTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
******************************************************************************
<p>Copyright FUJITSU LIMITED 2022
<p>*****************************************************************************
*/
package org.oscm.basyx.parser;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.eclipse.basyx.submodel.metamodel.api.ISubmodel;
import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
import org.eclipse.basyx.submodel.metamodel.map.Submodel;
import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
import org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.Property;
import org.junit.jupiter.api.Test;
import org.oscm.basyx.oscmmodel.ServiceParameterBasyx;

public class NameplateBasyxTest {

@Test
public void parseProperties() {
// given
ISubmodel nameplate = givenNameplate();
Optional<List<ServiceParameterBasyx>> params = NameplateBasyx.parseProperties(nameplate);

assertTrue(params.isPresent());
assertTrue(contains(params.get(), "ManufactName"), "Property not found ");
}

ISubmodel givenNameplate() {
String smIdShort = "Nameplate";
Identifier smIdentifier = new Identifier(IdentifierType.IRI, smIdShort);

Submodel submodel = new Submodel(smIdShort, smIdentifier);

Property manufactNameProp = new Property();
manufactNameProp.setIdShort("ManufactName");
manufactNameProp.setValue("Bob Manufacturer");

submodel.addSubmodelElement(manufactNameProp);
return submodel;
}

boolean contains(List<ServiceParameterBasyx> l, String name) {
List<ServiceParameterBasyx> sps =
l.stream().filter(p -> p.name.equals(name)).collect(Collectors.toList());
if (!sps.isEmpty()) {
return "String".equalsIgnoreCase(sps.get(0).type);
}
return false;
}
}

0 comments on commit d3771f6

Please sign in to comment.