Package org.apache.ambari.server.api.services

Examples of org.apache.ambari.server.api.services.Request


    verify(request, resource, query);
  }

  @Test
  public void testHandleRequest__InvalidQueryException() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    InvalidQueryException exception = new InvalidQueryException("test");

    expect(request.getResource()).andReturn(resource);
    expect(resource.getQuery()).andReturn(query);

    expect(request.getFields()).andReturn(Collections.<String, TemporalInfo>emptyMap());

    expect(request.getQueryPredicate()).andThrow(exception);
    replay(request, resource, query);

    //test
    ReadHandler handler = new ReadHandler();
    Result result = handler.handleRequest(request);
View Full Code Here


*/
public class DeleteHandlerTest {

  @Test
  public void testHandleRequest__Synchronous() throws Exception {
    Request request = createMock(Request.class);
    ResourceInstance resource = createMock(ResourceInstance.class);
    PersistenceManager pm = createStrictMock(PersistenceManager.class);
    RequestStatus status = createMock(RequestStatus.class);
    Resource resource1 = createMock(Resource.class);
    Resource resource2 = createMock(Resource.class);
    Predicate userPredicate = createNiceMock(Predicate.class);
    Query query = createNiceMock(Query.class);

    Set<Map<String, Object>> setResourceProperties = new HashSet<Map<String, Object>>();

    Set<Resource> setResources = new HashSet<Resource>();
    setResources.add(resource1);
    setResources.add(resource2);

    // expectations
    expect(request.getResource()).andReturn(resource).atLeastOnce();
    expect(request.getHttpBodyProperties()).andReturn(setResourceProperties).atLeastOnce();

    expect(request.getQueryPredicate()).andReturn(userPredicate).atLeastOnce();
    expect(resource.getQuery()).andReturn(query).atLeastOnce();
    query.setUserPredicate(userPredicate);

    expect(pm.delete(resource, setResourceProperties)).andReturn(status);
    expect(status.getStatus()).andReturn(RequestStatus.Status.Complete);
View Full Code Here

    verify(request, resource, pm, status, resource1, resource2, userPredicate, query);
  }

  @Test
  public void testHandleRequest__Asynchronous() throws Exception {
    Request request = createMock(Request.class);
    ResourceInstance resource = createMock(ResourceInstance.class);
    PersistenceManager pm = createStrictMock(PersistenceManager.class);
    RequestStatus status = createMock(RequestStatus.class);
    Resource resource1 = createMock(Resource.class);
    Resource resource2 = createMock(Resource.class);
    Resource requestResource = createMock(Resource.class);

    Set<Map<String, Object>> setResourceProperties = new HashSet<Map<String, Object>>();

    Set<Resource> setResources = new HashSet<Resource>();
    setResources.add(resource1);
    setResources.add(resource2);

    // expectations
    expect(request.getResource()).andReturn(resource);
    expect(request.getHttpBodyProperties()).andReturn(setResourceProperties);
    // test delete with no user predicate
    expect(request.getQueryPredicate()).andReturn(null).atLeastOnce();

    expect(pm.delete(resource, setResourceProperties)).andReturn(status);
    expect(status.getStatus()).andReturn(RequestStatus.Status.Accepted);
    expect(status.getAssociatedResources()).andReturn(setResources);
    expect(resource1.getType()).andReturn(Resource.Type.Cluster).anyTimes();
View Full Code Here

    }
  }

  @Test
  public void testHandleRequest__InvalidQuery() throws Exception {
    Request request = createNiceMock(Request.class);
    ResourceInstance resource = createNiceMock(ResourceInstance.class);
    Exception e = new InvalidQueryException("test exception");

    expect(request.getResource()).andReturn(resource);
    expect(request.getQueryPredicate()).andThrow(e);
    replay(request, resource);

    Result result = new DeleteHandler().handleRequest(request);
    assertEquals(ResultStatus.STATUS.BAD_REQUEST, result.getStatus().getStatus());
    assertTrue(result.getStatus().getMessage().contains(e.getMessage()));
View Full Code Here

*/
public class ReadHandlerTest {

  @Test
  public void testHandleRequest__InvalidField() {
    Request request = createNiceMock(Request.class);
    ResourceInstance resource = createNiceMock(ResourceInstance.class);
    Query query = createStrictMock(Query.class);

    Map<String, TemporalInfo> mapPartialResponseFields = new HashMap<String, TemporalInfo>();
    mapPartialResponseFields.put("foo/bar", null);
    Renderer renderer = new DefaultRenderer();

    expect(request.getResource()).andReturn(resource);
    expect(request.getFields()).andReturn(mapPartialResponseFields);
    expect(request.getRenderer()).andReturn(renderer);
    expect(resource.getQuery()).andReturn(query);

    query.setPageRequest(null);
    query.setRenderer(renderer);
    query.addProperty("foo/bar", null);
View Full Code Here

    verify(request, resource, query);
  }

  @Test
  public void testHandleRequest__OK() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);
    Result result = createStrictMock(Result.class);
    Renderer renderer = new DefaultRenderer();
    Capture<ResultStatus> resultStatusCapture = new Capture<ResultStatus>();

    Map<String, TemporalInfo> mapPartialResponseFields = new HashMap<String, TemporalInfo>();
    mapPartialResponseFields.put("foo", null);
    mapPartialResponseFields.put("bar/c", null);
    mapPartialResponseFields.put("bar/d/e", null);
    mapPartialResponseFields.put("category/", null);
    //expectations
    expect(request.getResource()).andReturn(resource);
    expect(resource.getQuery()).andReturn(query);

    expect(request.getPageRequest()).andReturn(null);
    expect(request.getRenderer()).andReturn(renderer);
    expect(request.getFields()).andReturn(mapPartialResponseFields);

    query.addProperty("foo", null);
    query.addProperty("bar/c", null);
    query.addProperty("bar/d/e", null);
    query.addProperty("category/", null);

    expect(request.getQueryPredicate()).andReturn(predicate);
    query.setUserPredicate(predicate);
    query.setPageRequest(null);
    query.setRenderer(renderer);
    expect(query.execute()).andReturn(result);
    result.setResultStatus(capture(resultStatusCapture));
View Full Code Here

    verify(request, resource, query, predicate, result);
  }

  @Test
  public void testHandleRequest__SystemException() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);
    Renderer renderer = new DefaultRenderer();

    expect(request.getResource()).andReturn(resource);
    expect(resource.getQuery()).andReturn(query);

    expect(request.getPageRequest()).andReturn(null);
    expect(request.getRenderer()).andReturn(renderer);
    expect(request.getFields()).andReturn(Collections.<String, TemporalInfo>emptyMap());

    expect(request.getQueryPredicate()).andReturn(predicate);
    query.setUserPredicate(predicate);
    query.setPageRequest(null);
    query.setRenderer(renderer);
    SystemException systemException = new SystemException("testMsg", new RuntimeException());
    expect(query.execute()).andThrow(systemException);
