8686import org .eclipse .digitaltwin .basyx .aasregistry .service .events .RegistryEvent .EventType ;
8787import org .eclipse .digitaltwin .basyx .aasregistry .service .tests .TestResourcesLoader ;
8888import org .eclipse .digitaltwin .basyx .kafka .KafkaAdapter ;
89+ import org .eclipse .digitaltwin .basyx .kafka .KafkaAdapters ;
8990import org .junit .After ;
9091import org .junit .Before ;
9192import org .junit .Rule ;
@@ -135,35 +136,33 @@ public abstract class BaseIntegrationTest {
135136
136137 private ObjectMapper mapper = new ObjectMapper ();
137138
139+
140+ private final KafkaAdapter <RegistryEvent > adapter = KafkaAdapters .getAdapter ("aas-registry" , RegistryEvent .class );
141+
138142 @ Rule
139143 public TestResourcesLoader resourceLoader = new TestResourcesLoader (BaseIntegrationTest .class .getPackageName (), mapper );
140144
141145 protected RegistryAndDiscoveryInterfaceApi api ;
142146
143147 @ Before
144148 public void setUp () throws Exception {
145- adapter ().skipMessages ();
146149 initClient ();
150+ adapter .skipMessages ();
147151 cleanup ();
148152 }
149153
154+
150155 protected void initClient () throws Exception {
151156 api = new RegistryAndDiscoveryInterfaceApi ("http" , "127.0.0.1" , port );
152157 }
153158
154159 protected void cleanup () throws ApiException , InterruptedException , DeserializationException {
155- adapter ().assertNoAdditionalMessages ();
156160 GetAssetAdministrationShellDescriptorsResult result = api .getAllAssetAdministrationShellDescriptors (null , null , null , null );
157161 for (AssetAdministrationShellDescriptor eachDescriptor : result .getResult ()) {
158162 api .deleteAssetAdministrationShellDescriptorById (eachDescriptor .getId ());
159163 assertThatEventWasSend (RegistryEvent .builder ().id (eachDescriptor .getId ()).type (EventType .AAS_UNREGISTERED ).build ());
160164 }
161- adapter ().assertNoAdditionalMessages ();
162- }
163-
164-
165- protected final KafkaAdapter <RegistryEvent > adapter () {
166- return new KafkaAdapter <>("localhost:9092" , "aas-registry" , RegistryEvent .class );
165+ adapter .assertNoAdditionalMessages ();
167166 }
168167
169168 @ Test
@@ -185,7 +184,7 @@ public void whenWritingParallel_transactionManagementWorks() throws ApiException
185184 assertThat (IntStream .iterate (0 , i -> i + 1 ).limit (300 ).parallel ().mapToObj (op ).filter (i -> i > 300 ).findAny ()).isEmpty ();
186185 assertThat (api .getAssetAdministrationShellDescriptorById (descriptor .getId ()).getSubmodelDescriptors ()).hasSize (300 );
187186 for (int i = 0 ; i < 300 ; i ++) {
188- RegistryEvent evt = adapter () .next ();
187+ RegistryEvent evt = adapter .next ();
189188 assertThat (evt .getId ()).isEqualTo (descriptor .getId ());
190189 assertThat (Integer .parseInt (evt .getSubmodelId ())).isGreaterThanOrEqualTo (0 ).isLessThan (300 );
191190
@@ -235,7 +234,7 @@ public void whenDeleteAll_thenAllDescriptorsAreRemoved() throws ApiException {
235234 HashSet <RegistryEvent > events = new HashSet <>();
236235 // we do not have a specific order, so read all events first
237236 for (int i = 0 ; i < DELETE_ALL_TEST_INSTANCE_COUNT ; i ++) {
238- events .add (adapter () .next ());
237+ events .add (adapter .next ());
239238 }
240239 for (int i = 0 ; i < DELETE_ALL_TEST_INSTANCE_COUNT ; i ++) {
241240 assertThat (events .remove (RegistryEvent .builder ().id ("id_" + i ).type (EventType .AAS_UNREGISTERED ).build ())).isTrue ();
@@ -256,7 +255,7 @@ public void whenCreateAndDeleteDescriptors_thenAllDescriptorsAreRemoved() throws
256255 all = api .getAllAssetAdministrationShellDescriptors (null , null , null , null ).getResult ();
257256 assertThat (all ).isEmpty ();
258257
259- adapter () .assertNoAdditionalMessages ();
258+ adapter .assertNoAdditionalMessages ();
260259 }
261260
262261 @ Test
@@ -288,7 +287,7 @@ public void whenRegisterAndUnregisterSubmodel_thenSubmodelIsCreatedAndDeleted()
288287
289288 aasDescriptor = api .getAssetAdministrationShellDescriptorById (aasId );
290289 assertThat (aasDescriptor .getSubmodelDescriptors ()).doesNotContain (toRegister );
291- adapter () .assertNoAdditionalMessages ();
290+ adapter .assertNoAdditionalMessages ();
292291 }
293292
294293 @ Test
@@ -622,7 +621,7 @@ private void assertRestResourceAvailable(String location) throws IOException {
622621 }
623622
624623 private void deleteAdminAssetShellDescriptor (String aasId ) throws ApiException {
625- adapter () .assertNoAdditionalMessages ();
624+ adapter .assertNoAdditionalMessages ();
626625
627626 int response = api .deleteAssetAdministrationShellDescriptorByIdWithHttpInfo (URLEncoder .encode (aasId , StandardCharsets .UTF_8 )).getStatusCode ();
628627 assertThat (response ).isEqualTo (NO_CONTENT );
@@ -646,7 +645,7 @@ private List<AssetAdministrationShellDescriptor> initialize() throws IOException
646645 }
647646
648647 private void assertThatEventWasSend (RegistryEvent expected ) {
649- RegistryEvent evt = adapter () .next ();
648+ RegistryEvent evt = adapter .next ();
650649 assertThat (evt ).isEqualTo (expected );
651650 }
652651
0 commit comments