List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphabetic
public static String randomAlphabetic(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alphabetic characters.
From source file:org.craftercms.studio.controller.services.rest.ConfigurationControllerTest.java
@Test public void testGetContent() throws Exception { when(this.configurationManagerMock.getContent(Mockito.any(Context.class), Mockito.anyString(), Mockito.any(ItemId.class))).thenReturn(getSampleConfiguration()); this.mockMvc.perform(get("/api/1/config/content/sample") .param("object", RandomStringUtils.randomAlphabetic(10)).accept(MediaType.ALL)) .andExpect(status().isOk()); verify(this.configurationManagerMock, times(1)).getContent(Mockito.any(Context.class), Mockito.anyString(), Mockito.any(ItemId.class)); }
From source file:org.craftercms.studio.controller.services.rest.ConfigurationControllerTest.java
@Test public void testWrite() throws Exception { doAnswer(new Answer<Void>() { @Override//from w w w .ja va 2s . co m public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Object[] args = invocationOnMock.getArguments(); return null; } }).when(this.configurationManagerMock).write(Mockito.any(Context.class), Mockito.anyString(), Mockito.any(ItemId.class), Mockito.any(InputStream.class)); this.mockMvc .perform(post("/api/1/config/write/sample").param("object", RandomStringUtils.randomAlphabetic(10)) .content(generateRequestBody(createWriteRequest()).getBytes()) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.ALL)) .andExpect(status().isOk()); verify(this.configurationManagerMock, times(1)).write(Mockito.any(Context.class), Mockito.anyString(), Mockito.any(ItemId.class), Mockito.any(InputStream.class)); }
From source file:org.craftercms.studio.controller.services.rest.ConfigurationControllerTest.java
@Test public void testWriteMissingRequestBody() throws Exception { doAnswer(new Answer<Void>() { @Override/*from w ww .j a va 2s .c om*/ public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Object[] args = invocationOnMock.getArguments(); return null; } }).when(this.configurationManagerMock).write(Mockito.any(Context.class), Mockito.anyString(), Mockito.any(ItemId.class), Mockito.any(InputStream.class)); this.mockMvc .perform(post("/api/1/config/write/sample").param("object", RandomStringUtils.randomAlphabetic(10)) .content(StringUtils.EMPTY).contentType(MediaType.APPLICATION_JSON).accept(MediaType.ALL)) .andExpect(status().isBadRequest()); verify(this.configurationManagerMock, times(0)).write(Mockito.any(Context.class), Mockito.anyString(), Mockito.any(ItemId.class), Mockito.any(InputStream.class)); }
From source file:org.craftercms.studio.controller.services.rest.DependencyControllerTest.java
@Test public void testAdd() throws Exception { doAnswer(new Answer<Void>() { @Override/*from w w w . jav a2 s. c o m*/ public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Object[] args = invocationOnMock.getArguments(); return null; } }).when(this.dependencyManagerMock).add(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); String itemsJSONList = generateRequestBody(generateItemListMock()); this.mockMvc.perform(post("/api/1/dependency/add/sample").accept(MediaType.ALL).param("itemId", "1") .param("operation", RandomStringUtils.randomAlphabetic(10)).content(itemsJSONList.getBytes())) .andExpect(status().isOk()); verify(this.dependencyManagerMock, times(1)).add(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); }
From source file:org.craftercms.studio.controller.services.rest.DependencyControllerTest.java
@Test public void testAddMissingItemId() throws Exception { doAnswer(new Answer<Void>() { @Override//from w w w. j a v a2 s . c om public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Object[] args = invocationOnMock.getArguments(); return null; } }).when(this.dependencyManagerMock).add(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); String itemsJSONList = generateRequestBody(generateItemListMock()); this.mockMvc.perform(post("/api/1/dependency/add/sample").accept(MediaType.ALL) .param("operation", RandomStringUtils.randomAlphabetic(10)).content(itemsJSONList.getBytes())) .andExpect(status().isBadRequest()); verify(this.dependencyManagerMock, times(0)).add(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); }
From source file:org.craftercms.studio.controller.services.rest.DependencyControllerTest.java
@Test public void testAddMissingDependencies() throws Exception { doAnswer(new Answer<Void>() { @Override/*from w ww .j a v a 2 s. c o m*/ public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Object[] args = invocationOnMock.getArguments(); return null; } }).when(this.dependencyManagerMock).add(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); this.mockMvc.perform(post("/api/1/dependency/add/sample").accept(MediaType.ALL).param("itemId", "1") .param("operation", RandomStringUtils.randomAlphabetic(10)).content(StringUtils.EMPTY.getBytes())) .andExpect(status().isBadRequest()); verify(this.dependencyManagerMock, times(0)).add(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); }
From source file:org.craftercms.studio.controller.services.rest.DependencyControllerTest.java
@Test public void testRemove() throws Exception { doAnswer(new Answer<Void>() { @Override/*w w w.j a v a2 s. co m*/ public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Object[] args = invocationOnMock.getArguments(); return null; } }).when(this.dependencyManagerMock).remove(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); String itemsJSONList = generateRequestBody(generateItemListMock()); this.mockMvc.perform(post("/api/1/dependency/remove/sample").accept(MediaType.ALL).param("itemId", "1") .param("operation", RandomStringUtils.randomAlphabetic(10)).content(itemsJSONList.getBytes())) .andExpect(status().isOk()); verify(this.dependencyManagerMock, times(1)).remove(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); }
From source file:org.craftercms.studio.controller.services.rest.DependencyControllerTest.java
@Test public void testRemoveMissingItemId() throws Exception { doAnswer(new Answer<Void>() { @Override/*from w w w.j a va 2s. co m*/ public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Object[] args = invocationOnMock.getArguments(); return null; } }).when(this.dependencyManagerMock).remove(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); String itemsJSONList = generateRequestBody(generateItemListMock()); this.mockMvc.perform(post("/api/1/dependency/remove/sample").accept(MediaType.ALL) .param("operation", RandomStringUtils.randomAlphabetic(10)).content(itemsJSONList.getBytes())) .andExpect(status().isBadRequest()); verify(this.dependencyManagerMock, times(0)).remove(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); }
From source file:org.craftercms.studio.controller.services.rest.DependencyControllerTest.java
@Test public void testRemoveMissingDependencies() throws Exception { doAnswer(new Answer<Void>() { @Override/* w w w. j a v a 2s . co m*/ public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Object[] args = invocationOnMock.getArguments(); return null; } }).when(this.dependencyManagerMock).remove(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); this.mockMvc.perform(post("/api/1/dependency/remove/sample").accept(MediaType.ALL).param("itemId", "1") .param("operation", RandomStringUtils.randomAlphabetic(10)).content(StringUtils.EMPTY.getBytes())) .andExpect(status().isBadRequest()); verify(this.dependencyManagerMock, times(0)).remove(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); }
From source file:org.craftercms.studio.controller.services.rest.DependencyControllerTest.java
@Test public void testUpdate() throws Exception { doAnswer(new Answer<Void>() { @Override//from ww w. ja va 2 s. c o m public Void answer(InvocationOnMock invocationOnMock) throws Throwable { Object[] args = invocationOnMock.getArguments(); return null; } }).when(this.dependencyManagerMock).update(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); String itemsJSONList = generateRequestBody(generateItemListMock()); this.mockMvc.perform(post("/api/1/dependency/update/sample").accept(MediaType.ALL).param("itemId", "1") .param("operation", RandomStringUtils.randomAlphabetic(10)).content(itemsJSONList.getBytes())) .andExpect(status().isOk()); verify(this.dependencyManagerMock, times(1)).update(Mockito.any(Context.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyListOf(Item.class)); }