Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding accend to table. #228

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public void importTopics(@RequestBody String topics) throws Exception {

@RequestMapping(value = "for", method = POST)
public Topic addFor(@RequestParam String uri, @RequestParam String name) throws Exception {
hasLength(name);
Topic topic = commonDao.get(Topic.class, "name", name);
if (topic == null) topic = commonDao.save(new Topic(name));
linkDao.save(new Link(topic, commonDao.get(UriGenerator.getClassByUri(uri), uri)));
Expand Down
60 changes: 53 additions & 7 deletions src/test/java/org/ayfaar/app/controllers/TopicControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.RestAssured.when;

@RunWith(SpringJUnit4ClassRunner.class)
Expand All @@ -19,17 +20,62 @@
public class TopicControllerTest {
@Test
public void testGet() {
when().
get("/api/topic/{name}/add-child/{child}", "1", "2").
then()
.log().all().
statusCode(HttpStatus.SC_OK);

// todo добавить ещё чайлда "3" и парента "4"

when().
get("/api/topic/{name}", "1").
then().
log().all().
statusCode(HttpStatus.SC_OK).
body("name", Matchers.is("1")).
body("uri", Matchers.is("тема:1")).
body("children", Matchers.hasItems("3", "2")).
body("parents", Matchers.hasItem("4"))
;
}

@Test
public void testAddFor() {
given().
contentType("application/x-www-form-urlencoded; charset=UTF-8"). // это чтобы русский понимал в параметрах
param("name", "1"). // имя темы
param("uri", "видео:youtube:_8vYBLrOq-w"). // uri объекта к которому прилинковать тему
when().
get("/api/topic/{name}", "1").
then().
post("/api/topic/for").
then().
log().all().
statusCode(HttpStatus.SC_OK).
statusCode(HttpStatus.SC_OK)
;
}

body("name", Matchers.is("1")).
body("uri", Matchers.is("тема:1")).
body("children", Matchers.hasItems("3", "2")).
body("parents", Matchers.hasItem("4"))
@Test
public void testAddChild() {
when().
get("/api/topic/{name}/add-child/{child}", "1", "2").
then().
log().all().
statusCode(HttpStatus.SC_OK)
;
}



@Test
public void testUnLink() {
// сначала прилинковываем
when().get("/api/topic/{name}/add-child/{child}", "1", "2").then().statusCode(HttpStatus.SC_OK);

when().
get("/api/topic/{name}/unlink/{linked}", "1", "2").
then().
log().all().
statusCode(HttpStatus.SC_OK)
;
}
}