io.dropwizard.jackson.Jackson Java Examples

The following examples show how to use io.dropwizard.jackson.Jackson. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AthenaAuditWriterTest.java    From emodb with Apache License 2.0 6 votes vote down vote up
private AthenaAuditWriter createWriter(String s3Path, String prefix, long maxFileSize, Duration maxBatchTime) {

        _auditService = mock(ScheduledExecutorService.class);
        _fileTransferService = mock(ExecutorService.class);

        AthenaAuditWriter writer = new AthenaAuditWriter(_s3, BUCKET, s3Path, maxFileSize,
                maxBatchTime, _tempStagingDir, prefix, Jackson.newObjectMapper(), _clock, true,
                log -> mock(RateLimitedLog.class), mock(MetricRegistry.class), _auditService, _fileTransferService);

        // On start two services should have been submitted: one to poll the audit queue and one to close log files and
        // initiate transfers.  Capture them now.

        ArgumentCaptor<Runnable> processQueuedAudits = ArgumentCaptor.forClass(Runnable.class);
        verify(_auditService).scheduleWithFixedDelay(processQueuedAudits.capture(), eq(0L), eq(1L), eq(TimeUnit.SECONDS));
        _processQueuedAudits = processQueuedAudits.getValue();

        ArgumentCaptor<Runnable> doLogFileMaintenance = ArgumentCaptor.forClass(Runnable.class);
        verify(_auditService).scheduleAtFixedRate(
                doLogFileMaintenance.capture(),
                longThat(new LessThan<>(maxBatchTime.toMillis()+1)),
                eq(maxBatchTime.toMillis()), eq(TimeUnit.MILLISECONDS));
        _doLogFileMaintenance = doLogFileMaintenance.getValue();

        return writer;
    }
 
Example #2
Source File: UpdateActionTest.java    From keywhiz with Apache License 2.0 6 votes vote down vote up
@Test
public void updateWithContentPipedInButNoContentFlag() throws Exception {
  updateActionConfig.name = secret.getDisplayName();
  updateActionConfig.description = "content test";
  updateActionConfig.json = "{\"owner\":\"example-name\", \"group\":\"example-group\"}";
  updateActionConfig.contentProvided = false;

  byte[] content = base64Decoder.decode(secret.getSecret());
  updateAction.stream = new ByteArrayInputStream(content);
  when(keywhizClient.getSanitizedSecretByName(secret.getName()))
      .thenThrow(new NotFoundException()); // Call checks for existence.

  // If the content flag is not specified, the content should not be sent to Keywhiz
  when(keywhizClient.updateSecret(secret.getName(), true, "content test", false, new byte[]{}, true,
      updateActionConfig.getMetadata(Jackson.newObjectMapper()), false, 0))
      .thenReturn(secretDetailResponse);

  updateAction.run();

  // Content should not have been sent to Keywhiz, even though it was piped in (warning should also have been printed to stdout)
  verify(keywhizClient, times(1)).updateSecret(secret.getName(), true, "content test", false, new byte[]{}, true,
      updateActionConfig.getMetadata(Jackson.newObjectMapper()), false, 0);
}
 
Example #3
Source File: UpdateActionTest.java    From keywhiz with Apache License 2.0 6 votes vote down vote up
@Test
public void updateWithMetadata() throws Exception {
  updateActionConfig.name = secret.getDisplayName();
  updateActionConfig.description = "metadata test";
  updateActionConfig.json = "{\"owner\":\"example-name\", \"group\":\"example-group\"}";
  updateActionConfig.contentProvided = true;

  byte[] content = base64Decoder.decode(secret.getSecret());
  updateAction.stream = new ByteArrayInputStream(content);
  when(keywhizClient.getSanitizedSecretByName(secret.getName()))
      .thenThrow(new NotFoundException()); // Call checks for existence.

  when(keywhizClient.updateSecret(secret.getName(), true, "metadata test", true, content, true,
      updateActionConfig.getMetadata(Jackson.newObjectMapper()), false, 0))
      .thenReturn(secretDetailResponse);

  updateAction.run();

  verify(keywhizClient, times(1)).updateSecret(secret.getName(), true, "metadata test", true, content, true,
      updateActionConfig.getMetadata(Jackson.newObjectMapper()), false, 0);
}
 
