org.springframework.hateoas.Resource

Here are the examples of the java api org.springframework.hateoas.Resource taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

46 Examples 7

18 Source : UserJPAController.java
with Apache License 2.0
from linnykoleh

@GetMapping(path = "/jpa/users/{id}")
public Resource<User> retrieveUser(@PathVariable int id) {
    final User user = userJPAService.findOne(id);
    if (Objects.isNull(user)) {
        throw new UserNotFoundException("There is no user with id: " + id);
    }
    final Resource<User> resource = new Resource<>(user);
    final ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClreplaced()).retrieveAllUsers());
    resource.add(linkTo.withRel("all-users"));
    return resource;
}

18 Source : ModelingProjectsSteps.java
with Apache License 2.0
from Activiti

@Step
public void checkCurrentProjectName(String projectName) {
    updateCurrentModelingObject();
    Resource<Project> currentContext = checkAndGetCurrentContext(Project.clreplaced);
    replacedertThat(currentContext.getContent().getName()).isEqualTo(projectName);
}

18 Source : ModelingModelsSteps.java
with Apache License 2.0
from Activiti

@Step
public void saveCurrentModel(boolean updateContent) {
    Resource<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();
}

18 Source : ModelingContextSteps.java
with Apache License 2.0
from Activiti

protected Resource<M> create(M m) {
    Resource<M> model = modelingContextHandler.getCurrentModelingContext().flatMap(this::getRelUri).map(this::modelingUri).map(uri -> service().createByUri(uri, m)).orElseGet(() -> service().create(m));
    return dirty(model);
}

17 Source : CustomerController.java
with Apache License 2.0
from yuanmabiji

@GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
HttpEnreplacedy<Resource<Customer>> showCustomer(@PathVariable Long id) {
    Resource<Customer> resource = new Resource<>(this.repository.findOne(id));
    resource.add(this.enreplacedyLinks.linkToSingleResource(Customer.clreplaced, id));
    return new ResponseEnreplacedy<>(resource, HttpStatus.OK);
}

17 Source : PersonController.java
with Apache License 2.0
from singram

/**
 * Person creation.
 * @return Person
 */
@RequestMapping(value = "/", method = RequestMethod.POST)
@ResponseBody
public ResponseEnreplacedy<?> savePerson(@RequestBody final Person person) {
    final Person persistedPerson = repository.save(person);
    final Resource<Person> resource = new Resource<Person>(persistedPerson);
    resource.add(linkTo(methodOn(PersonController.clreplaced).getPerson(persistedPerson.getId())).withSelfRel());
    return ResponseEnreplacedy.status(HttpStatus.CREATED).contentType(MediaType.APPLICATION_JSON).body(resource);
}

17 Source : PersonController.java
with Apache License 2.0
from singram

/**
 * Person retriever.
 * @return Person
 */
@RequestMapping(value = "/{personId}", method = RequestMethod.GET)
@ResponseBody
public ResponseEnreplacedy<?> getPerson(@PathVariable final Long personId) {
    final Person person = repository.findOne(personId);
    if (person == null) {
        return ResponseEnreplacedy.notFound().build();
    }
    final Resource<Person> resource = new Resource<Person>(person);
    resource.add(linkTo(methodOn(PersonController.clreplaced).getPerson(personId)).withSelfRel());
    return ResponseEnreplacedy.ok(resource);
}

17 Source : RestUserControllerTest.java
with MIT License
from lealceldeiro

/**
 * Test to be executed by JUnit.
 */
@Test
public void handleTransactionSystemException() throws Exception {
    String r = random.nextString();
    EUser u = new EUser(null, "a" + r + EXAMPLE_EMAIL, EXAMPLE_NAME + r, EXAMPLE_LAST_NAME, EXAMPLE_PreplacedWORD);
    Resource<EUser> resource = new Resource<>(u);
    mvc.perform(post(apiPrefix + "/" + ResourcePath.USER).contentType(MediaType.APPLICATION_JSON).header(authHeader, tokenType + " " + accessToken).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isUnprocessableEnreplacedy());
}

