Search in sources :

Example 6 with UserQuery

use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.

the class UserQueryDaoTest method testDeleteUserQueryTags.

@Test
public void testDeleteUserQueryTags() {
    Set<String> accs = new HashSet<String>();
    accs.add("public");
    int count = userQueryDao.deleteUserQueryTags(16, accs);
    UserQuery query = userQueryDao.getUserQueryById(16);
    assertEquals(1, count);
    assertExpectedUserQuery(query, 16, "spongebob", "myquery2", "my second query", true, "another sparql query", "ZZZZZU8V", Sets.<String>newHashSet());
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

Example 7 with UserQuery

use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.

the class UserQueryServiceTest method testGeneratePubIdInCreateUserQuery.

@Test
public void testGeneratePubIdInCreateUserQuery() {
    UserQuery userQuery = createUserQuery("ma requete", "une simple requete", "yet another sparql query", true);
    Mockito.when(dao.createUserQuery(userQuery)).thenThrow(new DuplicateKeyException("ERROR: duplicate key value violates unique constraint \"user_queries_pubid_udx\"\n" + "  Detail: Key (public_id)=(00000002) already exists.")).thenThrow(new DuplicateKeyException("ERROR: duplicate key value violates unique constraint \"user_queries_pubid_udx\"\n" + "  Detail: Key (public_id)=(00000002) already exists.")).thenReturn(1L);
    userQueryService.createUserQuery(userQuery);
    Mockito.verify(stringGenerator, times(3)).generateString();
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) Test(org.junit.Test) AbstractUnitBaseTest(org.nextprot.api.commons.dbunit.AbstractUnitBaseTest)

Example 8 with UserQuery

use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.

the class UserResourceAuthorizationServiceTest method testUpdateUserQueryService2.

@Test(expected = NotAuthorizedException.class)
public void testUpdateUserQueryService2() {
    UserQuery query = mockUserQuery("bobbylapointe");
    Mockito.when(userQueryDao.getUserQueryById(anyLong())).thenReturn(query);
    userQueryService.updateUserQuery(query);
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery) Test(org.junit.Test)

Example 9 with UserQuery

use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.

the class UserResourceAuthorizationServiceTest method mockUserQuery.

private static UserQuery mockUserQuery(String owner) {
    UserQuery query = Mockito.mock(UserQuery.class);
    Mockito.when(query.getOwnerName()).thenReturn(owner);
    Mockito.when(query.getOwnerId()).thenReturn(23L);
    Mockito.when(query.getSparql()).thenReturn("orkfiejjgijrtwithi");
    return query;
}
Also used : UserQuery(org.nextprot.api.user.domain.UserQuery)

Example 10 with UserQuery

use of org.nextprot.api.user.domain.UserQuery in project nextprot-api by calipho-sib.

the class SearchController method runQuery.

/**
 * Useful to build the cache for sparql queries on a target api server (typically build-api.nextprot.org)
 * @param queryId a query public id
 * @return either the number of entries returned by the queries (if query is a snorql only, the number returned will be 0) or an error message
 */
@RequestMapping(value = "/sparql/run", method = { RequestMethod.GET })
@ResponseBody
public Map<String, Object> runQuery(@RequestParam(value = "queryId", required = true) String queryId) {
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("queryId", queryId);
    try {
        UserQuery uq = userQueryService.getUserQueryByPublicId(queryId);
        List<String> entries = sparqlService.findEntries(uq.getSparql(), sparqlEndpoint.getUrl(), uq.getTitle());
        result.put("entryCount", entries.size());
    } catch (Exception e) {
        result.put("error", e.getMessage());
    }
    return result;
}
Also used : HashMap(java.util.HashMap) UserQuery(org.nextprot.api.user.domain.UserQuery) NextProtException(org.nextprot.api.commons.exception.NextProtException) SearchQueryException(org.nextprot.api.commons.exception.SearchQueryException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

UserQuery (org.nextprot.api.user.domain.UserQuery)33 Test (org.junit.Test)20 UserResourceBaseTest (org.nextprot.api.user.dao.test.base.UserResourceBaseTest)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 MVCBaseSecurityTest (org.nextprot.api.web.dbunit.base.mvc.MVCBaseSecurityTest)4 ResultSet (java.sql.ResultSet)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 NextProtException (org.nextprot.api.commons.exception.NextProtException)3 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ApiMethod (org.jsondoc.core.annotation.ApiMethod)2 AbstractUnitBaseTest (org.nextprot.api.commons.dbunit.AbstractUnitBaseTest)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 List (java.util.List)1 SearchQueryException (org.nextprot.api.commons.exception.SearchQueryException)1 SparqlEndpoint (org.nextprot.api.rdf.service.SparqlEndpoint)1