AsahFaroBackendClientImpl implements AsahFaroBackendClient { @Override public Long calculateExperimentEstimatedDaysDuration( long companyId, String experimentId, ExperimentSettings experimentSettings) { String days = _jsonWebServiceClient.doPost( String.class, _getBaseURI(companyId), StringUtil.replace( _PATH_EXPERIMENTS_ESTIMATED_DAYS_DURATION, "{experimentId}", experimentId), experimentSettings, _getHeaders(companyId)); if (Validator.isNull(days)) { return null; } try { return Long.valueOf(days); } catch (NumberFormatException numberFormatException) { if (_log.isDebugEnabled()) { _log.debug("Unable to parse " + days, numberFormatException); } return null; } } AsahFaroBackendClientImpl(
		JSONWebServiceClient jsonWebServiceClient); @Override Experiment addExperiment(long companyId, Experiment experiment); @Override Long calculateExperimentEstimatedDaysDuration(
		long companyId, String experimentId,
		ExperimentSettings experimentSettings); @Override void deleteExperiment(long companyId, String experimentId); @Override String getDataSourceId(long companyId); @Override Individual getIndividual(long companyId, String individualPK); @Override Results<Individual> getIndividualResults(
		long companyId, String individualSegmentId, int cur, int delta,
		List<OrderByField> orderByFields); @Override Results<IndividualSegment> getIndividualSegmentResults(
		long companyId, int cur, int delta, List<OrderByField> orderByFields); @Override Results<Topic> getInterestTermsResults(
		long companyId, String userId); @Override void updateExperiment(long companyId, Experiment experiment); @Override void updateExperimentDXPVariants(
		long companyId, String experimentId, DXPVariants dxpVariants);  }
@Test public void testCalculateExperimentEstimatedDaysDuration() { String days = "14"; Mockito.when( _jsonWebServiceClient.doPost( Mockito.eq(String.class), Mockito.anyString(), Mockito.anyString(), Mockito.any(ExperimentSettings.class), Mockito.anyMapOf(String.class, String.class)) ).thenReturn( days ); Assert.assertEquals( Long.valueOf(days), _asahFaroBackendClient.calculateExperimentEstimatedDaysDuration( RandomTestUtil.randomLong(), RandomTestUtil.randomString(), new ExperimentSettings())); }
@Test public void testCalculateExperimentEstimatedDaysDurationWithEmptyResult() { Mockito.when( _jsonWebServiceClient.doPost( Mockito.eq(String.class), Mockito.anyString(), Mockito.anyString(), Mockito.any(ExperimentSettings.class), Mockito.anyMapOf(String.class, String.class)) ).thenReturn( StringPool.BLANK ); Assert.assertNull( _asahFaroBackendClient.calculateExperimentEstimatedDaysDuration( RandomTestUtil.randomLong(), RandomTestUtil.randomString(), new ExperimentSettings())); }
@Test public void testCalculateExperimentEstimatedDaysDurationWithInvalidResult() { Mockito.when( _jsonWebServiceClient.doPost( Mockito.eq(String.class), Mockito.anyString(), Mockito.anyString(), Mockito.any(ExperimentSettings.class), Mockito.anyMapOf(String.class, String.class)) ).thenReturn( RandomTestUtil.randomString() ); Assert.assertNull( _asahFaroBackendClient.calculateExperimentEstimatedDaysDuration( RandomTestUtil.randomLong(), RandomTestUtil.randomString(), new ExperimentSettings())); }