Example #4
Source File: UpdateActionTest.java    From keywhiz with Apache License 2.0 6 votes vote down vote up
@Test
public void updateCallsUpdateForSecret() throws Exception {
  updateActionConfig.name = secret.getDisplayName();
  updateActionConfig.expiry = "2006-01-02T15:04:05Z";
  updateActionConfig.contentProvided = true;

  byte[] content = base64Decoder.decode(secret.getSecret());
  updateAction.stream = new ByteArrayInputStream(content);
  when(keywhizClient.getSanitizedSecretByName(secret.getName()))
      .thenThrow(new NotFoundException()); // Call checks for existence.

  when(keywhizClient.updateSecret(secret.getName(), false, "", true, content, false,
      updateActionConfig.getMetadata(Jackson.newObjectMapper()), true, 1136214245))
      .thenReturn(secretDetailResponse);

  updateAction.run();
  verify(keywhizClient, times(1)).updateSecret(secret.getName(), false, "", true, content, false,
      updateActionConfig.getMetadata(Jackson.newObjectMapper()), true, 1136214245);
}
 
Example #5
Source File: ConfigurationManagerTest.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeAll() throws Exception {
    server = new TestingServer();
    server.start();
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    taskFactory = new CassandraDaemonTask.Factory(mockCapabilities);
    configurationFactory = new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper()
                            .registerModule(new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");
    connectString = server.getConnectString();
}
 
Example #6
Source File: MacroBaseConfTest.java    From macrobase with Apache License 2.0 6 votes vote down vote up
@Test
public void testParsing() throws Exception {
    ConfigurationFactory<MacroBaseConf> cfFactory = new YamlConfigurationFactory<>(MacroBaseConf.class,
                                                                               null,
                                                                               Jackson.newObjectMapper(),
                                                                               "");
    MacroBaseConf conf = cfFactory.build(new File("src/test/resources/conf/simple.yaml"));


    assertEquals((Double) 0.1, conf.getDouble("this.is.a.double"));
    assertEquals((Integer) 100, conf.getInt("this.is.an.integer"));
    assertEquals((Long) 10000000000000L, conf.getLong("this.is.a.long"));
    assertEquals("Test", conf.getString("this.is.a.string"));

    List<String> stringList = Lists.newArrayList("T1", "T2", "T3", "T4");
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList").toArray());
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.without.spaces").toArray());
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.with.mixed.spaces").toArray());
}
 
Example #7
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@Test
void testGetAuthFilters() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setKeyStore(null);

    final List<ContainerRequestFilter> filters = TrellisUtils.getAuthFilters(config);
    assertFalse(filters.isEmpty(), "Auth filters are missing!");
    assertEquals(2L, filters.size(), "Incorrect auth filter count!");

    config.getAuth().getBasic().setEnabled(false);
    config.getAuth().getJwt().setEnabled(false);

    assertTrue(TrellisUtils.getAuthFilters(config).isEmpty(), "Auth filters should have been disabled!");
}
 
Example #8
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@Test
void testGetWebacService() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    when(mockResourceService.get(any())).thenAnswer(inv -> completedFuture(mockResource));
    when(mockResource.getMetadataGraphNames()).thenReturn(singleton(Trellis.PreferAccessControl));

    assertNotNull(TrellisUtils.getWebacService(config, mockResourceService), "WebAC configuration not present!");

    config.getAuth().getWebac().setEnabled(false);

    assertNull(TrellisUtils.getWebacService(config, mockResourceService),
            "WebAC config persists after disabling it!");

    config.getAuth().getWebac().setEnabled(true);

    final ResourceService mockRS = mock(ResourceService.class, inv -> {
        throw new TrellisRuntimeException("expected");
    });
    assertThrows(TrellisRuntimeException.class, () -> TrellisUtils.getWebacService(config, mockRS));
    config.getAuth().getWebac().setEnabled(false);
    assertNull(TrellisUtils.getWebacService(config, mockRS),
            "WebAC config persists after disabling it!");
}
 
