DATAREST-1470 - Switched to use factory methods of RepresentationModel types.
This commit is contained in:
@@ -58,7 +58,7 @@ public class DefaultSelfLinkProviderUnitTests {
|
||||
Class<?> type = invocation.getArgument(0);
|
||||
Object id = invocation.getArgument(1);
|
||||
|
||||
return new Link("/".concat(type.getName()).concat("/").concat(id.toString()));
|
||||
return Link.of("/".concat(type.getName()).concat("/").concat(id.toString()));
|
||||
});
|
||||
|
||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||
|
||||
@@ -176,7 +176,7 @@ public abstract class AbstractWebIntegrationTests {
|
||||
assertThat(href).as(message, " not", rel).isNull();
|
||||
}
|
||||
|
||||
return new Link(href, rel);
|
||||
return Link.of(href, rel);
|
||||
|
||||
} catch (InvalidPathException o_O) {
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
|
||||
for (Object href : uris) {
|
||||
|
||||
client.follow(new Link(href.toString())) //
|
||||
client.follow(Link.of(href.toString())) //
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ public class TestMvcClient {
|
||||
* @throws Exception
|
||||
*/
|
||||
public Links discover(LinkRelation rel) throws Exception {
|
||||
return discover(new Link("/"), rel);
|
||||
return discover(Link.of("/"), rel);
|
||||
}
|
||||
|
||||
public Link discoverUnique(String rel) throws Exception {
|
||||
|
||||
@@ -124,7 +124,7 @@ public class DataRest262Tests {
|
||||
JpaPersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(AircraftMovement.class);
|
||||
|
||||
EntityModel<Object> resource = PersistentEntityResource.build(movement, persistentEntity).//
|
||||
withLink(new Link("/api/airports/" + movement.id)).//
|
||||
withLink(Link.of("/api/airports/" + movement.id)).//
|
||||
build();
|
||||
|
||||
String result = mapper.writeValueAsString(resource);
|
||||
|
||||
@@ -370,7 +370,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
patchAndGet(frodosSiblingsLink, links.get(3).getHref(), TEXT_URI_LIST);
|
||||
|
||||
String pippinId = new UriTemplate("/people/{id}").match(links.get(3).getHref()).get("id");
|
||||
deleteAndVerify(new Link(frodosSiblingsLink.expand().getHref() + "/" + pippinId));
|
||||
deleteAndVerify(Link.of(frodosSiblingsLink.expand().getHref() + "/" + pippinId));
|
||||
|
||||
assertSiblingNames(frodosSiblingsLink, "Bilbo", "Merry");
|
||||
}
|
||||
@@ -507,7 +507,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
String content = response.getContentAsString();
|
||||
String href = JsonPath.read(content, firstAuthorPath.concat("._links.self.href"));
|
||||
|
||||
client.follow(new Link(href)).andExpect(client.hasLinkWithRel("books"));
|
||||
client.follow(Link.of(href)).andExpect(client.hasLinkWithRel("books"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-353
|
||||
@@ -766,7 +766,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
assertThat(JsonPath.<String> read(john, "$.firstName")).isNotNull();
|
||||
|
||||
// Assert sibling link exposed in resource pointed to
|
||||
Link selfLink = new Link(JsonPath.<String> read(john, "$._links.self.href"));
|
||||
Link selfLink = Link.of(JsonPath.<String> read(john, "$._links.self.href"));
|
||||
client.follow(selfLink).//
|
||||
andExpect(status().isOk()).//
|
||||
andExpect(jsonPath("$._links.siblings", is(notNullValue())));
|
||||
|
||||
@@ -85,7 +85,7 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests
|
||||
@Test // DATAREST-230, DATAREST-638
|
||||
public void profileRootLinkContainsMetadataForEachRepo() throws Exception {
|
||||
|
||||
Link profileLink = client.discoverUnique(new Link(ROOT_URI), ProfileResourceProcessor.PROFILE_REL);
|
||||
Link profileLink = client.discoverUnique(Link.of(ROOT_URI), ProfileResourceProcessor.PROFILE_REL);
|
||||
|
||||
assertThat(client.discoverUnique(profileLink, "self", MediaType.ALL)).isNotNull();
|
||||
assertThat(client.discoverUnique(profileLink, "people", MediaType.ALL)).isNotNull();
|
||||
@@ -100,7 +100,7 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests
|
||||
@Test // DATAREST-638
|
||||
public void profileLinkOnCollectionResourceLeadsToRepositorySpecificMetadata() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique(new Link(ROOT_URI), "people");
|
||||
Link peopleLink = client.discoverUnique(Link.of(ROOT_URI), "people");
|
||||
Link profileLink = client.discoverUnique(peopleLink, ProfileResourceProcessor.PROFILE_REL);
|
||||
|
||||
client.follow(profileLink, MediaTypes.ALPS_JSON).andExpect(status().is2xxSuccessful())
|
||||
|
||||
@@ -135,7 +135,7 @@ public class PersistentEntitySerializationTests {
|
||||
Person person = people.save(new Person("John", "Doe"));
|
||||
|
||||
PersistentEntityResource resource = PersistentEntityResource.build(person, persistentEntity).//
|
||||
withLink(new Link("/person/" + person.getId())).build();
|
||||
withLink(Link.of("/person/" + person.getId())).build();
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
mapper.writeValue(writer, resource);
|
||||
@@ -197,7 +197,7 @@ public class PersistentEntitySerializationTests {
|
||||
|
||||
PersistentEntityResource orderResource = PersistentEntityResource.//
|
||||
build(order, repositories.getPersistentEntity(Order.class)).//
|
||||
withLink(new Link("/orders/1")).//
|
||||
withLink(Link.of("/orders/1")).//
|
||||
build();
|
||||
|
||||
PagedModel<PersistentEntityResource> persistentEntityResource = new PagedModel<PersistentEntityResource>(
|
||||
@@ -238,8 +238,8 @@ public class PersistentEntitySerializationTests {
|
||||
|
||||
PersistentEntityResource resource = PersistentEntityResource.//
|
||||
build(dave, repositories.getPersistentEntity(Person.class)).//
|
||||
withLink(new Link("/people/1")).//
|
||||
withLink(new Link("/aditional", "processed")).//
|
||||
withLink(Link.of("/people/1")).//
|
||||
withLink(Link.of("/aditional", "processed")).//
|
||||
build();
|
||||
|
||||
String result = mapper.writeValueAsString(resource);
|
||||
@@ -284,7 +284,7 @@ public class PersistentEntitySerializationTests {
|
||||
|
||||
PersistentEntityResource resource = PersistentEntityResource//
|
||||
.build(guest, context.getRequiredPersistentEntity(Guest.class))//
|
||||
.withLink(new Link("/guests/1")).build();
|
||||
.withLink(Link.of("/guests/1")).build();
|
||||
|
||||
String result = mapper.writeValueAsString(resource);
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ public class PersistentEntitySerializationTests {
|
||||
|
||||
PersistentEntityResource userResource = PersistentEntityResource.//
|
||||
build(user, repositories.getPersistentEntity(User.class)).//
|
||||
withLink(new Link("/users/1")).//
|
||||
withLink(Link.of("/users/1")).//
|
||||
build();
|
||||
|
||||
PagedModel<PersistentEntityResource> persistentEntityResource = new PagedModel<PersistentEntityResource>(
|
||||
|
||||
@@ -68,7 +68,7 @@ class AbstractRepositoryRestController {
|
||||
Link selfLink = resource.getRequiredLink(IanaLinkRelations.SELF);
|
||||
LinkRelation rel = repoMapping.getItemResourceRel();
|
||||
|
||||
return new Link(selfLink.getHref(), rel);
|
||||
return Link.of(selfLink.getHref(), rel);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@@ -116,6 +116,6 @@ class AbstractRepositoryRestController {
|
||||
}
|
||||
|
||||
protected Link getDefaultSelfLink() {
|
||||
return new Link(ServletUriComponentsBuilder.fromCurrentRequest().build().toUriString());
|
||||
return Link.of(ServletUriComponentsBuilder.fromCurrentRequest().build().toUriString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,14 +96,14 @@ public class ProfileController {
|
||||
|
||||
RepresentationModel<?> profile = new RepresentationModel<>();
|
||||
|
||||
profile.add(new Link(getRootPath(this.configuration)).withSelfRel());
|
||||
profile.add(Link.of(getRootPath(this.configuration)).withSelfRel());
|
||||
|
||||
for (Class<?> domainType : this.repositories) {
|
||||
|
||||
ResourceMetadata mapping = this.mappings.getMetadataFor(domainType);
|
||||
|
||||
if (mapping.isExported()) {
|
||||
profile.add(new Link(getPath(this.configuration, mapping), mapping.getRel()));
|
||||
profile.add(Link.of(getPath(this.configuration, mapping), mapping.getRel()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ProfileResourceProcessor implements RepresentationModelProcessor<Re
|
||||
@Override
|
||||
public RepositoryLinksResource process(RepositoryLinksResource resource) {
|
||||
|
||||
resource.add(new Link(ProfileController.getRootPath(this.configuration), PROFILE_REL));
|
||||
resource.add(Link.of(ProfileController.getRootPath(this.configuration), PROFILE_REL));
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
SearchResourceMappings searchMappings = metadata.getSearchResourceMappings();
|
||||
|
||||
Links links = Links
|
||||
.of(new Link(ProfileController.getPath(this.config, metadata), ProfileResourceProcessor.PROFILE_REL));
|
||||
.of(Link.of(ProfileController.getPath(this.config, metadata), ProfileResourceProcessor.PROFILE_REL));
|
||||
|
||||
return searchMappings.isExported() //
|
||||
? links.and(entityLinks.linkFor(metadata.getDomainType()).slash(searchMappings.getPath())
|
||||
|
||||
@@ -204,7 +204,7 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
}
|
||||
|
||||
} else {
|
||||
return new EntityModel<>(prop.propertyValue);
|
||||
return EntityModel.of(prop.propertyValue);
|
||||
}
|
||||
|
||||
throw new ResourceNotFoundException();
|
||||
|
||||
@@ -342,7 +342,7 @@ public class RootResourceInformationToAlpsDescriptorConverter {
|
||||
String href = ProfileController.getPath(configuration, targetTypeMetadata) + "#"
|
||||
+ getRepresentationDescriptorId(targetTypeMetadata);
|
||||
|
||||
Link link = new Link(href).withSelfRel();
|
||||
Link link = Link.of(href).withSelfRel();
|
||||
|
||||
builder.//
|
||||
type(Type.SAFE).//
|
||||
|
||||
@@ -99,7 +99,7 @@ public class UriListHttpMessageConverter implements HttpMessageConverter<Represe
|
||||
|
||||
String line = scanner.nextLine();
|
||||
if (StringUtils.hasText(line)) {
|
||||
links.add(new Link(line));
|
||||
links.add(Link.of(line));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public class Associations {
|
||||
String href = path.slash(propertyMapping.getPath()).toString();
|
||||
UriTemplate template = UriTemplate.of(href).with(getProjectionVariable(property));
|
||||
|
||||
return Collections.singletonList(new Link(template, propertyMapping.getRel()));
|
||||
return Collections.singletonList(Link.of(template, propertyMapping.getRel()));
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -114,7 +114,7 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
||||
TemplateVariables variables = getTemplateVariables(components, metadata, pageable).//
|
||||
concat(getProjectionVariable(type));
|
||||
|
||||
return new Link(UriTemplate.of(href).with(variables), metadata.getRel());
|
||||
return Link.of(UriTemplate.of(href).with(variables), metadata.getRel());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -141,7 +141,7 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
||||
.toRequestId((Serializable) id, type);
|
||||
|
||||
Link link = linkFor(type).slash(mappedId).withRel(metadata.getItemResourceRel());
|
||||
return new Link(UriTemplate.of(link.getHref()).with(getProjectionVariable(type)).toString(),
|
||||
return Link.of(UriTemplate.of(link.getHref()).with(getProjectionVariable(type)).toString(),
|
||||
metadata.getItemResourceRel());
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
||||
concat(getTemplateVariables(uriComponents, mapping, pageable, sort)).//
|
||||
concat(getProjectionVariable(mapping.getReturnedDomainType()));
|
||||
|
||||
return new Link(UriTemplate.of(uriComponents.toString()).with(variables), mapping.getRel());
|
||||
return Link.of(UriTemplate.of(uriComponents.toString()).with(variables), mapping.getRel());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -101,7 +101,7 @@ public class AssociationLinksUnitTests {
|
||||
List<Link> associationLinks = links.getLinksFor(property.getRequiredAssociation(), new Path("/base"));
|
||||
|
||||
assertThat(associationLinks).hasSize(1);
|
||||
assertThat(associationLinks).contains(new Link("/base/property", "property"));
|
||||
assertThat(associationLinks).contains(Link.of("/base/property", "property"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
|
||||
@@ -43,7 +43,7 @@ public class PersistentEntityResourceUnitTests {
|
||||
@Mock PersistentEntity<?, ?> entity;
|
||||
|
||||
CollectionModel<EmbeddedWrapper> resources;
|
||||
Link link = new Link("http://localhost", "foo");
|
||||
Link link = Link.of("http://localhost", "foo");
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@@ -84,7 +84,7 @@ public class RepositoryPropertyReferenceControllerUnitTests {
|
||||
doReturn(new Sample()).when(invoker).invokeSave(any(Object.class));
|
||||
|
||||
RootResourceInformation information = new RootResourceInformation(metadata, entity, invoker);
|
||||
CollectionModel<Object> request = new CollectionModel<Object>(Collections.emptySet(), new Link("/reference/some-id"));
|
||||
CollectionModel<Object> request = new CollectionModel<Object>(Collections.emptySet(), Link.of("/reference/some-id"));
|
||||
|
||||
controller.createPropertyReference(information, HttpMethod.POST, request, 4711, "references");
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ public class AssociationsUnitTests {
|
||||
List<Link> links = associations.getLinksFor(getAssociation(Root.class, "relatedAndExported"), new Path(""));
|
||||
|
||||
assertThat(links).hasSize(1);
|
||||
assertThat(links).contains(new Link("/relatedAndExported", "relatedAndExported"));
|
||||
assertThat(links).contains(Link.of("/relatedAndExported", "relatedAndExported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -144,7 +144,7 @@ public class AssociationsUnitTests {
|
||||
List<Link> links = associations.getLinksFor(getAssociation(Root.class, "relatedAndExported"), new Path(""));
|
||||
|
||||
assertThat(links).hasSize(1);
|
||||
assertThat(links).contains(new Link("/relatedAndExported{?" + projectionParameterName + "}", "relatedAndExported"));
|
||||
assertThat(links).contains(Link.of("/relatedAndExported{?" + projectionParameterName + "}", "relatedAndExported"));
|
||||
}
|
||||
|
||||
private Association<? extends PersistentProperty<?>> getAssociation(Class<?> type, String name) {
|
||||
|
||||
Reference in New Issue
Block a user