DATAREST-224 - Introduce Maven POMs.

Adapted JpaWebTests to compile on Java6. Fixed some broken test case in Neo4jWebTests.
This commit is contained in:
Oliver Gierke
2014-01-19 19:12:34 +01:00
parent 5409bfd472
commit f02000e619
7 changed files with 346 additions and 11 deletions

View File

@@ -52,6 +52,7 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.context.WebApplicationContext;
import com.jayway.jsonpath.InvalidPathException;
import com.jayway.jsonpath.JsonPath;
/**
@@ -62,6 +63,8 @@ import com.jayway.jsonpath.JsonPath;
@ContextConfiguration(classes = RepositoryRestMvcConfiguration.class)
public abstract class AbstractWebIntegrationTests {
private static final String CONTENT_LINK_JSONPATH = "$._embedded.._links.%s.href[0]";
protected static MediaType DEFAULT_MEDIA_TYPE = org.springframework.hateoas.MediaTypes.HAL_JSON;
@Autowired WebApplicationContext context;
@@ -143,13 +146,34 @@ public abstract class AbstractWebIntegrationTests {
}
protected Link assertHasContentLinkWithRel(String rel, MockHttpServletResponse response) throws Exception {
return assertContentLinkWithRel(rel, response, true);
}
protected void assertDoesNotHaveContentLinkWithRel(String rel, MockHttpServletResponse response) throws Exception {
assertContentLinkWithRel(rel, response, false);
}
protected Link assertContentLinkWithRel(String rel, MockHttpServletResponse response, boolean expected)
throws Exception {
String content = response.getContentAsString();
String href = JsonPath.read(content, String.format("$.._links.%s.href[0]", rel)).toString();
assertThat("Expected to find a link with rel" + rel + " in the content section of the response!", href,
is(notNullValue()));
return new Link(href, rel);
try {
String href = JsonPath.read(content, String.format(CONTENT_LINK_JSONPATH, rel)).toString();
assertThat("Expected to find a link with rel" + rel + " in the content section of the response!", href,
is(expected ? notNullValue() : nullValue()));
return new Link(href, rel);
} catch (InvalidPathException o_O) {
if (expected) {
fail("Didn't find any content in the given response!");
}
return null;
}
}
protected void assertDoesNotHaveLinkWithRel(String rel, MockHttpServletResponse response) throws Exception {

View File

@@ -20,12 +20,10 @@ import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import org.junit.Before;
import org.junit.Test;
@@ -40,7 +38,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
/**
* Web integration tests specific to JPA.
@@ -189,7 +186,13 @@ public class JpaWebTests extends AbstractWebIntegrationTests {
private String readFile(String name) throws Exception {
ClassPathResource file = new ClassPathResource(name, getClass());
List<String> lines = Files.readAllLines(file.getFile().toPath(), Charset.forName("UTF-8"));
return StringUtils.collectionToDelimitedString(lines, System.lineSeparator());
StringBuilder builder = new StringBuilder();
Scanner scanner = new Scanner(file.getFile(), "UTF-8");
while (scanner.hasNextLine()) {
builder.append(scanner.nextLine());
}
return builder.toString();
}
}

View File

@@ -86,6 +86,6 @@ public class Neo4jWebTests extends AbstractWebIntegrationTests {
mvc.perform(delete(customerLink.getHref()));
// Assert no customers anymore
assertDoesNotHaveLinkWithRel("self", request(customers));
assertDoesNotHaveContentLinkWithRel("self", request(customers));
}
}