Example #9
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@Test
void testConfigurationAuth1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getAuth().getWebac().getEnabled(), "WebAC wasn't enabled!");
    assertEquals(100L, config.getAuth().getWebac().getCacheSize(), "Incorrect auth/webac/cacheSize value!");
    assertEquals(10L, config.getAuth().getWebac().getCacheExpireSeconds(), "Incorrect webac cache expiry!");
    assertTrue(config.getAuth().getBasic().getEnabled(), "Missing basic auth support!");
    assertEquals("users.auth", config.getAuth().getBasic().getUsersFile(), "Incorrect basic auth users file!");
    assertEquals("trellis", config.getAuth().getRealm(), "Incorrect auth realm!");

    config.getAuth().setRealm("foo");
    assertEquals("foo", config.getAuth().getRealm(), "Incorrect auth realm!");
    assertTrue(config.getAuth().getJwt().getEnabled(), "JWT not enabled!");
    assertEquals("xd1GuAwiP2+M+pyK+GlIUEAumSmFx5DP3dziGtVb1tA+/8oLXfSDMDZFkxVghyAd28rXImy18TmttUi+g0iomQ==",
            config.getAuth().getJwt().getKey(), "Incorrect JWT key!");

    assertEquals("password", config.getAuth().getJwt().getKeyStorePassword(), "Incorrect JWT keystore password!");
    assertEquals("/tmp/trellisData/keystore.jks", config.getAuth().getJwt().getKeyStore(), "Wrong keystore loc!");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("foo"), "'foo' missing from JWT key ids!");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("bar"), "'bar' missing from JWT key ids!");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("trellis"), "'trellis' missing from JWT key ids!");
    assertEquals(3, config.getAuth().getJwt().getKeyIds().size(), "Incorrect JWT Key id count!");
}
 
Example #10
Source File: EmailBuilderTest.java    From foxtrot with Apache License 2.0 6 votes vote down vote up
@Test
public void testCardinalityEmailBuild() throws JsonProcessingException {
    EmailBuilder emailBuilder = new EmailBuilder(new RichEmailBuilder(new StrSubstitutorEmailSubjectBuilder(),
                                                                      new StrSubstitutorEmailBodyBuilder()));
    GroupRequest groupRequest = new GroupRequest();
    groupRequest.setTable(TestUtils.TEST_TABLE_NAME);
    groupRequest.setNesting(Lists.newArrayList("os", "deviceId"));

    QueryProcessingError error = new QueryProcessingError(
            groupRequest,
            new CardinalityOverflowException(groupRequest,
                                             Jackson.newObjectMapper()
                                                     .writeValueAsString(
                                                             groupRequest),
                                             "deviceId",
                                             0.75));
    final Email email = emailBuilder.visit(error);
    Assert.assertEquals("Blocked query as it might have screwed up the cluster", email.getSubject());
    Assert.assertEquals(
            "Blocked Query: {\"opcode\":\"group\",\"filters\":[],\"bypassCache\":false,\"table\":\"test-table\"," +
                    "\"uniqueCountOn\":null,\"nesting\":[\"os\",\"deviceId\"],\"precision\":null}\n" +
                    "Suspect field: deviceId\n" +
                    "Probability of screwing up the cluster: 0.75",
            email.getContent());
}
 
