在通过TestProperties类启用的Jersey测试框架中看不到日志

时间:2019-05-13 13:15:17

标签: java rest jersey jersey-2.0 jersey-test-framework

我正在尝试使用Maven进行Jersey测试框架的测试,在这段代码中,我基本上是在测试资源,我还想将实体转储到控制台,并查看该类型的日志流量我收到的请求数量...这是我编写的代码示例。

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_TRAFFICTestProperties.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

0 个答案:

没有答案