-
Notifications
You must be signed in to change notification settings - Fork 47
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
Added test methods for submodelrepository and submodelservice #335
Changes from all commits
546ae39
ca72217
f7ed046
0c51f6d
719c0fd
2b61e9c
38530d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,18 +26,21 @@ | |
package org.eclipse.digitaltwin.basyx.submodelrepository.core; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.Property; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodel; | ||
import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; | ||
|
@@ -53,8 +56,12 @@ | |
import org.eclipse.digitaltwin.basyx.submodelservice.SubmodelServiceHelper; | ||
import org.eclipse.digitaltwin.basyx.submodelservice.SubmodelServiceSuite; | ||
import org.eclipse.digitaltwin.basyx.submodelservice.value.PropertyValue; | ||
import org.eclipse.digitaltwin.basyx.submodelservice.value.SubmodelValueOnly; | ||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
/** | ||
* Testsuite for implementations of the SubmodelRepository interface | ||
* | ||
|
@@ -65,6 +72,7 @@ public abstract class SubmodelRepositorySuite extends SubmodelServiceSuite { | |
private static final PaginationInfo NO_LIMIT_PAGINATION_INFO = new PaginationInfo(null, null); | ||
private static final String EMPTY_ID = " "; | ||
private static final String NULL_ID = null; | ||
private static final String ID = "testId"; | ||
|
||
protected abstract SubmodelRepository getSubmodelRepository(); | ||
|
||
|
@@ -259,6 +267,57 @@ public void getPaginatedSubmodel() { | |
assertEquals(1, cursorResult.getResult().size()); | ||
} | ||
|
||
@Test | ||
public void getSubmodelByIdMetadata() throws JsonProcessingException { | ||
SubmodelRepository repo = getSubmodelRepository(); | ||
Submodel expectedSubmodel = buildDummySubmodelWithNoSmElement(ID); | ||
expectedSubmodel.setSubmodelElements(null); | ||
repo.createSubmodel(expectedSubmodel); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A normal Submodel with SM Elements should be created but you can create an expected SM same as per the expected SM returned by the API. So that you can compare the expected and the actual. |
||
|
||
Submodel retrievedSubmodelMetadata = repo.getSubmodelByIdMetadata(ID); | ||
retrievedSubmodelMetadata.setSubmodelElements(null); | ||
|
||
assertEquals(expectedSubmodel, retrievedSubmodelMetadata); | ||
} | ||
|
||
@Test | ||
public void getSubmodelByIdValueOnly() throws JsonProcessingException { | ||
SubmodelRepository repo = getSubmodelRepository(); | ||
Submodel submodel = buildDummySubmodelWithNoSmElement(ID); | ||
|
||
List<SubmodelElement> submodelElements = buildDummySubmodelElements(); | ||
submodel.setSubmodelElements(submodelElements); | ||
repo.createSubmodel(submodel); | ||
|
||
SubmodelValueOnly expectedSmValueOnly = new SubmodelValueOnly(submodelElements); | ||
SubmodelValueOnly retrievedSmValueOnly = repo.getSubmodelByIdValueOnly(ID); | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
String expectedSmValueOnlyJSONContent = mapper.writeValueAsString(expectedSmValueOnly); | ||
String retrievedSmValueOnlyJSONContent = mapper.writeValueAsString(retrievedSmValueOnly); | ||
|
||
assertEquals(expectedSmValueOnlyJSONContent, retrievedSmValueOnlyJSONContent); | ||
} | ||
|
||
@Override | ||
@Test | ||
public void patchSubmodelElements() { | ||
SubmodelRepository repo = getSubmodelRepository(); | ||
Submodel submodel = buildDummySubmodelWithNoSmElement(ID); | ||
|
||
List<SubmodelElement> submodelElements = buildDummySubmodelElements(); | ||
submodel.setSubmodelElements(submodelElements); | ||
repo.createSubmodel(submodel); | ||
|
||
List<SubmodelElement> submodelElementsPatch = buildDummySubmodelElementsToPatch(); | ||
repo.patchSubmodelElements(ID, submodelElementsPatch); | ||
|
||
Submodel patchedSubmodel = repo.getSubmodel(ID); | ||
|
||
assertEquals(submodel.getSubmodelElements().size(), patchedSubmodel.getSubmodelElements().size()); | ||
assertEquals(submodelElementsPatch, patchedSubmodel.getSubmodelElements()); | ||
} | ||
|
||
// Has to be overwritten if backend does not support operations | ||
@Test | ||
public void invokeOperation() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update the license header to 2024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the License header to 2024