private static String generatePayPalNonce(BraintreeGateway gateway, QueryString payload) { String encodedClientToken = gateway.clientToken().generate(); String clientToken = TestHelper.decodeClientToken(encodedClientToken); String authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); Configuration configuration = gateway.getConfiguration(); String url = configuration.getBaseURL() + configuration.getMerchantPath() + "/client_api/v1/payment_methods/paypal_accounts"; payload .append("authorization_fingerprint", authorizationFingerprint) .append("shared_customer_identifier_type", "testing") .append("shared_customer_identifier", "test-identifier") .append("paypal_account[options][validate]", "false"); String responseBody; String nonce = ""; try { responseBody = HttpHelper.post(url, payload.toString()); nonce = extractParamFromJson("nonce", responseBody); } catch (Exception e) { throw new RuntimeException(e); } return nonce; }
public static String generateNonceForCreditCard( BraintreeGateway gateway, CreditCardRequest creditCardRequest, String customerId, boolean validate) { ClientTokenRequest clientTokenRequest = new ClientTokenRequest().customerId(customerId); String encodedClientToken = gateway.clientToken().generate(clientTokenRequest); String clientToken = TestHelper.decodeClientToken(encodedClientToken); String authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); Configuration configuration = gateway.getConfiguration(); String url = configuration.getBaseURL() + configuration.getMerchantPath() + "/client_api/v1/payment_methods/credit_cards"; QueryString payload = new QueryString(); payload .append("authorization_fingerprint", authorizationFingerprint) .append("shared_customer_identifier_type", "testing") .append("shared_customer_identifier", "fake_identifier") .append("credit_card[options][validate]", new Boolean(validate).toString()); String responseBody; String nonce = ""; try { String payloadString = payload.toString(); payloadString += "&" + creditCardRequest.toQueryString(); responseBody = HttpHelper.post(url, payloadString); nonce = extractParamFromJson("nonce", responseBody); } catch (Exception e) { throw new RuntimeException(e); } return nonce; }
public static String generateUnlockedNonce( BraintreeGateway gateway, String customerId, String creditCardNumber) { ClientTokenRequest request = new ClientTokenRequest(); if (customerId != null) { request = request.customerId(customerId); } String encodedClientToken = gateway.clientToken().generate(request); String clientToken = TestHelper.decodeClientToken(encodedClientToken); String authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); Configuration configuration = gateway.getConfiguration(); String url = configuration.getBaseURL() + configuration.getMerchantPath() + "/client_api/nonces.json"; QueryString payload = new QueryString(); payload .append("authorization_fingerprint", authorizationFingerprint) .append("shared_customer_identifier_type", "testing") .append("shared_customer_identifier", "test-identifier") .append("credit_card[number]", creditCardNumber) .append("credit_card[expiration_month]", "11") .append("share", "true") .append("credit_card[expiration_year]", "2099"); String responseBody; String nonce = ""; try { responseBody = HttpHelper.post(url, payload.toString()); nonce = extractParamFromJson("nonce", responseBody); } catch (Exception e) { throw new RuntimeException(e); } return nonce; }
@Test public void getCommand_formatting() { TestHelper th = new TestHelper("", ""); assertEquals( "test, no filter", "TestName?test&debug=true&nohistory=true&format=java", th.getCommand("TestName", "test", null, null)); assertEquals( "suite, no filter", "SuiteName?suite&debug=true&nohistory=true&format=java", th.getCommand("SuiteName", "suite", null, null)); assertEquals( "suite, with filter", "SuiteName?suite&debug=true&nohistory=true&format=java&suiteFilter=xxx", th.getCommand("SuiteName", "suite", "xxx", null)); assertEquals( "suite, with excludefilter", "SuiteName?suite&debug=true&nohistory=true&format=java&excludeSuiteFilter=xxx", th.getCommand("SuiteName", "suite", null, "xxx")); }
@Test public void testIgnoreElements() { Observable<Integer> observable = Observable.just(1, 2, 3).ignoreElements(); Subscriber<Object> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); verify(observer, never()).onNext(any(Integer.class)); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test public void testContainsWithEmptyObservable() { Observable<Boolean> observable = Observable.<String>empty().contains("a"); Subscriber<Object> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); verify(observer, times(1)).onNext(false); verify(observer, never()).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test public void testMaterializeDematerializeChaining() { Observable<Integer> obs = Observable.just(1); Observable<Integer> chained = obs.materialize().dematerialize(); Subscriber<Integer> observer = TestHelper.mockSubscriber(); chained.subscribe(observer); verify(observer, times(1)).onNext(1); verify(observer, times(1)).onComplete(); verify(observer, times(0)).onError(any(Throwable.class)); }
@Test @Ignore("null values are not allowed") public void testContainsWithNull() { Observable<Boolean> observable = Observable.just("a", "b", null).contains(null); Subscriber<Object> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); verify(observer, times(1)).onNext(true); verify(observer, never()).onNext(false); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test public void testContains() { Observable<Boolean> observable = Observable.just("a", "b", "c").contains("b"); // FIXME nulls not allowed, changed to "c" Subscriber<Boolean> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); verify(observer, times(1)).onNext(true); verify(observer, never()).onNext(false); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test public void testContainsWithInexistence() { Observable<Boolean> observable = Observable.just("a", "b").contains("c"); // FIXME null values are not allowed, removed Subscriber<Object> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); verify(observer, times(1)).onNext(false); verify(observer, never()).onNext(true); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test public void testOfType() { Observable<String> observable = Observable.just(1, "abc", false, 2L).ofType(String.class); Subscriber<Object> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); verify(observer, never()).onNext(1); verify(observer, times(1)).onNext("abc"); verify(observer, never()).onNext(false); verify(observer, never()).onNext(2L); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test public void testCreate() { Observable<String> observable = Observable.just("one", "two", "three"); Subscriber<String> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, times(1)).onNext("three"); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test public void testJustWithScheduler() { TestScheduler scheduler = new TestScheduler(); Observable<Integer> observable = Observable.fromArray(1, 2).subscribeOn(scheduler); Subscriber<Integer> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); inOrder.verify(observer, times(1)).onNext(2); inOrder.verify(observer, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); }
@Ignore // FIXME throwing is not allowed from the create?! @Test public void testOnSubscribeFails() { Subscriber<String> observer = TestHelper.mockSubscriber(); final RuntimeException re = new RuntimeException("bad impl"); Observable<String> o = Observable.create( s -> { throw re; }); o.subscribe(observer); verify(observer, times(0)).onNext(anyString()); verify(observer, times(0)).onComplete(); verify(observer, times(1)).onError(re); }
public static String generateEuropeBankAccountNonce(BraintreeGateway gateway, Customer customer) { SEPAClientTokenRequest request = new SEPAClientTokenRequest(); request.customerId(customer.getId()); request.mandateType(EuropeBankAccount.MandateType.BUSINESS); request.mandateAcceptanceLocation("Rostock, Germany"); String encodedClientToken = gateway.clientToken().generate(request); String clientToken = TestHelper.decodeClientToken(encodedClientToken); String authorizationFingerprint = extractParamFromJson("authorizationFingerprint", clientToken); Configuration configuration = gateway.getConfiguration(); String url = configuration.getBaseURL() + configuration.getMerchantPath() + "/client_api/v1/sepa_mandates"; QueryString payload = new QueryString(); payload .append("authorization_fingerprint", authorizationFingerprint) .append("sepa_mandate[locale]", "de-DE") .append("sepa_mandate[bic]", "DEUTDEFF") .append("sepa_mandate[iban]", "DE89370400440532013000") .append("sepa_mandate[accountHolderName]", "Bob Holder") .append("sepa_mandate[billingAddress][streetAddress]", "123 Currywurst Way") .append("sepa_mandate[billingAddress][extendedAddress]", "Lager Suite") .append("sepa_mandate[billingAddress][firstName]", "Wilhelm") .append("sepa_mandate[billingAddress][lastName]", "Dix") .append("sepa_mandate[billingAddress][locality]", "Frankfurt") .append("sepa_mandate[billingAddress][postalCode]", "60001") .append("sepa_mandate[billingAddress][countryCodeAlpha2]", "DE") .append("sepa_mandate[billingAddress][region]", "Hesse"); String responseBody; String nonce = ""; try { responseBody = HttpHelper.post(url, payload.toString()); nonce = extractParamFromJson("nonce", responseBody); } catch (Exception e) { throw new RuntimeException(e); } return nonce; }
@Test public void testOfTypeWithPolymorphism() { ArrayList<Integer> l1 = new ArrayList<>(); l1.add(1); LinkedList<Integer> l2 = new LinkedList<>(); l2.add(2); @SuppressWarnings("rawtypes") Observable<List> observable = Observable.<Object>just(l1, l2, "123").ofType(List.class); Subscriber<Object> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); verify(observer, times(1)).onNext(l1); verify(observer, times(1)).onNext(l2); verify(observer, never()).onNext("123"); verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test public void testPairInproc() { Ctx ctx = ZMQ.zmq_init(1); assertThat(ctx, notNullValue()); SocketBase sb = ZMQ.zmq_socket(ctx, ZMQ.ZMQ_PAIR); assertThat(sb, notNullValue()); boolean brc = ZMQ.zmq_bind(sb, "inproc://a"); assertThat(brc, is(true)); SocketBase sc = ZMQ.zmq_socket(ctx, ZMQ.ZMQ_PAIR); assertThat(sc, notNullValue()); brc = ZMQ.zmq_connect(sc, "inproc://a"); assertThat(brc, is(true)); TestHelper.bounce(sb, sc); // Tear down the wiring. ZMQ.zmq_close(sb); ZMQ.zmq_close(sc); ZMQ.zmq_term(ctx); }
@Test public void testImage01() throws Exception { byte[] stdout = TestHelper.readFile("../docs/examples/images_01/01/output-jhove.raw"); List<ResultTransformer.Entry> transformedData = jhoveMetadataTransformer.transform(stdout, null); ArrayList ignoredProperties = (ArrayList) image01Test02.get("ignoredSignificantProperties"); ArrayList recognizedProperties = (ArrayList) image01Test02.get("recognizedSignificantProperties"); LinkedHashMap<String, Object> specialProperties = (LinkedHashMap) image01Test02.get("specialSignificantProperties"); LinkedHashMap significantProperties = (LinkedHashMap) image01Test02.get("significantProperties"); t.runStandardTests( transformedData, recognizedProperties, ignoredProperties, specialProperties, extractorSignificantProperties, significantProperties, thisExtractor); }
@Before public void setup() { URL strokeCuratorConfigUrl = this.getClass() .getClassLoader() .getResource( TEST_ROOT_DIR + File.separator + RESOURCES_DIR + File.separator + RESOURCES_CONFIG_DIR + File.separator + STROKE_CURATOR_CONFIG_FILE); URL tokenEngineFileUrl = this.getClass() .getClassLoader() .getResource( TEST_ROOT_DIR + File.separator + RESOURCES_DIR + File.separator + RESOURCES_TOKEN_ENGINE_DIR + File.separator + TOKEN_ENGINE_FILE_NAME); TokenRecogEngine tokenRecogEngine = null; try { tokenRecogEngine = TestHelper.readTokenEngine(); } catch (Exception exc) { fail("Failed to read token engine"); } curator = new StrokeCuratorConfigurable(strokeCuratorConfigUrl, tokenRecogEngine); // For state injection test curatorPrime = new StrokeCuratorConfigurable(strokeCuratorConfigUrl, tokenRecogEngine); }
private Document getExampleDocument() { String html = TestHelper.getResourceAsString(new File("test_articles", "onet.html").getPath()); Document doc = Jsoup.parse(html); return doc; }
@Before public void before() { w = TestHelper.mockSubscriber(); }