Here are the examples of the java api org.springframework.hateoas.EntityModel taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
93 Examples
19
View Source File : Jackson2JsonApiIntegrationTest.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
@Test
void should_serialize_with_NON_NULL_annotation() throws Exception {
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
clreplaced NonNullExample {
private final String id = "1";
private final String test = null;
}
EnreplacedyModel<NonNullExample> enreplacedyModel = EnreplacedyModel.of(new NonNullExample());
String json = mapper.writeValuereplacedtring(enreplacedyModel);
compareWithFile(json, "nonNullAnnotationExample.json");
}
19
View Source File : Jackson2JsonApiIntegrationTest.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
@Test
void should_serialize_empty_enreplacedy_model() throws Exception {
final EnreplacedyModel<Object> representationModel = EnreplacedyModel.of(new Object());
String emptyDoc = mapper.writeValuereplacedtring(representationModel);
compareWithFile(emptyDoc, "emptyDoc.json");
}
19
View Source File : LinkedResourceMethodHandlerTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
public clreplaced LinkedResourceMethodHandlerTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
private ResourceContent resourceContent;
private LinkedResourceMethodHandler handler;
private MethodLinkAttributesResolver methodLinkAttributesResolver;
private MethodLinkUriResolver methodLinkUriResolver;
private EnreplacedyModel<ResourceContent> resource;
private PropertyValueFactory propertyValueFactory;
@Before
public void setUp() {
propertyValueFactory = mock(PropertyValueFactory.clreplaced);
methodLinkAttributesResolver = mock(MethodLinkAttributesResolver.clreplaced);
methodLinkUriResolver = mock(MethodLinkUriResolver.clreplaced);
JavreplacedistClientProxyFactory proxyFactory = new JavreplacedistClientProxyFactory();
resourceContent = new ResourceContent();
resource = new EnreplacedyModel<>(resourceContent);
handler = new LinkedResourceMethodHandler(resource, mock(RestOperations.clreplaced), proxyFactory, propertyValueFactory, methodLinkAttributesResolver, methodLinkUriResolver);
when(methodLinkAttributesResolver.resolveForMethod(any())).thenReturn(newRequiredLinkAttributes());
}
@Test
public void supportsAnyAnnotatedMethodIsTrue() {
replacedertThat(handler.supports(findMethod(ResourceContent.clreplaced, "anyAnnotatedMethod")), is(true));
}
@Test
public void supportsSetterForAnnotatedGetterIsTrue() {
replacedertThat(handler.supports(findMethod(ResourceContent.clreplaced, "setLinkedResource", String.clreplaced)), is(true));
}
@Test
public void supportsNonAnnotatedMethodIsFalse() {
replacedertThat(handler.supports(findMethod(ResourceContent.clreplaced, "nonAnnotatedMethod")), is(false));
}
@Test
public void invokeResolvesLinkFromLinkAttributes() throws InvocationTargetException, IllegalAccessException {
final Method getterMethod = findMethod(ResourceContent.clreplaced, "getLinkedResource");
when(methodLinkAttributesResolver.resolveForMethod(getterMethod)).thenReturn(new MethodLinkAttributes("x", true));
handler.invoke(resourceContent, getterMethod, null, new String[0]);
verify(methodLinkUriResolver).resolveForMethod(eq(resource), eq("x"), argThat(is(emptyArray())));
}
@Test
public void invokeWhenNoLinkAndRequiredLinkThrowsException() throws InvocationTargetException, IllegalAccessException {
final Method getterMethod = findMethod(ResourceContent.clreplaced, "getLinkedResource");
when(methodLinkAttributesResolver.resolveForMethod(any())).thenReturn(newRequiredLinkAttributes());
when(methodLinkUriResolver.resolveForMethod(any(), any(), any())).thenThrow(new NoSuchLinkException("x"));
thrown.expect(NoSuchLinkException.clreplaced);
thrown.expect(hasProperty("linkName", is("x")));
handler.invoke(resourceContent, getterMethod, null, new String[0]);
}
@Test
public void invokeWhenNoLinkAndOptionalLinkAndSingleValueReturnsNull() throws InvocationTargetException, IllegalAccessException {
final Method getterMethod = findMethod(ResourceContent.clreplaced, "getOptionalLinkedResource");
when(methodLinkAttributesResolver.resolveForMethod(any())).thenReturn(newOptionalLinkAttributes());
when(methodLinkUriResolver.resolveForMethod(any(), any(), any())).thenThrow(new NoSuchLinkException("x"));
Object result = handler.invoke(resourceContent, getterMethod, null, new String[0]);
replacedertThat(result, is(nullValue()));
}
@Test
public void invokeWhenNoLinkAndOptionalLinkAndCollectionValueReturnsEmpty() throws InvocationTargetException, IllegalAccessException {
final Method getterMethod = findMethod(ResourceContent.clreplaced, "getOptionalLinkedResources");
when(methodLinkAttributesResolver.resolveForMethod(any())).thenReturn(newOptionalLinkAttributes());
when(methodLinkUriResolver.resolveForMethod(any(), any(), any())).thenThrow(new NoSuchLinkException("x"));
SortedSet<String> set = new TreeSet<>();
when(propertyValueFactory.createCollection(SortedSet.clreplaced)).thenReturn(set);
Object result = handler.invoke(resourceContent, getterMethod, null, new String[0]);
replacedertThat(result, is(sameInstance(set)));
replacedertThat((Collection<?>) result, is(empty()));
}
@Test
public void invokeSetsAndReturnsSameLinkedResource() throws InvocationTargetException, IllegalAccessException {
final Method getterMethod = findMethod(ResourceContent.clreplaced, "getLinkedResource");
final Method setterMethod = findMethod(ResourceContent.clreplaced, "setLinkedResource", String.clreplaced);
handler.invoke(resourceContent, setterMethod, null, new String[] { "X" });
replacedertThat(handler.invoke(resourceContent, getterMethod, null, null), equalTo("X"));
}
@Test
public void invokeSetsAndReturnsNull() throws InvocationTargetException, IllegalAccessException {
final Method getterMethod = findMethod(ResourceContent.clreplaced, "getLinkedResource");
final Method setterMethod = findMethod(ResourceContent.clreplaced, "setLinkedResource", String.clreplaced);
handler.invoke(resourceContent, setterMethod, null, new String[] { null });
replacedertThat(handler.invoke(resourceContent, getterMethod, null, null), is(nullValue()));
}
private static MethodLinkAttributes newRequiredLinkAttributes() {
return new MethodLinkAttributes("_linkName", false);
}
private static MethodLinkAttributes newOptionalLinkAttributes() {
return new MethodLinkAttributes("_linkName", true);
}
@SuppressWarnings("unused")
private static clreplaced ResourceContent {
@LinkedResource
public void anyAnnotatedMethod() {
// no-op
}
@LinkedResource
public String getLinkedResource() {
return null;
}
@LinkedResource(optionalLink = true)
public String getOptionalLinkedResource() {
return null;
}
@LinkedResource(optionalLink = true)
public SortedSet<String> getOptionalLinkedResources() {
return null;
}
public void setLinkedResource(String value) {
// no-op
}
public String nonAnnotatedMethod() {
return null;
}
}
}
19
View Source File : ResourceIdMethodHandler.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
clreplaced ResourceIdMethodHandler implements ConditionalMethodHandler {
private final EnreplacedyModel<?> resource;
ResourceIdMethodHandler(EnreplacedyModel<?> resource) {
this.resource = resource;
}
@Override
public boolean supports(Method method) {
return method.isAnnotationPresent(ResourceId.clreplaced);
}
@Override
public Object invoke(Object self, Method method, Method proceed, Object[] args) {
Optional<Link> selfLink = resource.getLink(IreplacedinkRelations.SELF);
return selfLink.map(link -> URI.create(link.getHref())).orElse(null);
}
}
19
View Source File : LinkedResourceMethodHandler.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
private <F> Collection<F> updateCollectionWithLinkedResources(Collection<F> collection, CollectionModel<EnreplacedyModel<F>> resources) {
for (EnreplacedyModel<F> fResource : resources) {
collection.add(proxyFactory.create(fResource, restOperations));
}
return collection;
}
19
View Source File : LinkedResourceMethodHandler.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
private <F> F resolveSingleLinkedResource(URI replacedociationResource, Clreplaced<F> linkedEnreplacedyType) {
EnreplacedyModel<F> linkedResource = restOperations.getResource(replacedociationResource, linkedEnreplacedyType);
if (linkedResource == null) {
return null;
}
return proxyFactory.create(linkedResource, restOperations);
}
19
View Source File : Client.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
/**
* GET a single enreplacedy located at the given URI.
*
* @param uri the URI from which to retrieve the enreplacedy
* @return the enreplacedy, or null if not found
*/
public T get(URI uri) {
EnreplacedyModel<T> resource = restOperations.getResource(uri, enreplacedyType);
if (resource == null) {
return null;
}
return proxyFactory.create(resource, restOperations);
}
19
View Source File : Client.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
/**
* PATCH (partial update) of the enreplacedy at the given URI.
*
* @param uri a URI of the enreplacedy to update
* @param patch any type that can be serialized to a set of changes, for example a Map
* @return The patched enreplacedy, or null if no response content was returned
*/
public T patch(URI uri, Object patch) {
EnreplacedyModel<T> resource = restOperations.patchForResource(uri, patch, enreplacedyType);
return proxyFactory.create(resource, restOperations);
}
19
View Source File : ModelingProjectsSteps.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
private Response exportCurrentProject() {
EnreplacedyModel<Project> currentProject = checkAndGetCurrentContext(Project.clreplaced);
Link exportLink = currentProject.getLink("export").get();
replacedertThat(exportLink).isNotNull();
return modelingProjectService.exportProjectByUri(modelingUri(exportLink.getHref()));
}
19
View Source File : ModelingProjectsSteps.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Step
public EnreplacedyModel<Model> importModelInCurrentProject(File file) {
EnreplacedyModel<Project> currentProject = checkAndGetCurrentContext(Project.clreplaced);
Link importModelLink = currentProject.getLink("import").get();
replacedertThat(importModelLink).isNotNull();
return modelingProjectService.importProjectModelByUri(modelingUri(importModelLink.getHref()), file);
}
19
View Source File : ModelingProjectsSteps.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Step
public void updateProjectName(String newProjectName) {
EnreplacedyModel<Project> currentContext = checkAndGetCurrentContext(Project.clreplaced);
Project project = currentContext.getContent();
project.setName(newProjectName);
modelingProjectService.updateByUri(modelingUri(currentContext.getLink(SELF).get().getHref()), project);
}
19
View Source File : ModelingProjectsSteps.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
private Response validateCurrentProject() {
EnreplacedyModel<Project> currentProject = checkAndGetCurrentContext(Project.clreplaced);
Link exportLink = currentProject.getLink("export").get();
String validateLink = exportLink.getHref().replace("/export", "/validate");
replacedertThat(validateLink).isNotNull();
return modelingProjectService.validateProjectByUri(modelingUri(validateLink));
}
19
View Source File : ModelingProjectsSteps.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Step
public void checkCurrentProjectName(String projectName) {
updateCurrentModelingObject();
EnreplacedyModel<Project> currentContext = checkAndGetCurrentContext(Project.clreplaced);
replacedertThat(currentContext.getContent().getName()).isEqualTo(projectName);
}
19
View Source File : ModelingModelsSteps.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Step
public void checkCurrentModelVersion(String expectedModelVersion) {
EnreplacedyModel<Model> currentContext = checkAndGetCurrentContext(Model.clreplaced);
Model model = currentContext.getContent();
replacedertThat(model.getVersion()).isEqualTo(expectedModelVersion);
}
19
View Source File : ModelingModelsSteps.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
private List<Response> validateCurrentModel() throws IOException {
EnreplacedyModel<Model> currentContext = checkAndGetCurrentContext(Model.clreplaced);
replacedertThat(currentContext.getContent()).isInstanceOf(Model.clreplaced);
final Model model = currentContext.getContent();
model.setId(getModelId(currentContext));
List<Response> responses = new ArrayList<>();
responses.add(validateModel(currentContext, getFormData(model)));
if (Optional.ofNullable(model.getExtensions()).isPresent()) {
responses.add(validateExtensions(currentContext, getFormData(model, true)));
}
return responses;
}
19
View Source File : ModelingModelsSteps.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Step
public void saveCurrentModel(boolean updateContent) {
EnreplacedyModel<Model> currentContext = checkAndGetCurrentContext(Model.clreplaced);
replacedertThat(currentContext.getContent()).isInstanceOf(Model.clreplaced);
if (updateContent) {
String updateMsg = "updated content";
currentContext.getContent().setContent(updateMsg.getBytes());
}
saveModel(currentContext);
updateCurrentModelingObject();
}
19
View Source File : ModelingModelsSteps.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Step
public void addProcessVariableInCurrentModel(List<String> processVariable) {
EnreplacedyModel<Model> currentContext = checkAndGetCurrentContext(Model.clreplaced);
replacedertThat(currentContext.getContent()).isInstanceOf(Model.clreplaced);
Model model = currentContext.getContent();
addProcessVariableToModelModel(model, processVariable);
}
19
View Source File : ModelingModelsSteps.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Step
public void removeProcessVariableInCurrentModel(String processVariable) {
EnreplacedyModel<Model> currentContext = checkAndGetCurrentContext(Model.clreplaced);
replacedertThat(currentContext.getContent()).isInstanceOf(Model.clreplaced);
Model model = currentContext.getContent();
Optional.ofNullable(this.getExtensionFromMap(model)).map(Extensions::getProcessVariables).ifPresent(processVariables -> processVariables.remove(processVariable));
Optional.ofNullable(this.getExtensionFromMap(model)).map(Extensions::getVariablesMappings).map(mappings -> mappings.get(EXTENSIONS_TASK_NAME)).map(mappingsTypes -> mappingsTypes.get(INPUTS)).ifPresent(processVariableMappings -> processVariableMappings.remove(processVariable));
Optional.ofNullable(this.getExtensionFromMap(model)).map(Extensions::getVariablesMappings).map(mappings -> mappings.get(EXTENSIONS_TASK_NAME)).map(mappingsTypes -> mappingsTypes.get(OUTPUTS)).ifPresent(processVariableMappings -> processVariableMappings.remove(processVariable));
}
19
View Source File : ModelingModelsSteps.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Step
public void checkCurrentModelContainsVariables(String... processVariables) {
EnreplacedyModel<Model> currentContext = checkAndGetCurrentContext(Model.clreplaced);
Model model = currentContext.getContent();
replacedertThat(model.getExtensions()).isNotNull();
replacedertThat(this.getExtensionFromMap(model).getProcessVariables()).containsKeys(processVariables);
Arrays.stream(processVariables).forEach(processVariableId -> {
ProcessVariable processVariable = this.getExtensionFromMap(model).getProcessVariables().get(processVariableId);
replacedertThat(processVariable.getId()).isEqualTo(processVariableId);
replacedertThat(processVariable.getName()).isEqualTo(processVariableId);
replacedertThat(processVariable.isRequired()).isEqualTo(false);
replacedertThat(processVariable.getType()).isEqualTo("boolean");
replacedertThat(processVariable.getValue()).isEqualTo(true);
});
replacedertThat(this.getExtensionFromMap(model).getVariablesMappings()).containsKeys(EXTENSIONS_TASK_NAME);
replacedertThat(this.getExtensionFromMap(model).getVariablesMappings().get(EXTENSIONS_TASK_NAME)).containsKeys(INPUTS, OUTPUTS);
replacedertProcessVariableMappings(model, INPUTS, processVariables);
replacedertProcessVariableMappings(model, OUTPUTS, processVariables);
}
18
View Source File : Jackson2JsonApiIntegrationTest.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
@Test
void should_serialize_movies_with_long_id() throws Exception {
MovieWithLongId movie = new MovieWithLongId(1, "Star Wars", "long-movies");
EnreplacedyModel<MovieWithLongId> enreplacedyModel = EnreplacedyModel.of(movie).add(Links.of(Link.of("http://localhost/movies/1").withSelfRel()));
String movieJson = mapper.writeValuereplacedtring(enreplacedyModel);
compareWithFile(movieJson, "movieEnreplacedyModelWithLongId.json");
}
18
View Source File : Jackson2JsonApiIntegrationTest.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
@Test
void should_render_jsonapi_version() throws Exception {
Movie movie = new Movie("1", "Star Wars");
EnreplacedyModel<Movie> enreplacedyModel = EnreplacedyModel.of(movie);
mapper = createObjectMapper(new JsonApiConfiguration().withJsonApiVersionRendered(true));
String movieJson = mapper.writeValuereplacedtring(enreplacedyModel);
compareWithFile(movieJson, "movieEnreplacedyModelWithJsonApiVersion.json");
}
18
View Source File : Jackson2JsonApiIntegrationTest.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
@Test
void should_serialize_movie_with_complex_link() throws Exception {
MovieWithLongId movie = new MovieWithLongId(1, "Star Wars", "long-movies");
EnreplacedyModel<MovieWithLongId> enreplacedyModel = EnreplacedyModel.of(movie).add(Links.of(Link.of("http://localhost/movies/1").withRel("related").withName("link name").withreplacedle("link replacedle")));
String movieJson = mapper.writeValuereplacedtring(enreplacedyModel);
compareWithFile(movieJson, "movieEnreplacedyModelWithComplexLink.json");
}
18
View Source File : Jackson2JsonApiIntegrationTest.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
@Test
void should_serialize_custom_instant() throws Exception {
@Getter
clreplaced InstantExample {
private final String id = "1";
private final Instant instant;
InstantExample() {
instant = Instant.ofEpochSecond(1603465191);
}
}
EnreplacedyModel<InstantExample> enreplacedyModel = EnreplacedyModel.of(new InstantExample());
mapper.registerModule(new JavaTimeModule());
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
String instantJson = mapper.writeValuereplacedtring(enreplacedyModel);
compareWithFile(instantJson, "instantWithCustomConfig.json");
}
18
View Source File : JsonApiEntityModelDeserializer.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
@Override
protected EnreplacedyModel<?> convertToRepresentationModel(List<Object> resources, JsonApiDoreplacedent doc) {
replacedert.notNull(doc, "JsonApiDoreplacedent must not be null!");
Links links = doc.getLinks();
if (resources.size() == 1) {
EnreplacedyModel<Object> enreplacedyModel = EnreplacedyModel.of(resources.get(0));
if (links != null) {
enreplacedyModel.add(links);
}
if (doc.getData() == null) {
return enreplacedyModel;
}
HashMap<String, Object> relationships = (HashMap<String, Object>) ((HashMap<String, Object>) doc.getData()).get("relationships");
if (relationships != null) {
Object object = enreplacedyModel.getContent();
@SuppressWarnings("ConstantConditions")
final Field[] declaredFields = getAllDeclaredFields(object.getClreplaced());
for (Field field : declaredFields) {
field.setAccessible(true);
JsonApiRelationships relationshipsAnnotation = field.getAnnotation(JsonApiRelationships.clreplaced);
if (relationshipsAnnotation != null) {
Object relationship = relationships.get(relationshipsAnnotation.value());
try {
if (relationship != null) {
final Type genericType = field.getGenericType();
// expect collections to always be generic, like "List<Director>"
if (genericType instanceof ParameterizedType) {
ParameterizedType type = (ParameterizedType) genericType;
if (Collection.clreplaced.isreplacedignableFrom(field.getType())) {
Collection<Object> relationshipCollection;
if (Set.clreplaced.isreplacedignableFrom(field.getType())) {
relationshipCollection = new HashSet<>();
} else {
relationshipCollection = new ArrayList<>();
}
Object data = ((HashMap<?, ?>) relationship).get("data");
List<HashMap<String, String>> jsonApiRelationships;
if (data instanceof List) {
jsonApiRelationships = (List<HashMap<String, String>>) data;
} else if (data instanceof HashMap) {
HashMap<String, String> castedData = (HashMap<String, String>) data;
jsonApiRelationships = Collections.singletonList(castedData);
} else {
throw new IllegalArgumentException(CANNOT_DESERIALIZE_INPUT_TO_ENreplacedY_MODEL);
}
Type typeArgument = type.getActualTypeArguments()[0];
for (HashMap<String, String> entry : jsonApiRelationships) {
String json = objectMapper.writeValuereplacedtring(entry);
Object newInstance = objectMapper.readValue(json.getBytes(StandardCharsets.UTF_8), objectMapper.constructType(typeArgument));
// Object newInstance = typeArgClreplaced.getDeclaredConstructor().newInstance();
JsonApiResourceIdentifier.setJsonApiResourceFieldAttributeForObject(newInstance, JsonApiResourceIdentifier.JsonApiResourceField.id, entry.get("id"));
JsonApiResourceIdentifier.setJsonApiResourceFieldAttributeForObject(newInstance, JsonApiResourceIdentifier.JsonApiResourceField.type, entry.get("type"));
relationshipCollection.add(newInstance);
}
field.set(object, relationshipCollection);
}
} else {
// we expect a concrete type otherwise, like "Director"
Clreplaced<?> clazz = Clreplaced.forName(genericType.getTypeName());
Object newInstance = clazz.getDeclaredConstructor().newInstance();
HashMap<String, Object> data = (HashMap<String, Object>) ((HashMap<?, ?>) relationship).get("data");
JsonApiResourceIdentifier.setJsonApiResourceFieldAttributeForObject(newInstance, JsonApiResourceIdentifier.JsonApiResourceField.id, data.get("id").toString());
JsonApiResourceIdentifier.setJsonApiResourceFieldAttributeForObject(newInstance, JsonApiResourceIdentifier.JsonApiResourceField.type, data.get("type").toString());
field.set(object, newInstance);
}
}
} catch (Exception e) {
throw new IllegalArgumentException(CANNOT_DESERIALIZE_INPUT_TO_ENreplacedY_MODEL, e);
}
}
}
}
return enreplacedyModel;
}
throw new IllegalArgumentException(CANNOT_DESERIALIZE_INPUT_TO_ENreplacedY_MODEL);
}
18
View Source File : EmployeeController.java
License : Apache License 2.0
Project Creator : springdoc
License : Apache License 2.0
Project Creator : springdoc
@PostMapping("/employees")
@ResponseStatus(HttpStatus.CREATED)
ResponseEnreplacedy<EnreplacedyModel<Employee>> newEmployee(@RequestBody Employee employee) {
try {
Employee savedEmployee = repository.save(employee);
EnreplacedyModel<Employee> employeeResource = new //
EnreplacedyModel<>(//
savedEmployee, linkTo(methodOn(EmployeeController.clreplaced).findOne(savedEmployee.getId())).withSelfRel());
return //
ResponseEnreplacedy.created(//
new URI(employeeResource.getRequiredLink(IreplacedinkRelations.SELF).getHref())).body(employeeResource);
} catch (URISyntaxException e) {
return ResponseEnreplacedy.badRequest().body(null);
}
}
18
View Source File : EmployeeController.java
License : Apache License 2.0
Project Creator : springdoc
License : Apache License 2.0
Project Creator : springdoc
@PostMapping("/employees")
ResponseEnreplacedy<EnreplacedyModel<Employee>> newEmployee(@RequestBody Employee employee) {
try {
Employee savedEmployee = repository.save(employee);
EnreplacedyModel<Employee> employeeResource = new //
EnreplacedyModel<>(//
savedEmployee, linkTo(methodOn(EmployeeController.clreplaced).findOne(savedEmployee.getId())).withSelfRel());
return //
ResponseEnreplacedy.created(//
new URI(employeeResource.getRequiredLink(IreplacedinkRelations.SELF).getHref())).body(employeeResource);
} catch (URISyntaxException e) {
return ResponseEnreplacedy.badRequest().body(null);
}
}
18
View Source File : EmployeeController.java
License : Apache License 2.0
Project Creator : spring-projects
License : Apache License 2.0
Project Creator : spring-projects
@PostMapping("/employees")
ResponseEnreplacedy<?> newEmployee(@RequestBody Employee employee) {
try {
Employee savedEmployee = repository.save(employee);
EnreplacedyModel<Employee> employeeResource = //
EnreplacedyModel.of(//
savedEmployee, linkTo(methodOn(EmployeeController.clreplaced).findOne(savedEmployee.getId())).withSelfRel());
return //
ResponseEnreplacedy.created(//
new URI(employeeResource.getRequiredLink(IreplacedinkRelations.SELF).getHref())).body(employeeResource);
} catch (URISyntaxException e) {
return ResponseEnreplacedy.badRequest().body("Unable to create " + employee);
}
}
18
View Source File : SimpleResourceAssembler.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
/**
* Converts the given enreplacedy into a {@link Resource}.
*
* @param enreplacedy the enreplacedy
* @return a resource for the enreplacedy.
*/
@Override
public EnreplacedyModel<T> toModel(T enreplacedy) {
EnreplacedyModel<T> resource = new EnreplacedyModel<T>(enreplacedy);
addLinks(resource);
return resource;
}
18
View Source File : EventController.java
License : Apache License 2.0
Project Creator : odrotbohm
License : Apache License 2.0
Project Creator : odrotbohm
private EnreplacedyModel<AbstractEvent<?>> toResource(AbstractEvent<?> event) {
EnreplacedyModel<AbstractEvent<?>> resource = EnreplacedyModel.of(event);
resource.add(links.linkTo(methodOn(EventController.clreplaced).event(event.getId())).withSelfRel());
return resource;
}
18
View Source File : OrderController.java
License : Apache License 2.0
Project Creator : kbastani
License : Apache License 2.0
Project Creator : kbastani
/**
* Appends an {@link OrderEvent} domain event to the event log of the {@link Order} aggregate with the
* specified orderId.
*
* @param orderId is the unique identifier for the {@link Order}
* @param event is the {@link OrderEvent} that attempts to alter the state of the {@link Order}
* @return a hypermedia resource for the newly appended {@link OrderEvent}
*/
private EnreplacedyModel<OrderEvent> appendEventResource(Long orderId, OrderEvent event) {
EnreplacedyModel<OrderEvent> eventResource = null;
orderService.get(orderId).sendAsyncEvent(event);
if (event != null) {
eventResource = EnreplacedyModel.of(event, linkTo(OrderController.clreplaced).slash("orders").slash(orderId).slash("events").slash(event.getEventId()).withSelfRel(), linkTo(OrderController.clreplaced).slash("orders").slash(orderId).withRel("order"));
}
return eventResource;
}
18
View Source File : WebMvcPersonController.java
License : Apache License 2.0
Project Creator : ingogriebsch
License : Apache License 2.0
Project Creator : ingogriebsch
@GetMapping("/persons/search")
public CollectionModel<EnreplacedyModel<Person>> search(@RequestParam(value = "name", required = false) String name, @RequestParam(value = "age", required = false) Integer age) {
List<EnreplacedyModel<Person>> persons = new ArrayList<>();
for (int i = 0; i < PERSONS.size(); i++) {
EnreplacedyModel<Person> personModel = findOne(i);
boolean nameMatches = //
Optional.ofNullable(name).map(//
s -> personModel.getContent().getName().contains(s)).orElse(true);
boolean ageMatches = //
Optional.ofNullable(age).map(//
s -> personModel.getContent().getAge().equals(s)).orElse(true);
if (nameMatches && ageMatches) {
persons.add(personModel);
}
}
WebMvcPersonController controller = methodOn(WebMvcPersonController.clreplaced);
Link selfLink = //
linkTo(controller.findAll()).withSelfRel().andAffordance(//
afford(controller.insert(null))).andAffordance(afford(controller.search(null, null)));
return CollectionModel.of(persons, selfLink);
}
18
View Source File : RestOperationsTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void patchForResourceReturnsNull() {
Map<String, String> patch = new HashMap<>();
when(restTemplate.patchForObject(URI.create("http://example.com"), patch, ObjectNode.clreplaced)).thenReturn(null);
EnreplacedyModel<Enreplacedy> resource = restOperations.patchForResource(URI.create("http://example.com"), patch, Enreplacedy.clreplaced);
replacedertThat(resource, is(nullValue()));
}
18
View Source File : ResourceIdMethodHandlerTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void invokeWithResourceWithNoSelfLinkReturnsNull() {
EnreplacedyModel<Object> resource = new EnreplacedyModel<>(new Object(), Links.of(new Link("http://www.example.com/1", "some-other-rel")));
Object result = new ResourceIdMethodHandler(resource).invoke(null, null, null, null);
replacedertThat(result, is(nullValue()));
}
18
View Source File : ResourceIdMethodHandlerTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void invokeWithResourceWithSelfLinkReturnsLinkUri() {
EnreplacedyModel<Object> resource = new EnreplacedyModel<>(new Object(), Links.of(new Link("http://www.example.com/1", IreplacedinkRelations.SELF)));
Object result = new ResourceIdMethodHandler(resource).invoke(null, null, null, null);
replacedertThat(result, is(URI.create("http://www.example.com/1")));
}
18
View Source File : ResourceDeserializerTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void deserializeReturnsObjectOfResolvedType() throws Exception {
doReturn(ResolvedType.clreplaced).when(typeResolver).resolveType(any(), any(), any());
EnreplacedyModel<DeclaredType> resource = mapper.readValue("{\"field\":\"x\"}", new TypeReference<EnreplacedyModel<DeclaredType>>() {
});
replacedertThat("clreplaced", resource.getContent().getClreplaced(), Matchers.<Clreplaced<?>>equalTo(ResolvedType.clreplaced));
replacedertThat("field", ((ResolvedType) resource.getContent()).getField(), is("x"));
}
18
View Source File : ResourceDeserializerTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void deserializeReturnsObjectOfResolvedInterfaceType() throws Exception {
doReturn(ResolvedInterfaceType.clreplaced).when(typeResolver).resolveType(any(), any(), any());
EnreplacedyModel<DeclaredType> resource = mapper.readValue("{}", new TypeReference<EnreplacedyModel<DeclaredType>>() {
});
replacedertThat(ResolvedInterfaceType.clreplaced.isreplacedignableFrom(resource.getContent().getClreplaced()), is(true));
}
18
View Source File : ResourceDeserializerTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void deserializeReturnsObjectOfResolvedAbstractClreplacedType() throws Exception {
doReturn(ResolvedAbstractClreplacedType.clreplaced).when(typeResolver).resolveType(any(), any(), any());
EnreplacedyModel<DeclaredType> resource = mapper.readValue("{}", new TypeReference<EnreplacedyModel<DeclaredType>>() {
});
replacedertThat(ResolvedAbstractClreplacedType.clreplaced.isreplacedignableFrom(resource.getContent().getClreplaced()), is(true));
}
18
View Source File : MethodLinkUriResolverTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void resolveForMethodReturnsUriWithParamsExpanded() {
EnreplacedyModel<Object> resource = new EnreplacedyModel<>(new Object(), Links.of(new Link("http://www.example.com/{?x,y}", "link1")));
URI uri = new MethodLinkUriResolver().resolveForMethod(resource, "link1", new Object[] { "1", 2 });
replacedertThat(uri, is(URI.create("http://www.example.com/?x=1&y=2")));
}
18
View Source File : MethodLinkUriResolverTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void resolveForMethodWithNoMatchingLinkThrowsException() {
EnreplacedyModel<Object> resource = new EnreplacedyModel<>(new Object(), Links.of(new Link("http://www.example.com", "other")));
thrown.expect(NoSuchLinkException.clreplaced);
thrown.expect(hasProperty("linkName", is("link1")));
new MethodLinkUriResolver().resolveForMethod(resource, "link1", new Object[0]);
}
18
View Source File : JavassistClientProxyFactoryTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void createWithLinkedResourceTargetNotPresentReturnsProxyReturningNull() {
EnreplacedyModel<Enreplacedy> resource = new EnreplacedyModel<>(new Enreplacedy(), new Link("http://www.example.com/replacedociation/linked", "linked"));
when(restOperations.getResource(URI.create("http://www.example.com/replacedociation/linked"), Enreplacedy.clreplaced)).thenReturn(null);
Enreplacedy proxy = proxyFactory.create(resource, restOperations);
replacedertThat(proxy.linked(), is(nullValue()));
}
18
View Source File : JavassistClientProxyFactoryTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void createWithNullLinkedCollectionReturnsProxyWithLinkedResources() {
EnreplacedyModel<Enreplacedy> resource = new EnreplacedyModel<>(new Enreplacedy(), new Link("http://www.example.com/replacedociation/linked", "nullLinkedCollection"));
when(restOperations.getResources(URI.create("http://www.example.com/replacedociation/linked"), Enreplacedy.clreplaced)).thenReturn(new CollectionModel<>(asList(new EnreplacedyModel<>(new Enreplacedy(), new Link("http://www.example.com/1", IreplacedinkRelations.SELF)))));
Enreplacedy proxy = proxyFactory.create(resource, restOperations);
replacedertThat(proxy.getNullLinkedCollection().get(0).getId(), is(URI.create("http://www.example.com/1")));
}
18
View Source File : JavassistClientProxyFactoryTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void createReturnsProxyWithActive() {
Enreplacedy enreplacedy = new Enreplacedy();
enreplacedy.setActive(true);
EnreplacedyModel<Enreplacedy> resource = new EnreplacedyModel<>(enreplacedy, new Link("http://www.example.com/1", IreplacedinkRelations.SELF));
Enreplacedy proxy = proxyFactory.create(resource, mock(RestOperations.clreplaced));
replacedertThat(proxy.getId(), is(URI.create("http://www.example.com/1")));
replacedertThat(proxy.isActive(), is(true));
}
18
View Source File : JavassistClientProxyFactoryTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void createReturnsProxyWithLinkedResourceWithCustomRel() {
EnreplacedyModel<Enreplacedy> resource = new EnreplacedyModel<>(new Enreplacedy(), new Link("http://www.example.com/replacedociation/linked", "a:b"));
when(restOperations.getResource(URI.create("http://www.example.com/replacedociation/linked"), Enreplacedy.clreplaced)).thenReturn(new EnreplacedyModel<>(new Enreplacedy(), new Link("http://www.example.com/1", IreplacedinkRelations.SELF)));
Enreplacedy proxy = proxyFactory.create(resource, restOperations);
replacedertThat(proxy.getLinkedWithCustomRel().getId(), is(URI.create("http://www.example.com/1")));
}
18
View Source File : JavassistClientProxyFactoryTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void createReturnsProxyWithLinkedResource() {
EnreplacedyModel<Enreplacedy> resource = new EnreplacedyModel<>(new Enreplacedy(), new Link("http://www.example.com/replacedociation/linked", "linked"));
when(restOperations.getResource(URI.create("http://www.example.com/replacedociation/linked"), Enreplacedy.clreplaced)).thenReturn(new EnreplacedyModel<>(new Enreplacedy(), new Link("http://www.example.com/1", IreplacedinkRelations.SELF)));
Enreplacedy proxy = proxyFactory.create(resource, restOperations);
replacedertThat(proxy.linked().getId(), is(URI.create("http://www.example.com/1")));
}
18
View Source File : JavassistClientProxyFactoryTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void createReturnsProxyWithId() {
EnreplacedyModel<Enreplacedy> resource = new EnreplacedyModel<>(new Enreplacedy(), new Link("http://www.example.com/1", IreplacedinkRelations.SELF));
Enreplacedy proxy = proxyFactory.create(resource, mock(RestOperations.clreplaced));
replacedertThat(proxy.getId(), is(URI.create("http://www.example.com/1")));
}
18
View Source File : JavassistClientProxyFactoryTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void createReturnsProxyWithLinkedResources() {
EnreplacedyModel<Enreplacedy> resource = new EnreplacedyModel<>(new Enreplacedy(), new Link("http://www.example.com/replacedociation/linked", "linkedCollection"));
when(restOperations.getResources(URI.create("http://www.example.com/replacedociation/linked"), Enreplacedy.clreplaced)).thenReturn(new CollectionModel<>(asList(new EnreplacedyModel<>(new Enreplacedy(), new Link("http://www.example.com/1", IreplacedinkRelations.SELF)))));
Enreplacedy proxy = proxyFactory.create(resource, restOperations);
replacedertThat(proxy.getLinkedCollection().get(0).getId(), is(URI.create("http://www.example.com/1")));
}
18
View Source File : JavassistClientProxyFactoryTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void createReturnsProxyWithSettingValuesPossible() {
Enreplacedy enreplacedy = new Enreplacedy();
enreplacedy.setActive(true);
EnreplacedyModel<Enreplacedy> resource = new EnreplacedyModel<>(enreplacedy, new Link("http://www.example.com/1", IreplacedinkRelations.SELF));
Enreplacedy proxy = proxyFactory.create(resource, mock(RestOperations.clreplaced));
proxy.setActive(false);
replacedertThat(proxy.isActive(), is(false));
}
18
View Source File : ClientTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void getWithUriReturnsProxy() {
Enreplacedy expected = new Enreplacedy();
EnreplacedyModel<Enreplacedy> resource = new EnreplacedyModel<>(new Enreplacedy());
when(restOperations.getResource(URI.create("http://www.example.com/1"), Enreplacedy.clreplaced)).thenReturn(resource);
when(proxyFactory.create(resource, restOperations)).thenReturn(expected);
Enreplacedy proxy = client.get(URI.create("http://www.example.com/1"));
replacedertThat(proxy, is(expected));
}
18
View Source File : ClientTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void getReturnsProxy() {
Enreplacedy expected = new Enreplacedy();
EnreplacedyModel<Enreplacedy> resource = new EnreplacedyModel<>(new Enreplacedy());
when(restOperations.getResource(URI.create(BASE_URI + "/enreplacedies"), Enreplacedy.clreplaced)).thenReturn(resource);
when(proxyFactory.create(resource, restOperations)).thenReturn(expected);
Enreplacedy proxy = client.get();
replacedertThat(proxy, is(expected));
}
18
View Source File : ClientTest.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
@Test
public void getAllWithNoArgumentsReturnsProxyIterable() {
Enreplacedy expected = new Enreplacedy();
EnreplacedyModel<Enreplacedy> resource = new EnreplacedyModel<>(new Enreplacedy());
when(restOperations.getResources(URI.create(BASE_URI + "/enreplacedies"), Enreplacedy.clreplaced)).thenReturn(new CollectionModel<>(asList(resource)));
when(proxyFactory.create(resource, restOperations)).thenReturn(expected);
Iterable<Enreplacedy> proxies = client.getAll();
replacedertThat(proxies, contains(expected));
}
See More Examples