BasicRequestFactory implements RequestFactory { public <RequestType extends ConversationsRequest> Request create(RequestType request) { if (request instanceof ReviewsRequest) { return createFromReviewRequest((ReviewsRequest) request); } else if (request instanceof QuestionAndAnswerRequest) { return createFromQuestionAndAnswerRequest((QuestionAndAnswerRequest) request); }else if (request instanceof ReviewHighlightsRequest) { return createFromReviewHighlightsRequest((ReviewHighlightsRequest) request); } else if (request instanceof CommentsRequest) { return createFromCommentsRequest((CommentsRequest) request); } else if (request instanceof AuthorsRequest) { return createFromAuthorsRequest((AuthorsRequest) request); } else if (request instanceof BulkStoreRequest) { return createFromBulkStoreRequest((BulkStoreRequest) request); } else if (request instanceof BulkRatingsRequest) { return createFromBulkRatingsRequest((BulkRatingsRequest) request); } else if (request instanceof StoreReviewsRequest) { return createFromStoreReviewsRequest((StoreReviewsRequest) request); } else if (request instanceof BulkProductRequest) { return createFromBulkProductRequest((BulkProductRequest) request); } else if (request instanceof ProductDisplayPageRequest) { return createFromProductDisplayPageRequest((ProductDisplayPageRequest) request); } else if (request instanceof FeedbackSubmissionRequest) { return createFromFeedbackSubmissionRequest((FeedbackSubmissionRequest) request); } else if (request instanceof ReviewSubmissionRequest) { return createFromReviewSubmissionRequest((ReviewSubmissionRequest) request); } else if (request instanceof StoreReviewSubmissionRequest) { return createFromStoreReviewSubmissionRequest((StoreReviewSubmissionRequest) request); } else if (request instanceof QuestionSubmissionRequest) { return createFromQuestionSubmissionRequest((QuestionSubmissionRequest) request); } else if (request instanceof AnswerSubmissionRequest) { return createFromAnswerSubmissionRequest((AnswerSubmissionRequest) request); } else if (request instanceof CommentSubmissionRequest) { return createFromCommentSubmissionRequest((CommentSubmissionRequest) request); } else if (request instanceof PhotoUploadRequest) { return createFromPhotoUploadRequest((PhotoUploadRequest) request); } else if (request instanceof UserAuthenticationStringRequest) { return createFromUserAuthenticationStringRequest((UserAuthenticationStringRequest) request); } else if (request instanceof InitiateSubmitRequest) { return createFromInitiateSubmitRequest((InitiateSubmitRequest) request); } else if(request instanceof ProgressiveSubmitRequest) { return createFromProgressiveSubmitRequest((ProgressiveSubmitRequest) request); } throw new IllegalStateException("Unknown request type: " + request.getClass().getCanonicalName()); } BasicRequestFactory(BVMobileInfo bvMobileInfo, BVRootApiUrls bvRootApiUrls, BVConfig bvConfig, String bvSdkUserAgent, FingerprintProvider fingerprintProvider); Request create(RequestType request); static final String kDEVICE_FINGERPRINT; static final String kEMAIL_USER; }
@Test public void displayShouldHaveExtraQueryParams() throws Exception { final ReviewsRequest request = new ReviewsRequest.Builder("some1", 10, 10) .addCustomDisplayParameter("duck duck", "goose") .build(); final Request okRequest = requestFactory.create(request); final HttpUrl url = okRequest.url(); assertTrue(url.queryParameterValues("duck duck").contains("goose")); }
@Test public void displayShouldAllowOneToManyExtraQueryParams() throws Exception { final ReviewsRequest request = new ReviewsRequest.Builder("some1", 10, 10) .addCustomDisplayParameter("foo", "1") .addCustomDisplayParameter("foo", "2") .build(); final Request okRequest = requestFactory.create(request); final HttpUrl url = okRequest.url(); assertTrue(url.queryParameterValues("foo").contains("1")); assertTrue(url.queryParameterValues("foo").contains("2")); }
@Test public void reviewDisplayRequestCreateRequestWithFilter() { final Request okRequest = requestFactory.create(new ReviewsRequest.Builder(ReviewOptions.PrimaryFilter.AuthorId, "1234",10, 0) .build()); assertEquals("AuthorId:eq:1234",okRequest.url().queryParameter("Filter")); }
@Test public void reviewDisplayRequestCreateRequestWithFilterAndProductFilter() { final ReviewsRequest.Builder reviewsRequest = new ReviewsRequest.Builder(ReviewOptions.PrimaryFilter.AuthorId, "1234", 10, 0); reviewsRequest.addFilter(ReviewOptions.Filter.ProductId, EqualityOperator.EQ, "testproduct1"); final Request okRequest = requestFactory.create(reviewsRequest.build()); final List<String> filterParams = okRequest.url().queryParameterValues("Filter"); assertEquals("AuthorId:eq:1234", filterParams.get(0)); assertEquals("ProductId:eq:testproduct1", filterParams.get(1)); }
@Test public void createProductDisplayPageRequest() throws Exception { final ProductDisplayPageRequest request = new ProductDisplayPageRequest.Builder("prod1") .addFilter(ProductOptions.Filter.AverageOverallRating, EqualityOperator.GTE, "3") .addFilter(ProductOptions.Filter.IsActive, EqualityOperator.EQ, "true") .addIncludeContent(PDPContentType.Reviews, 5) .addIncludeContent(PDPContentType.Questions, 3) .addReviewSort(ReviewOptions.Sort.HasPhotos, SortOrder.DESC) .addIncludeStatistics(PDPContentType.Reviews) .build(); final Request okRequest = requestFactory.create(request); assertNotNull(okRequest); System.out.println(okRequest.toString()); final HttpUrl url = okRequest.url(); requestFactoryUtils.assertContainsGenericProperties(okRequest); assertTrue(url.queryParameterValues("Filter").contains("Id:eq:prod1")); assertTrue(url.queryParameterValues("Filter").contains("AverageOverallRating:gte:3")); assertTrue(url.queryParameterValues("Filter").contains("IsActive:eq:true")); assertEquals("Reviews,Questions", url.queryParameter("Include")); assertEquals("5", url.queryParameter("Limit_Reviews")); assertEquals("3", url.queryParameter("Limit_Questions")); assertTrue(url.queryParameterValues("Sort_Reviews").contains("HasPhotos:desc")); assertEquals("Reviews", url.queryParameter("Stats")); }
@Test public void submissionBvHostedAuthStage1_shouldChooseHostedAuthProviderOnly() throws Exception { final ReviewSubmissionRequest request = new ReviewSubmissionRequest.Builder(Action.Submit, "prod1") .authenticationProvider(new BVHostedAuthenticationProvider("red@email.com", "https: .hostedAuthenticationEmail("blue@email.com") .hostedAuthenticationCallback("https: .user("uasbleh") .build(); final Request okRequest = requestFactory.create(request); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "hostedauthentication_authenticationemail", "red%40email.com"); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "hostedauthentication_callbackurl", "https%3A%2F%2Fred.com%2Fauth"); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "User", "uasbleh", false); }
@Test public void submissionBvHostedAuthStage2_shouldChooseHostedAuthProviderOnly() throws Exception { final ReviewSubmissionRequest request = new ReviewSubmissionRequest.Builder(Action.Submit, "prod1") .authenticationProvider(new BVHostedAuthenticationProvider("bvhosteduas")) .hostedAuthenticationEmail("blue@email.com") .hostedAuthenticationCallback("https: .user("uasbleh") .build(); final Request okRequest = requestFactory.create(request); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "hostedauthentication_authenticationemail", "blue%40email.com", false); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "hostedauthentication_callbackurl", "https%3A%2F%2Fblue.com%2Fauth", false); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "User", "bvhosteduas"); }
@Test public void submissionSiteAuth_shouldChooseSiteAuthOnly() throws Exception { final ReviewSubmissionRequest request = new ReviewSubmissionRequest.Builder(Action.Submit, "prod1") .authenticationProvider(new SiteAuthenticationProvider("siteauthuas")) .hostedAuthenticationEmail("blue@email.com") .hostedAuthenticationCallback("https: .user("uasbleh") .build(); final Request okRequest = requestFactory.create(request); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "hostedauthentication_authenticationemail", "blue%40email.com", false); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "hostedauthentication_callbackurl", "https%3A%2F%2Fblue.com%2Fauth", false); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "User", "siteauthuas"); }
@Test public void submissionAuthPieceMeal_shouldExist() throws Exception { final ReviewSubmissionRequest request = new ReviewSubmissionRequest.Builder(Action.Submit, "prod1") .hostedAuthenticationEmail("blue@email.com") .hostedAuthenticationCallback("https: .user("uasbleh") .build(); final Request okRequest = requestFactory.create(request); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "hostedauthentication_authenticationemail", "blue%40email.com"); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "hostedauthentication_callbackurl", "https%3A%2F%2Fblue.com%2Fauth"); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "User", "uasbleh"); }
@Test public void feedbackSubmissionMustAlwaysBePreviewForAction() throws Exception { final FeedbackSubmissionRequest request = new FeedbackSubmissionRequest.Builder("content1").build(); final Request okRequest = requestFactory.create(request); System.out.println(okRequest); requestFactoryUtils.assertFormBodyContainsKeyValEncoded(okRequest, "action", "Preview"); }
@Test public void submissionShouldNotAllowNullFormParams() throws Exception { final ReviewSubmissionRequest request = new ReviewSubmissionRequest.Builder(Action.Preview, "prod1") .isRecommended(null) .build(); final Request okRequest = requestFactory.create(request); requestFactoryUtils.assertFormBodyContainsKeyEncoded(okRequest, "IsRecommended", false); }