Skip to content

Commit

Permalink
testcases for response of createSubmodelElement in submodelservice
Browse files Browse the repository at this point in the history
  • Loading branch information
VivekHub97 committed Oct 29, 2024
1 parent 28160ca commit 33cf443
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,11 @@ public void createSubmodelElement() {
property.setValue("205");

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

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

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

Expand All @@ -334,18 +336,20 @@ 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;
submodelService.createSubmodelElement(idShortPathPropertyInSmeCol, propertyInSmeCol);
SubmodelElement responseSubmodelElementCol = submodelService.createSubmodelElement(idShortPathPropertyInSmeCol, propertyInSmeCol);

String idShortPathPropertyInSmeList = DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_COLLECTION_ID_SHORT + "." + DummySubmodelFactory.SUBMODEL_OPERATIONAL_DATA_ELEMENT_LIST_ID_SHORT;
submodelService.createSubmodelElement(idShortPathPropertyInSmeList, propertyInSmeList);
SubmodelElement responseSubmodelElementList = 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 @@ -372,13 +376,14 @@ public void updateNonNestedSME() {
String idShortPath = "dummyProperty";

Property property = createDummyProperty(idShortPath);
submodelService.createSubmodelElement(property);
SubmodelElement responseSubmodelElement = 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
Original file line number Diff line number Diff line change
Expand Up @@ -97,34 +97,37 @@ public static void tearDownClass() {
public void createSubmodelElementEvent() throws DeserializationException {

SubmodelElement submodelElement = createSubmodelElementDummy("createSubmodelElementEventId");
submodelService.createSubmodelElement(submodelElement);
SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(submodelElement);

assertEquals(topicFactory.createCreateSubmodelElementTopic(submodelElement.getIdShort()), listener.lastTopic);
assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload));
assertEquals(submodelElement, responseSubmodelElement);
}

@Test
public void updateSubmodelElementEvent() throws DeserializationException {

SubmodelElement submodelElement = createSubmodelElementDummy("updateSubmodelElementEventId");
submodelService.createSubmodelElement(submodelElement);
SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(submodelElement);

SubmodelElementValue value = new PropertyValue("updatedValue");
submodelService.setSubmodelElementValue(submodelElement.getIdShort(), value);

assertEquals(topicFactory.createUpdateSubmodelElementTopic(submodelElement.getIdShort()), listener.lastTopic);
assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload));
assertEquals(submodelElement, responseSubmodelElement);
}

@Test
public void deleteSubmodelElementEvent() throws DeserializationException {

SubmodelElement submodelElement = createSubmodelElementDummy("deleteSubmodelElementEventId");
submodelService.createSubmodelElement(submodelElement);
SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(submodelElement);
submodelService.deleteSubmodelElement(submodelElement.getIdShort());

assertEquals(topicFactory.createDeleteSubmodelElementTopic(submodelElement.getIdShort()), listener.lastTopic);
assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload));
assertEquals(submodelElement, responseSubmodelElement);
}

@Test
Expand All @@ -133,13 +136,14 @@ public void createSubmodelElementWithoutValueEvent() throws DeserializationExcep
SubmodelElement submodelElement = createSubmodelElementDummy("noValueSubmodelElementEventId");
List<Qualifier> qualifierList = createNoValueQualifierList();
submodelElement.setQualifiers(qualifierList);
submodelService.createSubmodelElement(submodelElement);
SubmodelElement responseSubmodelElement = submodelService.createSubmodelElement(submodelElement);

assertEquals(topicFactory.createCreateSubmodelElementTopic(submodelElement.getIdShort()), listener.lastTopic);
assertNotEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload));

((Property) submodelElement).setValue(null);
assertEquals(submodelElement, deserializeSubmodelElementPayload(listener.lastPayload));
assertEquals(submodelElement, responseSubmodelElement);
}

private List<Qualifier> createNoValueQualifierList() {
Expand Down

0 comments on commit 33cf443

Please sign in to comment.