@Test
  public void addSimple() throws Exception {
    File cfg = tmp.newFile("xmlTransform.xml");
    Files.write(SUBSYSTEM_EMPTY, cfg, Charsets.UTF_8);

    OfflineManagementClient client =
        ManagementClient.offline(OfflineOptions.standalone().configurationFile(cfg).build());

    AddSecurityDomain addSecurityDomain = new AddSecurityDomain.Builder("creaperSecDomain").build();

    assertXmlIdentical(SUBSYSTEM_EMPTY, Files.toString(cfg, Charsets.UTF_8));
    client.apply(addSecurityDomain);
    assertXmlIdentical(SUBSYSTEM_SIMPLE, Files.toString(cfg, Charsets.UTF_8));
  }
  @Test(expected = CommandFailedException.class)
  public void existing() throws Exception {
    File cfg = tmp.newFile("xmlTransform.xml");
    Files.write(SUBSYSTEM_SIMPLE, cfg, Charsets.UTF_8);

    OfflineManagementClient client =
        ManagementClient.offline(OfflineOptions.standalone().configurationFile(cfg).build());

    AddSecurityDomain addSecurityDomain = new AddSecurityDomain.Builder("creaperSecDomain").build();

    assertXmlIdentical(SUBSYSTEM_SIMPLE, Files.toString(cfg, Charsets.UTF_8));
    client.apply(addSecurityDomain);

    fail(
        "Security domain creaperSecDomain already exists in configuration, exception should be thrown");
  }
  @Test
  public void removeTcpHandler() throws Exception {
    File cfg = tmp.newFile("xmlTransform.xml");
    Files.write(TEST_TCP_SYSLOG_HANDLER, cfg, Charsets.UTF_8);

    OfflineManagementClient client =
        ManagementClient.offline(OfflineOptions.standalone().configurationFile(cfg).build());

    RemoveAuditLogSyslogHandler removeHandler =
        new RemoveAuditLogSyslogHandler("creaper-tcp-handler");

    assertXmlIdentical(TEST_TCP_SYSLOG_HANDLER, Files.toString(cfg, Charsets.UTF_8));

    client.apply(removeHandler);
    assertXmlIdentical(NO_HANDLERS, Files.toString(cfg, Charsets.UTF_8));
  }
  @Test(expected = CommandFailedException.class)
  public void removeNonExistingSyslogHandler() throws Exception {
    File cfg = tmp.newFile("xmlTransform.xml");
    Files.write(NO_HANDLERS, cfg, Charsets.UTF_8);

    OfflineManagementClient client =
        ManagementClient.offline(OfflineOptions.standalone().configurationFile(cfg).build());

    RemoveAuditLogSyslogHandler removeHandler =
        new RemoveAuditLogSyslogHandler("non-existing-syslog-handler");

    assertXmlIdentical(NO_HANDLERS, Files.toString(cfg, Charsets.UTF_8));

    client.apply(removeHandler);
    fail("Specified syslog handler does not exist in configuration, an exception should be thrown");
  }
  @Test
  public void overrideExisting() throws Exception {
    File cfg = tmp.newFile("xmlTransform.xml");
    Files.write(SUBSYSTEM_SIMPLE, cfg, Charsets.UTF_8);

    OfflineManagementClient client =
        ManagementClient.offline(OfflineOptions.standalone().configurationFile(cfg).build());

    AddSecurityDomain addSecurityDomain =
        new AddSecurityDomain.Builder("creaperSecDomain")
            .cacheType("default")
            .replaceExisting()
            .build();

    assertXmlIdentical(SUBSYSTEM_SIMPLE, Files.toString(cfg, Charsets.UTF_8));
    client.apply(addSecurityDomain);
    assertXmlIdentical(SUBSYSTEM_EXPECTED_REPLACE, Files.toString(cfg, Charsets.UTF_8));
  }
