Skip to Content
2
Former Member
Apr 16, 2015 at 11:56 AM

Tomcat & port settings in unit test

362 Views

I wish to have a junit test to verify the content of returned xml data on REST web services.

JUnit test tries to connect e.g. to https://localhost:PORT/rest/v2/electronics/languages and check the result.

I've extended my test class from ServicelayerTest. Hybrisserver is started and the console shows some sign of Tomcat

  [yunitint] INFO  [main] (junit) [hybrisserver] Starting up hybris server
  [yunitint] INFO  [main] (junit) [hybrisserver] Configuration:
  [yunitint] INFO  [main] (junit) [hybrisserver] Cluster:     disabled
  [yunitint] INFO  [main] (junit) [hybrisserver] Tenant:      junit
  [yunitint] INFO  [main] (junit) [hybrisserver] OS:          Windows 7 6.1, amd64
  [yunitint] INFO  [main] (junit) [hybrisserver] Platform:    5.5.0.0-M3
  [yunitint] INFO  [main] (junit) [hybrisserver] Java:        Oracle Corporation
  [yunitint] INFO  [main] (junit) [hybrisserver]              Java(TM) SE Runtime Environment, 1.7.0_75-b13
  [yunitint] INFO  [main] (junit) [hybrisserver] VM Locale:   language=en,country=US,region=null
  [yunitint] INFO  [main] (junit) [hybrisserver] Cache:       RegionCache is not yet initialized. [de.hybris.platform.cache.impl.RegionCacheAdapter]
  [yunitint] INFO  [main] (junit) [hybrisserver] Server type: tomcat

However Tomcat seems not to be started. It's not running on the ports I define in local.properties

 tomcat.http.port=8080
 tomcat.ssl.port=8081

I've also tried the default ports 9001, 9002, and the embedded server port defined found in platformwebservices test classes (9998). They all produce the same exception:

  [yunitint] java.net.ConnectException: Connection refused: connect

Do I need to make additional settings for starting Tomcat? Or is junit using some other port for Tomcat?

As a workaround I checked how the platformwebservices/AbstractWebServicesTest is initializing server and tried to follow same process, but this reference is not found for my unit test (located in my extension)

 @Resource
 private EmbeddedServerBuilder tomcatEmbeddedServerBuilder;   

Am I possibly missing some dependencies or bean configurations?