Example #11
Source File: DatadogMetricFilterTest.java    From emodb with Apache License 2.0 6 votes vote down vote up
private ScheduledReporter createReporter(String json)
        throws Exception {
    ObjectMapper objectMapper = Jackson.newObjectMapper();
    ReporterFactory reporterFactory = objectMapper.readValue(json, ReporterFactory.class);

    assertTrue(reporterFactory instanceof DatadogExpansionFilteredReporterFactory);
    DatadogExpansionFilteredReporterFactory datadogReporterFactory = (DatadogExpansionFilteredReporterFactory) reporterFactory;

    // Replace the transport with our own mock for testing

    Transport transport = mock(Transport.class);
    when(transport.prepare()).thenReturn(_request);

    AbstractTransportFactory transportFactory = mock(AbstractTransportFactory.class);
    when(transportFactory.build()).thenReturn(transport);

    datadogReporterFactory.setTransport(transportFactory);

    // Build the reporter
    return datadogReporterFactory.build(_metricRegistry);
}
 
Example #12
Source File: AlchemyClient.java    From alchemy with MIT License 5 votes vote down vote up
/**
 * Constructs a client with reasonable multi-threading defaults
 */
public AlchemyClient(AlchemyClientConfiguration configuration) {
    final ObjectMapper mapper = Jackson.newObjectMapper();
    final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
    this.client = clientBuilder
        .using(executorService, mapper)
        .using(configuration)
        .build(CLIENT_NAME);
    this.configuration = configuration;
    configureObjectMapper(configuration, mapper);
}
 
Example #13
Source File: WithConfiguration.java    From breakerbox with Apache License 2.0 5 votes vote down vote up
protected static Environment environment() {
    return new Environment(
            "test",
            Jackson.newObjectMapper(),
            Validation.buildDefaultValidatorFactory().getValidator(),
            new MetricRegistry(),
            Thread.currentThread().getContextClassLoader());
}
 
Example #14
Source File: JsonCookieTest.java    From keywhiz with Apache License 2.0 5 votes vote down vote up
@Test public void handlesSerializedVersionField() throws Exception {
  JsonCookie expected = JsonCookie.create("session", "session-contents", "localhost", "/admin", true, true);

  String json = Resources.toString(Resources.getResource("fixtures/cookie_with_version.json"), UTF_8);
  JsonCookie actual = Jackson.newObjectMapper().readValue(json, JsonCookie.class);

  assertThat(actual).isEqualTo(expected);
}
 
Example #15
Source File: CloudWatchReporterFactoryTest.java    From dropwizard-metrics-cloudwatch with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyConfigurable() throws Exception {
    ObjectMapper mapper = Jackson.newObjectMapper();

    // dropwizard 0.9.1 changed the validation wiring a bit..
    Class<ValidatedValueUnwrapper> optValidatorClazz = (Class<ValidatedValueUnwrapper>) Class
            .forName("io.dropwizard.validation.valuehandling.OptionalValidatedValueUnwrapper");

    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    if (optValidatorClazz != null) {
        validator = Validation.byProvider(HibernateValidator.class).configure()
                .addValidatedValueHandler(optValidatorClazz.newInstance())
                .buildValidatorFactory().getValidator();
    }

    ConfigurationFactory<CloudWatchReporterFactory> configFactory =
            new ConfigurationFactory<>(CloudWatchReporterFactory.class,
                    validator, mapper, "dw");
    CloudWatchReporterFactory f = configFactory.build(new File(Resources.getResource("cw.yml").getFile()));

    assertEquals("[env=default]", f.getGlobalDimensions().toString());
    assertEquals("us-east-1", f.getAwsRegion());
    assertEquals("a.b", f.getNamespace());
    assertEquals("XXXXX", f.getAwsSecretKey());
    assertEquals("11111", f.getAwsAccessKeyId());
    assertEquals("p.neustar.biz", f.getAwsClientConfiguration().getProxyHost());
    assertNull(f.getAwsClientConfiguration().getProxyUsername());
}
 
