Skip to content

Commit

Permalink
#57
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhrobbins committed Dec 1, 2014
1 parent 7b4bf6f commit 1b708c3
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ public FlashCardDto findByQuestion(final String question) throws ServiceExceptio
public List<FlashCardDto> findFlashcardsForTag(Long tagId, Set<String> fields) throws FlashcardsException {
Map<String, String> uriVariables = new HashMap<String, String>();
uriVariables.put("tagId", String.valueOf(tagId));
return Arrays.asList(searchEntities(getEntityListUrl(), uriVariables, FlashCardDto[].class));
return Arrays.asList(searchEntities(getServerAddress() + ResourceUrls.flashcardsForTag, uriVariables, FlashCardDto[].class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.robbins.flashcards.client.util.ResourceUrls;
import org.robbins.flashcards.dto.TagDto;
import org.robbins.flashcards.exceptions.FlashcardsException;
import org.robbins.flashcards.exceptions.ServiceException;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -65,6 +64,6 @@ public TagDto findByName(final String name) throws ServiceException {
public List<TagDto> findTagsForFlashcard(final Long flashcardId, final Set<String> fields) {
Map<String, String> uriVariables = new HashMap<String, String>();
uriVariables.put("flashcardId", String.valueOf(flashcardId));
return Arrays.asList(searchEntities(getEntityListUrl(), uriVariables, TagDto[].class));
return Arrays.asList(searchEntities(getServerAddress() + ResourceUrls.tagsForFlashcard, uriVariables, TagDto[].class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ private ResourceUrls() {
public static final String userUpdate = "v1/users/{id}/update";

public static final String status = "status/";

public static final String tagsForFlashcard = "v1/flashcards/{flashcardId}/tags";

public static final String flashcardsForTag = "v1/tags/{tagId}/flashcards";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

import javax.inject.Inject;

import com.google.common.collect.Sets;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.robbins.flashcards.client.FlashcardClient;
import org.robbins.flashcards.client.GenericRestCrudFacade;
import org.robbins.flashcards.client.TagClient;
import org.robbins.flashcards.dto.FlashCardDto;
import org.robbins.flashcards.dto.TagDto;
import org.robbins.flashcards.exceptions.FlashcardsException;
Expand Down Expand Up @@ -46,6 +48,9 @@ public FlashCardDto getEntity() {
@Inject
private FlashcardClient client;

@Inject
private TagClient tagClient;

@Override
public GenericRestCrudFacade<FlashCardDto> getClient() {
return client;
Expand Down Expand Up @@ -103,4 +108,26 @@ public void createNewFlashCard_WithNewTag() throws FlashcardsException {

client.delete(newFlashCard.getId());
}

@Test
public void testFindFlashcardsForTag() throws FlashcardsException {
FlashCardDto flashCard = setupFlashcard();

List<FlashCardDto> results = client.findFlashcardsForTag(flashCard.getTags().iterator().next().getId(), null);
assertTrue(results != null);
assertTrue(results.size() == 1);

cleanupFlashcard(flashCard);
}

private FlashCardDto setupFlashcard() throws FlashcardsException {
FlashCardDto flashCardDto = TestDtoGenerator.createFlashCardDto("question", "answer");
flashCardDto.setTags(Sets.newHashSet(new TagDto("tag_name")));
return client.save(flashCardDto);
}

private void cleanupFlashcard(FlashCardDto flashCard) {
client.delete(flashCard.getId());
tagClient.delete(flashCard.getTags().iterator().next().getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@

import javax.inject.Inject;

import com.google.common.collect.Sets;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.robbins.flashcards.client.FlashcardClient;
import org.robbins.flashcards.client.GenericRestCrudFacade;
import org.robbins.flashcards.client.TagClient;
import org.robbins.flashcards.dto.FlashCardDto;
import org.robbins.flashcards.dto.TagDto;
import org.robbins.flashcards.exceptions.FlashcardsException;
import org.robbins.flashcards.tests.webservices.GenericEntityRestTest;
import org.robbins.flashcards.util.TestDtoGenerator;
import org.robbins.tests.IntegrationTest;
import org.springframework.test.context.ContextConfiguration;

import java.util.HashSet;
import java.util.List;

@Category(IntegrationTest.class)
@ContextConfiguration(locations = {"classpath*:applicatonContext-client.xml"})
public class TagsResourceIT extends GenericEntityRestTest<TagDto> {
Expand All @@ -29,6 +35,9 @@ public class TagsResourceIT extends GenericEntityRestTest<TagDto> {
@Inject
private TagClient client;

@Inject
private FlashcardClient flashcardClient;

@Override
public GenericRestCrudFacade<TagDto> getClient() {
return client;
Expand All @@ -44,9 +53,6 @@ public TagDto getEntity() {
return this.entity;
}

/**
* Test search by facility in.
*/
@Test
public void testSearchByName() throws FlashcardsException
{
Expand All @@ -57,9 +63,6 @@ public void testSearchByName() throws FlashcardsException
assertEquals(searchResult.getName(), TAG_NAME);
}

/**
* Execute updateEntity.
*/
@Test
public void testUpdateEntity() throws FlashcardsException {
final Long id = getEntity().getId();
Expand All @@ -74,4 +77,35 @@ public void testUpdateEntity() throws FlashcardsException {
final TagDto retrievedEntity = client.findOne(id);
assertEquals(UPDATED_VALUE, retrievedEntity.getName());
}

@Test
public void testFindByCreatedBy() throws FlashcardsException {
final Long userId = 4L;
List<TagDto> results = client.findByCreatedBy(userId, null);

assertTrue(results != null);
assertTrue(results.size() > 0);
}

@Test
public void testFindTagsForFlashcard() throws FlashcardsException {
FlashCardDto flashCard = setupFlashcard();

List<TagDto> results = client.findTagsForFlashcard(flashCard.getId(), null);
assertTrue(results != null);
assertTrue(results.size() == 1);

cleanupFlashcard(flashCard);
}

private FlashCardDto setupFlashcard() throws FlashcardsException {
FlashCardDto flashCardDto = TestDtoGenerator.createFlashCardDto("question", "answer");
flashCardDto.setTags(Sets.newHashSet(new TagDto("tag_name")));
return flashcardClient.save(flashCardDto);
}

private void cleanupFlashcard(FlashCardDto flashCard) {
flashcardClient.delete(flashCard.getId());
client.delete(flashCard.getTags().iterator().next().getId());
}
}

0 comments on commit 1b708c3

Please sign in to comment.