Я пытаюсь запустить тесты, используя maven для Jersey Test Framework. В этом коде я в основном пытаюсь протестировать ресурс, я также хотел вывести сущность на консоль, а также посмотреть трафик журналов для видазапроса я получаю ... Вот пример моего кода, который я написал.
package in.swapnilsingh;
import in.swapnilsingh.entity.Book;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.junit.Test;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.GenericType;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class BookResourceTest extends JerseyTest {
@Override
protected Application configure() {
enable(TestProperties.LOG_TRAFFIC);
enable(TestProperties.DUMP_ENTITY);
return new ResourceConfig().packages("in.swapnilsingh");
}
@Override
protected void configureClient(ClientConfig config) {
config.register(new LoggingFeature(Logger.getAnonymousLogger(), Level.INFO, LoggingFeature.Verbosity.PAYLOAD_TEXT, 1500));
}
@Test
public void testGetBook() {
Book response = target("books").path("1").request().get(Book.class);
assertNotNull(response);
}
@Test
public void testGetBooks() {
Collection<Book> response = target("books").request().get(new GenericType<Collection<Book>>() {
});
assertEquals(3, response.size());
}
}
Как вы можете видеть в методе configure()
, я включаю TestProperties.LOG_TRAFFIC
& TestProperties.DUMP_ENTITY
... Тем не менее, я не могу получить желаемый результат в журналах.Я также прилагаю журналы ниже.
"C:\Program Files\Java\jdk1.8.0_121\bin\java.exe" -Dmaven.multiModuleProjectDirectory=D:\IdeaProjects\books "-Dmaven.home=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.2\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.2\plugins\maven\lib\maven3\bin\m2.conf" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.2\lib\idea_rt.jar=59253:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.2\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version2019.1.2 test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building books 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ books ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\IdeaProjects\books\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ books ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ books ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\IdeaProjects\books\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ books ---
[INFO] Compiling 1 source file to D:\IdeaProjects\books\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ books ---
[INFO] Surefire report directory: D:\IdeaProjects\books\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running in.swapnilsingh.BookResourceTest
May 13, 2019 6:41:03 PM org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory$GrizzlyTestContainer <init>
INFO: Creating GrizzlyTestContainer configured at the base URI http://localhost:9998/
May 13, 2019 6:41:03 PM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [localhost:9998]
May 13, 2019 6:41:03 PM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
May 13, 2019 6:41:03 PM org.glassfish.grizzly.http.server.NetworkListener shutdownNow
INFO: Stopped listener bound to [localhost:9998]
May 13, 2019 6:41:03 PM org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory$GrizzlyTestContainer <init>
INFO: Creating GrizzlyTestContainer configured at the base URI http://localhost:9998/
May 13, 2019 6:41:03 PM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [localhost:9998]
May 13, 2019 6:41:03 PM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer-1] Started.
May 13, 2019 6:41:03 PM org.glassfish.grizzly.http.server.NetworkListener shutdownNow
INFO: Stopped listener bound to [localhost:9998]
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.908 sec
May 13, 2019 6:41:03 PM org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory$GrizzlyTestContainer <init>
INFO: Creating GrizzlyTestContainer configured at the base URI http://localhost:9998/
Running in.swapnilsingh.MyResourceTest
May 13, 2019 6:41:03 PM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [localhost:9998]
May 13, 2019 6:41:03 PM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer-2] Started.
May 13, 2019 6:41:03 PM org.glassfish.grizzly.http.server.NetworkListener shutdownNow
INFO: Stopped listener bound to [localhost:9998]
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.047 sec
Results :
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.553 s
[INFO] Finished at: 2019-05-13T18:41:04+05:30
[INFO] Final Memory: 17M/207M
[INFO] ------------------------------------------------------------------------
Process finished with exit code 0