View Full Code Here

    verify(request, resource, query, predicate);
  }

  @Test
  public void testHandleRequest__NoSuchParentResourceException() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);
    NoSuchParentResourceException exception = new NoSuchParentResourceException("exceptionMsg", new RuntimeException());
    Renderer renderer = new DefaultRenderer();

    expect(request.getResource()).andReturn(resource);
    expect(resource.getQuery()).andReturn(query);

    expect(request.getPageRequest()).andReturn(null);
    expect(request.getRenderer()).andReturn(renderer);
    expect(request.getFields()).andReturn(Collections.<String, TemporalInfo>emptyMap());

    expect(request.getQueryPredicate()).andReturn(predicate);
    query.setUserPredicate(predicate);
    query.setPageRequest(null);
    query.setRenderer(renderer);

    expect(query.execute()).andThrow(exception);
View Full Code Here

    verify(request, resource, query, predicate);
  }

  @Test
  public void testHandleRequest__UnsupportedPropertyException() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);
    Renderer renderer = new DefaultRenderer();
    UnsupportedPropertyException exception = new UnsupportedPropertyException(
        Resource.Type.Cluster, Collections.singleton("foo"));

    expect(request.getResource()).andReturn(resource);
    expect(resource.getQuery()).andReturn(query);

    expect(request.getPageRequest()).andReturn(null);
    expect(request.getRenderer()).andReturn(renderer);
    expect(request.getFields()).andReturn(Collections.<String, TemporalInfo>emptyMap());

    expect(request.getQueryPredicate()).andReturn(predicate);
    query.setUserPredicate(predicate);
    query.setPageRequest(null);
    query.setRenderer(renderer);

    expect(query.execute()).andThrow(exception);
View Full Code Here

    verify(request, resource, query, predicate);
  }

  @Test
  public void testHandleRequest__NoSuchResourceException_OK() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);
    NoSuchResourceException exception = new NoSuchResourceException("msg", new RuntimeException());
    Renderer renderer = new DefaultRenderer();

    expect(request.getResource()).andReturn(resource);
    expect(resource.getQuery()).andReturn(query);

    expect(request.getPageRequest()).andReturn(null);
    expect(request.getRenderer()).andReturn(renderer);
    expect(request.getFields()).andReturn(Collections.<String, TemporalInfo>emptyMap());

    expect(request.getQueryPredicate()).andReturn(predicate).anyTimes();
    query.setUserPredicate(predicate);
    query.setPageRequest(null);
    query.setRenderer(renderer);

    expect(query.execute()).andThrow(exception);
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.api.services.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.