Ejemplo n.º 6
0
  @Test(expected = CommandFailedException.class)
  public void existing() throws Exception {
    File cfg = tmp.newFile("xmlTransform.xml");
    String subsystemXml =
        String.format(SUBSYTEM_ORIGINAL, "<datasource pool-name=\"creaper-ds\"/>");
    Files.write(subsystemXml, cfg, Charsets.UTF_8);

    OfflineManagementClient client =
        ManagementClient.offline(OfflineOptions.standalone().configurationFile(cfg).build());

    AddDataSource addDataSource =
        new AddDataSource.Builder("creaper-ds")
            .connectionUrl("jdbc:h2:mem:test-creaper;DB_CLOSE_DELAY=-1;")
            .jndiName("java:/jboss/datasources/creaper-ds")
            .driverName("h2")
            .usernameAndPassword("creaper", "creaper")
            .build();

    assertXmlIdentical(subsystemXml, Files.toString(cfg, Charsets.UTF_8));
    client.apply(addDataSource);
    fail("Datasource creaper-ds already exists in configuration, exception should be thrown");
  }
Ejemplo n.º 7
0
  @Test
  public void transform() throws Exception {
    File cfg = tmp.newFile("xmlTransform.xml");
    String subsystemXml = String.format(SUBSYTEM_ORIGINAL, "<datasource pool-name=\"eap-qe\"/>");
    Files.write(subsystemXml, cfg, Charsets.UTF_8);

    OfflineManagementClient client =
        ManagementClient.offline(OfflineOptions.standalone().configurationFile(cfg).build());

    AddDataSource addDataSource =
        new AddDataSource.Builder("creaper-ds")
            .connectionUrl("jdbc:h2:mem:test-creaper;DB_CLOSE_DELAY=-1;")
            .jndiName("java:/jboss/datasources/creaper-ds")
            .driverName("h2")
            .usernameAndPassword("creaper", "creaper")
            .allocationRetry(3)
            .allocationRetryWaitMillis(1000)
            .allowMultipleUsers(true)
            .backgroundValidation(true)
            .backgroundValidationMillis(1000)
            .blockingTimeoutWaitMillis(1000)
            .checkValidConnectionSql("SELECT 1")
            .connectable(true)
            .addConnectionProperty("other-user-name", "right-its-other-username")
            .datasourceClass("org.h2.jdbcx.JdbcDataSource")
            .driverClass("org.h2.Driver")
            .exceptionSorterClass(
                "org.jboss.jca.adapters.jdbc.extensions.novendor.NullExceptionSorter")
            .addExceptionSorterProperty("exception-sorter-prop", "ok")
            .idleTimeoutMinutes(10)
            .jta(true)
            .managedConnectionPool(
                "org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool")
            .maxPoolSize(1)
            .minPoolSize(1)
            .newConnectionSql("SELECT 1")
            .flushStrategy(PoolFlushStrategy.ENTIRE_POOL)
            .prefill(true)
            .preparedStatementsCacheSize(3)
            .queryTimeout(20)
            .setTxQueryTimeout(true)
            .sharePreparedStatements(true)
            .spy(true)
            .staleConnectionCheckerClass(
                "org.jboss.jca.adapters.jdbc.extensions.novendor.NullStaleConnectionChecker")
            .addStaleConnectionCheckerProperty("stale-checker-prop", "ok")
            .statisticsEnabled(true)
            .trackPreparedStatements(TrackStatementType.TRUE)
            .transactionIsolation(TransactionIsolation.TRANSACTION_REPEATABLE_READ)
            .urlDelimiter(";")
            .useCcm(true)
            .useFastFailAllocation(false)
            .useJavaContext(true)
            .useStrictMinPoolSize(true)
            .useTryLock(60)
            .validateOnMatch(true)
            .validConnectionCheckerClass(
                "org.jboss.jca.adapters.jdbc.extensions.novendor.NullValidConnectionChecker")
            .addValidConnectionCheckerProperty("valid-checker-prop", "ok")
            .build();

    assertXmlIdentical(subsystemXml, Files.toString(cfg, Charsets.UTF_8));
    client.apply(addDataSource);
    assertXmlIdentical(SUBSYTEM_EXPECTED, Files.toString(cfg, Charsets.UTF_8));
  }