Example #16
Source File: ClientExample.java    From alchemy with MIT License 5 votes vote down vote up
private static AlchemyClient buildClient(String configurationFile) throws Exception {
    final Validator validator = BaseValidator.newValidator();
    final ObjectMapper mapper = Jackson.newObjectMapper();
    mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    final ConfigurationFactory<AlchemyClientConfiguration> configurationFactory =
        new DefaultConfigurationFactoryFactory<AlchemyClientConfiguration>().create(
            AlchemyClientConfiguration.class,
            validator,
            mapper,
            "");

    return new AlchemyClient(
        configurationFactory.build(new File(configurationFile))
    );
}
 
Example #17
Source File: ServiceMain.java    From helios with Apache License 2.0 5 votes vote down vote up
protected static Environment createEnvironment(final String name) {
  final Validator validator = Validation
      .byProvider(HibernateValidator.class)
      .configure()
      .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
      .buildValidatorFactory()
      .getValidator();
  return new Environment(name,
      Jackson.newObjectMapper(),
      validator,
      new MetricRegistry(),
      Thread.currentThread().getContextClassLoader());
}
 
Example #18
Source File: Cli.java    From oxd with Apache License 2.0 5 votes vote down vote up
private static OxdServerConfiguration parseConfiguration(String pathToYaml) throws IOException, ConfigurationException {
    if (StringUtils.isBlank(pathToYaml)) {
        System.out.println("Path to yml configuration file is not specified. Exit!");
        System.exit(1);
    }
    File file = new File(pathToYaml);
    if (!file.exists()) {
        System.out.println("Failed to find yml configuration file. Please check " + pathToYaml);
        System.exit(1);
    }

    DefaultConfigurationFactoryFactory<OxdServerConfiguration> configurationFactoryFactory = new DefaultConfigurationFactoryFactory<>();
    ConfigurationFactory<OxdServerConfiguration> configurationFactory = configurationFactoryFactory.create(OxdServerConfiguration.class, Validators.newValidatorFactory().getValidator(), Jackson.newObjectMapper(), "dw");
    return configurationFactory.build(file);
}
 
Example #19
Source File: SparseFieldSetFilterTest.java    From alchemy with MIT License 5 votes vote down vote up
@Before
public void setUp() {
    request = mock(ContainerRequestContext.class);
    response = mock(ContainerResponseContext.class);
    mapper = Jackson.newObjectMapper();
    filter = new SparseFieldSetFilter(mapper);
}
 
Example #20
Source File: JsonCookieTest.java    From keywhiz with Apache License 2.0 5 votes vote down vote up
@Test public void deserializesCookie() throws Exception {
  JsonCookie expected = JsonCookie.create("session", "session-contents", "localhost", "/admin", true, true);

  String json = Resources.toString(Resources.getResource("fixtures/cookie_valid.json"), UTF_8);
  JsonCookie actual = Jackson.newObjectMapper().readValue(json, JsonCookie.class);

  assertThat(actual).isEqualTo(expected);
}
 
Example #21
Source File: TestClients.java    From keywhiz with Apache License 2.0 5 votes vote down vote up
public static KeywhizClient keywhizClient() {
  String password = "ponies";
  KeyStore trustStore = keyStoreFromResource("dev_and_test_truststore.p12", password);

  OkHttpClient httpClient = HttpClients.builder()
      .addRequestInterceptors(
          new AuthHelper.AcceptRequestInterceptor(MediaType.APPLICATION_JSON))
      .build(trustStore);

  ObjectMapper mapper = KeywhizService.customizeObjectMapper(Jackson.newObjectMapper());
  return new KeywhizClient(mapper, httpClient, TEST_URL);
}
 
Example #22
Source File: SecretRetrievalCursor.java    From keywhiz with Apache License 2.0 5 votes vote down vote up
@Nullable public static String toString(@Nullable SecretRetrievalCursor cursor)
    throws JsonProcessingException {
  if (cursor == null) {
    return null;
  }
  ObjectMapper mapper = Jackson.newObjectMapper();
  return mapper.writeValueAsString(cursor);
}
 
