Search in sources :

Example 6 with UserProteinList

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

the class UserProteinListControllerIntegrationTest method leonardShouldBeAbleToAndCombineProteinLists.

// --------------------------------- GET PROTEINS ACC NUMBERS -----------------------------------------
/* Test is not applicable
	@Test
	public void leonardShouldBeAbleToLookAtHisOwnProteinListAccessionNumbers() throws Exception {

		String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));

		// call Set<String> getUserProteinListAccessionNumbers()
		String responseString = this.mockMvc.perform(get("/user/me/lists/leonardslist1/accnums").header("Authorization", "Bearer " + leonardToken)
				.accept(MediaType.APPLICATION_JSON))
				.andExpect(status().isOk())
				.andReturn().getResponse().getContentAsString();

		Set<String> accessionNumbers = new ObjectMapper().readValue(responseString, new TypeReference<Set<String>>() { });

		assertEquals(Sets.newHashSet("NX_Q14239","NX_Q8N5Z0","NX_P05185"), accessionNumbers);
	}

	@Test
	public void sheldonIsForbiddenToLookAtLeonardsProteinListAccessionNumbers() throws Exception {

		String sheldonToken = generateTokenWithExpirationDate("sheldon", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER" ));

		// call Set<String> getUserProteinListAccessionNumbers()
		this.mockMvc.perform(get("/user/me/lists/157/accnums").
				header("Authorization", "Bearer " + sheldonToken).accept(MediaType.APPLICATION_JSON)).
				andExpect(status().isForbidden());
	}*/
// --------------------------------- GET COMBINED PROTEIN LIST ----------------------------------------
@Test
public void leonardShouldBeAbleToAndCombineProteinLists() throws Exception {
    String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
    // call UserProteinList combineUserProteinList()
    String responseString = this.mockMvc.perform(get("/user/me/lists/combine?listname=leonardslist3&listname1=leonardslist1&listname2=leonardslist2&op=AND").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    UserProteinList userProteinList = new ObjectMapper().readValue(responseString, new TypeReference<UserProteinList>() {
    });
    assertEquals(23, userProteinList.getOwnerId());
    assertEquals(Sets.newHashSet("NX_Q8N5Z0"), userProteinList.getAccessionNumbers());
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) MVCBaseSecurityTest(org.nextprot.api.web.dbunit.base.mvc.MVCBaseSecurityTest)

Example 7 with UserProteinList

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

the class UserProteinListControllerIntegrationTest method leonardShouldBeAbleToNotInCombineProteinLists.

@Test
public void leonardShouldBeAbleToNotInCombineProteinLists() throws Exception {
    String leonardToken = generateTokenWithExpirationDate("leonard", 1, TimeUnit.DAYS, Arrays.asList("ROLE_USER"));
    // call UserProteinList combineUserProteinList()
    String responseString = this.mockMvc.perform(get("/user/me/lists/combine?listname=leonardslist3&listname1=leonardslist1&listname2=leonardslist2&op=NOT_IN").header("Authorization", "Bearer " + leonardToken).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
    UserProteinList userProteinList = new ObjectMapper().readValue(responseString, new TypeReference<UserProteinList>() {
    });
    assertEquals(23, userProteinList.getOwnerId());
    assertEquals(Sets.newHashSet("NX_Q14239", "NX_P05185"), userProteinList.getAccessionNumbers());
}
Also used : UserProteinList(org.nextprot.api.user.domain.UserProteinList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) MVCBaseSecurityTest(org.nextprot.api.web.dbunit.base.mvc.MVCBaseSecurityTest)

Example 8 with UserProteinList

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

the class UserProteinListServiceTest method testGeneratePubIdInCreateProteinList2.

@Test(expected = DuplicateKeyException.class)
public void testGeneratePubIdInCreateProteinList2() {
    UserProteinList proteinList = createUserProteinList("awesome", Sets.newHashSet("NX_P123"));
    Mockito.when(dao.createUserProteinList(proteinList)).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).thenThrow(new DuplicateKeyException("user_protein_lists_pubid_udx")).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 9 with UserProteinList

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

the class UserProteinListServiceTest method testGeneratePubIdInCreateProteinList3.

@Test(expected = DuplicateKeyException.class)
public void testGeneratePubIdInCreateProteinList3() {
    UserProteinList proteinList = createUserProteinList("awesome", Sets.newHashSet("NX_P123"));
    Mockito.when(dao.createUserProteinList(proteinList)).thenThrow(new DuplicateKeyException("")).thenReturn(1L);
    proteinListService.createUserProteinList(proteinList);
}
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 10 with UserProteinList

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

the class UserProteinListUtilsTest method testCombineNotInEmptySetThrowsException.

@Test(expected = NextProtException.class)
public void testCombineNotInEmptySetThrowsException() {
    UserProteinList l1 = createUserProteinList("cool1", Sets.newHashSet("NX_P123", "NX_P456"));
    UserProteinList l2 = createUserProteinList("cool2", Sets.newHashSet("NX_P123", "NX_P456"));
    UserProteinListUtils.combine(l1, l2, UserProteinListService.Operator.NOT_IN, "bobleponge", "coolio", null);
}
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