17 Source : ModelingModelsSteps.java
with Apache License 2.0
from Activiti

@Step
public void removeProcessVariableInCurrentModel(String processVariable) {
    Resource<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));
}

17 Source : ModelingModelsSteps.java
with Apache License 2.0
from Activiti

@Step
public void addProcessVariableInCurrentModel(List<String> processVariable) {
    Resource<Model> currentContext = checkAndGetCurrentContext(Model.clreplaced);
    replacedertThat(currentContext.getContent()).isInstanceOf(Model.clreplaced);
    Model model = currentContext.getContent();
    addProcessVariableToModelModel(model, processVariable);
}

17 Source : ModelingModelsSteps.java
with Apache License 2.0
from Activiti

private List<Response> validateCurrentModel() throws IOException {
    Resource<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;
}

16 Source : BookmarkControllerTest.java
with MIT License
from PacktPublishing

@Test
public void getABookmark() throws Exception {
    Bookmark input = getSimpleBookmark();
    String location = addBookmark(input);
    Resource<Bookmark> output = getBookmark(location);
    replacedertNotNull(output.getContent().getUrl());
    replacedertEquals(input.getUrl(), output.getContent().getUrl());
}

16 Source : BookmarkResourceAssembler.java
with MIT License
from PacktPublishing

@Override
public Resource<Bookmark> toResource(Bookmark enreplacedy) {
    Resource<Bookmark> resource = new Resource<>(enreplacedy, linkTo(methodOn(BookmarkController.clreplaced).getBookmark(enreplacedy.getUuid())).withSelfRel());
    if (request.isUserInRole("ADMIN")) {
        resource.add(linkTo(methodOn(BookmarkController.clreplaced).getBookmark(enreplacedy.getUuid())).withRel("update"), linkTo(methodOn(BookmarkController.clreplaced).getBookmark(enreplacedy.getUuid())).withRel("delete"));
    }
    return resource;
}

16 Source : TodoController.java
with MIT License
from PacktPublishing

@GetMapping(path = "/users/{name}/todos/{id}")
public Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id) {
    Todo todo = todoService.retrieveTodo(id);
    if (todo == null) {
        throw new TodoNotFoundException("Todo Not Found");
    }
    Resource<com.mastering.spring.springboot.bean.Todo> todoResource = new Resource<com.mastering.spring.springboot.bean.Todo>(todo);
    ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClreplaced()).retrieveTodos(name));
    todoResource.add(linkTo.withRel("parent"));
    return todoResource;
}

16 Source : RestUserControllerTest.java
with MIT License
from lealceldeiro

/**
 * Test to be executed by JUnit.
 */
@Test
public void handleDataIntegrityViolationException() throws Exception {
    String r = random.nextString();
    Resource<EUser> resource = EnreplacedyUtil.getSampleUserResource(r);
    mvc.perform(post(apiPrefix + "/" + ResourcePath.USER).contentType(MediaType.APPLICATION_JSON).header(authHeader, tokenType + " " + accessToken).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isCreated());
    resource = EnreplacedyUtil.getSampleUserResource(r);
    mvc.perform(post(apiPrefix + "/" + ResourcePath.USER).contentType(MediaType.APPLICATION_JSON).header(authHeader, tokenType + " " + accessToken).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isUnprocessableEnreplacedy());
}

16 Source : RestOwnedEntityControllerTest.java
with MIT License
from lealceldeiro

/**
 * Test to be executed by JUnit.
 */
