@@ -300,76 +300,80 @@ public void testSearch() throws JAXBException {
300300 client .release ();
301301 }
302302
303- @ Test
304- public void testHandleRegistry () {
305- int [] iterations = {1 ,2 };
306- for (int i : iterations ) {
307- DatabaseClientFactory .Bean clientFactoryBean = (i == 1 ) ? null : makeClientFactoryBean ();
308-
309- HandleFactoryRegistry registry =
310- (i == 1 ) ? DatabaseClientFactory .getHandleRegistry ()
311- : clientFactoryBean .getHandleRegistry ();
312-
313- registry .register (new BufferHandleFactory ());
314- assertTrue (registry .isRegistered (StringBuilder .class ));
315-
316- Set <Class <?>> registered = registry .listRegistered ();
317- assertTrue (registered .contains (StringBuilder .class ));
318-
319- ContentHandle <StringBuilder > handle = registry .makeHandle (StringBuilder .class );
320- assertNotNull (handle );
321- assertEquals (handle .getClass (),BufferHandle .class );
322-
323- // instantiate a client with a copy of the registry
324- DatabaseClient client =
325- (i == 1 ) ? DatabaseClientFactory .newClient (Common .HOST , Common .PORT , Common .newSecurityContext (Common .USER , Common .PASS ))
326- : clientFactoryBean .newClient ();
327-
328- registry .unregister (StringBuilder .class );
329- assertTrue (!registry .isRegistered (StringBuilder .class ));
330-
331- String beforeText = "A simple text document" ;
332-
333- TextDocumentManager textMgr = client .newTextDocumentManager ();
334- String textDocId = "/test/testAs1.txt" ;
335-
336- // use the handled class
337- StringBuilder buffer = new StringBuilder ();
338- buffer .append (beforeText );
339-
340- textMgr .writeAs (textDocId , buffer );
341- buffer = textMgr .readAs (textDocId , StringBuilder .class );
342- textMgr .delete (textDocId );
343- assertEquals (beforeText , buffer .toString ());
344-
345- boolean threwError = false ;
346- try {
347- textMgr .writeAs (textDocId , new Integer (5 ));
348- } catch (Exception e ) {
349- threwError = true ;
350- }
351- assertTrue (threwError );
352-
353- threwError = false ;
354- try {
355- textMgr .readAs (textDocId , Integer .class );
356- } catch (Exception e ) {
357- threwError = true ;
358- }
359- assertTrue (threwError );
360-
361- client .release ();
362- }
363- }
364-
365- private DatabaseClientFactory .Bean makeClientFactoryBean () {
366- DatabaseClientFactory .Bean clientFactoryBean = new DatabaseClientFactory .Bean ();
367- clientFactoryBean .setHost (Common .HOST );
368- clientFactoryBean .setPort (Common .PORT );
369- clientFactoryBean .setBasePath (Common .BASE_PATH );
370- clientFactoryBean .setSecurityContext (Common .newSecurityContext (Common .USER , Common .PASS ));
371- return clientFactoryBean ;
372- }
303+ @ Test
304+ void testHandleRegistryWithClientFactoryBean () {
305+ verifyHandleRegistry (makeClientFactoryBean ());
306+ }
307+
308+ @ Test
309+ void testHandleRegistryWithoutClientFactoryBean () {
310+ verifyHandleRegistry (null );
311+ }
312+
313+ private void verifyHandleRegistry (DatabaseClientFactory .Bean clientFactoryBean ) {
314+ HandleFactoryRegistry registry = clientFactoryBean == null ?
315+ DatabaseClientFactory .getHandleRegistry () :
316+ clientFactoryBean .getHandleRegistry ();
317+
318+ registry .register (new BufferHandleFactory ());
319+ assertTrue (registry .isRegistered (StringBuilder .class ));
320+
321+ Set <Class <?>> registered = registry .listRegistered ();
322+ assertTrue (registered .contains (StringBuilder .class ));
323+
324+ ContentHandle <StringBuilder > handle = registry .makeHandle (StringBuilder .class );
325+ assertNotNull (handle );
326+ assertEquals (handle .getClass (),BufferHandle .class );
327+
328+ // instantiate a client with a copy of the registry
329+ DatabaseClient client = clientFactoryBean == null ?
330+ Common .newClientBuilder ().build () :
331+ clientFactoryBean .newClient ();
332+
333+ registry .unregister (StringBuilder .class );
334+ assertTrue (!registry .isRegistered (StringBuilder .class ));
335+
336+ String beforeText = "A simple text document" ;
337+
338+ TextDocumentManager textMgr = client .newTextDocumentManager ();
339+ String textDocId = "/test/testAs1.txt" ;
340+
341+ // use the handled class
342+ StringBuilder buffer = new StringBuilder ();
343+ buffer .append (beforeText );
344+
345+ textMgr .writeAs (textDocId , buffer );
346+ buffer = textMgr .readAs (textDocId , StringBuilder .class );
347+ textMgr .delete (textDocId );
348+ assertEquals (beforeText , buffer .toString ());
349+
350+ boolean threwError = false ;
351+ try {
352+ textMgr .writeAs (textDocId , new Integer (5 ));
353+ } catch (Exception e ) {
354+ threwError = true ;
355+ }
356+ assertTrue (threwError );
357+
358+ threwError = false ;
359+ try {
360+ textMgr .readAs (textDocId , Integer .class );
361+ } catch (Exception e ) {
362+ threwError = true ;
363+ }
364+ assertTrue (threwError );
365+
366+ client .release ();
367+ }
368+
369+ private DatabaseClientFactory .Bean makeClientFactoryBean () {
370+ DatabaseClientFactory .Bean clientFactoryBean = new DatabaseClientFactory .Bean ();
371+ clientFactoryBean .setHost (Common .HOST );
372+ clientFactoryBean .setPort (Common .PORT );
373+ clientFactoryBean .setBasePath (Common .BASE_PATH );
374+ clientFactoryBean .setSecurityContext (Common .newSecurityContext (Common .USER , Common .PASS ));
375+ return clientFactoryBean ;
376+ }
373377
374378 static public class BufferHandle
375379 extends BaseHandle <String , String >
0 commit comments