Java源码示例:org.apache.logging.log4j.core.config.ConfigurationException

示例1
@Test
public void builderThrowsIfKeyIsInvalid() throws IOException {

    // given
    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(PEMCertInfo.configExceptionMessage);

    File invalidKey = createInvalidKey();

    JKSCertInfo testCertInfo = createTestCertInfoBuilder()
            .withKeystorePath(invalidKey.getAbsolutePath())
            .build();

    // when
    testCertInfo.applyTo(mock(HttpClientFactory.Builder.class));

}
 
示例2
@Test
public void throwsWhenBothParamsAreNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withUsername(null)
            .withPassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(AnyOf.anyOf(
            StringContains.containsString("username"),
            StringContains.containsString("password"))
    );

    // when
    builder.build();

}
 
示例3
@Test
public void throwsWhenBothParamsAreNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withUsername(null)
            .withPassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(AnyOf.anyOf(
            StringContains.containsString("username"),
            StringContains.containsString("password"))
    );

    // when
    builder.build();

}
 
示例4
@Test(expected = ConfigurationException.class)
public void throwsExceptionOnUnresolvedAppender() {

    // given
    Appender appender = mock(Appender.class);
    when(appender.isStarted()).thenReturn(true);
    Configuration configuration = mock(Configuration.class);
    String testAppenderRef = "testAppenderRef";
    when(configuration.getAppender(testAppenderRef)).thenReturn(null);

    FailoverPolicy<String> failoverPolicy = createTestFailoverPolicy(testAppenderRef, configuration);

    String failedMessage = "test failed message";

    // when
    failoverPolicy.deliver(failedMessage);

}
 
示例5
@Test
public void increaseThrowsWhenResizeWouldNotTakeAnyEffect() {

    // given
    ResizePolicy policy = UnlimitedResizePolicy.newBuilder().withResizeFactor(0.1).build();

    ItemSourcePool pool = mock(ItemSourcePool.class);
    Integer initialPoolSize = 5;
    when(pool.getInitialSize()).thenReturn(initialPoolSize);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("will not resize given pool");

    // when
    policy.increase(pool);

}
 
示例6
@Test
public void lifecycleStartFailsIfNoListenersConfigured() throws IOException {

    // given
    ChronicleMapRetryFailoverPolicy failoverPolicy = createDefaultTestFailoverPolicyBuilder().build();

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(
            RetryListener.class.getSimpleName()
                    + " was not provided for "
                    + ChronicleMapRetryFailoverPolicy.class.getSimpleName()
    );

    // when
    failoverPolicy.start();

}
 
示例7
@Test
public void builderThrowsIfKeyIsInvalid() throws IOException {

    // given
    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(PEMCertInfo.configExceptionMessage);

    File invalidKey = createInvalidKey();

    JKSCertInfo testCertInfo = createTestCertInfoBuilder()
            .withKeystorePath(invalidKey.getAbsolutePath())
            .build();

    // when
    testCertInfo.applyTo(mock(HttpClientConfig.Builder.class));

}
 
示例8
@Test
public void builderThrowsIfCantReadKey() {

    // given
    PEMCertInfo testCertInfo = createTestCertInfoBuilder()
            .withKeyPath(TEST_KEY_PATH_WITH_PASSPHRASE)
            .withKeyPassphrase("")
            .build();

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(PEMCertInfo.configExceptionMessage);

    // when
    testCertInfo.applyTo(mock(HttpClientConfig.Builder.class));

}
 
示例9
@Test
public void throwsWhenFoundFactoryWasIncompatible() {

    // given
    BatchEmitterServiceProvider serviceProvider = spy(new BatchEmitterServiceProvider());
    TestBatchEmitterFactory emitterFactory = mock(TestBatchEmitterFactory.class);
    Iterator<BatchEmitterFactory> iterator = new ArrayList<BatchEmitterFactory>() {{
        add(emitterFactory);
    }}.iterator();

    when(mockServiceLoader.iterator()).thenReturn(iterator);

    when(emitterFactory.accepts(Matchers.<Class<TestHttpObjectFactory>>any())).thenReturn(false);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No compatible BatchEmitter implementations");

    // when
    createWithTestValues(serviceProvider);

}
 
示例10
/**
 * Attempts to resize given pool.
 * <p>
 * Additional pool size is calculated based on it's {@link ItemSourcePool#getInitialSize()}.
 * <p>
 * Single resize operation will never increase pool's size by more than 100%
 *
 * @param itemSourcePool pool to be resized
 * @throws ConfigurationException when {@code resizeFactor * initialPoolSize == 0}
 * @return true, if resize operation was successful, false otherwise
 */
@Override
public boolean increase(ItemSourcePool itemSourcePool) {

    int initialPoolSize = itemSourcePool.getInitialSize();
    int additionalPoolSize = (int) (initialPoolSize * resizeFactor);

    if (additionalPoolSize == 0) {
        throw new ConfigurationException(String.format("Applying %s with resizeFactor %s will not resize given pool [%s] with initialPoolSize %s",
                ResizePolicy.class.getSimpleName(),
                resizeFactor,
                itemSourcePool.getName(),
                itemSourcePool.getInitialSize()));
    }

    itemSourcePool.incrementPoolSize(additionalPoolSize);

    return true;
}
 
