• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MockLowLevelHttpResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.api.client.testing.http.MockLowLevelHttpResponse的典型用法代码示例。如果您正苦于以下问题:Java MockLowLevelHttpResponse类的具体用法?Java MockLowLevelHttpResponse怎么用?Java MockLowLevelHttpResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MockLowLevelHttpResponse类属于com.google.api.client.testing.http包,在下文中一共展示了MockLowLevelHttpResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testSetCustomAttributes

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void testSetCustomAttributes() throws Exception {
  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
  response.setContent(TestUtils.loadResource("createUser.json"));
  MockHttpTransport transport = new MockHttpTransport.Builder()
      .setLowLevelHttpResponse(response)
      .build();
  FirebaseUserManager userManager = new FirebaseUserManager(gson, transport, credentials);
  TestResponseInterceptor interceptor = new TestResponseInterceptor();
  userManager.setInterceptor(interceptor);
  // should not throw
  ImmutableMap<String, Object> claims = ImmutableMap.<String, Object>of(
      "admin", true, "package", "gold");
  JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
  userManager.updateUser(new UpdateRequest("testuser")
      .setCustomClaims(claims), jsonFactory);
  checkRequestHeaders(interceptor);

  ByteArrayOutputStream out = new ByteArrayOutputStream();
  interceptor.getResponse().getRequest().getContent().writeTo(out);
  GenericJson parsed = jsonFactory.fromString(new String(out.toByteArray()), GenericJson.class);
  assertEquals("testuser", parsed.get("localId"));
  assertEquals(jsonFactory.toString(claims), parsed.get("customAttributes"));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:25,代码来源:FirebaseUserManagerTest.java


示例2: testGetUserMalformedJsonError

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void testGetUserMalformedJsonError() throws Exception {
  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
  response.setContent("{\"not\" json}");
  MockHttpTransport transport = new MockHttpTransport.Builder()
      .setLowLevelHttpResponse(response)
      .build();
  FirebaseUserManager userManager = new FirebaseUserManager(gson, transport, credentials);
  try {
    userManager.getUserById("testuser");
    fail("No error thrown for JSON error");
  }  catch (FirebaseAuthException e) {
    assertTrue(e.getCause() instanceof IOException);
    assertEquals(FirebaseUserManager.INTERNAL_ERROR, e.getErrorCode());
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:17,代码来源:FirebaseUserManagerTest.java


示例3: testGetUserUnexpectedHttpError

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void testGetUserUnexpectedHttpError() throws Exception {
  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
  response.setContent("{\"not\" json}");
  response.setStatusCode(500);
  MockHttpTransport transport = new MockHttpTransport.Builder()
      .setLowLevelHttpResponse(response)
      .build();
  FirebaseUserManager userManager = new FirebaseUserManager(gson, transport, credentials);
  try {
    userManager.getUserById("testuser");
    fail("No error thrown for JSON error");
  }  catch (FirebaseAuthException e) {
    assertTrue(e.getCause() instanceof HttpResponseException);
    assertEquals("Unexpected HTTP response with status: 500; body: {\"not\" json}",
        e.getMessage());
    assertEquals(FirebaseUserManager.INTERNAL_ERROR, e.getErrorCode());
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:20,代码来源:FirebaseUserManagerTest.java


示例4: configureMock

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
protected static HttpTransport configureMock() {
    return new MockHttpTransport() {
        @Override
        public LowLevelHttpRequest buildRequest(String method, final String url) throws IOException {
            return new MockLowLevelHttpRequest() {
                @Override
                public LowLevelHttpResponse execute() throws IOException {
                    MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
                    response.setStatusCode(200);
                    response.setContentType(Json.MEDIA_TYPE);
                    if (url.startsWith(GCE_METADATA_URL)) {
                        logger.info("--> Simulate GCE Auth/Metadata response for [{}]", url);
                        response.setContent(readGoogleInternalJsonResponse(url));
                    } else {
                        logger.info("--> Simulate GCE API response for [{}]", url);
                        response.setContent(readGoogleApiJsonResponse(url));
                    }

                    return response;
                }
            };
        }
    };
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:GceMockUtils.java


示例5: buildRequest

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
  callCount ++;

  if (!HttpMethods.GET.equals(method) || !expectedUrl.equals(url)) {
    // Throw RuntimeException to fail the test.
    throw new RuntimeException();
  }

  return new MockLowLevelHttpRequest() {
    @Override
    public LowLevelHttpResponse execute() throws IOException {
      MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
      response.setStatusCode(HttpStatusCodes.STATUS_CODE_OK);
      response.setContentType(Json.MEDIA_TYPE);
      response.setContent(jsonResponse);
      return response;
    }
  };
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:21,代码来源:DefautKeyUriSupplierTest.java


示例6: buildRequest

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
  return new MockLowLevelHttpRequest() {
    @Override
    public LowLevelHttpResponse execute() throws IOException {
      if (ioException != null) {
        throw ioException;
      }
      MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
      response.setStatusCode(HttpStatus.SC_ACCEPTED);
      response.setContentType(Json.MEDIA_TYPE);
      response.setContent(content);
      return response;
    }
  };
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:17,代码来源:DefaultJwksSupplierTest.java


示例7: mockClient

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
/**
 * Return a Client that is mocked to return the given HTTP response.
 *
 * @param httpResponse The full HTTP response data
 * @return The Client instance
 */
public Client mockClient(final String httpResponse) {
  Client client = new Client();

  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          return mockResponse(response, httpResponse);
        }
      };
    }
  };

  client.setTransport(transport);

  return client;
}
 
开发者ID:dnsimple,项目名称:dnsimple-java,代码行数:27,代码来源:DnsimpleTestBase.java


示例8: constructHttpRequest

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
private HttpRequest constructHttpRequest(final String content) throws IOException {
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
          result.setContentType("application/json");
          result.setContent(content);
          return result;
        }
      };
    }
  };
  return transport.createRequestFactory().buildGetRequest(new GenericUrl("https://google.com"))
      .setParser(new JsonObjectParser(new JacksonFactory()));
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:19,代码来源:GoogleAuthTest.java