@Test
public void handleDataIntegrityViolationException() throws Exception {
    boolean initial = configService.isMultiEnreplacedy();
    // allow new owned enreplacedies registration
    if (!initial) {
        configService.setIsMultiEnreplacedy(true);
    }
    final String r = random.nextString();
    Resource<EOwnedEnreplacedy> resource = EnreplacedyUtil.getSampleEnreplacedyResource(r);
    mvc.perform(post(apiPrefix + "/" + ResourcePath.OWNED_ENreplacedY).contentType(MediaType.APPLICATION_JSON).header(sc.getATokenHeader(), tokenType + " " + accessToken).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isCreated());
    resource = EnreplacedyUtil.getSampleEnreplacedyResource(r);
    mvc.perform(post(apiPrefix + "/" + ResourcePath.OWNED_ENreplacedY).contentType(MediaType.APPLICATION_JSON).header(sc.getATokenHeader(), tokenType + " " + accessToken).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isUnprocessableEnreplacedy());
    // restart initial config
    if (!initial) {
        configService.setIsMultiEnreplacedy(false);
    }
}

16 Source : TaskResourceAssemblerTest.java
with Apache License 2.0
from Activiti

@Test
public void toResourceShouldReturnResourceWithReleaseAndCompleteLinksWhenStatusIsreplacedigned() {
    Task model = new TaskImpl("my-identifier", "myTask", CREATED);
    given(converter.from(model)).willReturn(new CloudTaskImpl(model));
    Resource<CloudTask> resource = resourcereplacedembler.toResource(model);
    replacedertThat(resource.getLink("claim")).isNotNull();
    replacedertThat(resource.getLink("release")).isNull();
    replacedertThat(resource.getLink("complete")).isNull();
}

16 Source : TaskResourceAssemblerTest.java
with Apache License 2.0
from Activiti

@Test
public void toResourceShouldReturnResourceWithProcessInstanceLinkForProcessInstanceTask() {
    // process instance task
    Task model = new TaskImpl("my-identifier", "myTask", CREATED);
    ((TaskImpl) model).setProcessInstanceId("processInstanceId");
    given(converter.from(model)).willReturn(new CloudTaskImpl(model));
    Resource<CloudTask> resource = resourcereplacedembler.toResource(model);
    replacedertThat(resource.getLink("processInstance")).isNotNull();
}

16 Source : TaskResourceAssemblerTest.java
with Apache License 2.0
from Activiti

@Test
public void toResourceShouldNotReturnResourceWithProcessInstanceLinkWhenNewTaskIsCreated() {
    Task model = new TaskImpl("my-identifier", "myTask", CREATED);
    given(converter.from(model)).willReturn(new CloudTaskImpl(model));
    Resource<CloudTask> resource = resourcereplacedembler.toResource(model);
    // a new standalone task doesn't have a bond to a process instance
    // and should not return the rel 'processInstance'
    replacedertThat(resource.getLink("processInstance")).isNull();
}

16 Source : TaskResourceAssemblerTest.java
with Apache License 2.0
from Activiti

@Test
public void toResourceShouldReturnResourceWithClaimLinkWhenStatusIsNotreplacedigned() {
    Task model = new TaskImpl("my-identifier", "myTask", replacedIGNED);
    given(converter.from(model)).willReturn(new CloudTaskImpl(model));
    Resource<CloudTask> resource = resourcereplacedembler.toResource(model);
    replacedertThat(resource.getLink("claim")).isNull();
    replacedertThat(resource.getLink("release")).isNotNull();
    replacedertThat(resource.getLink("complete")).isNotNull();
}

16 Source : ModelingProjectsSteps.java
with Apache License 2.0
from Activiti

private Response exportCurrentProject() {
    Resource<Project> currentProject = checkAndGetCurrentContext(Project.clreplaced);
    Link exportLink = currentProject.getLink("export");
    replacedertThat(exportLink).isNotNull();
    return modelingProjectService.exportProjectByUri(modelingUri(exportLink.getHref()));
}

16 Source : ModelingModelsSteps.java
with Apache License 2.0
from Activiti