示例11
@Override
public void execute(IndexTemplate indexTemplate) {
    try {
        createClient().admin().indices().putTemplate(
                new PutIndexTemplateRequest()
                        .name(indexTemplate.getName())
                        .source(indexTemplate.getSource(), XContentType.JSON)
        );
    } catch (Exception e) {
        throw new ConfigurationException(e.getMessage(), e);
    }
}
 
示例12
@Test
public void builderThrowsOnNullTargetClass() {

    // given
    JacksonMixIn.Builder builder = createDefaultTestBuilder();
    builder.withTargetClass(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No targetClass provided for " + JacksonMixIn.PLUGIN_NAME);

    // when
    builder.build();

}
 
示例13
@Test
public void defaultBatchListenerDoesntThrow() {

    // given
    BulkProcessorObjectFactory factory = createTestObjectFactoryBuilder().build();
    Function<BulkRequest, Boolean> batchListener = factory.createBatchListener(failedPayload -> {
        throw new ConfigurationException("test exception");
    });

    // when
    batchListener.apply(null);

}
 
示例14
@Test
public void builderThrowsIfKeystorePathIsNotConfigured() {

    // given
    JKSCertInfo.Builder builder = createTestCertInfoBuilder()
            .withKeystorePath(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No keystorePath provided for " + PLUGIN_NAME);

    // when
    builder.build();

}
 
示例15
@Override
public TestHttpObjectFactory build() {
    if (serverUris == null) {
        throw new ConfigurationException("No serverUris provided for JestClientConfig");
    }
    return new TestHttpObjectFactory(Arrays.asList(serverUris.split(";")), connTimeout, readTimeout, maxTotalConnection, defaultMaxTotalConnectionPerRoute, discoveryEnabled);
}
 
示例16
public int getPort(String serverUri) {
    try {
        return new URI(serverUri).getPort();
    } catch (URISyntaxException e) {
        throw new ConfigurationException(e);
    }
}
 
示例17
@Test
public void throwsWhenUsernameIsNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withUsername(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("username");

    // when
    builder.build();

}
 
示例18
@Test
public void throwsWhenPasswordIsNull() {

    // given
    BasicCredentials.Builder builder = createTestBuilder()
            .withPassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("password");

    // when
    builder.build();

}
 
示例19
@Test(expected = ConfigurationException.class)
public void builderFailsIfServerUrisStringIsNull() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    String serverUris = null;

    // when
    builder.withServerUris(serverUris);
    builder.build();

}
 
示例20
@Test
public void builderThrowsIfSourceFactoryIsNotProvided() {

    // given
    HCHttp.Builder builder = createDefaultHttpObjectFactoryBuilder();
    builder.withItemSourceFactory(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No " + PooledItemSourceFactory.class.getSimpleName() + " provided");

    // when
    builder.build();

}
 
示例21
@Test
public void builderThrowsIfMaxBatchesInFlightEqualsZero() {

    // given
    Log4j2BatchLimitBackoffPolicy.Builder builder = Log4j2BatchLimitBackoffPolicy.newBuilder()
            .withMaxBatchesInFlight(0);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("maxBatchesInFlight must be higher than 0 for " +
            BatchLimitBackoffPolicy.class.getSimpleName());

    // when
    builder.build();

}
 
示例22
@Test
public void builderThrowsIfTruststorePasswordIsSetToNull() {

    // given
    JKSCertInfo.Builder builder= createTestCertInfoBuilder()
            .withTruststorePassword(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("truststorePassword");

    // when
    builder.build();

}
 
示例23
@Test
public void throwsIfCertInfoNotConfigured() {

    // given
    XPackAuth.Builder builder = createTestBuilder()
            .withCertInfo(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("certInfo");

    // when
    builder.build();

}
 
示例24
@Test(expected = ConfigurationException.class)
public void builderThrowsExceptioWhenIndexNameIsNull() {

    // when
    RollingIndexNameFormatter.Builder builder = createRollingIndexNameFormatterBuilder();
    builder.withIndexName(null);

    // then
    builder.build();
}
 
示例25
@Test
public void builderFailsWhenValueIsNull() {

    // given
    ClientSetting.Builder clientSetting = createDefaultTestClientSettingBuilder()
            .withValue(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No value provided for " + ClientSetting.NAME);

    // when
    clientSetting.build();

}
 
示例26
@Test
public void getHostThrowsOnInvalidUri() {

    // given
    String url = "${";
    UriParser uriParser = new UriParser();

    expectedException.expect(ConfigurationException.class);

    // when
    uriParser.getHost(url);
}
 
示例27
public String getHost(String s) {
    try {
        return new URI(s).getHost();
    } catch (URISyntaxException e) {
        throw new ConfigurationException(e);
    }
}
 
示例28
public int getPort(String serverUri) {
    try {
        return new URI(serverUri).getPort();
    } catch (URISyntaxException e) {
        throw new ConfigurationException(e);
    }
}
 
示例29
@Test
public void builderThrowsIfTruststorePathIsNotConfigured() {

    // given
    JKSCertInfo.Builder builder = createTestCertInfoBuilder()
            .withTruststorePath(null);

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("No truststorePath provided for " + PLUGIN_NAME);

    // when
    builder.build();

}
 
示例30
@Override
public ClientSetting build() {

    if (name == null) {
        throw new ConfigurationException("No name provided for " + NAME);
    }

    if (value == null) {
        throw new ConfigurationException("No value provided for " + NAME);
    }

    return new ClientSetting(name, value);

}