Example #23
Source File: SecretRetrievalCursor.java    From keywhiz with Apache License 2.0 5 votes vote down vote up
@Nullable public static String toUrlEncodedString(@Nullable SecretRetrievalCursor cursor)
    throws JsonProcessingException {
  if (cursor == null) {
    return null;
  }
  ObjectMapper mapper = Jackson.newObjectMapper();
  // URL-encode the JSON value
  return URLEncoder.encode(mapper.writeValueAsString(cursor), UTF_8);
}
 
Example #24
Source File: SecretRetrievalCursor.java    From keywhiz with Apache License 2.0 5 votes vote down vote up
@Nullable public static SecretRetrievalCursor fromUrlEncodedString(@Nullable String encodedJson) {
  if (encodedJson == null) {
    return null;
  }
  String jsonDecoded = URLDecoder.decode(encodedJson, UTF_8);
  ObjectMapper mapper = Jackson.newObjectMapper();
  try {
    return mapper.readValue(jsonDecoded, SecretRetrievalCursor.class);
  } catch (Exception e) {
    return null;
  }
}
 
Example #25
Source File: UpgradeCommand.java    From irontest with Apache License 2.0 5 votes vote down vote up
private IronTestConfiguration getIronTestConfiguration(String ironTestHome) throws IOException, ConfigurationException {
    Path configYmlFilePath = Paths.get(ironTestHome, "config.yml");
    ObjectMapper objectMapper = Jackson.newObjectMapper();
    Validator validator = Validators.newValidator();
    YamlConfigurationFactory<IronTestConfiguration> factory =
            new YamlConfigurationFactory<>(IronTestConfiguration.class, validator, objectMapper, "dw");
    IronTestConfiguration configuration = factory.build(configYmlFilePath.toFile());
    return configuration;
}
 
Example #26
Source File: DatabusClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, MetricRegistry metricRegistry, String serviceName) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
 
Example #27
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationGeneral1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("Trellis", config.getDefaultName(), "Incorrect default name!");
    assertEquals(86400, config.getCache().getMaxAge(), "Incorrect maxAge!");
    assertTrue(config.getCache().getMustRevalidate(), "Incorrect cache/mustRevalidate value!");
    assertFalse(config.getCache().getNoCache(), "Incorrect cache/noCache value!");
    assertEquals(10L, config.getJsonld().getCacheSize(), "Incorrect jsonld/cacheSize value!");
    assertEquals(48L, config.getJsonld().getCacheExpireHours(), "Incorrect jsonld/cacheExpireHours value!");
    assertFalse(config.getIsVersioningEnabled(), "Incorrect versioning value!");
    assertTrue(config.getJsonld().getContextDomainWhitelist().isEmpty(), "Incorrect jsonld/contextDomainWhitelist");
    assertTrue(config.getJsonld().getContextWhitelist().contains("http://example.org/context.json"),
            "Incorrect jsonld/contextWhitelist value!");
    assertNull(config.getResources(), "Unexpected resources value!");
    assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hub value!");
    assertEquals(2, config.getBinaryHierarchyLevels(), "Incorrect binaryHierarchyLevels value!");
    assertEquals(1, config.getBinaryHierarchyLength(), "Incorrect binaryHierarchyLength value!");
    assertEquals("my.cluster.node", config.any().get("cassandraAddress"), "Incorrect custom value!");
    assertEquals(245993, config.any().get("cassandraPort"), "Incorrect custom value (2)!");
    @SuppressWarnings("unchecked")
    final Map<String, Object> extraConfig = (Map<String, Object>) config.any().get("extraConfigValues");
    assertTrue((Boolean) extraConfig.get("one"), "Invalid nested custom values as boolean!");
    @SuppressWarnings("unchecked")
    final List<String> list = (List<String>) extraConfig.get("two");
    assertEquals(newArrayList("value1", "value2"), list, "Invalid nested custom values as list!");
}
 
Example #28
Source File: QueueClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
 
Example #29
Source File: DataStoreClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
 
Example #30
Source File: UserAccessControlClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}