@Step
public void checkCurrentModelVersion(String expectedModelVersion) {
    Resource<Model> currentContext = checkAndGetCurrentContext(Model.clreplaced);
    Model model = currentContext.getContent();
    replacedertThat(model.getVersion()).isEqualTo(expectedModelVersion);
}

15 Source : RestOwnedEntityControllerTest.java
with MIT License
from lealceldeiro

/**
 * Test to be executed by JUnit.
 */
@Test
public void handleTransactionSystemException() throws Exception {
    boolean initial = configService.isMultiEnreplacedy();
    // allow new owned enreplacedies registration
    if (!initial) {
        configService.setIsMultiEnreplacedy(true);
    }
    final String r = random.nextString();
    EOwnedEnreplacedy e = new EOwnedEnreplacedy(null, StringUtil.EXAMPLE_USERNAME + r, StringUtil.EXAMPLE_DESCRIPTION + r);
    Resource<EOwnedEnreplacedy> resource = new Resource<>(e);
    mvc.perform(post(apiPrefix + "/" + ResourcePath.OWNED_ENreplacedY).contentType(MediaType.APPLICATION_JSON).header(sc.getATokenHeader(), tokenType + " " + accessToken).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isUnprocessableEnreplacedy());
    // restart initial config
    if (!initial) {
        configService.setUserRegistrationAllowed(false);
    }
}

15 Source : ModelingProjectsSteps.java
with Apache License 2.0
from Activiti

private Response validateCurrentProject() {
    Resource<Project> currentProject = checkAndGetCurrentContext(Project.clreplaced);
    Link exportLink = currentProject.getLink("export");
    String validateLink = exportLink.getHref().replace("/export", "/validate");
    replacedertThat(validateLink).isNotNull();
    return modelingProjectService.validateProjectByUri(modelingUri(validateLink));
}

15 Source : ModelingProjectsSteps.java
with Apache License 2.0
from Activiti

@Step
public Resource<Model> importModelInCurrentProject(File file) {
    Resource<Project> currentProject = checkAndGetCurrentContext(Project.clreplaced);
    Link importModelLink = currentProject.getLink("import");
    replacedertThat(importModelLink).isNotNull();
    return modelingProjectService.importProjectModelByUri(modelingUri(importModelLink.getHref()), file);
}

14 Source : TodoController.java
with MIT License
from PacktPublishing

@GetMapping(path = "/users/{name}/todos/{id}")
public Resource<Todo> retrieveTodo(@PathVariable String name, @PathVariable int id) {
    Todo todo = todoService.retrieveTodo(id);
    if (todo == null) {
        throw new TodoNotFoundException("Todo Not Found");
    }
    Resource<Todo> todoResource = new Resource<com.mastering.spring.springboot.bean.Todo>(todo);
    ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClreplaced()).retrieveTodos(name));
    todoResource.add(linkTo.withRel("parent"));
    return todoResource;
}

14 Source : TaskVariablesResourceAssemblerTest.java
with Apache License 2.0
from Activiti

@Test
public void toResourceShouldReturnResourceWithSelfLinkContainingResourceId() {
    // given
    VariableInstance model = new VariableInstanceImpl<>("var", "string", "value", "procInstId");
    ((VariableInstanceImpl) model).setTaskId("my-identifier");
    given(converter.from(model)).willReturn(new CloudVariableInstanceImpl<>(model));
    // when
    Resource<CloudVariableInstance> resource = resourcereplacedembler.toResource(model);
    // then
    Link globalVariablesLink = resource.getLink("variables");
    replacedertThat(globalVariablesLink).isNotNull();
    replacedertThat(globalVariablesLink.getHref()).contains("my-identifier");
}

14 Source : TaskResourceAssemblerTest.java
with Apache License 2.0
from Activiti

