Skip to content

Commit

Permalink
some fixes and testcase updates
Browse files Browse the repository at this point in the history
  • Loading branch information
VivekHub97 committed Oct 29, 2024
1 parent 33cf443 commit b160d85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public interface SubmodelService {

/**
* Creates a Submodel Element
* @return
*
*/
public SubmodelElement createSubmodelElement(SubmodelElement submodelElement);
Expand All @@ -102,7 +101,7 @@ public interface SubmodelService {
* the SubmodelElement IdShortPath
* @param submodelElement
* the submodel element to be created
* @return
* @return the SubmodelElement
* @throws ElementDoesNotExistException
* If the submodel element defined in the path does not exist
*/
Expand All @@ -113,6 +112,7 @@ public interface SubmodelService {
*
* @param idShortPath
* @param submodelElement
* @return the SubmodelElement
* @throws ElementDoesNotExistException
* If the submodel element defined in the path does not exist
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ public static Property createDummyProperty(String idShort, String value, DataTyp
.build();
}

public static SubmodelElement createDummySME(String idShort, String value, DataTypeDefXsd dataType) {
return new DefaultProperty.Builder().idShort(idShort)
.category("cat1")
.value(value)
.valueType(dataType)
.build();
}

public static File createDummyFile(String idShort, String contentType, String value) {
return new DefaultFile.Builder().idShort(idShort)
.category("file")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,9 @@ public void createSubmodelElement() {
property.setValue("205");

SubmodelService submodelService = getSubmodelService(technicalData);
SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(property);
submodelService.createSubmodelElement(property);

SubmodelElement submodelEl = submodelService.getSubmodelElement("test123");

assertEquals(submodelEl, responseSubmodelElement);
assertEquals("test123", submodelEl.getIdShort());
}

Expand All @@ -336,20 +334,18 @@ public void createNestedSubmodelElement() {
Property propertyInSmeList = new DefaultProperty.Builder().idShort("test456").category("cat1").value("305").valueType(DataTypeDefXsd.INTEGER).build();

String idShortPathPropertyInSmeCol = DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_COLLECTION_ID_SHORT;
SubmodelElement responseSubmodelElementCol = submodelService.createSubmodelElement(idShortPathPropertyInSmeCol, propertyInSmeCol);
submodelService.createSubmodelElement(idShortPathPropertyInSmeCol, propertyInSmeCol);

String idShortPathPropertyInSmeList = DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_COLLECTION_ID_SHORT + "." + DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_LIST_ID_SHORT;
SubmodelElement responseSubmodelElementList = submodelService.createSubmodelElement(idShortPathPropertyInSmeList, propertyInSmeList);
submodelService.createSubmodelElement(idShortPathPropertyInSmeList, propertyInSmeList);

idShortPathPropertyInSmeCol = idShortPathPropertyInSmeCol.concat(".test123");
SubmodelElement propertyInCollectionCreated = submodelService.getSubmodelElement(idShortPathPropertyInSmeCol);
assertEquals("test123", propertyInCollectionCreated.getIdShort());
assertEquals(propertyInCollectionCreated, responseSubmodelElementCol);

idShortPathPropertyInSmeList = idShortPathPropertyInSmeList.concat("[1]");
SubmodelElement propertyInSmeListCreated = submodelService.getSubmodelElement(idShortPathPropertyInSmeList);
assertEquals("test456", propertyInSmeListCreated.getIdShort());
assertEquals(propertyInSmeListCreated, responseSubmodelElementList);
}

@Test
Expand All @@ -376,14 +372,13 @@ public void updateNonNestedSME() {
String idShortPath = "dummyProperty";

Property property = createDummyProperty(idShortPath);
SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(property);
submodelService.createSubmodelElement(property);

Property expectedUpdatedProperty = SubmodelServiceHelper.createDummyProperty(idShortPath, "arbitraryValue", DataTypeDefXsd.STRING);
submodelService.updateSubmodelElement(idShortPath, expectedUpdatedProperty);

Property actualUpdatedProperty = (Property) submodelService.getSubmodelElement(idShortPath);
assertEquals(expectedUpdatedProperty, actualUpdatedProperty);
assertEquals(submodelService.getSubmodelElement(idShortPath), responseSubmodelElement);
}

@Test
Expand Down Expand Up @@ -723,6 +718,10 @@ private DefaultEntity createDummyEntityWithStatement(SubmodelElement submodelEle
private DefaultProperty createDummyProperty(String idShort) {
return new DefaultProperty.Builder().idShort(idShort).category("cat1").value("123").valueType(DataTypeDefXsd.INTEGER).build();
}

private SubmodelElement createDummySME(String idShort) {
return new DefaultProperty.Builder().idShort(idShort).value("123").build();
}

private InputStream getInputStreamOfDummyFile(String fileContent) throws FileNotFoundException, IOException {
return new ByteArrayInputStream(fileContent.getBytes());
Expand Down

0 comments on commit b160d85

Please sign in to comment.