package org.anderes.edu.jee.sample;

import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
import static javax.ws.rs.core.Response.Status.CREATED;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

import java.net.URI;
import java.net.URISyntaxException;

import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Variant;

import org.anderes.edu.jee.rest.sample.HelloWorldResource;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;

public class HelloWorldResourceTest extends JerseyTest {
     
    @Override
    protected Application configure() {
        return new ResourceConfig(HelloWorldResource.class);
    }
 
    @Test
    public void testPOST() {
        final Variant variant = new Variant(TEXT_PLAIN_TYPE, "de_CH", "UTF-8");
        final Entity<String> entity = Entity.entity("Hello World!", variant);
        
        final String hello = target("helloworld").request().buildPost(entity).invoke().readEntity(String.class);
        assertEquals("Hello World!", hello);
    }
    
    @Test
    public void shouldBeNewMessage() throws URISyntaxException {
        
        // given
        final Variant variant = new Variant(TEXT_PLAIN_TYPE, "de_CH", "UTF-8");
        final Entity<String> entity = Entity.entity("Hello World!", variant);
        
        // when
        final Response response = target("helloworld").request().buildPut(entity).invoke();
        
        // then
        assertThat("Unerwartete Antwort vom Server.", response.getStatus(), is(CREATED.getStatusCode()));
        assertThat("Unerwartetet location", response.getLocation(), is(new URI("http://localhost:9998/helloworld/2033")));        
    }
}

@@ -166,81 +166,87 @@
 tic 
-org.hamcrest.CoreMatchers.is;%0D%0Aimport static org.junit.Assert.assertEqual
+javax.ws.rs.core.Response.Status.OK;%0D%0Aimport static org.hamcrest.CoreMatchers.i
 s;%0D%0A
@@ -904,178 +904,128 @@
 oid 
-testPOST() %7B%0D%0A        final Variant variant = new Variant(TEXT_PLAIN_TYPE, %22de_CH%22, %22UTF-8%22);%0D%0A        final Entity%3CString%3E entity = Entity.entity(%22H
+shouldBeSayHallo() %7B%0D%0A             %0D%0A    %09// when%0D%0A        final Response response = target(%22h
 ello
- W
+w
 orld
-!%22, variant
+%22).request().get(
 );%0D%0A
@@ -1046,86 +1046,111 @@
     
-final String hello = target(%22helloworld%22).request().buildPost(entity).invoke()
+// then%0D%0A        assertThat(response.getStatus(), is(OK.getStatusCode()));%0D%0A        assertThat(response
 .rea
@@ -1174,30 +1174,11 @@
 ass)
-;%0D%0A        assertEqual
+, i
 s(%22H
@@ -1191,17 +1191,10 @@
 orld
-!%22, hello
+%22)
 );%0D%0A
@@ -1569,17 +1569,18 @@
 ).buildP
-u
+os
 t(entity

Test zum laufen gebracht