@Test
public void toResourceShouldReturnResourceWithSelfLinkContainingResourceId() {
    Task model = new TaskImpl("my-identifier", "myTask", CREATED);
    given(converter.from(model)).willReturn(new CloudTaskImpl(model));
    Resource<CloudTask> resource = resourcereplacedembler.toResource(model);
    Link selfResourceLink = resource.getLink("self");
    replacedertThat(selfResourceLink).isNotNull();
    replacedertThat(selfResourceLink.getHref()).contains("my-identifier");
}

14 Source : ProcessInstanceVariablesResourceAssemblerTest.java
with Apache License 2.0
from Activiti

@Test
public void toResourceShouldReturnResourceWithSelfLinkContainingResourceId() {
    // given
    VariableInstance model = new VariableInstanceImpl<>("var", "string", "value", "my-identifier");
    given(converter.from(model)).willReturn(new CloudVariableInstanceImpl<>(model));
    // when
    Resource<CloudVariableInstance> resource = resourcereplacedembler.toResource(model);
    // then
    Link processVariablesLink = resource.getLink("processVariables");
    replacedertThat(processVariablesLink).isNotNull();
    replacedertThat(processVariablesLink.getHref()).contains("my-identifier");
}

14 Source : ProcessDefinitionMetaResourceAssemblerTest.java
with Apache License 2.0
from Activiti

@Test
public void toResourceShouldReturnResourceWithSelfLinkContainingResourceId() {
    ProcessDefinitionMeta model = mock(ProcessDefinitionMeta.clreplaced);
    when(model.getId()).thenReturn("my-identifier");
    Resource<ProcessDefinitionMeta> resource = resourcereplacedembler.toResource(model);
    Link selfResourceLink = resource.getLink("self");
    replacedertThat(selfResourceLink).isNotNull();
    replacedertThat(selfResourceLink.getHref()).contains("my-identifier");
    Link metaResourceLink = resource.getLink("meta");
    replacedertThat(metaResourceLink).isNotNull();
    replacedertThat(metaResourceLink.getHref()).contains("my-identifier");
}

14 Source : ModelingProjectsSteps.java
with Apache License 2.0
from Activiti

@Step
public void updateProjectName(String newProjectName) {
    Resource<Project> currentContext = checkAndGetCurrentContext(Project.clreplaced);
    Project project = currentContext.getContent();
    project.setName(newProjectName);
    modelingProjectService.updateByUri(modelingUri(currentContext.getLink(REL_SELF).getHref()), project);
}

13 Source : BookmarkControllerTest.java
with MIT License
from PacktPublishing

@Test
public void updateABookmark() throws Exception {
    Bookmark input = getSimpleBookmark();
    String location = addBookmark(input);
    Resource<Bookmark> output = getBookmark(location);
    String result = mvc.perform(put(output.getId().getHref()).contentType(MediaType.APPLICATION_JSON_UTF8).accept("application/hal+json;charset=UTF-8", "application/json;charset=UTF-8").content(objectMapper.writeValuereplacedtring(output.getContent().withUrl("http://kulinariweb.de"))).with(csrf())).andDo(print()).andExpect(status().isOk()).andReturn().getResponse().getContentreplacedtring();
    output = objectMapper.readValue(result, new TypeReference<Resource<Bookmark>>() {
    });
    replacedertEquals("http://kulinariweb.de", output.getContent().getUrl());
}

13 Source : BookmarkControllerTest.java
with MIT License
from PacktPublishing

@Test
public void updateABookmarkStaleFails() throws Exception {
    Bookmark input = getSimpleBookmark();
    String location = addBookmark(input);
    Resource<Bookmark> output = getBookmark(location);
    mvc.perform(put(output.getId().getHref()).contentType(MediaType.APPLICATION_JSON_UTF8).accept("application/hal+json;charset=UTF-8", "application/json;charset=UTF-8").content(objectMapper.writeValuereplacedtring(output.getContent().withUrl("http://kulinariweb.de"))).with(csrf())).andDo(print()).andExpect(status().isOk()).andReturn().getResponse().getContentreplacedtring();
    mvc.perform(put(output.getId().getHref()).contentType(MediaType.APPLICATION_JSON_UTF8).accept("application/hal+json;charset=UTF-8", "application/json;charset=UTF-8").content(objectMapper.writeValuereplacedtring(output.getContent().withUrl("http://kulinariweb2.de"))).with(csrf())).andDo(print()).andExpect(status().isConflict());
}

