Urbanleg
Urbanleg

Reputation: 6542

spring test \ Junit - skip configuration on tests

I have the following class:

@Configuration
@EnableWebSocketMessageBroker
@EnableScheduling
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {

config.enableStompBrokerRelay(
                  "/topic",
                  "/queue/");
config.setApplicationDestinationPrefixes("/app");
}


@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {

registry.addEndpoint(
             "/wsdemo").withSockJS();
}

}

I would like to be able to NOT configure the class above whenever I'm running tests. is that possible?

Thanks!

Upvotes: 0

Views: 658

Answers (2)

nazlo
nazlo

Reputation: 431

If you have separate "application-context.xml" for your tests, then there you must have directive:

<context:component-scan base-package="...">
...
</context:component-scan>

Modify it as below:

<context:component-scan base-package="...">
...
    <context:exclude-filter type="regex" expression="{package}.WebSocketConfig"/>
</context:component-scan>

Upvotes: 0

TrueDub
TrueDub

Reputation: 5070

A plain Junit test (without the spring runner) will ensure the class is not configured. you can then use mock objects (see Mockito) to satisfy any dependencies.

Upvotes: 1

Related Questions