Skip to content

Commit e0a8d53

Browse files
committed
Adds HTTP Tests
1 parent 983f002 commit e0a8d53

6 files changed

Lines changed: 62 additions & 9 deletions

File tree

basyx.aasrepository/basyx.aasrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryApiHTTPController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation;
3939
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
4040
import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId;
41+
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSpecificAssetId;
4142
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository;
4243
import org.eclipse.digitaltwin.basyx.aasrepository.http.pagination.GetAssetAdministrationShellsResult;
4344
import org.eclipse.digitaltwin.basyx.aasrepository.http.pagination.GetReferencesResult;
@@ -241,7 +242,7 @@ private List<SpecificAssetId> getDecodedSpecificAssetIds(List<Base64UrlEncodedId
241242
for (Base64UrlEncodedIdentifier base64UrlEncodedIdentifier : assetIds) {
242243

243244
var decodedString = base64UrlEncodedIdentifier.getIdentifier();
244-
result.add(objectMapper.readValue(decodedString, SpecificAssetId.class));
245+
result.add(objectMapper.readValue(decodedString, DefaultSpecificAssetId.class));
245246

246247
}
247248

basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.hc.core5.http.ProtocolException;
4444
import org.apache.hc.core5.http.io.entity.EntityUtils;
4545
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.DeserializationException;
46+
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell;
4647
import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier;
4748
import org.eclipse.digitaltwin.basyx.http.HttpBaSyxHeader;
4849
import org.eclipse.digitaltwin.basyx.http.pagination.Base64UrlEncodedCursor;
@@ -148,19 +149,49 @@ public void getAllAasWhenEmpty() throws IOException {
148149

149150
assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode());
150151
}
151-
152+
152153
@Test
153154
public void getAllPaginatedAas() throws IOException, ParseException {
154155
createMultipleAasOnServer();
155-
156+
156157
CloseableHttpResponse retrievalResponse = getAllAas();
157158
assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode());
158-
159+
159160
String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse);
160-
161+
161162
BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAasJSONString(), getJSONWithoutCursorInfo(actualJsonFromServer));
162163
}
163164

165+
@Test
166+
public void getAllAasWithAssetIds() throws IOException, ParseException {
167+
createMultipleAasOnServer();
168+
CloseableHttpResponse retrievalResponse = getAllAasAssetIdsParam();
169+
assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode());
170+
171+
String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse);
172+
BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAas1JSONString(), getJSONWithoutCursorInfo(actualJsonFromServer));
173+
}
174+
175+
@Test
176+
public void getAllAasWithGlobalAssetIds() throws IOException, ParseException {
177+
createMultipleAasOnServer();
178+
CloseableHttpResponse retrievalResponse = getAllAasGlobalAssetIdsParam();
179+
assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode());
180+
181+
String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse);
182+
BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAas1JSONString(), getJSONWithoutCursorInfo(actualJsonFromServer));
183+
}
184+
185+
@Test
186+
public void getAllAasWithIdShort() throws IOException, ParseException {
187+
createMultipleAasOnServer();
188+
CloseableHttpResponse retrievalResponse = getAllAasIdShortParam();
189+
assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode());
190+
191+
String actualJsonFromServer = BaSyxHttpTestUtils.getResponseAsString(retrievalResponse);
192+
BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedAas1JSONString(), getJSONWithoutCursorInfo(actualJsonFromServer));
193+
}
194+
164195
@Test
165196
public void deleteAas() throws IOException {
166197
createDummyAasOnServer(getAas1JSONString());
@@ -450,6 +481,18 @@ protected CloseableHttpResponse getAllAas() throws IOException {
450481
return BaSyxHttpTestUtils.executeGetOnURL(getURL());
451482
}
452483

484+
protected CloseableHttpResponse getAllAasAssetIdsParam() throws IOException {
485+
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJ0ZXN0SWQiLA0KInZhbHVlIjoidGVzdFZhbHVlIg0KfQ");
486+
}
487+
488+
protected CloseableHttpResponse getAllAasGlobalAssetIdsParam() throws IOException {
489+
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?assetIds=ew0KIm5hbWUiOiJnbG9iYWxBc3NldElkIiwNCiJ2YWx1ZSI6Imdsb2JhbEFzc2V0SWQiDQp9");
490+
}
491+
492+
protected CloseableHttpResponse getAllAasIdShortParam() throws IOException {
493+
return BaSyxHttpTestUtils.executeGetOnURL(getURL()+"?idShort=ExampleMotor");
494+
}
495+
453496
private CloseableHttpResponse getSpecificAas(String aasId) throws IOException {
454497
String url = getSpecificAasAccessURL(aasId);
455498
return BaSyxHttpTestUtils.executeGetOnURL(url);

basyx.aasrepository/basyx.aasrepository-http/src/test/resources/AasSimple_1.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
"id": "customIdentifier",
55
"assetInformation": {
66
"assetKind": "Instance",
7-
"globalAssetId": "globalAssetId"
7+
"globalAssetId": "globalAssetId",
8+
"specificAssetIds": [
9+
{
10+
"name": "testId",
11+
"value": "testValue"
12+
}
13+
]
814
}
915
}

basyx.aasrepository/basyx.aasrepository-http/src/test/resources/AllPaginatedAas.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"modelType": "AssetAdministrationShell",
1515
"assetInformation": {
1616
"assetKind": "Instance",
17-
"globalAssetId": "globalAssetId"
17+
"globalAssetId": "globalAssetId",
18+
"specificAssetIds":[{"name":"testId","value":"testValue"}]
1819
},
1920
"id": "customIdentifier",
2021
"idShort": "ExampleMotor"

basyx.aasrepository/basyx.aasrepository-http/src/test/resources/PaginatedAasSimple_1.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"modelType": "AssetAdministrationShell",
66
"assetInformation": {
77
"assetKind": "Instance",
8-
"globalAssetId": "globalAssetId"
8+
"globalAssetId": "globalAssetId",
9+
"specificAssetIds":[{"name":"testId","value":"testValue"}]
910
},
1011
"id": "customIdentifier",
1112
"idShort": "ExampleMotor"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"assetKind":"Instance",
3-
"globalAssetId":"globalAssetId"
3+
"globalAssetId":"globalAssetId",
4+
"specificAssetIds":[{"name":"testId","value":"testValue"}]
45
}

0 commit comments

Comments
 (0)