13 Source : BookmarkControllerTest.java
with MIT License
from PacktPublishing

@Test
public void updateABookmarkFailsBecauseUrlIsNotValid() throws Exception {
    Bookmark input = getSimpleBookmark();
    String location = addBookmark(input);
    Resource<Bookmark> output = getBookmark(location);
    output.getContent().setUrl("broken://url.me");
    mvc.perform(put(output.getId().getHref()).contentType(MediaType.APPLICATION_JSON_UTF8).accept("application/hal+json;charset=UTF-8", "application/json;charset=UTF-8").content(objectMapper.writeValuereplacedtring(output.getContent())).with(csrf())).andDo(print()).andExpect(status().isBadRequest()).andExpect(jsonPath("$[0].field").value("url"));
}

13 Source : BookmarkControllerTest.java
with MIT License
from PacktPublishing

@Test
public void updateABookmarkFailsBecauseDescriptionIsNull() throws Exception {
    Bookmark input = getSimpleBookmark();
    String location = addBookmark(input);
    Resource<Bookmark> output = getBookmark(location);
    output.getContent().setDescription(null);
    mvc.perform(put(output.getId().getHref()).contentType(MediaType.APPLICATION_JSON_UTF8).accept("application/hal+json;charset=UTF-8", "application/json;charset=UTF-8").content(objectMapper.writeValuereplacedtring(output.getContent())).with(csrf())).andDo(print()).andExpect(status().isBadRequest()).andExpect(jsonPath("$[0].field").value("description"));
}

13 Source : AsyncGetService.java
with Apache License 2.0
from microservices-demo

@Async
public <T> Future<Resource<T>> getResource(URI url, TypeReferences.ResourceType<T> type) throws InterruptedException, IOException {
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(url).accept(HAL_JSON).build();
    LOG.debug("Requesting: " + request.toString());
    Resource<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
    LOG.debug("Received: " + body.toString());
    return new AsyncResult<>(body);
}

13 Source : SecurityControllerTest.java
with MIT License
from lealceldeiro

/**
 * Test to be executed by JUnit.
 */
@Test
public void signUpKO() throws Exception {
    boolean initial = configService.isUserRegistrationAllowed();
    if (initial) {
        configService.setUserRegistrationAllowed(false);
    }
    Resource<EUser> resource = getSampleUserResource(random.nextString());
    mvc.perform(post(apiPrefix + sc.getSignUpUrl()).contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isConflict());
    if (initial) {
        configService.setUserRegistrationAllowed(true);
    }
}

13 Source : DefaultControllerAdviceTest.java
with MIT License
from lealceldeiro

/**
 * Test to be executed by JUnit.
 */
@Test
public void handleDataIntegrityViolationException() throws Exception {
    boolean initial = configService.isUserRegistrationAllowed();
    // allow new user registration
    if (!initial) {
        configService.setUserRegistrationAllowed(true);
    }
    final String r = random.nextString();
    Resource<EUser> resource = getSampleUserResource(r);
    mvc.perform(post(apiPrefix + sc.getSignUpUrl()).contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isCreated());
    resource = getSampleUserResource(r);
    mvc.perform(post(apiPrefix + sc.getSignUpUrl()).contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isUnprocessableEnreplacedy());
    // restart initial config
    if (!initial) {
        configService.setUserRegistrationAllowed(false);
    }
}

13 Source : ProcessDefinitionResourceAssemblerTest.java
with Apache License 2.0
from Activiti