示例9: buildHttpResponse

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
/**
 * Builds a HttpResponse with the given string response.
 *
 * @param header header value to provide or null if none.
 * @param uploadId upload id to provide in the url upload id param or null if none.
 * @param uploadType upload type to provide in url upload type param or null if none.
 * @return HttpResponse with the given parameters
 * @throws IOException
 */
private HttpResponse buildHttpResponse(String header, String uploadId, String uploadType)
    throws IOException {
  MockHttpTransport.Builder builder = new MockHttpTransport.Builder();
  MockLowLevelHttpResponse resp = new MockLowLevelHttpResponse();
  builder.setLowLevelHttpResponse(resp);
  resp.setStatusCode(200);
  GenericUrl url = new GenericUrl(HttpTesting.SIMPLE_URL);
  if (header != null) {
    resp.addHeader("X-GUploader-UploadID", header);
  }
  if (uploadId != null) {
    url.put("upload_id", uploadId);
  }
  if (uploadType != null) {
    url.put("uploadType", uploadType);
  }
  return builder.build().createRequestFactory().buildGetRequest(url).execute();
}
 
开发者ID:apache,项目名称:beam,代码行数:28,代码来源:UploadIdResponseInterceptorTest.java


示例10: testFileSizeWhenFileNotFoundNonBatch

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void testFileSizeWhenFileNotFoundNonBatch() throws Exception {
  MockLowLevelHttpResponse notFoundResponse = new MockLowLevelHttpResponse();
  notFoundResponse.setContent("");
  notFoundResponse.setStatusCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND);

  MockHttpTransport mockTransport =
          new MockHttpTransport.Builder().setLowLevelHttpResponse(notFoundResponse).build();

  GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
  GcsUtil gcsUtil = pipelineOptions.getGcsUtil();

  gcsUtil.setStorageClient(new Storage(mockTransport, Transport.getJsonFactory(), null));

  thrown.expect(FileNotFoundException.class);
  gcsUtil.fileSize(GcsPath.fromComponents("testbucket", "testobject"));
}
 
开发者ID:apache,项目名称:beam,代码行数:18,代码来源:GcsUtilTest.java


