-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only convert submodel references to IRIs.
- Loading branch information
Showing
5 changed files
with
343 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...nkedfactory.core/src/test/java/io/github/linkedfactory/core/rdf4j/aas/AasServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package io.github.linkedfactory.core.rdf4j.aas; | ||
|
||
import io.github.linkedfactory.core.rdf4j.common.BaseFederatedServiceResolver; | ||
import org.apache.http.StatusLine; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.federation.FederatedService; | ||
import org.eclipse.rdf4j.repository.sail.SailRepository; | ||
import org.eclipse.rdf4j.sail.memory.MemoryStore; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
/** | ||
* Tests for extraction data from AAS shells and submodels via SPARQL. | ||
*/ | ||
public class AasServiceTest extends Mockito { | ||
static String toResponse(String json) { | ||
return String.format("{\"result\": [%s]}", json); | ||
} | ||
|
||
@Test | ||
public void testPropertyExtractionByIdShort() throws Exception { | ||
var mockedHttpClient = mock(CloseableHttpClient.class); | ||
var statusLine = mock(StatusLine.class); | ||
when(statusLine.getStatusCode()).thenReturn(200); | ||
|
||
var shellsResponse = mock(CloseableHttpResponse.class); | ||
when(shellsResponse.getStatusLine()).thenReturn(statusLine); | ||
when(shellsResponse.getEntity()).thenReturn(new StringEntity( | ||
toResponse(new String(getClass().getResourceAsStream("/aas/AAS_Motor_1_Type_shell.json").readAllBytes()))) | ||
); | ||
when(mockedHttpClient.execute(argThat(httpUriRequest -> | ||
httpUriRequest != null && httpUriRequest.getURI().toString().contains("/shells")))).thenReturn(shellsResponse); | ||
var submodelResponse = mock(CloseableHttpResponse.class); | ||
when(submodelResponse.getStatusLine()).thenReturn(statusLine); | ||
when(submodelResponse.getEntity()).thenReturn(new StringEntity( | ||
new String(getClass().getResourceAsStream("/aas/AAS_Motor_1_Type_Submodel_TechnicalData.json").readAllBytes())) | ||
); | ||
when(mockedHttpClient.execute(argThat(httpUriRequest -> | ||
httpUriRequest != null && httpUriRequest.getURI().toString().contains("/submodels/")))).thenReturn(submodelResponse); | ||
|
||
var client = new AasClient("http://example.org/") { | ||
@Override | ||
protected CloseableHttpClient createHttpClient() { | ||
return mockedHttpClient; | ||
} | ||
}; | ||
|
||
var memoryStore = new MemoryStore(); | ||
var repo = new SailRepository(memoryStore); | ||
repo.setFederatedServiceResolver(new BaseFederatedServiceResolver() { | ||
public FederatedService createService(String url) { | ||
return new AasFederatedService(client, this::getExecutorService); | ||
} | ||
}); | ||
repo.init(); | ||
|
||
try { | ||
try (var conn = repo.getConnection()) { | ||
var query = conn.prepareTupleQuery("prefix aas: <https://admin-shell.io/aas/3/0/> " + | ||
"select * {" + | ||
"service <aas-api:http://aasx-server:5001> {" + | ||
"<aas-api:endpoint> <aas-api:shells> ?shell ." + | ||
" ?shell aas:idShort ?shellId ." + | ||
" ?shell aas:submodels ?sm." + | ||
" ?sm aas:semanticId/aas:keys/aas:value \"https://admin-shell.io/ZVEI/TechnicalData/Submodel/1/2\"." + | ||
" ?sm (!<:>)+ ?element ." + | ||
" { ?element a aas:Property } union { ?element a aas:MultiLanguageProperty }\n" + | ||
" ?element aas:idShort \"ProductClassId\" ; " + | ||
" aas:valueId/aas:keys/aas:value ?productClassId." + | ||
"}" + | ||
"}"); | ||
try (var result = query.evaluate()) { | ||
Assert.assertTrue(result.hasNext()); | ||
while (result.hasNext()) { | ||
var bindings = result.next(); | ||
Assert.assertEquals("0173-1#01-BAB253#016", | ||
bindings.getValue("productClassId").stringValue()); | ||
} | ||
} | ||
} | ||
} finally { | ||
repo.shutDown(); | ||
} | ||
} | ||
} |
208 changes: 208 additions & 0 deletions
208
...ub.linkedfactory.core/src/test/resources/aas/AAS_Motor_1_Type_Submodel_TechnicalData.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
{ | ||
"idShort": "TechnicalData", | ||
"id": "https://eplan.com/example/sm/motor/technicaldata_4", | ||
"kind": "Instance", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "GlobalReference", | ||
"value": "https://admin-shell.io/ZVEI/TechnicalData/Submodel/1/2" | ||
} | ||
] | ||
}, | ||
"submodelElements": [ | ||
{ | ||
"idShort": "GeneralInformation", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "ConceptDescription", | ||
"value": "https://admin-shell.io/ZVEI/TechnicalData/GeneralInformation/1/1" | ||
} | ||
] | ||
}, | ||
"value": [ | ||
{ | ||
"idShort": "ManufacturerName", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "GlobalReference", | ||
"value": "0173-1#02-AAO677#002" | ||
} | ||
] | ||
}, | ||
"valueType": "xs:string", | ||
"value": "SEW", | ||
"modelType": "Property" | ||
}, | ||
{ | ||
"idShort": "ManufacturerArticleNumber", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "GlobalReference", | ||
"value": "0173-1#02-AAO676#003" | ||
} | ||
] | ||
}, | ||
"valueType": "xs:string", | ||
"value": "SEW.K19DRS71M4/TH", | ||
"modelType": "Property" | ||
}, | ||
{ | ||
"idShort": "ManufacturerLogo", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "GlobalReference", | ||
"value": "https://admin-shell.io/ZVEI/TechnicalData/ManufacturerLogo/1/1" | ||
} | ||
] | ||
}, | ||
"contentType": "", | ||
"modelType": "File" | ||
}, | ||
{ | ||
"idShort": "ManufacturerProductDesignation", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "GlobalReference", | ||
"value": "0173-1#02-AAW338#001 " | ||
} | ||
] | ||
}, | ||
"value": [ | ||
{ | ||
"language": "de", | ||
"text": "MotorProtectionCircuitBreaker zum Schutz von Motoren" | ||
} | ||
], | ||
"modelType": "MultiLanguageProperty" | ||
}, | ||
{ | ||
"idShort": "ManufacturerOrderCode", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "GlobalReference", | ||
"value": "0173-1#02-AAO227#002" | ||
} | ||
] | ||
}, | ||
"valueType": "xs:string", | ||
"value": "K19DRS71M4/TH", | ||
"modelType": "Property" | ||
}, | ||
{ | ||
"idShort": "ProductImage", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "GlobalReference", | ||
"value": "https://admin-shell.io/ZVEI/TechnicalData/ProductImage/1/1" | ||
} | ||
] | ||
}, | ||
"contentType": "", | ||
"modelType": "File" | ||
} | ||
], | ||
"modelType": "SubmodelElementCollection" | ||
}, | ||
{ | ||
"idShort": "ProductClassifications", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "ConceptDescription", | ||
"value": "https://admin-shell.io/ZVEI/TechnicalData/ProductClassifications/1/1" | ||
} | ||
] | ||
}, | ||
"value": [ | ||
{ | ||
"idShort": "ProductClassificationItem", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "ConceptDescription", | ||
"value": "https://admin-shell.io/ZVEI/TechnicalData/ProductClassificationItem/1/1" | ||
} | ||
] | ||
}, | ||
"value": [ | ||
{ | ||
"idShort": "ProductClassificationSystem", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "ConceptDescription", | ||
"value": "https://admin-shell.io/ZVEI/TechnicalData/ProductClassificationSystem/1/1" | ||
} | ||
] | ||
}, | ||
"valueType": "xs:string", | ||
"value": "ECLASS", | ||
"modelType": "Property" | ||
}, | ||
{ | ||
"idShort": "ClassificationSystemVersion", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "ConceptDescription", | ||
"value": "https://admin-shell.io/ZVEI/TechnicalData/ClassificationSystemVersion/1/1" | ||
} | ||
] | ||
}, | ||
"valueType": "xs:string", | ||
"value": "13.0", | ||
"modelType": "Property" | ||
}, | ||
{ | ||
"idShort": "ProductClassId", | ||
"semanticId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "ConceptDescription", | ||
"value": "https://admin-shell.io/ZVEI/TechnicalData/ProductClassId/1/1" | ||
} | ||
] | ||
}, | ||
"valueType": "xs:string", | ||
"value": "27-02-22-90 High voltage three-phase current asynchronous motor (unspecified)", | ||
"valueId": { | ||
"type": "ExternalReference", | ||
"keys": [ | ||
{ | ||
"type": "GlobalReference", | ||
"value": "0173-1#01-BAB253#016" | ||
} | ||
] | ||
}, | ||
"modelType": "Property" | ||
} | ||
], | ||
"modelType": "SubmodelElementCollection" | ||
} | ||
], | ||
"modelType": "SubmodelElementCollection" | ||
} | ||
], | ||
"modelType": "Submodel" | ||
} |
Oops, something went wrong.