Fiz conforme exercício mas não está aparecendo o log das transações no servidor. Poderiam me ajudar?
package br.com.alura.loja;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.filter.LoggingFilter;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.xstream.XStream;
import br.com.alura.loja.modelo.Carrinho;
import br.com.alura.loja.modelo.Produto;
import br.com.alura.loja.modelo.Projeto;
import junit.framework.Assert;
public class ClienteTest {
private HttpServer server;
private Client client;
@Before
public void before(){
server = Servidor.inicializaServidor();
ClientConfig config = new ClientConfig();
config.register(new LoggingFilter());
this.client = ClientBuilder.newClient(config);
}
@After
public void after() {
server.stop();
}
@Test
public void testaQueBuscarUmCarrinhoTrazOCarrinhoEsperado() {
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080");
String conteudo = target.path("/carrinhos/1").request().get(String.class);
Carrinho carrinho = (Carrinho) new XStream().fromXML(conteudo);
Assert.assertEquals("Rua Vergueiro 3185, 8 andar", carrinho.getRua());
}
@Test
public void testaQueBuscarUmProjetoTrazOProjetoEsperado() {
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080");
String conteudo = target.path("/projetos/1").request().get(String.class);
Projeto projeto = (Projeto) new XStream().fromXML(conteudo);
Assert.assertEquals("Minha loja", projeto.getNome());
}
@Test
public void testeParaOPost(){
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080");
Carrinho carrinho = new Carrinho();
carrinho.adiciona(new Produto(314L, "Tablet", 999, 1));
carrinho.setRua("Rua Vergueiro");
carrinho.setCidade("Sao Paulo");
String xml = carrinho.toXML();
Entity<String> entity = Entity.entity(xml, MediaType.APPLICATION_XML);
Response response = target.path("/carrinhos").request().post(entity);
Assert.assertEquals(201, response.getStatus());
String location = response.getHeaderString("Location");
String conteudo = client.target(location).request().get(String.class);
Assert.assertTrue(conteudo.contains("Tablet"));
}
}
package br.com.alura.loja;
import java.io.IOException;
import java.net.URI;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
public class Servidor {
public static void main(String[] args) throws IOException {
HttpServer server = inicializaServidor();
System.out.println("Servidor rodando");
System.in.read();
server.stop();
}
static HttpServer inicializaServidor() {
ResourceConfig config = new ResourceConfig().packages("br.com.alura.loja");
URI uri = URI.create("http://localhost:8080/");
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri, config);
return server;
}
}
Segue resultado do log:
dez 07, 2016 12:36:37 PM org.glassfish.jersey.server.ApplicationHandler initialize
INFORMAÇÕES: Initiating Jersey application, version Jersey: 2.5 2013-12-18 14:27:29...
dez 07, 2016 12:36:37 PM org.glassfish.grizzly.http.server.NetworkListener start
INFORMAÇÕES: Started listener bound to [localhost:8080]
dez 07, 2016 12:36:37 PM org.glassfish.grizzly.http.server.HttpServer start
INFORMAÇÕES: [HttpServer] Started.
dez 07, 2016 12:36:38 PM org.glassfish.grizzly.http.server.NetworkListener stop
INFORMAÇÕES: Stopped listener bound to [localhost:8080]
dez 07, 2016 12:36:38 PM org.glassfish.jersey.server.ApplicationHandler initialize
INFORMAÇÕES: Initiating Jersey application, version Jersey: 2.5 2013-12-18 14:27:29...
dez 07, 2016 12:36:38 PM org.glassfish.grizzly.http.server.NetworkListener start
INFORMAÇÕES: Started listener bound to [localhost:8080]
dez 07, 2016 12:36:38 PM org.glassfish.grizzly.http.server.HttpServer start
INFORMAÇÕES: [HttpServer-1] Started.
dez 07, 2016 12:36:38 PM org.glassfish.grizzly.http.server.NetworkListener stop
INFORMAÇÕES: Stopped listener bound to [localhost:8080]
dez 07, 2016 12:36:38 PM org.glassfish.jersey.server.ApplicationHandler initialize
INFORMAÇÕES: Initiating Jersey application, version Jersey: 2.5 2013-12-18 14:27:29...
dez 07, 2016 12:36:38 PM org.glassfish.grizzly.http.server.NetworkListener start
INFORMAÇÕES: Started listener bound to [localhost:8080]
dez 07, 2016 12:36:38 PM org.glassfish.grizzly.http.server.HttpServer start
INFORMAÇÕES: [HttpServer-2] Started.
dez 07, 2016 12:36:38 PM org.glassfish.grizzly.http.server.NetworkListener stop
INFORMAÇÕES: Stopped listener bound to [localhost:8080]