3535
3636import java .util .Arrays ;
3737import java .util .List ;
38+ import java .util .Optional ;
3839import java .util .stream .Collectors ;
3940
4041import org .eclipse .digitaltwin .aas4j .v3 .model .AssetAdministrationShell ;
42+ import org .eclipse .digitaltwin .aas4j .v3 .model .Reference ;
4143import org .eclipse .digitaltwin .aas4j .v3 .model .Submodel ;
4244import org .eclipse .digitaltwin .basyx .aasenvironment .client .exceptions .NoValidEndpointFoundException ;
4345import org .eclipse .digitaltwin .basyx .aasenvironment .client .resolvers .AasDescriptorResolver ;
7375 *
7476 */
7577public class TestConnectedAasManager {
76- protected final static String AAS_REPOSITORY_BASE_PATH = "http://localhost:8081" ;
77- protected final static String SM_REPOSITORY_BASE_PATH = "http://localhost:8081" ;
78- protected final static String AAS_REGISTRY_BASE_PATH = "http://localhost:8050" ;
79- protected final static String SM_REGISTRY_BASE_PATH = "http://localhost:8060" ;
78+ protected static final String AAS_REPOSITORY_BASE_PATH = "http://localhost:8081" ;
79+ protected static final String SM_REPOSITORY_BASE_PATH = "http://localhost:8081" ;
80+ protected static final String AAS_REGISTRY_BASE_PATH = "http://localhost:8050" ;
81+ protected static final String SM_REGISTRY_BASE_PATH = "http://localhost:8060" ;
8082
8183 protected static ConfigurableApplicationContext appContext ;
8284 protected static AasRepository aasRepository ;
8385 protected static SubmodelRepository smRepository ;
8486
85- protected final static TestFixture FIXTURE = new TestFixture (AAS_REPOSITORY_BASE_PATH , SM_REPOSITORY_BASE_PATH );
87+ protected static final TestFixture FIXTURE = new TestFixture (AAS_REPOSITORY_BASE_PATH , SM_REPOSITORY_BASE_PATH );
8688
8789 protected static ConnectedAasRepository connectedAasRepository ;
8890 protected static ConnectedSubmodelRepository connectedSmRepository ;
@@ -146,20 +148,19 @@ public void createAas() throws ApiException {
146148 public void createSubmodelInAas () throws Exception {
147149 Submodel expectedSm = FIXTURE .buildSmPos1 ();
148150 SubmodelDescriptor expectedDescriptor = FIXTURE .buildSmPos1Descriptor ();
151+ Reference expectedRef = FIXTURE .buildSmPos1Ref ();
149152
150153 aasManager .createSubmodelInAas (TestFixture .AAS_PRE1_ID , expectedSm );
151154
152155 InOrder inOrder = inOrder (connectedSmRepository , smRegistryApi , connectedAasRepository );
153156
154- inOrder .verify (connectedSmRepository , times (1 ))
155- .createSubmodel (expectedSm );
156- inOrder .verify (smRegistryApi , times (1 ))
157- .postSubmodelDescriptor (expectedDescriptor );
158- inOrder .verify (connectedAasRepository , times (1 ))
159- .addSubmodelReference (eq (TestFixture .AAS_PRE1_ID ), any ());
157+ inOrder .verify (connectedSmRepository , times (1 )).createSubmodel (expectedSm );
158+ inOrder .verify (smRegistryApi , times (1 )).postSubmodelDescriptor (expectedDescriptor );
159+ inOrder .verify (connectedAasRepository , times (1 )).addSubmodelReference (eq (TestFixture .AAS_PRE1_ID ), any ());
160160
161161 assertEquals (expectedSm , getSubmodelFromRepo (TestFixture .SM_POS1_ID ));
162162 assertEquals (expectedDescriptor , getDescriptorFromSubmodelRegistry (TestFixture .SM_POS1_ID ));
163+ assertEquals (expectedRef , getSubmodelRefFromAasRepository (TestFixture .AAS_PRE1_ID , TestFixture .SM_POS1_ID ).get ());
163164 }
164165
165166 @ Test
@@ -195,7 +196,7 @@ public void deleteSubmodelOfAas() throws Exception {
195196 }
196197
197198 @ Test
198- public void getAas () throws ApiException , NoValidEndpointFoundException {
199+ public void getAas () throws NoValidEndpointFoundException {
199200 AssetAdministrationShell expectedAas = FIXTURE .buildAasPre1 ();
200201
201202 AssetAdministrationShell actualAas = aasManager .getAasService (TestFixture .AAS_PRE1_ID )
@@ -205,7 +206,7 @@ public void getAas() throws ApiException, NoValidEndpointFoundException {
205206 }
206207
207208 @ Test
208- public void getSubmodel () throws Exception {
209+ public void getSubmodel () {
209210 Submodel expectedSm = FIXTURE .buildSmPre1 ();
210211
211212 Submodel actualSm = aasManager .getSubmodelService (TestFixture .SM_PRE1_ID )
@@ -340,4 +341,14 @@ protected void cleanUpRepositories() {
340341 }
341342 }
342343
344+ private Optional <Reference > getSubmodelRefFromAasRepository (String aasId , String smId ) {
345+ return aasManager .getAasService (aasId )
346+ .getAAS ()
347+ .getSubmodels ()
348+ .stream ()
349+ .filter (ref -> ref .getKeys ().stream ()
350+ .anyMatch (key -> key .getValue ().equals (smId )))
351+ .findAny ();
352+ }
353+
343354}
0 commit comments