@Test
public void toResourceShouldReturnResourceWithSelfLinkContainingResourceId() {
    ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
    processDefinition.setId("my-identifier");
    given(converter.from(processDefinition)).willReturn(new CloudProcessDefinitionImpl(processDefinition));
    Resource<CloudProcessDefinition> processDefinitionResource = resourcereplacedembler.toResource(processDefinition);
    Link selfResourceLink = processDefinitionResource.getLink("self");
    replacedertThat(selfResourceLink).isNotNull();
    replacedertThat(selfResourceLink.getHref()).contains("my-identifier");
}

12 Source : DefaultControllerAdviceTest.java
with MIT License
from lealceldeiro

/**
 * Test to be executed by JUnit.
 */
@Test
public void handleTransactionSystemException() throws Exception {
    boolean initial = configService.isUserRegistrationAllowed();
    // allow new user registration
    if (!initial) {
        configService.setUserRegistrationAllowed(true);
    }
    final String r = random.nextString();
    EUser u = new EUser(null, "a" + r + EXAMPLE_EMAIL, EXAMPLE_NAME + r, EXAMPLE_LAST_NAME, EXAMPLE_PreplacedWORD);
    Resource<EUser> resource = new Resource<>(u);
    mvc.perform(post(apiPrefix + sc.getSignUpUrl()).contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isUnprocessableEnreplacedy());
    // restart initial config
    if (!initial) {
        configService.setUserRegistrationAllowed(false);
    }
}

12 Source : ProcessInstanceResourceAssemblerTest.java
with Apache License 2.0
from Activiti

@Test
public void toResourceShouldReturnResourceWithSelfLinkContainingResourceId() {
    // given
    CloudProcessInstance cloudModel = mock(CloudProcessInstance.clreplaced);
    given(cloudModel.getId()).willReturn("my-identifier");
    ProcessInstance model = mock(ProcessInstance.clreplaced);
    given(toCloudProcessInstanceConverter.from(model)).willReturn(cloudModel);
    // when
    Resource<CloudProcessInstance> resource = resourcereplacedembler.toResource(model);
    // then
    Link selfResourceLink = resource.getLink("self");
    replacedertThat(selfResourceLink).isNotNull();
    replacedertThat(selfResourceLink.getHref()).contains("my-identifier");
}

12 Source : ModelingModelsSteps.java
with Apache License 2.0
from Activiti

@Step
public void checkCurrentModelContainsVariables(String... processVariables) {
    Resource<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);
}

11 Source : ServiceDocumentControllerTest.java
with MIT License
from PacktPublishing

@Test
public void getServiceDoreplacedent() throws Exception {
    String result = mvc.perform(MockMvcRequestBuilders.get("/").accept("application/hal+json;charset=UTF-8")).andDo(print()).andExpect(content().contentTypeCompatibleWith("application/hal+json;charset=UTF-8")).andReturn().getResponse().getContentreplacedtring();
    Resource<String> value = mapper.readValue(result, new TypeReference<Resource<String>>() {
    });
    List<String> linkRels = value.getLinks().stream().map(link -> link.getRel()).collect(Collectors.toList());
    replacedertThat(linkRels, Matchers.hasItem("self"));
    replacedertEquals(value.getLink("self"), value.getId());
    replacedertTrue(value.hasLink("bookmarks"));
}

9 Source : RestUserControllerTest.java
with MIT License
from lealceldeiro

/**
 * Test to be executed by JUnit.
 */