示例11: createMockTransport

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
private MockHttpTransport createMockTransport (final ByteSource iirdeaResponse) {
  return new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      mockRequest = new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          response.setContentType(PLAIN_TEXT_UTF_8.toString());
          response.setContent(iirdeaResponse.read());
          return response;
        }
      };
      mockRequest.setUrl(url);
      return mockRequest;
    }
  };
}
 
开发者ID:google,项目名称:nomulus,代码行数:20,代码来源:IcannHttpReporterTest.java


示例12: makeResponseException

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
/** Returns a valid GoogleJsonResponseException for the given status code and error message.  */
private GoogleJsonResponseException makeResponseException(
    final int statusCode,
    final String message) throws Exception {
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(statusCode);
          response.setContentType(Json.MEDIA_TYPE);
          response.setContent(String.format(
              "{\"error\":{\"code\":%d,\"message\":\"%s\",\"domain\":\"global\","
              + "\"reason\":\"duplicate\"}}",
              statusCode,
              message));
          return response;
        }};
    }};
  HttpRequest request = transport.createRequestFactory()
      .buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL)
      .setThrowExceptionOnExecuteError(false);
  return GoogleJsonResponseException.from(new JacksonFactory(), request.execute());
}
 
开发者ID:google,项目名称:nomulus,代码行数:27,代码来源:DirectoryGroupsConnectionTest.java


示例13: sendFirebaseMessage_create

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void sendFirebaseMessage_create() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  firebaseChannel.sendFirebaseMessage("my_key", new Game());

  verify(mockHttpTransport, times(1)).buildRequest(
      "PATCH", FIREBASE_DB_URL + "/channels/my_key.json");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java


示例14: sendFirebaseMessage_delete

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void sendFirebaseMessage_delete() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  firebaseChannel.sendFirebaseMessage("my_key", null);

  verify(mockHttpTransport, times(1)).buildRequest(
      "DELETE", FIREBASE_DB_URL + "/channels/my_key.json");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java


示例15: firebasePut

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void firebasePut() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;
  Game game = new Game();

  firebaseChannel.firebasePut(FIREBASE_DB_URL + "/my/path", game);

  verify(mockHttpTransport, times(1)).buildRequest("PUT", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java


示例16: firebasePatch

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void firebasePatch() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;
  Game game = new Game();

  firebaseChannel.firebasePatch(FIREBASE_DB_URL + "/my/path", game);

  verify(mockHttpTransport, times(1)).buildRequest("PATCH", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java


示例17: firebasePost

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void firebasePost() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;
  Game game = new Game();

  firebaseChannel.firebasePost(FIREBASE_DB_URL + "/my/path", game);

  verify(mockHttpTransport, times(1)).buildRequest("POST", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:25,代码来源:FirebaseChannelTest.java


示例18: firebaseGet

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void firebaseGet() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  firebaseChannel.firebaseGet(FIREBASE_DB_URL + "/my/path");

  verify(mockHttpTransport, times(1)).buildRequest("GET", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:24,代码来源:FirebaseChannelTest.java


示例19: firebaseDelete

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void firebaseDelete() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  firebaseChannel.firebaseDelete(FIREBASE_DB_URL + "/my/path");

  verify(mockHttpTransport, times(1)).buildRequest("DELETE", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:24,代码来源:FirebaseChannelTest.java


示例20: firebaseGet

import com.google.api.client.testing.http.MockLowLevelHttpResponse; //导入依赖的package包/类
@Test
public void firebaseGet() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport =
      spy(
          new MockHttpTransport() {
            @Override
            public LowLevelHttpRequest buildRequest(String method, String url)
                throws IOException {
              return new MockLowLevelHttpRequest() {
                @Override
                public LowLevelHttpResponse execute() throws IOException {
                  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
                  response.setStatusCode(200);
                  return response;
                }
              };
            }
          });
  FirebaseChannel.getInstance().httpTransport = mockHttpTransport;

  firebaseChannel.firebaseGet(FIREBASE_DB_URL + "/my/path");

  verify(mockHttpTransport, times(1)).buildRequest("GET", FIREBASE_DB_URL + "/my/path");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:FirebaseChannelTest.java



注:本文中的com.google.api.client.testing.http.MockLowLevelHttpResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ShortWritable类代码示例发布时间:2022-05-21
下一篇:
Java Plugin类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap