@Before
  public void before() throws ClientPoolException, StorageClientException, AccessDeniedException {

    javax.jcr.Session jcrSession =
        Mockito.mock(
            javax.jcr.Session.class,
            Mockito.withSettings().extraInterfaces(SessionAdaptable.class));
    session = repository.loginAdministrative("ieb");
    Mockito.when(((SessionAdaptable) jcrSession).getSession()).thenReturn(session);
    Mockito.when(resourceResolver.adaptTo(javax.jcr.Session.class)).thenReturn(jcrSession);
    when(request.getRemoteUser()).thenReturn("ieb");
    when(request.getResourceResolver()).thenReturn(resourceResolver);

    servlet = new LiteUserExistsServlet();
  }
  @Before
  public void setUp() throws Exception {
    driver =
        Mockito.mock(
            WebDriver.class, Mockito.withSettings().extraInterfaces(JavascriptExecutor.class));
    js = (JavascriptExecutor) driver;
    // Global Mocks
    Mockito.when(js.executeScript(Mockito.contains("Ext.Ajax.isLoading()")))
        .thenReturn(Boolean.FALSE);
    byExtJsGetCmp = new ByExtJsGetCmp(driver);

    WebElement mockedEl = Mockito.mock(WebElement.class);
    cmpIdBy = byExtJsGetCmp.byExtJsGetCmp("cmp_id");
    Mockito.when(cmpIdBy.findElement(driver)).thenReturn(mockedEl);
  }
Ejemplo n.º 3
0
  private <T> MockData<T> createMethodInvocationControl(
      final String mockName,
      Class<T> type,
      Method[] methods,
      boolean isSpy,
      Object delegator,
      MockSettings mockSettings) {
    final MockSettingsImpl settings;
    if (mockSettings == null) {
      // We change the context classloader to the current CL in order for the Mockito
      // framework to load it's plugins (such as MockMaker) correctly.
      final ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(MockCreator.class.getClassLoader());
      try {
        settings = (MockSettingsImpl) Mockito.withSettings();
      } finally {
        Thread.currentThread().setContextClassLoader(originalCL);
      }
    } else {
      settings = (MockSettingsImpl) mockSettings;
    }

    if (isSpy) {
      settings.defaultAnswer(Mockito.CALLS_REAL_METHODS);
    }

    settings.setMockName(new MockNameImpl(mockName));
    settings.setTypeToMock(type);

    InternalMockHandler mockHandler = new MockHandlerFactory().create(settings);
    MethodInterceptorFilter filter = new PowerMockMethodInterceptorFilter(mockHandler, settings);
    final T mock =
        new ClassImposterizer(new InstantiatorProvider().getInstantiator(settings))
            .imposterise(filter, type);
    ClassLoader classLoader = mock.getClass().getClassLoader();
    if (classLoader instanceof MockClassLoader) {
      MockClassLoader mcl = (MockClassLoader) classLoader;
      mcl.cache(mock.getClass());
    }
    final MockitoMethodInvocationControl invocationControl =
        new MockitoMethodInvocationControl(
            filter, isSpy && delegator == null ? new Object() : delegator, mock, methods);

    return new MockData<T>(invocationControl, mock);
  }
Ejemplo n.º 4
0
  public void execute(Map<String, Object> context, List<String[]> args) {
    if (args.size() != 0) {
      String[] a = args.get(0);
      String name = a[0].trim();
      String leftInput = a[1].trim();

      ObjectSource objectSource = (ObjectSource) context.get(leftInput);

      ObjectSink mockedSink =
          Mockito.mock(ObjectSink.class, Mockito.withSettings().extraInterfaces(DSLMock.class));

      objectSource.addObjectSink(mockedSink);

      context.put(name, mockedSink);
    } else {
      throw new IllegalArgumentException("Cannot parse arguments " + args);
    }
  }
Ejemplo n.º 5
0
  @Test
  public void testProperPost()
      throws ServletException, IOException, RepositoryException, JSONException,
          AccessDeniedException, StorageClientException {
    SlingHttpServletRequest request = createMock(SlingHttpServletRequest.class);
    SlingHttpServletResponse response = createMock(SlingHttpServletResponse.class);

    javax.jcr.Session jcrSession =
        Mockito.mock(
            javax.jcr.Session.class,
            Mockito.withSettings().extraInterfaces(SessionAdaptable.class));
    Session mockSession = mock(Session.class);
    ContentManager contentManager = mock(ContentManager.class);
    when(mockSession.getContentManager()).thenReturn(contentManager);
    Mockito.when(((SessionAdaptable) jcrSession).getSession()).thenReturn(mockSession);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    Mockito.when(resourceResolver.adaptTo(javax.jcr.Session.class)).thenReturn(jcrSession);
    expect(request.getResourceResolver()).andReturn(resourceResolver);

    // Provide parameters
    String[] dimensions = new String[] {"16x16", "32x32"};
    addStringRequestParameter(request, "img", "/~johndoe/people.png");
    addStringRequestParameter(request, "save", "/~johndoe/breadcrumbs");
    addStringRequestParameter(request, "x", "10");
    addStringRequestParameter(request, "y", "10");
    addStringRequestParameter(request, "width", "70");
    addStringRequestParameter(request, "height", "70");
    addStringRequestParameter(request, "dimensions", StringUtils.join(dimensions, 0, ';'));
    expect(request.getRemoteUser()).andReturn("johndoe");

    String imagePath = "a:johndoe/people.png";
    when(contentManager.getInputStream(imagePath))
        .thenReturn(getClass().getClassLoader().getResourceAsStream("people.png"));
    when(contentManager.get(anyString())).thenReturn(new Content("foo", null));

    SparseContentResource someResource = mock(SparseContentResource.class);
    when(someResource.adaptTo(Content.class))
        .thenReturn(
            new Content(
                imagePath,
                ImmutableMap.of(
                    "mimeType", (Object) "image/png", "_bodyLocation", "2011/lt/zz/x8")));
    JackrabbitSession jrSession = mock(JackrabbitSession.class);
    SparseMapUserManager userManager = mock(SparseMapUserManager.class);
    when(userManager.getSession()).thenReturn(mockSession);
    when(jrSession.getUserManager()).thenReturn(userManager);
    when(resourceResolver.adaptTo(javax.jcr.Session.class)).thenReturn(jrSession);
    when(resourceResolver.getResource(anyString())).thenReturn(someResource);

    // Capture output.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter write = new PrintWriter(baos);
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    expect(response.getWriter()).andReturn(write);

    replay();
    servlet.doPost(request, response);
    write.flush();

    String s = baos.toString("UTF-8");
    JSONObject o = new JSONObject(s);

    JSONArray files = o.getJSONArray("files");
    assertEquals(2, files.length());
    for (int i = 0; i < files.length(); i++) {
      String url = files.getString(i);
      assertEquals("/~johndoe/breadcrumbs/" + dimensions[i] + "_people.png", url);
    }
  }