@Test
public void create() throws Exception {
    final String r = random.nextString();
    EUser u = EnreplacedyUtil.getSampleUser(r);
    Resource<EUser> resource = new Resource<>(u);
    ReflectionTestUtils.setField(resource, "links", null);
    ConstrainedFields fields = new ConstrainedFields(EUser.clreplaced);
    mvc.perform(post(apiPrefix + "/" + ResourcePath.USER).contentType(MediaType.APPLICATION_JSON).header(authHeader, tokenType + " " + accessToken).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isCreated()).andDo(restDocResHandler.doreplacedent(requestFields(fields.withPath("username").description(EUserMeta.USERNAME_INFO), fields.withPath("email").description(EUserMeta.EMAIL_INFO), fields.withPath("name").description(EUserMeta.NAME_INFO), fields.withPath("lastName").description(EUserMeta.LAST_NAME_INFO), fields.withPath("preplacedword").description(EUserMeta.PreplacedWORD_INFO), fields.withPath("enabled").optional().description(EUserMeta.ENABLED_INFO), fields.withPath("authorities").optional().ignored(), fields.withPath("emailVerified").optional().ignored(), fields.withPath("accountNonExpired").optional().ignored(), fields.withPath("accountNonLocked").optional().ignored(), fields.withPath("credentialsNonExpired").optional().ignored(), fields.withPath("links").optional().ignored())));
}

9 Source : DefaultControllerAdviceTest.java
with MIT License
from lealceldeiro

/**
 * Test to be executed by JUnit.
 */
@Test
public void handleGmsGeneralException() throws Exception {
    boolean initial = configService.isUserRegistrationAllowed();
    // do not allow new user registration
    if (initial) {
        configService.setUserRegistrationAllowed(false);
    }
    Resource<EUser> resource = getSampleUserResource();
    final MockHttpServletResponse result = mvc.perform(post(apiPrefix + sc.getSignUpUrl()).contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValuereplacedtring(resource))).andReturn().getResponse();
    replacedertNotEquals("Status expected: not <404> but was:<404>", HttpStatus.NOT_FOUND.value(), result.getStatus());
    JSONObject resObj = new JSONObject(result.getContentreplacedtring());
    // request is not supposed to finish ok in this scenario
    String suffix = msg.getMessage("request.finished.KO");
    replacedertTrue("Request is supposed to finish KO in this scenario", resObj.getString(dc.getResMessageHolder()).endsWith(suffix));
    // restart initial config
    if (initial) {
        configService.setUserRegistrationAllowed(true);
    }
}

1 Source : SecurityControllerTest.java
with MIT License
from lealceldeiro

/**
 * Test to be executed by JUnit.
 */
@Test
public void signUp() throws Exception {
    boolean initial = configService.isUserRegistrationAllowed();
    // allow new user registration
    if (!initial) {
        configService.setUserRegistrationAllowed(true);
    }
    final String r = random.nextString();
    EUser u = EnreplacedyUtil.getSampleUser(r);
    u.setEnabled(false);
    Resource<EUser> resource = new Resource<>(u);
    ReflectionTestUtils.setField(resource, "links", null);
    final ConstrainedFields fields = new ConstrainedFields(EUser.clreplaced);
    mvc.perform(post(apiPrefix + sc.getSignUpUrl()).contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValuereplacedtring(resource))).andExpect(status().isCreated()).andDo(restDocResHandler.doreplacedent(requestFields(fields.withPath("username").description(EUserMeta.USERNAME_INFO), fields.withPath("email").description(EUserMeta.EMAIL_INFO), fields.withPath("name").description(EUserMeta.NAME_INFO), fields.withPath("lastName").description(EUserMeta.LAST_NAME_INFO), fields.withPath("preplacedword").description(EUserMeta.PreplacedWORD_INFO), fields.withPath("enabled").optional().description(EUserMeta.ENABLED_INFO), fields.withPath("authorities").optional().ignored(), fields.withPath("emailVerified").optional().ignored(), fields.withPath("accountNonExpired").optional().ignored(), fields.withPath("accountNonLocked").optional().ignored(), fields.withPath("credentialsNonExpired").optional().ignored(), fields.withPath("links").optional().ignored())));
    if (!initial) {
        configService.setUserRegistrationAllowed(false);
    }
}