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());
}
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());
}
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();
}
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);
}
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);
}
Aggregations