From ef9bb70fa1fe3744e971837eb78c6c004cd1e989 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 15 Mar 2018 23:24:13 +0300 Subject: boot: simplify test configuration --- juick-xmpp-wip/build.gradle | 18 +------ .../src/test/java/com/juick/xmpp/XMPPTests.java | 59 ++++------------------ 2 files changed, 12 insertions(+), 65 deletions(-) (limited to 'juick-xmpp-wip') diff --git a/juick-xmpp-wip/build.gradle b/juick-xmpp-wip/build.gradle index ad49cf16..4b63c2f7 100644 --- a/juick-xmpp-wip/build.gradle +++ b/juick-xmpp-wip/build.gradle @@ -1,21 +1,5 @@ -apply plugin: 'java' -apply plugin: 'war' -apply plugin: 'org.springframework.boot' -apply plugin: 'io.spring.dependency-management' - dependencies { compile project(':juick-server-jdbc') compile project(':juick-server-web') - - testCompile project(path: ':juick-core', configuration: 'testArtifacts') - testCompile project(path: ':juick-server', configuration: 'testArtifacts') - testCompile project(path: ':juick-server-jdbc', configuration: 'testArtifacts') - testCompile ('net.sourceforge.htmlunit:htmlunit:2.29') + testCompile("org.springframework.boot:spring-boot-starter-test") } - -compileJava.options.encoding = 'UTF-8' - -configurations { - all*.exclude module: 'commons-logging' -} - diff --git a/juick-xmpp-wip/src/test/java/com/juick/xmpp/XMPPTests.java b/juick-xmpp-wip/src/test/java/com/juick/xmpp/XMPPTests.java index 2cad5fb4..72d9dfe9 100644 --- a/juick-xmpp-wip/src/test/java/com/juick/xmpp/XMPPTests.java +++ b/juick-xmpp-wip/src/test/java/com/juick/xmpp/XMPPTests.java @@ -17,25 +17,16 @@ package com.juick.xmpp; -import com.gargoylesoftware.htmlunit.WebClient; import com.juick.components.XMPPRouter; import com.juick.components.configuration.BotAppConfiguration; -import com.juick.configuration.MockDataConfiguration; -import com.juick.service.MessengerService; -import com.juick.service.PrivacyQueriesService; -import com.juick.service.ShowQueriesService; -import org.junit.Before; +import com.juick.configuration.DataConfiguration; +import com.juick.service.ImagesService; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder; -import org.springframework.web.context.WebApplicationContext; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit4.SpringRunner; import rocks.xmpp.addr.Jid; import rocks.xmpp.core.XmppException; import rocks.xmpp.core.session.ConnectionEvent; @@ -52,40 +43,12 @@ import java.util.concurrent.ExecutorService; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@ContextConfiguration +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, + classes = { BotAppConfiguration.class, DataConfiguration.class}) public class XMPPTests { - @Configuration - @Import(value = { - BotAppConfiguration.class, MockDataConfiguration.class - }) - static class Config { - @Bean - public ShowQueriesService showQueriesService() { - return Mockito.mock(ShowQueriesService.class); - } - @Bean - public PrivacyQueriesService privacyQueriesService() { - return Mockito.mock(PrivacyQueriesService.class); - } - @Bean - public MessengerService messengerService() { - return Mockito.mock(MessengerService.class); - } - } - - @Inject - private WebApplicationContext wac; - - private WebClient webClient; - - @Before - public void setup() { - webClient = MockMvcWebClientBuilder.webAppContextSetup(this.wac).build(); - webClient.getOptions().setJavaScriptEnabled(false); - } - + @MockBean + ImagesService imagesService; @Inject XMPPRouter router; @Inject -- cgit v1.2.3