Search in sources :

Example 41 with UserProteinList

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

the class UserProteinListServiceTest method testCreateProteinList.

@Test
public void testCreateProteinList() {
    final UserProteinList proteinList = createUserProteinList("awesome", Sets.newHashSet("NX_P123"));
    dressMockedUserProteinListDao(proteinList, 10);
    UserProteinList created = proteinListService.createUserProteinList(proteinList);
    assertEquals(10, created.getId());
    assertEquals("awesome", created.getName());
    assertEquals(Sets.newHashSet("NX_P123"), created.getAccessionNumbers());
    Mockito.verify(stringGenerator, times(1)).generateString();
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) Test(org.junit.Test) AbstractUnitBaseTest(org.nextprot.api.commons.dbunit.AbstractUnitBaseTest)

Example 42 with UserProteinList

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

the class UserProteinListServiceTest method createUserProteinList.

/*@Test
	public void testAddAccessions() {

		Set<String> s1 = new HashSet<String>();
		s1.add("NX_P123");
		s1.add("NX_P456");

		UserProteinList l1 = proteinListService.createUserProteinList(mockSpongeBobProteinList("cool1", s1));

		Set<String> accs = new HashSet<String>();
		s1.add("NX_P124");

		this.proteinListService.updateUserProteinListMetadata(l1.getId(), accs);
	}

	@Test
	public void testRemoveAccessions() {
		Set<String> s1 = new HashSet<String>();
		s1.add("NX_P123");
		s1.add("NX_P456");

		UserProteinList l1 = this.proteinListService.createUserProteinList(mockSpongeBobProteinList("cool1", s1));

		assertEquals("cool1", l1.getName());
		assertEquals(2, l1.getAccessionNumbers().size());

		Set<String> remAcc = new HashSet<String>();
		remAcc.add("NX_P123");
		this.proteinListService.removeAccessionNumbers(l1.getId(), remAcc);

		l1 = this.proteinListService.getUserProteinListById(l1.getId());
		assertEquals("cool1", l1.getName());
		assertEquals(1, l1.getAccessionNumbers().size());

	}*/
public static UserProteinList createUserProteinList(String name, Set<String> accessions) {
    UserProteinList ul = new UserProteinList();
    ul.setName(name);
    ul.setAccessions(accessions);
    return ul;
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList)

Example 43 with UserProteinList

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

the class UserProteinListServiceTest method testGeneratePubIdInCreateProteinList.

@Test
public void testGeneratePubIdInCreateProteinList() {
    UserProteinList proteinList = createUserProteinList("awesome", Sets.newHashSet("NX_P123"));
    Mockito.when(dao.createUserProteinList(proteinList)).thenThrow(new DuplicateKeyException("PreparedStatementCallback; SQL [INSERT INTO np_users.user_protein_lists (list_name, description, owner_id, public_id)\n" + "VALUES (?, ?, ?, ?);]; ERROR: duplicate key value violates unique constraint \"user_protein_lists_pubid_udx\"\n" + "  Detail: Key (public_id)=(00000001) already exists.; nested exception is org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint \"user_protein_lists_pubid_udx\"\n" + "  Detail: Key (public_id)=(00000001) already exists.")).thenThrow(new DuplicateKeyException("PreparedStatementCallback; SQL [INSERT INTO np_users.user_protein_lists (list_name, description, owner_id, public_id)\n" + "VALUES (?, ?, ?, ?);]; ERROR: duplicate key value violates unique constraint \"user_protein_lists_pubid_udx\"\n" + "  Detail: Key (public_id)=(00000001) already exists.; nested exception is org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint \"user_protein_lists_pubid_udx\"\n" + "  Detail: Key (public_id)=(00000001) already exists.")).thenReturn(1L);
    proteinListService.createUserProteinList(proteinList);
    Mockito.verify(stringGenerator, times(3)).generateString();
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) Test(org.junit.Test) AbstractUnitBaseTest(org.nextprot.api.commons.dbunit.AbstractUnitBaseTest)

Example 44 with UserProteinList

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

the class UserProteinListUtilsTest method testCombineOr.

@Test
public void testCombineOr() {
    UserProteinList l1 = createUserProteinList("cool1", Sets.newHashSet("NX_P123", "NX_P456"));
    UserProteinList l2 = createUserProteinList("cool2", Sets.newHashSet("NX_P123", "NX_P321"));
    UserProteinList l3 = UserProteinListUtils.combine(l1, l2, UserProteinListService.Operator.OR, "bobleponge", "coolio", null);
    assertEquals("coolio", l3.getName());
    assertEquals(3, l3.getAccessionNumbers().size());
    assertEquals("bobleponge", l3.getOwner());
    assertEquals(Sets.newHashSet("NX_P123", "NX_P456", "NX_P321"), l3.getAccessionNumbers());
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) UserProteinListServiceTest.createUserProteinList(org.nextprot.api.user.service.UserProteinListServiceTest.createUserProteinList) Test(org.junit.Test)

Example 45 with UserProteinList

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

the class UserProteinListUtilsTest method testCombineAnd.

@Test
public void testCombineAnd() {
    UserProteinList l1 = createUserProteinList("cool1", Sets.newHashSet("NX_P123", "NX_P456"));
    UserProteinList l2 = createUserProteinList("cool2", Sets.newHashSet("NX_P123", "NX_P321"));
    UserProteinList l3 = UserProteinListUtils.combine(l1, l2, UserProteinListService.Operator.AND, "bobleponge", "homie", null);
    assertEquals("homie", l3.getName());
    assertEquals(1, l3.getAccessionNumbers().size());
    assertEquals("bobleponge", l3.getOwner());
    assertEquals("NX_P123", l3.getAccessionNumbers().iterator().next());
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) UserProteinListServiceTest.createUserProteinList(org.nextprot.api.user.service.UserProteinListServiceTest.createUserProteinList) Test(org.junit.Test)

Aggregations

UserProteinList (org.nextprot.api.user.domain.UserProteinList)51 Test (org.junit.Test)38 UserResourceBaseTest (org.nextprot.api.user.dao.test.base.UserResourceBaseTest)13 UserProteinListServiceTest.createUserProteinList (org.nextprot.api.user.service.UserProteinListServiceTest.createUserProteinList)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 MVCBaseSecurityTest (org.nextprot.api.web.dbunit.base.mvc.MVCBaseSecurityTest)8 HashSet (java.util.HashSet)5 AbstractUnitBaseTest (org.nextprot.api.commons.dbunit.AbstractUnitBaseTest)4 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)3 ApiMethod (org.jsondoc.core.annotation.ApiMethod)2 NextProtException (org.nextprot.api.commons.exception.NextProtException)2 UserQuery (org.nextprot.api.user.domain.UserQuery)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)2 IOException (java.io.IOException)1 List (java.util.List)1 AutocompleteSearchResult (org.nextprot.api.solr.AutocompleteSearchResult)1 Query (org.nextprot.api.solr.Query)1 SearchResult (org.nextprot.api.solr.SearchResult)1